diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-09-16 20:42:02 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-09-16 20:42:02 +0000 |
commit | cf3b6f2504596812db1fcef0df8ce5b3449c4aac (patch) | |
tree | 1a525e666be197564611bc00f666dd45ebc273e0 /lib/CodeGen/CGCall.cpp | |
parent | 93ae947df36133c7a26a0c7d325c0679916ed2ed (diff) |
IRgen/ABI: Add support for realigning structures which are passed by indirect
reference.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114114 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r-- | lib/CodeGen/CGCall.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 475dfa5c10..ae00040ec7 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -866,9 +866,29 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, switch (ArgI.getKind()) { case ABIArgInfo::Indirect: { llvm::Value *V = AI; + if (hasAggregateLLVMType(Ty)) { - // Do nothing, aggregates and complex variables are accessed by - // reference. + // Aggregates and complex variables are accessed by reference. All we + // need to do is realign the value, if requested + if (ArgI.getIndirectRealign()) { + llvm::Value *AlignedTemp = CreateMemTemp(Ty, "coerce"); + + // Copy from the incoming argument pointer to the temporary with the + // appropriate alignment. + // + // FIXME: We should have a common utility for generating an aggregate + // copy. + const llvm::Type *I8PtrTy = llvm::Type::getInt8PtrTy(VMContext, 0); + unsigned Size = getContext().getTypeSize(Ty) / 8; + Builder.CreateCall5(CGM.getMemCpyFn(I8PtrTy, I8PtrTy, IntPtrTy), + Builder.CreateBitCast(AlignedTemp, I8PtrTy), + Builder.CreateBitCast(V, I8PtrTy), + llvm::ConstantInt::get(IntPtrTy, Size), + Builder.getInt32(ArgI.getIndirectAlign()), + /*Volatile=*/Builder.getInt1(false)); + + V = AlignedTemp; + } } else { // Load scalar value from indirect argument. unsigned Alignment = getContext().getTypeAlignInChars(Ty).getQuantity(); |