]> granicus.if.org Git - clang/commitdiff
IRgen: Use hasAggregateLLVMType instead of isSingleValueType() for cases that
authorDaniel Dunbar <daniel@zuster.org>
Fri, 5 Feb 2010 17:51:33 +0000 (17:51 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 5 Feb 2010 17:51:33 +0000 (17:51 +0000)
need to deal with aggregates specially; this is consistent with the rest of IRgen.

Also, simplify EmitParmDecl and don't worry about using Decl::getNameAsString.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95393 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGStmt.cpp

index e27c5e4e51ae51aba31b09ce5e4468a25eedab7c..d18b87fb9ac6118f93add7c7a8ce81817d413933 100644 (file)
@@ -690,25 +690,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!");
index 888070145572e615487b9e435a5138d8f1ff7deb..427975deb1458d89213beab697e925fbb9aad0bc 100644 (file)
@@ -549,14 +549,13 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) {
 
   if (LV.isSimple()) {
     llvm::Value *Ptr = LV.getAddress();
-    const llvm::Type *EltTy =
-      cast<llvm::PointerType>(Ptr->getType())->getElementType();
 
     // Simple scalar l-value.
-    if (EltTy->isSingleValueType())
+    if (!CodeGenFunction::hasAggregateLLVMType(ExprType))
       return RValue::get(EmitLoadOfScalar(Ptr, LV.isVolatileQualified(),
                                           ExprType));
 
+    // FIXME: This case shouldn't be necessary?
     assert(ExprType->isFunctionType() && "Unknown scalar value");
     return RValue::get(Ptr);
   }
index 7ea8b08c238e188a02b461b83eea7422fceb77e0..008a480b9c121af0fccb6cb76f9639f5988b9a87 100644 (file)
@@ -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);