]> granicus.if.org Git - clang/commitdiff
Implement codegen for __builtin_choose_expr. For example:
authorChris Lattner <sabre@nondot.org>
Sat, 4 Aug 2007 00:20:15 +0000 (00:20 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 4 Aug 2007 00:20:15 +0000 (00:20 +0000)
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 :)

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

AST/StmtPrinter.cpp
CodeGen/CGExpr.cpp
CodeGen/CodeGenFunction.h
clang.xcodeproj/project.pbxproj

index bdbbc12b1853a6694bb32748eb2253ad59ce7633..41aa6468dbf9abab7b3f829e8af0c7bea72de5c7 100644 (file)
@@ -490,9 +490,9 @@ void StmtPrinter::VisitTypesCompatibleExpr(TypesCompatibleExpr *Node) {
 void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) {
   OS << "__builtin_choose_expr(";
   PrintExpr(Node->getCond());
-  OS << ",";
+  OS << ", ";
   PrintExpr(Node->getLHS());
-  OS << ",";
+  OS << ", ";
   PrintExpr(Node->getRHS());
   OS << ")";
 }
index 9697686b1a7ccbe507b16f14b6075df138d36eba..534376edf1e14748c00ede2892dd8c0959005256 100644 (file)
@@ -637,6 +637,8 @@ RValue CodeGenFunction::EmitExpr(const Expr *E) {
   
   case Expr::ConditionalOperatorClass:
     return EmitConditionalOperator(cast<ConditionalOperator>(E));
+  case Expr::ChooseExprClass:
+    return EmitChooseExpr(cast<ChooseExpr>(E));
   }
   
 }
@@ -658,6 +660,16 @@ RValue CodeGenFunction::EmitTypesCompatibleExpr(const TypesCompatibleExpr *E) {
                                             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
index 4c79498c4626cbfaea73f8e6fe02428e3ece527e..0cc5f0ddbe040eeff4813e85fd8be8298aa1ba64 100644 (file)
@@ -58,6 +58,7 @@ namespace clang {
   class ArraySubscriptExpr;
   class OCUVectorElementExpr;
   class ConditionalOperator;
+  class ChooseExpr;
   class PreDefinedExpr;
   
   class BlockVarDecl;
@@ -399,6 +400,7 @@ public:
   
   // Conditional Operator.
   RValue EmitConditionalOperator(const ConditionalOperator *E);
+  RValue EmitChooseExpr(const ChooseExpr *E);
 };
 }  // end namespace CodeGen
 }  // end namespace clang
index 06fbbc579c48e0d3a19d8dbc558ce8c91207cfab..352b750534e6c99549492ef672c2e9ab79e4d553 100644 (file)
                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>"; };