[cfe-commits] r57161 - /cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Chris Lattner sabre at nondot.org
Sun Oct 5 23:56:41 PDT 2008


Author: lattner
Date: Mon Oct  6 01:56:41 2008
New Revision: 57161

URL: http://llvm.org/viewvc/llvm-project?rev=57161&view=rev
Log:
always try to fold a builtin before emitting it.  In the future
it is possible that a builtin could sometimes be folded (e.g. __builtin_clz)
if it's operand is a constant.

Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=57161&r1=57160&r2=57161&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Oct  6 01:56:41 2008
@@ -37,30 +37,17 @@
 }
 
 RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
-  switch (BuiltinID) {
-  default: break;  // Handle intrinsics and libm functions below.
-      
-  case Builtin::BI__builtin_huge_val:
-  case Builtin::BI__builtin_huge_valf:
-  case Builtin::BI__builtin_huge_vall:
-  case Builtin::BI__builtin_inf:
-  case Builtin::BI__builtin_inff:
-  case Builtin::BI__builtin_infl:
-  case Builtin::BI__builtin_nan:
-  case Builtin::BI__builtin_nanf:
-  case Builtin::BI__builtin_nanl:
-  case Builtin::BI__builtin_classify_type:
-  case Builtin::BI__builtin_constant_p: {
-    APValue Result;
-    if (!E->tryEvaluate(Result, CGM.getContext()))
-      break;  // Not a constant, expand below.
-    
+  // See if we can constant fold this builtin.  If so, don't emit it at all.
+  APValue Result;
+  if (E->tryEvaluate(Result, CGM.getContext())) {
     if (Result.isInt())
       return RValue::get(llvm::ConstantInt::get(Result.getInt()));
     assert(Result.isFloat() && "Unsupported constant type");
     return RValue::get(llvm::ConstantFP::get(Result.getFloat()));
   }
       
+  switch (BuiltinID) {
+  default: break;  // Handle intrinsics and libm functions below.
   case Builtin::BI__builtin___CFStringMakeConstantString: {
     const Expr *Arg = E->getArg(0);
     





More information about the cfe-commits mailing list