diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-04 00:20:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-04 00:20:15 +0000 |
commit | 94f05e36488fd08e404ac409d3bcb1db1da1bd4d (patch) | |
tree | d4a14855abf00fea4d0143320d1c5790a3323ae7 | |
parent | 345dc62fd5d2980aab3ab2218dd0234f6bcea279 (diff) |
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 :)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40801 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | AST/StmtPrinter.cpp | 4 | ||||
-rw-r--r-- | CodeGen/CGExpr.cpp | 12 | ||||
-rw-r--r-- | CodeGen/CodeGenFunction.h | 2 | ||||
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 2 |
4 files changed, 17 insertions, 3 deletions
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp index bdbbc12b18..41aa6468db 100644 --- a/AST/StmtPrinter.cpp +++ b/AST/StmtPrinter.cpp @@ -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 << ")"; } diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index 9697686b1a..534376edf1 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -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 diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h index 4c79498c46..0cc5f0ddbe 100644 --- a/CodeGen/CodeGenFunction.h +++ b/CodeGen/CodeGenFunction.h @@ -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 diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 06fbbc579c..352b750534 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -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>"; }; |