diff options
| author | Arthur Eubanks <aeubanks@google.com> | 2021-07-09 09:37:50 -0700 |
|---|---|---|
| committer | Arthur Eubanks <aeubanks@google.com> | 2021-08-19 09:56:08 -0700 |
| commit | 33d44b762e6526434438762cecd05cc0d29bcec4 (patch) | |
| tree | cbe6ba5f15f4646244fd38d628d99e7e1756f4f0 /llvm/lib/Transforms/Utils/InlineFunction.cpp | |
| parent | 06a4c858901d72389e01fbdd0f83b03c74d56831 (diff) | |
[OpaquePtr][Inline] Use byval type instead of pointee type
Reviewed By: #opaque-pointers, dblaikie
Differential Revision: https://reviews.llvm.org/D105711
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Utils/InlineFunction.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 2673867bb7d2..ae913a2d9448 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1375,13 +1375,13 @@ static void UpdateCallGraphAfterInlining(CallBase &CB, CallerNode->removeCallEdgeFor(*cast<CallBase>(&CB)); } -static void HandleByValArgumentInit(Value *Dst, Value *Src, Module *M, - BasicBlock *InsertBlock, +static void HandleByValArgumentInit(Type *ByValType, Value *Dst, Value *Src, + Module *M, BasicBlock *InsertBlock, InlineFunctionInfo &IFI) { - Type *AggTy = cast<PointerType>(Src->getType())->getElementType(); IRBuilder<> Builder(InsertBlock, InsertBlock->begin()); - Value *Size = Builder.getInt64(M->getDataLayout().getTypeStoreSize(AggTy)); + Value *Size = + Builder.getInt64(M->getDataLayout().getTypeStoreSize(ByValType)); // Always generate a memcpy of alignment 1 here because we don't know // the alignment of the src pointer. Other optimizations can infer @@ -1392,13 +1392,13 @@ static void HandleByValArgumentInit(Value *Dst, Value *Src, Module *M, /// When inlining a call site that has a byval argument, /// we have to make the implicit memcpy explicit by adding it. -static Value *HandleByValArgument(Value *Arg, Instruction *TheCall, +static Value *HandleByValArgument(Type *ByValType, Value *Arg, + Instruction *TheCall, const Function *CalledFunc, InlineFunctionInfo &IFI, unsigned ByValAlignment) { - PointerType *ArgTy = cast<PointerType>(Arg->getType()); - Type *AggTy = ArgTy->getElementType(); - + assert(cast<PointerType>(Arg->getType()) + ->isOpaqueOrPointeeTypeMatches(ByValType)); Function *Caller = TheCall->getFunction(); const DataLayout &DL = Caller->getParent()->getDataLayout(); @@ -1426,7 +1426,7 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall, } // Create the alloca. If we have DataLayout, use nice alignment. - Align Alignment(DL.getPrefTypeAlignment(AggTy)); + Align Alignment(DL.getPrefTypeAlignment(ByValType)); // If the byval had an alignment specified, we *must* use at least that // alignment, as it is required by the byval argument (and uses of the @@ -1434,7 +1434,7 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall, Alignment = max(Alignment, MaybeAlign(ByValAlignment)); Value *NewAlloca = - new AllocaInst(AggTy, DL.getAllocaAddrSpace(), nullptr, Alignment, + new AllocaInst(ByValType, DL.getAllocaAddrSpace(), nullptr, Alignment, Arg->getName(), &*Caller->begin()->begin()); IFI.StaticAllocas.push_back(cast<AllocaInst>(NewAlloca)); @@ -1894,8 +1894,13 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, { // Scope to destroy VMap after cloning. ValueToValueMapTy VMap; + struct ByValInit { + Value *Dst; + Value *Src; + Type *Ty; + }; // Keep a list of pair (dst, src) to emit byval initializations. - SmallVector<std::pair<Value*, Value*>, 4> ByValInit; + SmallVector<ByValInit, 4> ByValInits; // When inlining a function that contains noalias scope metadata, // this metadata needs to be cloned so that the inlined blocks @@ -1920,10 +1925,12 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, // or readnone, because the copy would be unneeded: the callee doesn't // modify the struct. if (CB.isByValArgument(ArgNo)) { - ActualArg = HandleByValArgument(ActualArg, &CB, CalledFunc, IFI, + ActualArg = HandleByValArgument(CB.getParamByValType(ArgNo), ActualArg, + &CB, CalledFunc, IFI, CalledFunc->getParamAlignment(ArgNo)); if (ActualArg != *AI) - ByValInit.push_back(std::make_pair(ActualArg, (Value*) *AI)); + ByValInits.push_back( + {ActualArg, (Value *)*AI, CB.getParamByValType(ArgNo)}); } VMap[&*I] = ActualArg; @@ -1970,8 +1977,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, } // Inject byval arguments initialization. - for (std::pair<Value*, Value*> &Init : ByValInit) - HandleByValArgumentInit(Init.first, Init.second, Caller->getParent(), + for (ByValInit &Init : ByValInits) + HandleByValArgumentInit(Init.Ty, Init.Dst, Init.Src, Caller->getParent(), &*FirstNewBlock, IFI); Optional<OperandBundleUse> ParentDeopt = |
