[cfe-commits] r41217 - in /cfe/trunk: CodeGen/CGAggExpr.cpp CodeGen/CGComplexExpr.cpp CodeGen/CGStmt.cpp CodeGen/CodeGenFunction.h clang.xcodeproj/project.pbxproj

Chris Lattner sabre at nondot.org
Mon Aug 20 22:54:01 PDT 2007


Author: lattner
Date: Tue Aug 21 00:54:00 2007
New Revision: 41217

URL: http://llvm.org/viewvc/llvm-project?rev=41217&view=rev
Log:
Split complex arithmetic codegen out from aggregate codegen.
This means that we get rid of tons of intermediate allocas.  For
example:

void foo(double _Complex a, double _Complex b) {
   a = b+a+a;
}

this used to have 4 temporary allocas, now it has zero of them.
This also simplifies the individual visitor methods because they
now can all operate on real/imag pairs instead of having to 
load/store all over the place.


Added:
    cfe/trunk/CodeGen/CGComplexExpr.cpp
Modified:
    cfe/trunk/CodeGen/CGAggExpr.cpp
    cfe/trunk/CodeGen/CGStmt.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h
    cfe/trunk/clang.xcodeproj/project.pbxproj

Modified: cfe/trunk/CodeGen/CGAggExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGAggExpr.cpp?rev=41217&r1=41216&r2=41217&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGAggExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGAggExpr.cpp Tue Aug 21 00:54:00 2007
@@ -45,10 +45,6 @@
   /// then loads the result into DestPtr.
   void EmitAggLoadOfLValue(const Expr *E);
   
-  /// EmitComplexExpr - Emit the specified complex expression, returning the
-  /// real and imaginary values.
-  ComplexPairTy EmitComplexExpr(const Expr *E);
-
   
   //===--------------------------------------------------------------------===//
   //                            Visitor Methods
@@ -70,7 +66,6 @@
   //  case Expr::CastExprClass: 
   //  case Expr::CallExprClass:
   void VisitBinaryOperator(const BinaryOperator *BO);
-  void VisitBinAdd(const BinaryOperator *E);
   void VisitBinAssign(const BinaryOperator *E);
 
   
@@ -83,22 +78,6 @@
 //                                Utilities
 //===----------------------------------------------------------------------===//
 
-/// EmitComplexExpr - Emit the specified complex expression, returning the
-/// real and imaginary values.
-AggExprEmitter::ComplexPairTy AggExprEmitter::EmitComplexExpr(const Expr *E) {
-  // Create a temporary alloca to hold this result.
-  llvm::Value *TmpPtr = CGF.CreateTempAlloca(CGF.ConvertType(E->getType()));
-
-  // Emit the expression into TmpPtr.
-  AggExprEmitter(CGF, TmpPtr, false).Visit(const_cast<Expr*>(E));
-
-  // Return the real/imag values by reloading them from the stack.
-  llvm::Value *Real, *Imag;
-  CGF.EmitLoadOfComplex(TmpPtr, Real, Imag);
-  return std::make_pair(Real, Imag);
-}
-
-
 /// EmitAggLoadOfLValue - Given an expression with aggregate type that
 /// represents a value lvalue, this method emits the address of the lvalue,
 /// then loads the result into DestPtr.
