[cfe-commits] r40801 - in /cfe/trunk: AST/StmtPrinter.cpp CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h clang.xcodeproj/project.pbxproj

Chris Lattner sabre at nondot.org
Fri Aug 3 17:20:15 PDT 2007


Author: lattner
Date: Fri Aug  3 19:20:15 2007
New Revision: 40801

URL: http://llvm.org/viewvc/llvm-project?rev=40801&view=rev
Log:
Implement codegen for __builtin_choose_expr.  For example:

struct X { int A; };

void foo() {
  struct X s;
  int i;
  i = __builtin_choose_expr(0, s, i);
}

compiles to:

        %tmp = load i32* %i             ; <i32> [#uses=1]
        store i32 %tmp, i32* %i

wow :)


Modified:
    cfe/trunk/AST/StmtPrinter.cpp
    cfe/trunk/CodeGen/CGExpr.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h
    cfe/trunk/clang.xcodeproj/project.pbxproj

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=40801&r1=40800&r2=40801&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Fri Aug  3 19:20:15 2007
@@ -490,9 +490,9 @@
 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
   OS << "__builtin_choose_expr(";
   PrintExpr(Node->getCond());
-  OS << ",";
+  OS << ", ";
   PrintExpr(Node->getLHS());
-  OS << ",";
+  OS << ", ";
   PrintExpr(Node->getRHS());
   OS << ")";
 }

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

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Aug  3 19:20:15 2007
@@ -637,6 +637,8 @@
   
   case Expr::ConditionalOperatorClass:
     return EmitConditionalOperator(cast<ConditionalOperator>(E));
+  case Expr::ChooseExprClass:
+    return EmitChooseExpr(cast<ChooseExpr>(E));
   }
   
 }
@@ -658,6 +660,16 @@
                                             E->typesAreCompatible()));
 }
 
+/// EmitChooseExpr - Implement __builtin_choose_expr.
+RValue CodeGenFunction::EmitChooseExpr(const ChooseExpr *E) {
+  llvm::APSInt CondVal(32);
+  bool IsConst = E->getCond()->isIntegerConstantExpr(CondVal, getContext());
+  assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst;
+  
+  // Emit the LHS or RHS as appropriate.
+  return EmitExpr(CondVal != 0 ? E->getLHS() : E->getRHS());
+}
+
 
 RValue CodeGenFunction::EmitArraySubscriptExprRV(const ArraySubscriptExpr *E) {
   // Emit subscript expressions in rvalue context's.  For most cases, this just

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Fri Aug  3 19:20:15 2007
@@ -58,6 +58,7 @@
   class ArraySubscriptExpr;
   class OCUVectorElementExpr;
   class ConditionalOperator;
+  class ChooseExpr;
   class PreDefinedExpr;
   
   class BlockVarDecl;
@@ -399,6 +400,7 @@
   
   // Conditional Operator.
   RValue EmitConditionalOperator(const ConditionalOperator *E);
+  RValue EmitChooseExpr(const ChooseExpr *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=40801&r1=40800&r2=40801&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Aug  3 19:20:15 2007
@@ -196,7 +196,7 @@
 		1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
 		84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = Parse/AttributeList.cpp; sourceTree = "<group>"; };
 		84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; };
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
 		DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };





More information about the cfe-commits mailing list