@@ -1375,13 +1375,13 @@ static void UpdateCallGraphAfterInlining(CallBase &CB,
1375
1375
CallerNode->removeCallEdgeFor (*cast<CallBase>(&CB));
1376
1376
}
1377
1377
1378
- static void HandleByValArgumentInit (Value *Dst , Value *Src, Module *M ,
1379
- BasicBlock *InsertBlock,
1378
+ static void HandleByValArgumentInit (Type *ByValType , Value *Dst, Value *Src ,
1379
+ Module *M, BasicBlock *InsertBlock,
1380
1380
InlineFunctionInfo &IFI) {
1381
- Type *AggTy = cast<PointerType>(Src->getType ())->getElementType ();
1382
1381
IRBuilder<> Builder (InsertBlock, InsertBlock->begin ());
1383
1382
1384
- Value *Size = Builder.getInt64 (M->getDataLayout ().getTypeStoreSize (AggTy));
1383
+ Value *Size =
1384
+ Builder.getInt64 (M->getDataLayout ().getTypeStoreSize (ByValType));
1385
1385
1386
1386
// Always generate a memcpy of alignment 1 here because we don't know
1387
1387
// the alignment of the src pointer. Other optimizations can infer
@@ -1392,13 +1392,13 @@ static void HandleByValArgumentInit(Value *Dst, Value *Src, Module *M,
1392
1392
1393
1393
// / When inlining a call site that has a byval argument,
1394
1394
// / we have to make the implicit memcpy explicit by adding it.
1395
- static Value *HandleByValArgument (Value *Arg, Instruction *TheCall,
1395
+ static Value *HandleByValArgument (Type *ByValType, Value *Arg,
1396
+ Instruction *TheCall,
1396
1397
const Function *CalledFunc,
1397
1398
InlineFunctionInfo &IFI,
1398
1399
unsigned ByValAlignment) {
1399
- PointerType *ArgTy = cast<PointerType>(Arg->getType ());
1400
- Type *AggTy = ArgTy->getElementType ();
1401
-
1400
+ assert (cast<PointerType>(Arg->getType ())
1401
+ ->isOpaqueOrPointeeTypeMatches (ByValType));
1402
1402
Function *Caller = TheCall->getFunction ();
1403
1403
const DataLayout &DL = Caller->getParent ()->getDataLayout ();
1404
1404
@@ -1426,15 +1426,15 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall,
1426
1426
}
1427
1427
1428
1428
// Create the alloca. If we have DataLayout, use nice alignment.
1429
- Align Alignment (DL.getPrefTypeAlignment (AggTy ));
1429
+ Align Alignment (DL.getPrefTypeAlignment (ByValType ));
1430
1430
1431
1431
// If the byval had an alignment specified, we *must* use at least that
1432
1432
// alignment, as it is required by the byval argument (and uses of the
1433
1433
// pointer inside the callee).
1434
1434
Alignment = max (Alignment, MaybeAlign (ByValAlignment));
1435
1435
1436
1436
Value *NewAlloca =
1437
- new AllocaInst (AggTy , DL.getAllocaAddrSpace (), nullptr , Alignment,
1437
+ new AllocaInst (ByValType , DL.getAllocaAddrSpace (), nullptr , Alignment,
1438
1438
Arg->getName (), &*Caller->begin ()->begin ());
1439
1439
IFI.StaticAllocas .push_back (cast<AllocaInst>(NewAlloca));
1440
1440
@@ -1894,8 +1894,13 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
1894
1894
1895
1895
{ // Scope to destroy VMap after cloning.
1896
1896
ValueToValueMapTy VMap;
1897
+ struct ByValInit {
1898
+ Value *Dst;
1899
+ Value *Src;
1900
+ Type *Ty;
1901
+ };
1897
1902
// Keep a list of pair (dst, src) to emit byval initializations.
1898
- SmallVector<std::pair<Value*, Value*>, 4 > ByValInit ;
1903
+ SmallVector<ByValInit, 4 > ByValInits ;
1899
1904
1900
1905
// When inlining a function that contains noalias scope metadata,
1901
1906
// this metadata needs to be cloned so that the inlined blocks
@@ -1920,10 +1925,12 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
1920
1925
// or readnone, because the copy would be unneeded: the callee doesn't
1921
1926
// modify the struct.
1922
1927
if (CB.isByValArgument (ArgNo)) {
1923
- ActualArg = HandleByValArgument (ActualArg, &CB, CalledFunc, IFI,
1928
+ ActualArg = HandleByValArgument (CB.getParamByValType (ArgNo), ActualArg,
1929
+ &CB, CalledFunc, IFI,
1924
1930
CalledFunc->getParamAlignment (ArgNo));
1925
1931
if (ActualArg != *AI)
1926
- ByValInit.push_back (std::make_pair (ActualArg, (Value*) *AI));
1932
+ ByValInits.push_back (
1933
+ {ActualArg, (Value *)*AI, CB.getParamByValType (ArgNo)});
1927
1934
}
1928
1935
1929
1936
VMap[&*I] = ActualArg;
@@ -1970,8 +1977,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
1970
1977
}
1971
1978
1972
1979
// Inject byval arguments initialization.
1973
- for (std::pair<Value*, Value*> &Init : ByValInit )
1974
- HandleByValArgumentInit (Init.first , Init.second , Caller->getParent (),
1980
+ for (ByValInit &Init : ByValInits )
1981
+ HandleByValArgumentInit (Init.Ty , Init.Dst , Init. Src , Caller->getParent (),
1975
1982
&*FirstNewBlock, IFI);
1976
1983
1977
1984
Optional<OperandBundleUse> ParentDeopt =
0 commit comments