<div dir="ltr">Hi,<div><br></div><div>This change increases the size of a CallArg, and thus that of a CallArgList, dramatically (an LValue is *much* larger than an RValue, and unlike an RValue, does not appear to be at all optimized for size). This results in CallArgList (which contains inline storage for 16 CallArgs) ballooning in size from ~500 bytes to 2KB, resulting in stack overflows on programs with deep ASTs.</div><div><br></div><div>Given that this introduces a regression (due to stack overflow), I've reverted in r327195. Sorry about that.</div><div><br></div><div>The program it broke looked something like this:</div><div><br></div><div><div>struct VectorBuilder {</div><div> VectorBuilder &operator,(int);</div><div>};</div><div>void f() {</div><div> VectorBuilder(),</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,</div><div> 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0;</div><div>}</div></div><div><br></div><div>using Eigen's somewhat-ridiculous comma initializer technique (<a href="https://eigen.tuxfamily.org/dox/group__TutorialAdvancedInitialization.html">https://eigen.tuxfamily.org/dox/group__TutorialAdvancedInitialization.html</a>) to build an approx 40 x 40 array.</div><div><br></div><div>An AST 1600 levels deep is somewhat extreme, but it still seems like something we should be able to handle within our default 8MB stack limit.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 March 2018 at 13:45, Yaxun Liu via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: yaxunl<br>
Date: Wed Mar 7 13:45:40 2018<br>
New Revision: 326946<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=326946&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=326946&view=rev</a><br>
Log:<br>
CodeGen: Fix address space of indirect function argument<br>
<br>
The indirect function argument is in alloca address space in LLVM IR. However,<br>
during Clang codegen for C++, the address space of indirect function argument<br>
should match its address space in the source code, i.e., default addr space, even<br>
for indirect argument. This is because destructor of the indirect argument may<br>
be called in the caller function, and address of the indirect argument may be<br>
taken, in either case the indirect function argument is expected to be in default<br>
addr space, not the alloca address space.<br>
<br>
Therefore, the indirect function argument should be mapped to the temp var<br>
casted to default address space. The caller will cast it to alloca addr space<br>
when passing it to the callee. In the callee, the argument is also casted to the<br>
default address space and used.<br>
<br>
CallArg is refactored to facilitate this fix.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D34367" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D34367</a><br>
<br>
Added:<br>
cfe/trunk/test/CodeGenCXX/<wbr>amdgcn-func-arg.cpp<br>
Modified:<br>
cfe/trunk/lib/CodeGen/<wbr>CGAtomic.cpp<br>
cfe/trunk/lib/CodeGen/CGCall.<wbr>cpp<br>
cfe/trunk/lib/CodeGen/CGCall.h<br>
cfe/trunk/lib/CodeGen/CGClass.<wbr>cpp<br>
cfe/trunk/lib/CodeGen/CGDecl.<wbr>cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CGExprCXX.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CGGPUBuiltin.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CGObjCGNU.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CGObjCMac.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h<br>
cfe/trunk/lib/CodeGen/<wbr>ItaniumCXXABI.cpp<br>
cfe/trunk/lib/CodeGen/<wbr>MicrosoftCXXABI.cpp<br>
cfe/trunk/test/CodeGenOpenCL/<a href="http://addr-space-struct-arg.cl" rel="noreferrer" target="_blank">a<wbr>ddr-space-struct-arg.cl</a><br>
cfe/trunk/test/CodeGenOpenCL/<a href="http://byval.cl" rel="noreferrer" target="_blank">b<wbr>yval.cl</a><br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CGAtomic.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGAtomic.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CGAtomic.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CGAtomic.cpp Wed Mar 7 13:45:40 2018<br>
@@ -1160,7 +1160,7 @@ RValue CodeGenFunction::<wbr>EmitAtomicExpr(A<br>
if (UseOptimizedLibcall && Res.getScalarVal()) {<br>
llvm::Value *ResVal = Res.getScalarVal();<br>
if (PostOp) {<br>
- llvm::Value *LoadVal1 = Args[1].RV.getScalarVal();<br>
+ llvm::Value *LoadVal1 = Args[1].getRValue(*this).<wbr>getScalarVal();<br>
ResVal = Builder.CreateBinOp(PostOp, ResVal, LoadVal1);<br>
}<br>
if (E->getOp() == AtomicExpr::AO__atomic_nand_<wbr>fetch)<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGCall.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGCall.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/CGCall.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGCall.<wbr>cpp Wed Mar 7 13:45:40 2018<br>
@@ -1040,42 +1040,49 @@ void CodeGenFunction::<wbr>ExpandTypeFromArgs<br>
}<br>
<br>
void CodeGenFunction::<wbr>ExpandTypeToArgs(<br>
- QualType Ty, RValue RV, llvm::FunctionType *IRFuncTy,<br>
+ QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy,<br>
SmallVectorImpl<llvm::Value *> &IRCallArgs, unsigned &IRCallArgPos) {<br>
auto Exp = getTypeExpansion(Ty, getContext());<br>
if (auto CAExp = dyn_cast<<wbr>ConstantArrayExpansion>(Exp.<wbr>get())) {<br>
- forConstantArrayExpansion(*<wbr>this, CAExp, RV.getAggregateAddress(),<br>
- [&](Address EltAddr) {<br>
- RValue EltRV =<br>
- convertTempToRValue(EltAddr, CAExp->EltTy, SourceLocation());<br>
- ExpandTypeToArgs(CAExp->EltTy, EltRV, IRFuncTy, IRCallArgs, IRCallArgPos);<br>
- });<br>
+ Address Addr = Arg.hasLValue() ? Arg.getKnownLValue().<wbr>getAddress()<br>
+ : Arg.getKnownRValue().<wbr>getAggregateAddress();<br>
+ forConstantArrayExpansion(<br>
+ *this, CAExp, Addr, [&](Address EltAddr) {<br>
+ CallArg EltArg = CallArg(<br>
+ convertTempToRValue(EltAddr, CAExp->EltTy, SourceLocation()),<br>
+ CAExp->EltTy);<br>
+ ExpandTypeToArgs(CAExp->EltTy, EltArg, IRFuncTy, IRCallArgs,<br>
+ IRCallArgPos);<br>
+ });<br>
} else if (auto RExp = dyn_cast<RecordExpansion>(Exp.<wbr>get())) {<br>
- Address This = RV.getAggregateAddress();<br>
+ Address This = Arg.hasLValue() ? Arg.getKnownLValue().<wbr>getAddress()<br>
+ : Arg.getKnownRValue().<wbr>getAggregateAddress();<br>
for (const CXXBaseSpecifier *BS : RExp->Bases) {<br>
// Perform a single step derived-to-base conversion.<br>
Address Base =<br>
GetAddressOfBaseClass(This, Ty->getAsCXXRecordDecl(), &BS, &BS + 1,<br>
/*NullCheckValue=*/false, SourceLocation());<br>
- RValue BaseRV = RValue::getAggregate(Base);<br>
+ CallArg BaseArg = CallArg(RValue::getAggregate(<wbr>Base), BS->getType());<br>
<br>
// Recurse onto bases.<br>
- ExpandTypeToArgs(BS->getType()<wbr>, BaseRV, IRFuncTy, IRCallArgs,<br>
+ ExpandTypeToArgs(BS->getType()<wbr>, BaseArg, IRFuncTy, IRCallArgs,<br>
IRCallArgPos);<br>
}<br>
<br>
LValue LV = MakeAddrLValue(This, Ty);<br>
for (auto FD : RExp->Fields) {<br>
- RValue FldRV = EmitRValueForField(LV, FD, SourceLocation());<br>
- ExpandTypeToArgs(FD->getType()<wbr>, FldRV, IRFuncTy, IRCallArgs,<br>
+ CallArg FldArg =<br>
+ CallArg(EmitRValueForField(LV, FD, SourceLocation()), FD->getType());<br>
+ ExpandTypeToArgs(FD->getType()<wbr>, FldArg, IRFuncTy, IRCallArgs,<br>
IRCallArgPos);<br>
}<br>
} else if (isa<ComplexExpansion>(Exp.<wbr>get())) {<br>
- ComplexPairTy CV = RV.getComplexVal();<br>
+ ComplexPairTy CV = Arg.getKnownRValue().<wbr>getComplexVal();<br>
IRCallArgs[IRCallArgPos++] = CV.first;<br>
IRCallArgs[IRCallArgPos++] = CV.second;<br>
} else {<br>
assert(isa<NoExpansion>(Exp.<wbr>get()));<br>
+ auto RV = Arg.getKnownRValue();<br>
assert(RV.isScalar() &&<br>
"Unexpected non-scalar rvalue during struct expansion.");<br>
<br>
@@ -3418,13 +3425,17 @@ void CodeGenFunction::EmitCallArgs(<br>
assert(InitialArgSize + 1 == Args.size() &&<br>
"The code below depends on only adding one arg per EmitCallArg");<br>
(void)InitialArgSize;<br>
- RValue RVArg = Args.back().RV;<br>
- EmitNonNullArgCheck(RVArg, ArgTypes[Idx], (*Arg)->getExprLoc(), AC,<br>
- ParamsToSkip + Idx);<br>
- // @llvm.objectsize should never have side-effects and shouldn't need<br>
- // destruction/cleanups, so we can safely "emit" it after its arg,<br>
- // regardless of right-to-leftness<br>
- MaybeEmitImplicitObjectSize(<wbr>Idx, *Arg, RVArg);<br>
+ // Since pointer argument are never emitted as LValue, it is safe to emit<br>
+ // non-null argument check for r-value only.<br>
+ if (!Args.back().hasLValue()) {<br>
+ RValue RVArg = Args.back().getKnownRValue();<br>
+ EmitNonNullArgCheck(RVArg, ArgTypes[Idx], (*Arg)->getExprLoc(), AC,<br>
+ ParamsToSkip + Idx);<br>
+ // @llvm.objectsize should never have side-effects and shouldn't need<br>
+ // destruction/cleanups, so we can safely "emit" it after its arg,<br>
+ // regardless of right-to-leftness<br>
+ MaybeEmitImplicitObjectSize(<wbr>Idx, *Arg, RVArg);<br>
+ }<br>
}<br>
<br>
if (!LeftToRight) {<br>
@@ -3471,6 +3482,31 @@ struct DisableDebugLocationUpdates {<br>
<br>
} // end anonymous namespace<br>
<br>
+RValue CallArg::getRValue(<wbr>CodeGenFunction &CGF) const {<br>
+ if (!HasLV)<br>
+ return RV;<br>
+ LValue Copy = CGF.MakeAddrLValue(CGF.<wbr>CreateMemTemp(Ty), Ty);<br>
+ CGF.EmitAggregateCopy(Copy, LV, Ty, LV.isVolatile());<br>
+ IsUsed = true;<br>
+ return RValue::getAggregate(Copy.<wbr>getAddress());<br>
+}<br>
+<br>
+void CallArg::copyInto(<wbr>CodeGenFunction &CGF, Address Addr) const {<br>
+ LValue Dst = CGF.MakeAddrLValue(Addr, Ty);<br>
+ if (!HasLV && RV.isScalar())<br>
+ CGF.EmitStoreOfScalar(RV.<wbr>getScalarVal(), Dst, /*init=*/true);<br>
+ else if (!HasLV && RV.isComplex())<br>
+ CGF.EmitStoreOfComplex(RV.<wbr>getComplexVal(), Dst, /*init=*/true);<br>
+ else {<br>
+ auto Addr = HasLV ? LV.getAddress() : RV.getAggregateAddress();<br>
+ LValue SrcLV = CGF.MakeAddrLValue(Addr, Ty);<br>
+ CGF.EmitAggregateCopy(Dst, SrcLV, Ty,<br>
+ HasLV ? LV.isVolatileQualified()<br>
+ : RV.isVolatileQualified());<br>
+ }<br>
+ IsUsed = true;<br>
+}<br>
+<br>
void CodeGenFunction::EmitCallArg(<wbr>CallArgList &args, const Expr *E,<br>
QualType type) {<br>
DisableDebugLocationUpdates Dis(*this, E);<br>
@@ -3536,15 +3572,7 @@ void CodeGenFunction::EmitCallArg(<wbr>CallAr<br>
cast<CastExpr>(E)-><wbr>getCastKind() == CK_LValueToRValue) {<br>
LValue L = EmitLValue(cast<CastExpr>(E)-><wbr>getSubExpr());<br>
assert(L.isSimple());<br>
- if (L.getAlignment() >= getContext().<wbr>getTypeAlignInChars(type)) {<br>
- args.add(L.asAggregateRValue()<wbr>, type, /*NeedsCopy*/true);<br>
- } else {<br>
- // We can't represent a misaligned lvalue in the CallArgList, so copy<br>
- // to an aligned temporary now.<br>
- LValue Dest = MakeAddrLValue(CreateMemTemp(<wbr>type), type);<br>
- EmitAggregateCopy(Dest, L, type, L.isVolatile());<br>
- args.add(RValue::getAggregate(<wbr>Dest.getAddress()), type);<br>
- }<br>
+ args.addUncopiedAggregate(L, type);<br>
return;<br>
}<br>
<br>
@@ -3702,16 +3730,6 @@ CodeGenFunction::<wbr>EmitCallOrInvoke(llvm::<br>
return llvm::CallSite(Inst);<br>
}<br>
<br>
-/// \brief Store a non-aggregate value to an address to initialize it. For<br>
-/// initialization, a non-atomic store will be used.<br>
-static void EmitInitStoreOfNonAggregate(<wbr>CodeGenFunction &CGF, RValue Src,<br>
- LValue Dst) {<br>
- if (Src.isScalar())<br>
- CGF.EmitStoreOfScalar(Src.<wbr>getScalarVal(), Dst, /*init=*/true);<br>
- else<br>
- CGF.EmitStoreOfComplex(Src.<wbr>getComplexVal(), Dst, /*init=*/true);<br>
-}<br>
-<br>
void CodeGenFunction::<wbr>deferPlaceholderReplacement(<wbr>llvm::Instruction *Old,<br>
llvm::Value *New) {<br>
DeferredReplacements.push_<wbr>back(std::make_pair(Old, New));<br>
@@ -3804,7 +3822,6 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();<br>
I != E; ++I, ++info_it, ++ArgNo) {<br>
const ABIArgInfo &ArgInfo = info_it->info;<br>
- RValue RV = I->RV;<br>
<br>
// Insert a padding argument to ensure proper alignment.<br>
if (IRFunctionArgs.hasPaddingArg(<wbr>ArgNo))<br>
@@ -3818,13 +3835,16 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
case ABIArgInfo::InAlloca: {<br>
assert(NumIRArgs == 0);<br>
assert(getTarget().getTriple()<wbr>.getArch() == llvm::Triple::x86);<br>
- if (RV.isAggregate()) {<br>
+ if (I->isAggregate()) {<br>
// Replace the placeholder with the appropriate argument slot GEP.<br>
+ Address Addr = I->hasLValue()<br>
+ ? I->getKnownLValue().<wbr>getAddress()<br>
+ : I->getKnownRValue().<wbr>getAggregateAddress();<br>
llvm::Instruction *Placeholder =<br>
- cast<llvm::Instruction>(RV.<wbr>getAggregatePointer());<br>
+ cast<llvm::Instruction>(Addr.<wbr>getPointer());<br>
CGBuilderTy::InsertPoint IP = Builder.saveIP();<br>
Builder.SetInsertPoint(<wbr>Placeholder);<br>
- Address Addr = createInAllocaStructGEP(<wbr>ArgInfo.getInAllocaFieldIndex(<wbr>));<br>
+ Addr = createInAllocaStructGEP(<wbr>ArgInfo.getInAllocaFieldIndex(<wbr>));<br>
Builder.restoreIP(IP);<br>
deferPlaceholderReplacement(<wbr>Placeholder, Addr.getPointer());<br>
} else {<br>
@@ -3837,22 +3857,20 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
// from {}* to (%struct.foo*)*.<br>
if (Addr.getType() != MemType)<br>
Addr = Builder.CreateBitCast(Addr, MemType);<br>
- LValue argLV = MakeAddrLValue(Addr, I->Ty);<br>
- EmitInitStoreOfNonAggregate(*<wbr>this, RV, argLV);<br>
+ I->copyInto(*this, Addr);<br>
}<br>
break;<br>
}<br>
<br>
case ABIArgInfo::Indirect: {<br>
assert(NumIRArgs == 1);<br>
- if (RV.isScalar() || RV.isComplex()) {<br>
+ if (!I->isAggregate()) {<br>
// Make a temporary alloca to pass the argument.<br>
Address Addr = CreateMemTemp(I->Ty, ArgInfo.getIndirectAlign(),<br>
"indirect-arg-temp", false);<br>
IRCallArgs[FirstIRArg] = Addr.getPointer();<br>
<br>
- LValue argLV = MakeAddrLValue(Addr, I->Ty);<br>
- EmitInitStoreOfNonAggregate(*<wbr>this, RV, argLV);<br>
+ I->copyInto(*this, Addr);<br>
} else {<br>
// We want to avoid creating an unnecessary temporary+copy here;<br>
// however, we need one in three cases:<br>
@@ -3860,32 +3878,51 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
// source. (This case doesn't occur on any common architecture.)<br>
// 2. If the argument is byval, RV is not sufficiently aligned, and<br>
// we cannot force it to be sufficiently aligned.<br>
- // 3. If the argument is byval, but RV is located in an address space<br>
- // different than that of the argument (0).<br>
- Address Addr = RV.getAggregateAddress();<br>
+ // 3. If the argument is byval, but RV is not located in default<br>
+ // or alloca address space.<br>
+ Address Addr = I->hasLValue()<br>
+ ? I->getKnownLValue().<wbr>getAddress()<br>
+ : I->getKnownRValue().<wbr>getAggregateAddress();<br>
+ llvm::Value *V = Addr.getPointer();<br>
CharUnits Align = ArgInfo.getIndirectAlign();<br>
const llvm::DataLayout *TD = &CGM.getDataLayout();<br>
- const unsigned RVAddrSpace = Addr.getType()-><wbr>getAddressSpace();<br>
- const unsigned ArgAddrSpace =<br>
- (FirstIRArg < IRFuncTy->getNumParams()<br>
- ? IRFuncTy->getParamType(<wbr>FirstIRArg)-><wbr>getPointerAddressSpace()<br>
- : 0);<br>
- if ((!ArgInfo.getIndirectByVal() && I->NeedsCopy) ||<br>
- (ArgInfo.getIndirectByVal() && Addr.getAlignment() < Align &&<br>
- llvm::<wbr>getOrEnforceKnownAlignment(<wbr>Addr.getPointer(),<br>
- Align.getQuantity(), *TD)<br>
- < Align.getQuantity()) ||<br>
- (ArgInfo.getIndirectByVal() && (RVAddrSpace != ArgAddrSpace))) {<br>
+<br>
+ assert((FirstIRArg >= IRFuncTy->getNumParams() ||<br>
+ IRFuncTy->getParamType(<wbr>FirstIRArg)-><wbr>getPointerAddressSpace() ==<br>
+ TD->getAllocaAddrSpace()) &&<br>
+ "indirect argument must be in alloca address space");<br>
+<br>
+ bool NeedCopy = false;<br>
+<br>
+ if (Addr.getAlignment() < Align &&<br>
+ llvm::<wbr>getOrEnforceKnownAlignment(V, Align.getQuantity(), *TD) <<br>
+ Align.getQuantity()) {<br>
+ NeedCopy = true;<br>
+ } else if (I->hasLValue()) {<br>
+ auto LV = I->getKnownLValue();<br>
+ auto AS = LV.getAddressSpace();<br>
+ if ((!ArgInfo.getIndirectByVal() &&<br>
+ (LV.getAlignment() >=<br>
+ getContext().<wbr>getTypeAlignInChars(I->Ty))) ||<br>
+ (ArgInfo.getIndirectByVal() &&<br>
+ ((AS != LangAS::Default && AS != LangAS::opencl_private &&<br>
+ AS != CGM.getASTAllocaAddressSpace()<wbr>)))) {<br>
+ NeedCopy = true;<br>
+ }<br>
+ }<br>
+ if (NeedCopy) {<br>
// Create an aligned temporary, and copy to it.<br>
Address AI = CreateMemTemp(I->Ty, ArgInfo.getIndirectAlign(),<br>
"byval-temp", false);<br>
IRCallArgs[FirstIRArg] = AI.getPointer();<br>
- LValue Dest = MakeAddrLValue(AI, I->Ty);<br>
- LValue Src = MakeAddrLValue(Addr, I->Ty);<br>
- EmitAggregateCopy(Dest, Src, I->Ty, RV.isVolatileQualified());<br>
+ I->copyInto(*this, AI);<br>
} else {<br>
// Skip the extra memcpy call.<br>
- IRCallArgs[FirstIRArg] = Addr.getPointer();<br>
+ auto *T = V->getType()-><wbr>getPointerElementType()-><wbr>getPointerTo(<br>
+ CGM.getDataLayout().<wbr>getAllocaAddrSpace());<br>
+ IRCallArgs[FirstIRArg] = getTargetHooks().<wbr>performAddrSpaceCast(<br>
+ *this, V, LangAS::Default, CGM.getASTAllocaAddressSpace()<wbr>, T,<br>
+ true);<br>
}<br>
}<br>
break;<br>
@@ -3902,10 +3939,12 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
ArgInfo.getDirectOffset() == 0) {<br>
assert(NumIRArgs == 1);<br>
llvm::Value *V;<br>
- if (RV.isScalar())<br>
- V = RV.getScalarVal();<br>
+ if (!I->isAggregate())<br>
+ V = I->getKnownRValue().<wbr>getScalarVal();<br>
else<br>
- V = Builder.CreateLoad(RV.<wbr>getAggregateAddress());<br>
+ V = Builder.CreateLoad(<br>
+ I->hasLValue() ? I->getKnownLValue().<wbr>getAddress()<br>
+ : I->getKnownRValue().<wbr>getAggregateAddress());<br>
<br>
// Implement swifterror by copying into a new swifterror argument.<br>
// We'll write back in the normal path out of the call.<br>
@@ -3943,12 +3982,12 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
<br>
// FIXME: Avoid the conversion through memory if possible.<br>
Address Src = Address::invalid();<br>
- if (RV.isScalar() || RV.isComplex()) {<br>
+ if (!I->isAggregate()) {<br>
Src = CreateMemTemp(I->Ty, "coerce");<br>
- LValue SrcLV = MakeAddrLValue(Src, I->Ty);<br>
- EmitInitStoreOfNonAggregate(*<wbr>this, RV, SrcLV);<br>
+ I->copyInto(*this, Src);<br>
} else {<br>
- Src = RV.getAggregateAddress();<br>
+ Src = I->hasLValue() ? I->getKnownLValue().<wbr>getAddress()<br>
+ : I->getKnownRValue().<wbr>getAggregateAddress();<br>
}<br>
<br>
// If the value is offset in memory, apply the offset now.<br>
@@ -4002,9 +4041,12 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
<br>
llvm::Value *tempSize = nullptr;<br>
Address addr = Address::invalid();<br>
- if (RV.isAggregate()) {<br>
- addr = RV.getAggregateAddress();<br>
+ if (I->isAggregate()) {<br>
+ addr = I->hasLValue() ? I->getKnownLValue().<wbr>getAddress()<br>
+ : I->getKnownRValue().<wbr>getAggregateAddress();<br>
+<br>
} else {<br>
+ RValue RV = I->getKnownRValue();<br>
assert(RV.isScalar()); // complex should always just be direct<br>
<br>
llvm::Type *scalarType = RV.getScalarVal()->getType();<br>
@@ -4041,7 +4083,7 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
<br>
case ABIArgInfo::Expand:<br>
unsigned IRArgPos = FirstIRArg;<br>
- ExpandTypeToArgs(I->Ty, RV, IRFuncTy, IRCallArgs, IRArgPos);<br>
+ ExpandTypeToArgs(I->Ty, *I, IRFuncTy, IRCallArgs, IRArgPos);<br>
assert(IRArgPos == FirstIRArg + NumIRArgs);<br>
break;<br>
}<br>
@@ -4393,7 +4435,7 @@ RValue CodeGenFunction::EmitCall(<wbr>const C<br>
OffsetValue);<br>
} else if (const auto *AA = TargetDecl->getAttr<<wbr>AllocAlignAttr>()) {<br>
llvm::Value *ParamVal =<br>
- CallArgs[AA->getParamIndex() - 1].RV.getScalarVal();<br>
+ CallArgs[AA->getParamIndex() - 1].getRValue(*this).<wbr>getScalarVal();<br>
EmitAlignmentAssumption(Ret.<wbr>getScalarVal(), ParamVal);<br>
}<br>
}<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGCall.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGCall.h?rev=326946&r1=326945&<wbr>r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/CGCall.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CGCall.h Wed Mar 7 13:45:40 2018<br>
@@ -213,12 +213,46 @@ public:<br>
};<br>
<br>
struct CallArg {<br>
- RValue RV;<br>
+ private:<br>
+ union {<br>
+ RValue RV;<br>
+ LValue LV; /// The argument is semantically a load from this l-value.<br>
+ };<br>
+ bool HasLV;<br>
+<br>
+ /// A data-flow flag to make sure getRValue and/or copyInto are not<br>
+ /// called twice for duplicated IR emission.<br>
+ mutable bool IsUsed;<br>
+<br>
+ public:<br>
QualType Ty;<br>
- bool NeedsCopy;<br>
- CallArg(RValue rv, QualType ty, bool needscopy)<br>
- : RV(rv), Ty(ty), NeedsCopy(needscopy)<br>
- { }<br>
+ CallArg(RValue rv, QualType ty)<br>
+ : RV(rv), HasLV(false), IsUsed(false), Ty(ty) {}<br>
+ CallArg(LValue lv, QualType ty)<br>
+ : LV(lv), HasLV(true), IsUsed(false), Ty(ty) {}<br>
+ bool hasLValue() const { return HasLV; }<br>
+ QualType getType() const { return Ty; }<br>
+<br>
+ /// \returns an independent RValue. If the CallArg contains an LValue,<br>
+ /// a temporary copy is returned.<br>
+ RValue getRValue(CodeGenFunction &CGF) const;<br>
+<br>
+ LValue getKnownLValue() const {<br>
+ assert(HasLV && !IsUsed);<br>
+ return LV;<br>
+ }<br>
+ RValue getKnownRValue() const {<br>
+ assert(!HasLV && !IsUsed);<br>
+ return RV;<br>
+ }<br>
+ void setRValue(RValue _RV) {<br>
+ assert(!HasLV);<br>
+ RV = _RV;<br>
+ }<br>
+<br>
+ bool isAggregate() const { return HasLV || RV.isAggregate(); }<br>
+<br>
+ void copyInto(CodeGenFunction &CGF, Address A) const;<br>
};<br>
<br>
/// CallArgList - Type for representing both the value and type of<br>
@@ -248,8 +282,10 @@ public:<br>
llvm::Instruction *IsActiveIP;<br>
};<br>
<br>
- void add(RValue rvalue, QualType type, bool needscopy = false) {<br>
- push_back(CallArg(rvalue, type, needscopy));<br>
+ void add(RValue rvalue, QualType type) { push_back(CallArg(rvalue, type)); }<br>
+<br>
+ void addUncopiedAggregate(LValue LV, QualType type) {<br>
+ push_back(CallArg(LV, type));<br>
}<br>
<br>
/// Add all the arguments from another CallArgList to this one. After doing<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGClass.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGClass.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/CGClass.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGClass.<wbr>cpp Wed Mar 7 13:45:40 2018<br>
@@ -2077,7 +2077,8 @@ void CodeGenFunction::<wbr>EmitCXXConstructor<br>
assert(Args.size() == 2 && "unexpected argcount for trivial ctor");<br>
<br>
QualType SrcTy = D->getParamDecl(0)->getType().<wbr>getNonReferenceType();<br>
- Address Src(Args[1].RV.getScalarVal(), getNaturalTypeAlignment(SrcTy)<wbr>);<br>
+ Address Src(Args[1].getRValue(*this).<wbr>getScalarVal(),<br>
+ getNaturalTypeAlignment(SrcTy)<wbr>);<br>
LValue SrcLVal = MakeAddrLValue(Src, SrcTy);<br>
QualType DestTy = getContext().getTypeDeclType(<wbr>ClassDecl);<br>
LValue DestLVal = MakeAddrLValue(This, DestTy);<br>
@@ -2131,8 +2132,7 @@ void CodeGenFunction::<wbr>EmitInheritedCXXCo<br>
const CXXConstructorDecl *D, bool ForVirtualBase, Address This,<br>
bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E) {<br>
CallArgList Args;<br>
- CallArg ThisArg(RValue::get(This.<wbr>getPointer()), D->getThisType(getContext()),<br>
- /*NeedsCopy=*/false);<br>
+ CallArg ThisArg(RValue::get(This.<wbr>getPointer()), D->getThisType(getContext()));<br>
<br>
// Forward the parameters.<br>
if (InheritedFromVBase &&<br>
@@ -2196,7 +2196,7 @@ void CodeGenFunction::<wbr>EmitInlinedInherit<br>
assert(Args.size() >= Params.size() && "too few arguments for call");<br>
for (unsigned I = 0, N = Args.size(); I != N; ++I) {<br>
if (I < Params.size() && isa<ImplicitParamDecl>(Params[<wbr>I])) {<br>
- const RValue &RV = Args[I].RV;<br>
+ const RValue &RV = Args[I].getRValue(*this);<br>
assert(!RV.isComplex() && "complex indirect params not supported");<br>
ParamValue Val = RV.isScalar()<br>
? ParamValue::forDirect(RV.<wbr>getScalarVal())<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDecl.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGDecl.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/CGDecl.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDecl.<wbr>cpp Wed Mar 7 13:45:40 2018<br>
@@ -1882,6 +1882,22 @@ void CodeGenFunction::EmitParmDecl(<wbr>const<br>
llvm::Type *IRTy = ConvertTypeForMem(Ty)-><wbr>getPointerTo(AS);<br>
if (DeclPtr.getType() != IRTy)<br>
DeclPtr = Builder.CreateBitCast(DeclPtr, IRTy, D.getName());<br>
+ // Indirect argument is in alloca address space, which may be different<br>
+ // from the default address space.<br>
+ auto AllocaAS = CGM.getASTAllocaAddressSpace()<wbr>;<br>
+ auto *V = DeclPtr.getPointer();<br>
+ auto SrcLangAS = getLangOpts().OpenCL ? LangAS::opencl_private : AllocaAS;<br>
+ auto DestLangAS =<br>
+ getLangOpts().OpenCL ? LangAS::opencl_private : LangAS::Default;<br>
+ if (SrcLangAS != DestLangAS) {<br>
+ assert(getContext().<wbr>getTargetAddressSpace(<wbr>SrcLangAS) ==<br>
+ CGM.getDataLayout().<wbr>getAllocaAddrSpace());<br>
+ auto DestAS = getContext().<wbr>getTargetAddressSpace(<wbr>DestLangAS);<br>
+ auto *T = V->getType()-><wbr>getPointerElementType()-><wbr>getPointerTo(DestAS);<br>
+ DeclPtr = Address(getTargetHooks().<wbr>performAddrSpaceCast(<br>
+ *this, V, SrcLangAS, DestLangAS, T, true),<br>
+ DeclPtr.getAlignment());<br>
+ }<br>
<br>
// Push a destructor cleanup for this parameter if the ABI requires it.<br>
// Don't push a cleanup in a thunk for a method that will also emit a<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CGExprCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGExprCXX.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CGExprCXX.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CGExprCXX.cpp Wed Mar 7 13:45:40 2018<br>
@@ -265,7 +265,7 @@ RValue CodeGenFunction::<wbr>EmitCXXMemberOrO<br>
// when it isn't necessary; just produce the proper effect here.<br>
LValue RHS = isa<CXXOperatorCallExpr>(CE)<br>
? MakeNaturalAlignAddrLValue(<br>
- (*RtlArgs)[0].RV.getScalarVal(<wbr>),<br>
+ (*RtlArgs)[0].getRValue(*this)<wbr>.getScalarVal(),<br>
(*(CE->arg_begin() + 1))->getType())<br>
: EmitLValue(*CE->arg_begin());<br>
EmitAggregateAssign(This, RHS, CE->getType());<br>
@@ -1490,7 +1490,7 @@ static void EnterNewDeleteCleanup(CodeGe<br>
AllocAlign);<br>
for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {<br>
auto &Arg = NewArgs[I + NumNonPlacementArgs];<br>
- Cleanup->setPlacementArg(I, Arg.RV, Arg.Ty);<br>
+ Cleanup->setPlacementArg(I, Arg.getRValue(CGF), Arg.Ty);<br>
}<br>
<br>
return;<br>
@@ -1521,8 +1521,8 @@ static void EnterNewDeleteCleanup(CodeGe<br>
AllocAlign);<br>
for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {<br>
auto &Arg = NewArgs[I + NumNonPlacementArgs];<br>
- Cleanup->setPlacementArg(I, DominatingValue<RValue>::save(<wbr>CGF, Arg.RV),<br>
- Arg.Ty);<br>
+ Cleanup->setPlacementArg(<br>
+ I, DominatingValue<RValue>::save(<wbr>CGF, Arg.getRValue(CGF)), Arg.Ty);<br>
}<br>
<br>
CGF.initFullExprCleanup();<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CGGPUBuiltin.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGGPUBuiltin.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGGPUBuiltin.cpp?rev=326946&<wbr>r1=326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CGGPUBuiltin.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CGGPUBuiltin.cpp Wed Mar 7 13:45:40 2018<br>
@@ -83,8 +83,9 @@ CodeGenFunction::<wbr>EmitNVPTXDevicePrintfCa<br>
/* ParamsToSkip = */ 0);<br>
<br>
// We don't know how to emit non-scalar varargs.<br>
- if (std::any_of(Args.begin() + 1, Args.end(),<br>
- [](const CallArg &A) { return !A.RV.isScalar(); })) {<br>
+ if (std::any_of(Args.begin() + 1, Args.end(), [&](const CallArg &A) {<br>
+ return !A.getRValue(*this).isScalar()<wbr>;<br>
+ })) {<br>
CGM.ErrorUnsupported(E, "non-scalar arg to printf");<br>
return RValue::get(llvm::ConstantInt:<wbr>:get(IntTy, 0));<br>
}<br>
@@ -97,7 +98,7 @@ CodeGenFunction::<wbr>EmitNVPTXDevicePrintfCa<br>
} else {<br>
llvm::SmallVector<llvm::Type *, 8> ArgTypes;<br>
for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I)<br>
- ArgTypes.push_back(Args[I].RV.<wbr>getScalarVal()->getType());<br>
+ ArgTypes.push_back(Args[I].<wbr>getRValue(*this).getScalarVal(<wbr>)->getType());<br>
<br>
// Using llvm::StructType is correct only because printf doesn't accept<br>
// aggregates. If we had to handle aggregates here, we'd have to manually<br>
@@ -109,7 +110,7 @@ CodeGenFunction::<wbr>EmitNVPTXDevicePrintfCa<br>
<br>
for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I) {<br>
llvm::Value *P = Builder.CreateStructGEP(<wbr>AllocaTy, Alloca, I - 1);<br>
- llvm::Value *Arg = Args[I].RV.getScalarVal();<br>
+ llvm::Value *Arg = Args[I].getRValue(*this).<wbr>getScalarVal();<br>
Builder.CreateAlignedStore(<wbr>Arg, P, DL.getPrefTypeAlignment(Arg-><wbr>getType()));<br>
}<br>
BufferPtr = Builder.CreatePointerCast(<wbr>Alloca, llvm::Type::getInt8PtrTy(Ctx))<wbr>;<br>
@@ -117,6 +118,6 @@ CodeGenFunction::<wbr>EmitNVPTXDevicePrintfCa<br>
<br>
// Invoke vprintf and return.<br>
llvm::Function* VprintfFunc = GetVprintfDeclaration(CGM.<wbr>getModule());<br>
- return RValue::get(<br>
- Builder.CreateCall(<wbr>VprintfFunc, {Args[0].RV.getScalarVal(), BufferPtr}));<br>
+ return RValue::get(Builder.<wbr>CreateCall(<br>
+ VprintfFunc, {Args[0].getRValue(*this).<wbr>getScalarVal(), BufferPtr}));<br>
}<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CGObjCGNU.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGObjCGNU.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CGObjCGNU.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CGObjCGNU.cpp Wed Mar 7 13:45:40 2018<br>
@@ -1441,7 +1441,7 @@ CGObjCGNU::<wbr>GenerateMessageSend(CodeGenFu<br>
}<br>
<br>
// Reset the receiver in case the lookup modified it<br>
- ActualArgs[0] = CallArg(RValue::get(Receiver), ASTIdTy, false);<br>
+ ActualArgs[0] = CallArg(RValue::get(Receiver), ASTIdTy);<br>
<br>
imp = EnforceType(Builder, imp, MSI.MessengerType);<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CGObjCMac.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CGObjCMac.cpp?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CGObjCMac.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CGObjCMac.cpp Wed Mar 7 13:45:40 2018<br>
@@ -1708,7 +1708,7 @@ struct NullReturnState {<br>
e = Method->param_end(); i != e; ++i, ++I) {<br>
const ParmVarDecl *ParamDecl = (*i);<br>
if (ParamDecl->hasAttr<<wbr>NSConsumedAttr>()) {<br>
- RValue RV = I->RV;<br>
+ RValue RV = I->getRValue(CGF);<br>
assert(RV.isScalar() &&<br>
"NullReturnState::complete - arg not on object");<br>
CGF.EmitARCRelease(RV.<wbr>getScalarVal(), ARCImpreciseLifetime);<br>
@@ -7071,7 +7071,7 @@ CGObjCNonFragileABIMac::<wbr>EmitVTableMessag<br>
CGF.getPointerAlign());<br>
<br>
// Update the message ref argument.<br>
- args[1].RV = RValue::get(mref.getPointer())<wbr>;<br>
+ args[1].setRValue(RValue::get(<wbr>mref.getPointer()));<br>
<br>
// Load the function to call from the message ref table.<br>
Address calleeAddr =<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h?rev=326946&<wbr>r1=326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>CodeGenFunction.h Wed Mar 7 13:45:40 2018<br>
@@ -3899,10 +3899,10 @@ private:<br>
void ExpandTypeFromArgs(QualType Ty, LValue Dst,<br>
SmallVectorImpl<llvm::Value *>::iterator &AI);<br>
<br>
- /// ExpandTypeToArgs - Expand an RValue \arg RV, with the LLVM type for \arg<br>
+ /// ExpandTypeToArgs - Expand an CallArg \arg Arg, with the LLVM type for \arg<br>
/// Ty, into individual arguments on the provided vector \arg IRCallArgs,<br>
/// starting at index \arg IRCallArgPos. See ABIArgInfo::Expand.<br>
- void ExpandTypeToArgs(QualType Ty, RValue RV, llvm::FunctionType *IRFuncTy,<br>
+ void ExpandTypeToArgs(QualType Ty, CallArg Arg, llvm::FunctionType *IRFuncTy,<br>
SmallVectorImpl<llvm::Value *> &IRCallArgs,<br>
unsigned &IRCallArgPos);<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>ItaniumCXXABI.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>ItaniumCXXABI.cpp?rev=326946&<wbr>r1=326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>ItaniumCXXABI.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>ItaniumCXXABI.cpp Wed Mar 7 13:45:40 2018<br>
@@ -1474,8 +1474,7 @@ CGCXXABI::AddedStructorArgs ItaniumCXXAB<br>
llvm::Value *VTT =<br>
CGF.GetVTTParameter(<wbr>GlobalDecl(D, Type), ForVirtualBase, Delegating);<br>
QualType VTTTy = getContext().getPointerType(<wbr>getContext().VoidPtrTy);<br>
- Args.insert(Args.begin() + 1,<br>
- CallArg(RValue::get(VTT), VTTTy, /*needscopy=*/false));<br>
+ Args.insert(Args.begin() + 1, CallArg(RValue::get(VTT), VTTTy));<br>
return AddedStructorArgs::prefix(1); // Added one arg.<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/<wbr>MicrosoftCXXABI.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>MicrosoftCXXABI.cpp?rev=<wbr>326946&r1=326945&r2=326946&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/CodeGen/<wbr>MicrosoftCXXABI.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/<wbr>MicrosoftCXXABI.cpp Wed Mar 7 13:45:40 2018<br>
@@ -1537,8 +1537,7 @@ CGCXXABI::AddedStructorArgs MicrosoftCXX<br>
}<br>
RValue RV = RValue::get(MostDerivedArg);<br>
if (FPT->isVariadic()) {<br>
- Args.insert(Args.begin() + 1,<br>
- CallArg(RV, getContext().IntTy, /*needscopy=*/false));<br>
+ Args.insert(Args.begin() + 1, CallArg(RV, getContext().IntTy));<br>
return AddedStructorArgs::prefix(1);<br>
}<br>
Args.add(RV, getContext().IntTy);<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/<wbr>amdgcn-func-arg.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/amdgcn-func-arg.cpp?rev=326946&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGenCXX/amdgcn-func-arg.<wbr>cpp?rev=326946&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGenCXX/<wbr>amdgcn-func-arg.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/<wbr>amdgcn-func-arg.cpp Wed Mar 7 13:45:40 2018<br>
@@ -0,0 +1,94 @@<br>
+// RUN: %clang_cc1 -O0 -triple amdgcn -emit-llvm %s -o - | FileCheck %s<br>
+<br>
+class A {<br>
+public:<br>
+ int x;<br>
+ A():x(0) {}<br>
+ ~A() {}<br>
+};<br>
+<br>
+class B {<br>
+int x[100];<br>
+};<br>
+<br>
+A g_a;<br>
+B g_b;<br>
+<br>
+void func_with_ref_arg(A &a);<br>
+void func_with_ref_arg(B &b);<br>
+<br>
+// CHECK-LABEL: define void @_Z22func_with_indirect_arg1A(<wbr>%class.A addrspace(5)* %a)<br>
+// CHECK: %p = alloca %class.A*, align 8, addrspace(5)<br>
+// CHECK: %[[r1:.+]] = addrspacecast %class.A* addrspace(5)* %p to %class.A**<br>
+// CHECK: %[[r0:.+]] = addrspacecast %class.A addrspace(5)* %a to %class.A*<br>
+// CHECK: store %class.A* %[[r0]], %class.A** %[[r1]], align 8<br>
+void func_with_indirect_arg(A a) {<br>
+ A *p = &a;<br>
+}<br>
+<br>
+// CHECK-LABEL: define void @_Z22test_indirect_arg_autov()<br>
+// CHECK: %a = alloca %class.A, align 4, addrspace(5)<br>
+// CHECK: %[[r0:.+]] = addrspacecast %class.A addrspace(5)* %a to %class.A*<br>
+// CHECK: %agg.tmp = alloca %class.A, align 4, addrspace(5)<br>
+// CHECK: %[[r1:.+]] = addrspacecast %class.A addrspace(5)* %agg.tmp to %class.A*<br>
+// CHECK: call void @_ZN1AC1Ev(%class.A* %[[r0]])<br>
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64<br>
+// CHECK: %[[r4:.+]] = addrspacecast %class.A* %[[r1]] to %class.A addrspace(5)*<br>
+// CHECK: call void @_Z22func_with_indirect_arg1A(<wbr>%class.A addrspace(5)* %[[r4]])<br>
+// CHECK: call void @_ZN1AD1Ev(%class.A* %[[r1]])<br>
+// CHECK: call void @_Z17func_with_ref_argR1A(%<wbr>class.A* dereferenceable(4) %[[r0]])<br>
+// CHECK: call void @_ZN1AD1Ev(%class.A* %[[r0]])<br>
+void test_indirect_arg_auto() {<br>
+ A a;<br>
+ func_with_indirect_arg(a);<br>
+ func_with_ref_arg(a);<br>
+}<br>
+<br>
+// CHECK: define void @_Z24test_indirect_arg_<wbr>globalv()<br>
+// CHECK: %agg.tmp = alloca %class.A, align 4, addrspace(5)<br>
+// CHECK: %[[r0:.+]] = addrspacecast %class.A addrspace(5)* %agg.tmp to %class.A*<br>
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64<br>
+// CHECK: %[[r2:.+]] = addrspacecast %class.A* %[[r0]] to %class.A addrspace(5)*<br>
+// CHECK: call void @_Z22func_with_indirect_arg1A(<wbr>%class.A addrspace(5)* %[[r2]])<br>
+// CHECK: call void @_ZN1AD1Ev(%class.A* %[[r0]])<br>
+// CHECK: call void @_Z17func_with_ref_argR1A(%<wbr>class.A* dereferenceable(4) addrspacecast (%class.A addrspace(1)* @g_a to %class.A*))<br>
+void test_indirect_arg_global() {<br>
+ func_with_indirect_arg(g_a);<br>
+ func_with_ref_arg(g_a);<br>
+}<br>
+<br>
+// CHECK-LABEL: define void @_Z19func_with_byval_arg1B(%<wbr>class.B addrspace(5)* byval align 4 %b)<br>
+// CHECK: %p = alloca %class.B*, align 8, addrspace(5)<br>
+// CHECK: %[[r1:.+]] = addrspacecast %class.B* addrspace(5)* %p to %class.B**<br>
+// CHECK: %[[r0:.+]] = addrspacecast %class.B addrspace(5)* %b to %class.B*<br>
+// CHECK: store %class.B* %[[r0]], %class.B** %[[r1]], align 8<br>
+void func_with_byval_arg(B b) {<br>
+ B *p = &b;<br>
+}<br>
+<br>
+// CHECK-LABEL: define void @_Z19test_byval_arg_autov()<br>
+// CHECK: %b = alloca %class.B, align 4, addrspace(5)<br>
+// CHECK: %[[r0:.+]] = addrspacecast %class.B addrspace(5)* %b to %class.B*<br>
+// CHECK: %agg.tmp = alloca %class.B, align 4, addrspace(5)<br>
+// CHECK: %[[r1:.+]] = addrspacecast %class.B addrspace(5)* %agg.tmp to %class.B*<br>
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64<br>
+// CHECK: %[[r4:.+]] = addrspacecast %class.B* %[[r1]] to %class.B addrspace(5)*<br>
+// CHECK: call void @_Z19func_with_byval_arg1B(%<wbr>class.B addrspace(5)* byval align 4 %[[r4]])<br>
+// CHECK: call void @_Z17func_with_ref_argR1B(%<wbr>class.B* dereferenceable(400) %[[r0]])<br>
+void test_byval_arg_auto() {<br>
+ B b;<br>
+ func_with_byval_arg(b);<br>
+ func_with_ref_arg(b);<br>
+}<br>
+<br>
+// CHECK-LABEL: define void @_Z21test_byval_arg_globalv()<br>
+// CHECK: %agg.tmp = alloca %class.B, align 4, addrspace(5)<br>
+// CHECK: %[[r0:.+]] = addrspacecast %class.B addrspace(5)* %agg.tmp to %class.B*<br>
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64<br>
+// CHECK: %[[r2:.+]] = addrspacecast %class.B* %[[r0]] to %class.B addrspace(5)*<br>
+// CHECK: call void @_Z19func_with_byval_arg1B(%<wbr>class.B addrspace(5)* byval align 4 %[[r2]])<br>
+// CHECK: call void @_Z17func_with_ref_argR1B(%<wbr>class.B* dereferenceable(400) addrspacecast (%class.B addrspace(1)* @g_b to %class.B*))<br>
+void test_byval_arg_global() {<br>
+ func_with_byval_arg(g_b);<br>
+ func_with_ref_arg(g_b);<br>
+}<br>
<br>
Modified: cfe/trunk/test/CodeGenOpenCL/<a href="http://addr-space-struct-arg.cl" rel="noreferrer" target="_blank">a<wbr>ddr-space-struct-arg.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/addr-space-struct-arg.cl?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGenOpenCL/addr-space-<wbr>struct-arg.cl?rev=326946&r1=<wbr>326945&r2=326946&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGenOpenCL/<a href="http://addr-space-struct-arg.cl" rel="noreferrer" target="_blank">a<wbr>ddr-space-struct-arg.cl</a> (original)<br>
+++ cfe/trunk/test/CodeGenOpenCL/<a href="http://addr-space-struct-arg.cl" rel="noreferrer" target="_blank">a<wbr>ddr-space-struct-arg.cl</a> Wed Mar 7 13:45:40 2018<br>
@@ -1,5 +1,6 @@<br>
// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s<br>
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn-amdhsa-amd | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s<br>
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s<br>
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,<wbr>AMDGCN20 %s<br>
<br>
typedef struct {<br>
int cells[9];<br>
@@ -35,6 +36,9 @@ struct LargeStructTwoMember {<br>
int2 y[20];<br>
};<br>
<br>
+#if __OPENCL_C_VERSION__ >= 200<br>
+struct LargeStructOneMember g_s;<br>
+#endif<br>
<br>
// X86-LABEL: define void @foo(%struct.Mat4X4* noalias sret %agg.result, %struct.Mat3X3* byval align 4 %in)<br>
// AMDGCN-LABEL: define %struct.Mat4X4 @foo([9 x i32] %in.coerce)<br>
@@ -80,10 +84,42 @@ void FuncOneMember(struct StructOneMembe<br>
}<br>
<br>
// AMDGCN-LABEL: define void @FuncOneLargeMember(%struct.<wbr>LargeStructOneMember addrspace(5)* byval align 8 %u)<br>
+// AMDGCN-NOT: addrspacecast<br>
+// AMDGCN: store <2 x i32> %{{.*}}, <2 x i32> addrspace(5)*<br>
void FuncOneLargeMember(struct LargeStructOneMember u) {<br>
u.x[0] = (int2)(0, 0);<br>
}<br>
<br>
+// AMDGCN20-LABEL: define void @test_indirect_arg_globl()<br>
+// AMDGCN20: %[[byval_temp:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)<br>
+// AMDGCN20: %[[r0:.*]] = bitcast %struct.LargeStructOneMember addrspace(5)* %[[byval_temp]] to i8 addrspace(5)*<br>
+// AMDGCN20: call void @llvm.memcpy.p5i8.p1i8.i64(i8 addrspace(5)* align 8 %[[r0]], i8 addrspace(1)* align 8 bitcast (%struct.LargeStructOneMember addrspace(1)* @g_s to i8 addrspace(1)*), i64 800, i1 false)<br>
+// AMDGCN20: call void @FuncOneLargeMember(%struct.<wbr>LargeStructOneMember addrspace(5)* byval align 8 %[[byval_temp]])<br>
+#if __OPENCL_C_VERSION__ >= 200<br>
+void test_indirect_arg_globl(void) {<br>
+ FuncOneLargeMember(g_s);<br>
+}<br>
+#endif<br>
+<br>
+// AMDGCN-LABEL: define amdgpu_kernel void @test_indirect_arg_local()<br>
+// AMDGCN: %[[byval_temp:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)<br>
+// AMDGCN: %[[r0:.*]] = bitcast %struct.LargeStructOneMember addrspace(5)* %[[byval_temp]] to i8 addrspace(5)*<br>
+// AMDGCN: call void @llvm.memcpy.p5i8.p3i8.i64(i8 addrspace(5)* align 8 %[[r0]], i8 addrspace(3)* align 8 bitcast (%struct.LargeStructOneMember addrspace(3)* @test_indirect_arg_local.l_s to i8 addrspace(3)*), i64 800, i1 false)<br>
+// AMDGCN: call void @FuncOneLargeMember(%struct.<wbr>LargeStructOneMember addrspace(5)* byval align 8 %[[byval_temp]])<br>
+kernel void test_indirect_arg_local(void) {<br>
+ local struct LargeStructOneMember l_s;<br>
+ FuncOneLargeMember(l_s);<br>
+}<br>
+<br>
+// AMDGCN-LABEL: define void @test_indirect_arg_private()<br>
+// AMDGCN: %[[p_s:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)<br>
+// AMDGCN-NOT: @llvm.memcpy<br>
+// AMDGCN-NEXT: call void @FuncOneLargeMember(%struct.<wbr>LargeStructOneMember addrspace(5)* byval align 8 %[[p_s]])<br>
+void test_indirect_arg_private(<wbr>void) {<br>
+ struct LargeStructOneMember p_s;<br>
+ FuncOneLargeMember(p_s);<br>
+}<br>
+<br>
// AMDGCN-LABEL: define amdgpu_kernel void @KernelOneMember<br>
// AMDGCN-SAME: (<2 x i32> %[[u_coerce:.*]])<br>
// AMDGCN: %[[u:.*]] = alloca %struct.StructOneMember, align 8, addrspace(5)<br>
@@ -112,7 +148,6 @@ void FuncLargeTwoMember(struct LargeStru<br>
u.y[0] = (int2)(0, 0);<br>
}<br>
<br>
-<br>
// AMDGCN-LABEL: define amdgpu_kernel void @KernelTwoMember<br>
// AMDGCN-SAME: (%struct.StructTwoMember %[[u_coerce:.*]])<br>
// AMDGCN: %[[u:.*]] = alloca %struct.StructTwoMember, align 8, addrspace(5)<br>
<br>
Modified: cfe/trunk/test/CodeGenOpenCL/<a href="http://byval.cl" rel="noreferrer" target="_blank">b<wbr>yval.cl</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/byval.cl?rev=326946&r1=326945&r2=326946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGenOpenCL/byval.cl?rev=<wbr>326946&r1=326945&r2=326946&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/CodeGenOpenCL/<a href="http://byval.cl" rel="noreferrer" target="_blank">b<wbr>yval.cl</a> (original)<br>
+++ cfe/trunk/test/CodeGenOpenCL/<a href="http://byval.cl" rel="noreferrer" target="_blank">b<wbr>yval.cl</a> Wed Mar 7 13:45:40 2018<br>
@@ -1,5 +1,4 @@<br>
// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn %s | FileCheck %s<br>
-// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn---opencl %s | FileCheck %s<br>
<br>
struct A {<br>
int x[100];<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>