@@ -122,143 +101,6 @@
 void AggExprEmitter::VisitBinaryOperator(const BinaryOperator *E) {
   fprintf(stderr, "Unimplemented aggregate binary expr!\n");
   E->dump();
-#if 0
-  switch (E->getOpcode()) {
-  default:
-    return;
-  case BinaryOperator::Mul:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitMul(LHS, RHS, E->getType());
-  case BinaryOperator::Div:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitDiv(LHS, RHS, E->getType());
-  case BinaryOperator::Rem:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitRem(LHS, RHS, E->getType());
-  case BinaryOperator::Add:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    if (!E->getType()->isPointerType())
-      return EmitAdd(LHS, RHS, E->getType());
-      
-      return EmitPointerAdd(LHS, E->getLHS()->getType(),
-                            RHS, E->getRHS()->getType(), E->getType());
-  case BinaryOperator::Sub:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    
-    if (!E->getLHS()->getType()->isPointerType())
-      return EmitSub(LHS, RHS, E->getType());
-      
-      return EmitPointerSub(LHS, E->getLHS()->getType(),
-                            RHS, E->getRHS()->getType(), E->getType());
-  case BinaryOperator::Shl:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitShl(LHS, RHS, E->getType());
-  case BinaryOperator::Shr:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitShr(LHS, RHS, E->getType());
-  case BinaryOperator::And:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitAnd(LHS, RHS, E->getType());
-  case BinaryOperator::Xor:
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitXor(LHS, RHS, E->getType());
-  case BinaryOperator::Or :
-    LHS = EmitExpr(E->getLHS());
-    RHS = EmitExpr(E->getRHS());
-    return EmitOr(LHS, RHS, E->getType());
-  case BinaryOperator::MulAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitMul(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::DivAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitDiv(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::RemAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitRem(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::AddAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitAdd(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::SubAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitSub(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::ShlAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitShl(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::ShrAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitShr(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::AndAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitAnd(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::OrAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitOr(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::XorAssign: {
-    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
-    LValue LHSLV;
-    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
-    LHS = EmitXor(LHS, RHS, CAO->getComputationType());
-    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
-  }
-  case BinaryOperator::Comma: return EmitBinaryComma(E);
-  }
-#endif
-}
-
-void AggExprEmitter::VisitBinAdd(const BinaryOperator *E) {
-  // This must be a complex number.
-  ComplexPairTy LHS = EmitComplexExpr(E->getLHS());
-  ComplexPairTy RHS = EmitComplexExpr(E->getRHS());
-  
-  llvm::Value *ResR = CGF.Builder.CreateAdd(LHS.first,  RHS.first,  "add.r");
-  llvm::Value *ResI = CGF.Builder.CreateAdd(LHS.second, RHS.second, "add.i");
-  
-  CGF.EmitStoreOfComplex(ResR, ResI, DestPtr /*FIXME: Volatile!*/);
 }
 
 void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
@@ -275,7 +117,6 @@
   }
 }
 
-
 void AggExprEmitter::VisitConditionalOperator(const ConditionalOperator *E) {
   llvm::BasicBlock *LHSBlock = new llvm::BasicBlock("cond.?");
   llvm::BasicBlock *RHSBlock = new llvm::BasicBlock("cond.:");

Added: cfe/trunk/CodeGen/CGComplexExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGComplexExpr.cpp?rev=41217&view=auto

==============================================================================
--- cfe/trunk/CodeGen/CGComplexExpr.cpp (added)
+++ cfe/trunk/CodeGen/CGComplexExpr.cpp Tue Aug 21 00:54:00 2007
@@ -0,0 +1,313 @@
+//===--- CGComplexExpr.cpp - Emit LLVM Code for Complex Exprs -------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Expr nodes with complex types as LLVM code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CodeGenFunction.h"
+#include "CodeGenModule.h"
+#include "clang/AST/AST.h"
+#include "llvm/Constants.h"
+#include "llvm/Function.h"
+#include "llvm/Support/Compiler.h"
+using namespace clang;
+using namespace CodeGen;
+
+//===----------------------------------------------------------------------===//
+//                        Aggregate Expression Emitter
+//===----------------------------------------------------------------------===//
+
+typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
+
+namespace  {
+class VISIBILITY_HIDDEN ComplexExprEmitter
+  : public StmtVisitor<ComplexExprEmitter, ComplexPairTy> {
+  CodeGenFunction &CGF;
+public:
+  ComplexExprEmitter(CodeGenFunction &cgf) : CGF(cgf) {
+  }
+
+  
+  //===--------------------------------------------------------------------===//
+  //                               Utilities
+  //===--------------------------------------------------------------------===//
+
+  /// EmitLoadOfLValue - Given an expression with complex type that represents a
+  /// value l-value, this method emits the address of the l-value, then loads
+  /// and returns the result.
+  ComplexPairTy EmitLoadOfLValue(const Expr *E);
+  
+  
+  //===--------------------------------------------------------------------===//
+  //                            Visitor Methods
+  //===--------------------------------------------------------------------===//
+  
+  ComplexPairTy VisitStmt(Stmt *S) {
+    fprintf(stderr, "Unimplemented agg expr!\n");
+    S->dump();
+    return ComplexPairTy();
+  }
+  ComplexPairTy VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr());}
+
+  // l-values.
+  ComplexPairTy VisitDeclRefExpr(DeclRefExpr *DRE) {
+    return EmitLoadOfLValue(DRE);
+  }
+  //  case Expr::ArraySubscriptExprClass:
+
+  // Operators.
+  //  case Expr::UnaryOperatorClass:
+  //  case Expr::ImplicitCastExprClass:
+  //  case Expr::CastExprClass: 
+  //  case Expr::CallExprClass:
+  ComplexPairTy VisitBinaryOperator(const BinaryOperator *BO);
+  ComplexPairTy VisitBinAdd        (const BinaryOperator *E);
+  ComplexPairTy VisitBinAssign     (const BinaryOperator *E);
+
+  
+  ComplexPairTy VisitConditionalOperator(const ConditionalOperator *CO);
+  //  case Expr::ChooseExprClass:
+};
+}  // end anonymous namespace.
+
+//===----------------------------------------------------------------------===//
+//                                Utilities
+//===----------------------------------------------------------------------===//
+
+/// EmitLoadOfLValue - Given an expression with complex type that represents a
+/// value l-value, this method emits the address of the l-value, then loads
+/// and returns the result.
+ComplexPairTy ComplexExprEmitter::EmitLoadOfLValue(const Expr *E) {
+  LValue LV = CGF.EmitLValue(E);
+  assert(LV.isSimple() && "Can't have complex bitfield, vector, etc");
+  
+  // Load the real/imag values.
+  llvm::Value *Real, *Imag;
+  CGF.EmitLoadOfComplex(LV.getAddress(), Real, Imag);
+  return ComplexPairTy(Real, Imag);
+}
+
+//===----------------------------------------------------------------------===//
+//                            Visitor Methods
+//===----------------------------------------------------------------------===//
+
+ComplexPairTy ComplexExprEmitter::VisitBinaryOperator(const BinaryOperator *E) {
+  fprintf(stderr, "Unimplemented aggregate binary expr!\n");
+  E->dump();
+  return ComplexPairTy();
+#if 0
+  switch (E->getOpcode()) {
+  default:
+    return;
+  case BinaryOperator::Mul:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitMul(LHS, RHS, E->getType());
+  case BinaryOperator::Div:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitDiv(LHS, RHS, E->getType());
+  case BinaryOperator::Rem:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitRem(LHS, RHS, E->getType());
+  case BinaryOperator::Add:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    if (!E->getType()->isPointerType())
+      return EmitAdd(LHS, RHS, E->getType());
+      
+      return EmitPointerAdd(LHS, E->getLHS()->getType(),
+                            RHS, E->getRHS()->getType(), E->getType());
+  case BinaryOperator::Sub:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    
+    if (!E->getLHS()->getType()->isPointerType())
+      return EmitSub(LHS, RHS, E->getType());
+      
+      return EmitPointerSub(LHS, E->getLHS()->getType(),
+                            RHS, E->getRHS()->getType(), E->getType());
+  case BinaryOperator::Shl:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitShl(LHS, RHS, E->getType());
+  case BinaryOperator::Shr:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitShr(LHS, RHS, E->getType());
+  case BinaryOperator::And:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitAnd(LHS, RHS, E->getType());
+  case BinaryOperator::Xor:
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitXor(LHS, RHS, E->getType());
+  case BinaryOperator::Or :
+    LHS = EmitExpr(E->getLHS());
+    RHS = EmitExpr(E->getRHS());
+    return EmitOr(LHS, RHS, E->getType());
+  case BinaryOperator::MulAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitMul(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::DivAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitDiv(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::RemAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitRem(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::AddAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitAdd(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::SubAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitSub(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::ShlAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitShl(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::ShrAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitShr(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::AndAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitAnd(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::OrAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitOr(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::XorAssign: {
+    const CompoundAssignOperator *CAO = cast<CompoundAssignOperator>(E);
+    LValue LHSLV;
+    EmitCompoundAssignmentOperands(CAO, LHSLV, LHS, RHS);
+    LHS = EmitXor(LHS, RHS, CAO->getComputationType());
+    return EmitCompoundAssignmentResult(CAO, LHSLV, LHS);
+  }
+  case BinaryOperator::Comma: return EmitBinaryComma(E);
+  }
+#endif
+}
+
+ComplexPairTy ComplexExprEmitter::VisitBinAdd(const BinaryOperator *E) {
+  // This must be a complex number.
+  ComplexPairTy LHS = Visit(E->getLHS());
+  ComplexPairTy RHS = Visit(E->getRHS());
+  
+  llvm::Value *ResR = CGF.Builder.CreateAdd(LHS.first,  RHS.first,  "add.r");
+  llvm::Value *ResI = CGF.Builder.CreateAdd(LHS.second, RHS.second, "add.i");
+
+  return ComplexPairTy(ResR, ResI);
+}
+
+ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  assert(E->getLHS()->getType().getCanonicalType() ==
+         E->getRHS()->getType().getCanonicalType() && "Invalid assignment");
+  // Emit the RHS.
+  ComplexPairTy Val = Visit(E->getRHS());
+
+  // Compute the address to store into.
+  LValue LHS = CGF.EmitLValue(E->getLHS());
+  
+  // Store into it.
+  // FIXME: Volatility!
+  CGF.EmitStoreOfComplex(Val.first, Val.second, LHS.getAddress());
+  return Val;
+}
+
+
+ComplexPairTy ComplexExprEmitter::
+VisitConditionalOperator(const ConditionalOperator *E) {
+  llvm::BasicBlock *LHSBlock = new llvm::BasicBlock("cond.?");
+  llvm::BasicBlock *RHSBlock = new llvm::BasicBlock("cond.:");
+  llvm::BasicBlock *ContBlock = new llvm::BasicBlock("cond.cont");
+  
+  llvm::Value *Cond = CGF.EvaluateExprAsBool(E->getCond());
+  CGF.Builder.CreateCondBr(Cond, LHSBlock, RHSBlock);
+  
+  CGF.EmitBlock(LHSBlock);
+  
+  // Handle the GNU extension for missing LHS.
+  assert(E->getLHS() && "Must have LHS for aggregate value");
+
+  ComplexPairTy LHS = Visit(E->getLHS());
+  CGF.Builder.CreateBr(ContBlock);
+  LHSBlock = CGF.Builder.GetInsertBlock();
+  
+  CGF.EmitBlock(RHSBlock);
+  
+  ComplexPairTy RHS = Visit(E->getRHS());
+  CGF.Builder.CreateBr(ContBlock);
+  RHSBlock = CGF.Builder.GetInsertBlock();
+  
+  CGF.EmitBlock(ContBlock);
+  
+  // Create a PHI node for the real part.
+  llvm::PHINode *RealPN = CGF.Builder.CreatePHI(LHS.first->getType(), "cond.r");
+  RealPN->reserveOperandSpace(2);
+  RealPN->addIncoming(LHS.first, LHSBlock);
+  RealPN->addIncoming(RHS.first, RHSBlock);
+
+  // Create a PHI node for the imaginary part.
+  llvm::PHINode *ImagPN = CGF.Builder.CreatePHI(LHS.first->getType(), "cond.i");
+  ImagPN->reserveOperandSpace(2);
+  ImagPN->addIncoming(LHS.second, LHSBlock);
+  ImagPN->addIncoming(RHS.second, RHSBlock);
+  
+  return ComplexPairTy(RealPN, ImagPN);
+}
+
+//===----------------------------------------------------------------------===//
+//                         Entry Point into this File
+//===----------------------------------------------------------------------===//
+
+/// EmitComplexExpr - Emit the computation of the specified expression of
+/// complex type, ignoring the result.
+void CodeGenFunction::EmitComplexExpr(const Expr *E) {
+  assert(E && E->getType()->isComplexType() &&
+         "Invalid complex expression to emit");
+  
+  ComplexExprEmitter(*this).Visit(const_cast<Expr*>(E));
+}
+

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

==============================================================================
--- cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/CodeGen/CGStmt.cpp Tue Aug 21 00:54:00 2007
@@ -31,7 +31,9 @@
     // Must be an expression in a stmt context.  Emit the value and ignore the
     // result.
     if (const Expr *E = dyn_cast<Expr>(S)) {
-      if (hasAggregateLLVMType(E->getType()))
+      if (E->getType()->isComplexType()) {
+        EmitComplexExpr(E);
+      } else if (hasAggregateLLVMType(E->getType()))
         EmitAggExpr(E, 0, false);  // Emit an aggregate, ignoring the result.
       else
         EmitExpr(E);

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Tue Aug 21 00:54:00 2007
@@ -413,6 +413,10 @@
   /// aggregate type.  The result is computed into DestPtr.  Note that if
   /// DestPtr is null, the value of the aggregate expression is not needed.
   void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
+  
+  /// EmitComplexExpr - Emit the computation of the specified expression of
+  /// complex type, ignoring the result.
+  void EmitComplexExpr(const Expr *E);
 };
 }  // end namespace CodeGen
 }  // end namespace clang

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41217&r1=41216&r2=41217&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Aug 21 00:54:00 2007
@@ -25,6 +25,7 @@
 		DE17336E0B068DC20080B521 /* DeclSpec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE17336D0B068DC20080B521 /* DeclSpec.cpp */; };
 		DE1733700B068DC60080B521 /* DeclSpec.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE17336F0B068DC60080B521 /* DeclSpec.h */; };
 		DE1F22030A7D852A00FBF588 /* Parser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F22020A7D852A00FBF588 /* Parser.h */; };
+		DE224FF80C7AA98800D370A5 /* CGComplexExpr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE224FF70C7AA98800D370A5 /* CGComplexExpr.cpp */; };
 		DE344AB80AE5DF6D00DBC861 /* HeaderSearch.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE344AB70AE5DF6D00DBC861 /* HeaderSearch.h */; };
 		DE344B540AE5E46C00DBC861 /* HeaderSearch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE344B530AE5E46C00DBC861 /* HeaderSearch.cpp */; };
 		DE3450D70AEB543100DBC861 /* DirectoryLookup.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3450D60AEB543100DBC861 /* DirectoryLookup.h */; };
@@ -213,6 +214,7 @@
 		DE17336D0B068DC20080B521 /* DeclSpec.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = DeclSpec.cpp; path = Parse/DeclSpec.cpp; sourceTree = "<group>"; };
 		DE17336F0B068DC60080B521 /* DeclSpec.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DeclSpec.h; path = clang/Parse/DeclSpec.h; sourceTree = "<group>"; };
 		DE1F22020A7D852A00FBF588 /* Parser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Parser.h; path = clang/Parse/Parser.h; sourceTree = "<group>"; };
+		DE224FF70C7AA98800D370A5 /* CGComplexExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = CGComplexExpr.cpp; path = CodeGen/CGComplexExpr.cpp; sourceTree = "<group>"; };
 		DE344AB70AE5DF6D00DBC861 /* HeaderSearch.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HeaderSearch.h; sourceTree = "<group>"; };
 		DE344B530AE5E46C00DBC861 /* HeaderSearch.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HeaderSearch.cpp; sourceTree = "<group>"; };
 		DE3450D60AEB543100DBC861 /* DirectoryLookup.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DirectoryLookup.h; sourceTree = "<group>"; };
@@ -433,6 +435,7 @@
 				1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */,
 				DE4264FB0C113592005A861D /* CGDecl.cpp */,
 				DEF2EFF20C6CDD74000C4259 /* CGAggExpr.cpp */,
+				DE224FF70C7AA98800D370A5 /* CGComplexExpr.cpp */,
 				DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */,
 				DE4772F90C10EAE5002239E8 /* CGStmt.cpp */,
 				DE928B120C05659200231DA4 /* ModuleBuilder.cpp */,
@@ -688,6 +691,7 @@
 				DEF2EFF30C6CDD74000C4259 /* CGAggExpr.cpp in Sources */,
 				DEF2F0100C6CFED5000C4259 /* SemaChecking.cpp in Sources */,
 				1ABC36940C7A4BDC006DB0AB /* CGBuiltin.cpp in Sources */,
+				DE224FF80C7AA98800D370A5 /* CGComplexExpr.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};





More information about the cfe-commits mailing list