From 14afbe9448d5b9ddb0acce5e0ed046c083726f85 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 10 Sep 2021 18:13:08 +0200 Subject: [PATCH] [CallLowering] Support opaque pointers Always use the byval/inalloca/preallocated type (which is required nowadays), don't fall back on the pointer element type. This requires adding Function::getParamPreallocatedType() to mirror the CallBase API, so that the templated code can work with both. --- llvm/include/llvm/IR/Function.h | 5 +++++ llvm/lib/CodeGen/GlobalISel/CallLowering.cpp | 18 ++++++++++-------- .../AArch64/GlobalISel/irtranslator-stack-objects.ll | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index 36a756e..a618ff8 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -478,6 +478,11 @@ public: return AttributeSets.getParamByRefType(ArgNo); } + /// Extract the preallocated type for a parameter. + Type *getParamPreallocatedType(unsigned ArgNo) const { + return AttributeSets.getParamPreallocatedType(ArgNo); + } + /// Extract the number of dereferenceable bytes for a parameter. /// @param ArgNo Index of an argument, with 0 being the first function arg. uint64_t getParamDereferenceableBytes(unsigned ArgNo) const { diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp index 0498d7e..f6a0439 100644 --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -166,19 +166,21 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx, Align MemAlign = DL.getABITypeAlign(Arg.Ty); if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated()) { assert(OpIdx >= AttributeList::FirstArgIndex); - Type *ElementTy = PtrTy->getElementType(); + unsigned ParamIdx = OpIdx - AttributeList::FirstArgIndex; - auto Ty = - Attrs.getAttributeAtIndex(OpIdx, Attribute::ByVal).getValueAsType(); - Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : ElementTy)); + Type *ElementTy = FuncInfo.getParamByValType(ParamIdx); + if (!ElementTy) + ElementTy = FuncInfo.getParamInAllocaType(ParamIdx); + if (!ElementTy) + ElementTy = FuncInfo.getParamPreallocatedType(ParamIdx); + assert(ElementTy && "Must have byval, inalloca or preallocated type"); + Flags.setByValSize(DL.getTypeAllocSize(ElementTy)); // For ByVal, alignment should be passed from FE. BE will guess if // this info is not there but there are cases it cannot get right. - if (auto ParamAlign = - FuncInfo.getParamStackAlign(OpIdx - AttributeList::FirstArgIndex)) + if (auto ParamAlign = FuncInfo.getParamStackAlign(ParamIdx)) MemAlign = *ParamAlign; - else if ((ParamAlign = - FuncInfo.getParamAlign(OpIdx - AttributeList::FirstArgIndex))) + else if ((ParamAlign = FuncInfo.getParamAlign(ParamIdx))) MemAlign = *ParamAlign; else MemAlign = Align(getTLI()->getByValTypeAlignment(ElementTy, DL)); diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-objects.ll b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-objects.ll index ff08431..b80af25 100644 --- a/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-objects.ll +++ b/llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-stack-objects.ll @@ -1,4 +1,5 @@ ; RUN: llc -global-isel -mtriple=aarch64-unknown-unknown -stop-after=irtranslator -verify-machineinstrs %s -o - | FileCheck %s +; RUN: llc -global-isel -mtriple=aarch64-unknown-unknown -stop-after=irtranslator -verify-machineinstrs -opaque-pointers %s -o - | FileCheck %s ; The byval object should not be immutable, but the non-byval stack ; passed argument should be. -- 2.7.4