diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-08-21 02:24:36 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-08-21 02:24:36 +0000 |
commit | 91a16fa3265686b90054715eea504d9b4a13438b (patch) | |
tree | 1231112a41bba5d9569021926912372d6c1fe842 /lib/CodeGen/CGCall.cpp | |
parent | 4cac2a157c5a3d7c8f6cd79b52e891184623f29e (diff) |
IRgen: Change Emit{Load,Store}OfScalar to take a required Alignment argument and
update callers as best I can.
- This is a work in progress, our alignment handling is very horrible / sketchy -- I am just aiming for monotonic improvement.
- Serious review appreciated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111707 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r-- | lib/CodeGen/CGCall.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 2ba44714c7..6e32e1e1b4 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -854,7 +854,8 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, // reference. } else { // Load scalar value from indirect argument. - V = EmitLoadOfScalar(V, false, Ty); + unsigned Alignment = getContext().getTypeAlignInChars(Ty).getQuantity(); + V = EmitLoadOfScalar(V, false, Alignment, Ty); if (!getContext().typesAreCompatible(Ty, Arg->getType())) { // This must be a promotion, for something like // "void a(x) short x; {..." @@ -930,7 +931,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, // Match to what EmitParmDecl is expecting for this type. if (!CodeGenFunction::hasAggregateLLVMType(Ty)) { - V = EmitLoadOfScalar(V, false, Ty); + V = EmitLoadOfScalar(V, false, AlignmentToUse, Ty); if (!getContext().typesAreCompatible(Ty, Arg->getType())) { // This must be a promotion, for something like // "void a(x) short x; {..." @@ -987,7 +988,8 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI) { const ABIArgInfo &RetAI = FI.getReturnInfo(); switch (RetAI.getKind()) { - case ABIArgInfo::Indirect: + case ABIArgInfo::Indirect: { + unsigned Alignment = getContext().getTypeAlignInChars(RetTy).getQuantity(); if (RetTy->isAnyComplexType()) { ComplexPairTy RT = LoadComplexFromAddr(ReturnValue, false); StoreComplexToAddr(RT, CurFn->arg_begin(), false); @@ -995,9 +997,10 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI) { // Do nothing; aggregrates get evaluated directly into the destination. } else { EmitStoreOfScalar(Builder.CreateLoad(ReturnValue), CurFn->arg_begin(), - false, RetTy); + false, Alignment, RetTy); } break; + } case ABIArgInfo::Extend: case ABIArgInfo::Direct: @@ -1080,7 +1083,8 @@ RValue CodeGenFunction::EmitDelegateCallArg(const VarDecl *Param) { if (hasAggregateLLVMType(ArgType)) return RValue::getAggregate(Local); - return RValue::get(EmitLoadOfScalar(Local, false, ArgType)); + unsigned Alignment = getContext().getDeclAlign(Param).getQuantity(); + return RValue::get(EmitLoadOfScalar(Local, false, Alignment, ArgType)); } RValue CodeGenFunction::EmitCallArg(const Expr *E, QualType ArgType) { @@ -1140,19 +1144,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, const ABIArgInfo &ArgInfo = info_it->info; RValue RV = I->first; + unsigned Alignment = + getContext().getTypeAlignInChars(I->second).getQuantity(); switch (ArgInfo.getKind()) { - case ABIArgInfo::Indirect: + case ABIArgInfo::Indirect: { if (RV.isScalar() || RV.isComplex()) { // Make a temporary alloca to pass the argument. Args.push_back(CreateMemTemp(I->second)); if (RV.isScalar()) - EmitStoreOfScalar(RV.getScalarVal(), Args.back(), false, I->second); + EmitStoreOfScalar(RV.getScalarVal(), Args.back(), false, + Alignment, I->second); else StoreComplexToAddr(RV.getComplexVal(), Args.back(), false); } else { Args.push_back(RV.getAggregateAddr()); } break; + } case ABIArgInfo::Ignore: break; @@ -1173,7 +1181,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, llvm::Value *SrcPtr; if (RV.isScalar()) { SrcPtr = CreateMemTemp(I->second, "coerce"); - EmitStoreOfScalar(RV.getScalarVal(), SrcPtr, false, I->second); + EmitStoreOfScalar(RV.getScalarVal(), SrcPtr, false, Alignment, + I->second); } else if (RV.isComplex()) { SrcPtr = CreateMemTemp(I->second, "coerce"); StoreComplexToAddr(RV.getComplexVal(), SrcPtr, false); @@ -1294,12 +1303,14 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, CI->setName("call"); switch (RetAI.getKind()) { - case ABIArgInfo::Indirect: + case ABIArgInfo::Indirect: { + unsigned Alignment = getContext().getTypeAlignInChars(RetTy).getQuantity(); if (RetTy->isAnyComplexType()) return RValue::getComplex(LoadComplexFromAddr(Args[0], false)); if (CodeGenFunction::hasAggregateLLVMType(RetTy)) return RValue::getAggregate(Args[0]); - return RValue::get(EmitLoadOfScalar(Args[0], false, RetTy)); + return RValue::get(EmitLoadOfScalar(Args[0], false, Alignment, RetTy)); + } case ABIArgInfo::Ignore: // If we are ignoring an argument that had a result, make sure to @@ -1347,11 +1358,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, } CreateCoercedStore(CI, StorePtr, DestIsVolatile, *this); + unsigned Alignment = getContext().getTypeAlignInChars(RetTy).getQuantity(); if (RetTy->isAnyComplexType()) return RValue::getComplex(LoadComplexFromAddr(DestPtr, false)); if (CodeGenFunction::hasAggregateLLVMType(RetTy)) return RValue::getAggregate(DestPtr); - return RValue::get(EmitLoadOfScalar(DestPtr, false, RetTy)); + return RValue::get(EmitLoadOfScalar(DestPtr, false, Alignment, RetTy)); } case ABIArgInfo::Expand: |