@@ -1022,8 +1022,8 @@ static void forConstantArrayExpansion(CodeGenFunction &CGF,
1022
1022
}
1023
1023
}
1024
1024
1025
- void CodeGenFunction::ExpandTypeFromArgs (
1026
- QualType Ty, LValue LV, SmallVectorImpl< llvm::Value *>::iterator &AI) {
1025
+ void CodeGenFunction::ExpandTypeFromArgs (QualType Ty, LValue LV,
1026
+ llvm::Function::arg_iterator &AI) {
1027
1027
assert (LV.isSimple () &&
1028
1028
" Unexpected non-simple lvalue during struct expansion." );
1029
1029
@@ -1052,17 +1052,17 @@ void CodeGenFunction::ExpandTypeFromArgs(
1052
1052
ExpandTypeFromArgs (FD->getType (), SubLV, AI);
1053
1053
}
1054
1054
} else if (isa<ComplexExpansion>(Exp.get ())) {
1055
- auto realValue = *AI++;
1056
- auto imagValue = *AI++;
1055
+ auto realValue = & *AI++;
1056
+ auto imagValue = & *AI++;
1057
1057
EmitStoreOfComplex (ComplexPairTy (realValue, imagValue), LV, /* init*/ true );
1058
1058
} else {
1059
1059
// Call EmitStoreOfScalar except when the lvalue is a bitfield to emit a
1060
1060
// primitive store.
1061
1061
assert (isa<NoExpansion>(Exp.get ()));
1062
1062
if (LV.isBitField ())
1063
- EmitStoreThroughLValue (RValue::get (*AI++), LV);
1063
+ EmitStoreThroughLValue (RValue::get (& *AI++), LV);
1064
1064
else
1065
- EmitStoreOfScalar (*AI++, LV);
1065
+ EmitStoreOfScalar (& *AI++, LV);
1066
1066
}
1067
1067
}
1068
1068
@@ -2329,27 +2329,21 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2329
2329
// simplify.
2330
2330
2331
2331
ClangToLLVMArgMapping IRFunctionArgs (CGM.getContext (), FI);
2332
- // Flattened function arguments.
2333
- SmallVector<llvm::Value *, 16 > FnArgs;
2334
- FnArgs.reserve (IRFunctionArgs.totalIRArgs ());
2335
- for (auto &Arg : Fn->args ()) {
2336
- FnArgs.push_back (&Arg);
2337
- }
2338
- assert (FnArgs.size () == IRFunctionArgs.totalIRArgs ());
2332
+ assert (Fn->arg_size () == IRFunctionArgs.totalIRArgs ());
2339
2333
2340
2334
// If we're using inalloca, all the memory arguments are GEPs off of the last
2341
2335
// parameter, which is a pointer to the complete memory area.
2342
2336
Address ArgStruct = Address::invalid ();
2343
2337
if (IRFunctionArgs.hasInallocaArg ()) {
2344
- ArgStruct = Address (FnArgs[ IRFunctionArgs.getInallocaArgNo ()] ,
2338
+ ArgStruct = Address (Fn-> getArg ( IRFunctionArgs.getInallocaArgNo ()) ,
2345
2339
FI.getArgStructAlignment ());
2346
2340
2347
2341
assert (ArgStruct.getType () == FI.getArgStruct ()->getPointerTo ());
2348
2342
}
2349
2343
2350
2344
// Name the struct return parameter.
2351
2345
if (IRFunctionArgs.hasSRetArg ()) {
2352
- auto AI = cast<llvm::Argument>(FnArgs[ IRFunctionArgs.getSRetArgNo ()] );
2346
+ auto AI = Fn-> getArg ( IRFunctionArgs.getSRetArgNo ());
2353
2347
AI->setName (" agg.result" );
2354
2348
AI->addAttr (llvm::Attribute::NoAlias);
2355
2349
}
@@ -2400,7 +2394,8 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2400
2394
2401
2395
case ABIArgInfo::Indirect: {
2402
2396
assert (NumIRArgs == 1 );
2403
- Address ParamAddr = Address (FnArgs[FirstIRArg], ArgI.getIndirectAlign ());
2397
+ Address ParamAddr =
2398
+ Address (Fn->getArg (FirstIRArg), ArgI.getIndirectAlign ());
2404
2399
2405
2400
if (!hasScalarEvaluationKind (Ty)) {
2406
2401
// Aggregates and complex variables are accessed by reference. All we
@@ -2436,16 +2431,18 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2436
2431
2437
2432
case ABIArgInfo::Extend:
2438
2433
case ABIArgInfo::Direct: {
2439
-
2440
- // If we have the trivial case, handle it with no muss and fuss.
2441
- if (!isa<llvm::StructType>(ArgI.getCoerceToType ()) &&
2442
- ArgI.getCoerceToType () == ConvertType (Ty) &&
2443
- ArgI.getDirectOffset () == 0 ) {
2434
+ auto AI = Fn->getArg (FirstIRArg);
2435
+ llvm::Type *LTy = ConvertType (Arg->getType ());
2436
+
2437
+ // Prepare parameter attributes. So far, only attributes for pointer
2438
+ // parameters are prepared. See
2439
+ // http://llvm.org/docs/LangRef.html#paramattrs.
2440
+ if (ArgI.getDirectOffset () == 0 && LTy->isPointerTy () &&
2441
+ ArgI.getCoerceToType ()->isPointerTy ()) {
2444
2442
assert (NumIRArgs == 1 );
2445
- llvm::Value *V = FnArgs[FirstIRArg];
2446
- auto AI = cast<llvm::Argument>(V);
2447
2443
2448
2444
if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {
2445
+ // Set `nonnull` attribute if any.
2449
2446
if (getNonNullAttr (CurCodeDecl, PVD, PVD->getType (),
2450
2447
PVD->getFunctionScopeIndex ()) &&
2451
2448
!CGM.getCodeGenOpts ().NullPointerIsValid )
@@ -2483,6 +2480,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2483
2480
AI->addAttr (llvm::Attribute::NonNull);
2484
2481
}
2485
2482
2483
+ // Set `align` attribute if any.
2486
2484
const auto *AVAttr = PVD->getAttr <AlignValueAttr>();
2487
2485
if (!AVAttr)
2488
2486
if (const auto *TOTy = dyn_cast<TypedefType>(OTy))
@@ -2500,14 +2498,24 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2500
2498
}
2501
2499
}
2502
2500
2501
+ // Set 'noalias' if an argument type has the `restrict` qualifier.
2503
2502
if (Arg->getType ().isRestrictQualified () ||
2504
2503
(CurCodeDecl &&
2505
2504
CurCodeDecl->hasAttr <SYCLIntelKernelArgsRestrictAttr>() &&
2506
2505
Arg->getType ()->isPointerType ()))
2507
2506
AI->addAttr (llvm::Attribute::NoAlias);
2507
+ }
2508
+
2509
+ // Prepare the argument value. If we have the trivial case, handle it
2510
+ // with no muss and fuss.
2511
+ if (!isa<llvm::StructType>(ArgI.getCoerceToType ()) &&
2512
+ ArgI.getCoerceToType () == ConvertType (Ty) &&
2513
+ ArgI.getDirectOffset () == 0 ) {
2514
+ assert (NumIRArgs == 1 );
2508
2515
2509
2516
// LLVM expects swifterror parameters to be used in very restricted
2510
2517
// ways. Copy the value into a less-restricted temporary.
2518
+ llvm::Value *V = AI;
2511
2519
if (FI.getExtParameterInfo (ArgNo).getABI ()
2512
2520
== ParameterABI::SwiftErrorResult) {
2513
2521
QualType pointeeTy = Ty->getPointeeType ();
@@ -2569,7 +2577,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2569
2577
2570
2578
assert (STy->getNumElements () == NumIRArgs);
2571
2579
for (unsigned i = 0 , e = STy->getNumElements (); i != e; ++i) {
2572
- auto AI = FnArgs[ FirstIRArg + i] ;
2580
+ auto AI = Fn-> getArg ( FirstIRArg + i) ;
2573
2581
AI->setName (Arg->getName () + " .coerce" + Twine (i));
2574
2582
Address EltPtr = Builder.CreateStructGEP (AddrToStoreInto, i);
2575
2583
Builder.CreateStore (AI, EltPtr);
@@ -2582,7 +2590,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2582
2590
} else {
2583
2591
// Simple case, just do a coerced store of the argument into the alloca.
2584
2592
assert (NumIRArgs == 1 );
2585
- auto AI = FnArgs[ FirstIRArg] ;
2593
+ auto AI = Fn-> getArg ( FirstIRArg) ;
2586
2594
AI->setName (Arg->getName () + " .coerce" );
2587
2595
CreateCoercedStore (AI, Ptr, /* DstIsVolatile=*/ false , *this );
2588
2596
}
@@ -2615,7 +2623,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2615
2623
continue ;
2616
2624
2617
2625
auto eltAddr = Builder.CreateStructGEP (alloca, i);
2618
- auto elt = FnArgs[ argIndex++] ;
2626
+ auto elt = Fn-> getArg ( argIndex++) ;
2619
2627
Builder.CreateStore (elt, eltAddr);
2620
2628
}
2621
2629
assert (argIndex == FirstIRArg + NumIRArgs);
@@ -2630,11 +2638,11 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
2630
2638
LValue LV = MakeAddrLValue (Alloca, Ty);
2631
2639
ArgVals.push_back (ParamValue::forIndirect (Alloca));
2632
2640
2633
- auto FnArgIter = FnArgs. begin () + FirstIRArg;
2641
+ auto FnArgIter = Fn-> arg_begin () + FirstIRArg;
2634
2642
ExpandTypeFromArgs (Ty, LV, FnArgIter);
2635
- assert (FnArgIter == FnArgs. begin () + FirstIRArg + NumIRArgs);
2643
+ assert (FnArgIter == Fn-> arg_begin () + FirstIRArg + NumIRArgs);
2636
2644
for (unsigned i = 0 , e = NumIRArgs; i != e; ++i) {
2637
- auto AI = FnArgs[ FirstIRArg + i] ;
2645
+ auto AI = Fn-> getArg ( FirstIRArg + i) ;
2638
2646
AI->setName (Arg->getName () + " ." + Twine (i));
2639
2647
}
2640
2648
break ;
0 commit comments