[cfe-commits] r41344 - in /cfe/trunk/CodeGen: CGComplexExpr.cpp CGExpr.cpp CGStmt.cpp CodeGenFunction.h

Chris Lattner sabre at nondot.org
Thu Aug 23 16:43:34 PDT 2007


Author: lattner
Date: Thu Aug 23 18:43:33 2007
New Revision: 41344

URL: http://llvm.org/viewvc/llvm-project?rev=41344&view=rev
Log:
implement passing of complex and aggregates through call args.

Modified:
    cfe/trunk/CodeGen/CGComplexExpr.cpp
    cfe/trunk/CodeGen/CGExpr.cpp
    cfe/trunk/CodeGen/CGStmt.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/CodeGen/CGComplexExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGComplexExpr.cpp?rev=41344&r1=41343&r2=41344&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGComplexExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGComplexExpr.cpp Thu Aug 23 18:43:33 2007
@@ -314,3 +314,13 @@
   return ComplexExprEmitter(*this).Visit(const_cast<Expr*>(E));
 }
 
+/// EmitComplexExprIntoAddr - Emit the computation of the specified expression
+/// of complex type, storing into the specified Value*.
+void CodeGenFunction::EmitComplexExprIntoAddr(const Expr *E,
+                                              llvm::Value *DestAddr) {
+  assert(E && E->getType()->isComplexType() &&
+         "Invalid complex expression to emit");
+  ComplexExprEmitter Emitter(*this);
+  ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
+  Emitter.EmitStoreOfComplex(Val, DestAddr, false);
+}

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

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Thu Aug 23 18:43:33 2007
@@ -509,6 +509,27 @@
 //                             Expression Emission
 //===--------------------------------------------------------------------===//
 
+/// EmitAnyExpr - Emit an expression of any type: scalar, complex, aggregate,
+/// returning an rvalue corresponding to it.  If NeedResult is false, the
+/// result of the expression doesn't need to be generated into memory.
+RValue CodeGenFunction::EmitAnyExpr(const Expr *E, bool NeedResult) {
+  if (!hasAggregateLLVMType(E->getType()))
+    return EmitExpr(E);
+  
+  llvm::Value *DestMem = 0;
+  if (NeedResult)
+    DestMem = CreateTempAlloca(ConvertType(E->getType()));
+  
+  if (!E->getType()->isComplexType()) {
+    EmitAggExpr(E, DestMem, false);
+  } else if (NeedResult)
+    EmitComplexExprIntoAddr(E, DestMem);
+  else
+    EmitComplexExpr(E);
+  
+  return RValue::getAggregate(DestMem);
+}
+
 RValue CodeGenFunction::EmitExpr(const Expr *E) {
   assert(E && !hasAggregateLLVMType(E->getType()) &&
          "Invalid scalar expression to emit");
@@ -693,7 +714,7 @@
   
   for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
     QualType ArgTy = E->getArg(i)->getType();
-    RValue ArgVal = EmitExpr(E->getArg(i));
+    RValue ArgVal = EmitAnyExpr(E->getArg(i));
     
     // If this argument has prototype information, convert it.
     if (ArgTyIt != ArgTyEnd) {
@@ -711,7 +732,6 @@
       }
     }
     
-    
     if (ArgVal.isScalar())
       Args.push_back(ArgVal.getVal());
     else  // Pass by-address.  FIXME: Set attribute bit on call.

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

==============================================================================
--- cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/CodeGen/CGStmt.cpp Thu Aug 23 18:43:33 2007
@@ -31,12 +31,7 @@
     // Must be an expression in a stmt context.  Emit the value and ignore the
     // result.
     if (const Expr *E = dyn_cast<Expr>(S)) {
-      if (E->getType()->isComplexType()) {
-        EmitComplexExpr(E);
-      } else if (hasAggregateLLVMType(E->getType()))
-        EmitAggExpr(E, 0, false);  // Emit an aggregate, ignoring the result.
-      else
-        EmitExpr(E);
+      EmitAnyExpr(E, false);
     } else {
       printf("Unimplemented stmt!\n");
       S->dump();

Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41344&r1=41343&r2=41344&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Thu Aug 23 18:43:33 2007
@@ -340,6 +340,11 @@
   RValue EmitCompoundAssignmentResult(const CompoundAssignOperator *E,
                                       LValue LHSLV, RValue ResV);
   
+  /// EmitAnyExpr - Emit an expression of any type: scalar, complex, aggregate,
+  /// returning an rvalue corresponding to it.  If NeedResult is false, the
+  /// result of the expression doesn't need to be generated into memory.
+  RValue EmitAnyExpr(const Expr *E, bool NeedResult = true);
+  
   RValue EmitExpr(const Expr *E);
   RValue EmitIntegerLiteral(const IntegerLiteral *E);
   RValue EmitFloatingLiteral(const FloatingLiteral *E);
@@ -409,8 +414,12 @@
   void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
   
   /// EmitComplexExpr - Emit the computation of the specified expression of
-  /// complex type, ignoring the result.
+  /// complex type, returning the result.
   ComplexPairTy EmitComplexExpr(const Expr *E);
+  
+  /// EmitComplexExprIntoAddr - Emit the computation of the specified expression
+  /// of complex type, storing into the specified Value*.
+  void EmitComplexExprIntoAddr(const Expr *E, llvm::Value *DestAddr);
 };
 }  // end namespace CodeGen
 }  // end namespace clang





More information about the cfe-commits mailing list