[cfe-commits] r95393 - in /cfe/trunk/lib/CodeGen: CGDecl.cpp CGExpr.cpp CGStmt.cpp

Daniel Dunbar daniel at zuster.org
Fri Feb 5 09:51:33 PST 2010


Author: ddunbar
Date: Fri Feb  5 11:51:33 2010
New Revision: 95393

URL: http://llvm.org/viewvc/llvm-project?rev=95393&view=rev
Log:
IRgen: Use hasAggregateLLVMType instead of isSingleValueType() for cases that
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.

Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=95393&r1=95392&r2=95393&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Feb  5 11:51:33 2010
@@ -690,25 +690,19 @@
   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"));
+    // 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);
-    } else {
-      // Otherwise, if this is an aggregate, just use the input pointer.
-      DeclPtr = Arg;
-    }
-    Arg->setName(D.getNameAsString());
+    // 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!");

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=95393&r1=95392&r2=95393&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Feb  5 11:51:33 2010
@@ -549,14 +549,13 @@
 
   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);
   }

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=95393&r1=95392&r2=95393&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Feb  5 11:51:33 2010
@@ -861,14 +861,13 @@
                                            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);





More information about the cfe-commits mailing list