aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-02-08 22:53:07 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-02-08 22:53:07 +0000
commite86bcf0d9ea62cc75e545787896083f8a6bc81a1 (patch)
treeadb63821117f85182b35358cdfaa0fc0a3dc8111
parentba915af51ced751c46e7c2b9c6f3b59d2e668825 (diff)
Reapply r95393, without the change to CGExpr. I was wrong in assuming that the
element type always matched the converted LLVM type for ExprType. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95596 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGDecl.cpp26
-rw-r--r--lib/CodeGen/CGExpr.cpp2
-rw-r--r--lib/CodeGen/CGStmt.cpp5
3 files changed, 14 insertions, 19 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index f33c2eb80e..632dcc1953 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -703,25 +703,19 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg) {
CanQualType CTy = getContext().getCanonicalType(Ty);
llvm::Value *DeclPtr;
- if (!Ty->isConstantSizeType()) {
- // Variable sized values always are passed by-reference.
+ // If this is an aggregate or variable sized value, reuse the input pointer.
+ if (!Ty->isConstantSizeType() ||
+ CodeGenFunction::hasAggregateLLVMType(Ty)) {
DeclPtr = Arg;
} else {
- // A fixed sized single-value variable becomes an alloca in the entry block.
- const llvm::Type *LTy = ConvertTypeForMem(Ty);
- if (LTy->isSingleValueType()) {
- // TODO: Alignment
- DeclPtr = CreateTempAlloca(LTy);
- DeclPtr->setName(D.getNameAsString() + llvm::StringRef(".addr"));
-
- // Store the initial value into the alloca.
- EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Ty);
- } else {
- // Otherwise, if this is an aggregate, just use the input pointer.
- DeclPtr = Arg;
- }
- Arg->setName(D.getNameAsString());
+ // Otherwise, create a temporary to hold the value.
+ DeclPtr = CreateTempAlloca(ConvertTypeForMem(Ty));
+ DeclPtr->setName(D.getName() + ".addr");
+
+ // Store the initial value into the alloca.
+ EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Ty);
}
+ Arg->setName(D.getName());
llvm::Value *&DMEntry = LocalDeclMap[&D];
assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index d258945079..943e890074 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -553,6 +553,8 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
cast<llvm::PointerType>(Ptr->getType())->getElementType();
// Simple scalar l-value.
+ //
+ // FIXME: We shouldn't have to use isSingleValueType here.
if (EltTy->isSingleValueType())
return RValue::get(EmitLoadOfScalar(Ptr, LV.isVolatileQualified(),
ExprType));
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 7ea8b08c23..008a480b9c 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -861,14 +861,13 @@ llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S,
std::string &ConstraintStr) {
llvm::Value *Arg;
if (Info.allowsRegister() || !Info.allowsMemory()) {
- const llvm::Type *Ty = ConvertType(InputExpr->getType());
-
- if (Ty->isSingleValueType()) {
+ if (!CodeGenFunction::hasAggregateLLVMType(InputExpr->getType())) {
Arg = EmitScalarExpr(InputExpr);
} else {
InputExpr = InputExpr->IgnoreParenNoopCasts(getContext());
LValue Dest = EmitLValue(InputExpr);
+ const llvm::Type *Ty = ConvertType(InputExpr->getType());
uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty);
if (Size <= 64 && llvm::isPowerOf2_64(Size)) {
Ty = llvm::IntegerType::get(VMContext, Size);