[cfe-commits] r59375 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Anders Carlsson andersca at mac.com
Sat Nov 15 12:45:50 PST 2008


Author: andersca
Date: Sat Nov 15 14:45:50 2008
New Revision: 59375

URL: http://llvm.org/viewvc/llvm-project?rev=59375&view=rev
Log:
Check in code that uses tryEvaluate for emitting constant exprs (not used yet).

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

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sat Nov 15 14:45:50 2008
@@ -836,12 +836,41 @@
                                                 CodeGenFunction *CGF) {
   QualType type = Context.getCanonicalType(E->getType());
 
+#ifdef USE_TRY_EVALUATE
+  APValue V;
+  if (E->tryEvaluate(V, Context)) {
+    // FIXME: Assert that the value doesn't have any side effects.
+    switch (V.getKind()) {
+    default: assert(0 && "unhandled value kind!");
+    case APValue::LValue: {
+      if (V.getLValueBase())
+        break;
+      
+      llvm::Constant *C = llvm::ConstantInt::get(llvm::Type::Int64Ty,
+                                                 V.getLValueOffset());
+      
+      return llvm::ConstantExpr::getIntToPtr(C, getTypes().ConvertType(type));
+    }
+    case APValue::Int:
+      llvm::Constant *C = llvm::ConstantInt::get(V.getInt());
+      
+      if (C->getType() == llvm::Type::Int1Ty) {
+        const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
+        C = llvm::ConstantExpr::getZExt(C, BoolTy);
+      }
+      return C;
+    case APValue::Float:
+      return llvm::ConstantFP::get(V.getFloat());
+    }
+  }
+#else
   if (type->isIntegerType()) {
     llvm::APSInt Value(static_cast<uint32_t>(Context.getTypeSize(type)));
     if (E->isIntegerConstantExpr(Value, Context)) {
       return llvm::ConstantInt::get(Value);
     } 
   }
+#endif
 
   llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E));
   if (C->getType() == llvm::Type::Int1Ty) {





More information about the cfe-commits mailing list