[cfe-commits] r146306 - /cfe/trunk/lib/AST/ExprConstant.cpp

Richard Smith richard-llvm at metafoo.co.uk
Fri Dec 9 17:10:13 PST 2011


Author: rsmith
Date: Fri Dec  9 19:10:13 2011
New Revision: 146306

URL: http://llvm.org/viewvc/llvm-project?rev=146306&view=rev
Log:
Add a fast path to the constant evaluator for integer literals. This speeds up
compilation of some translation units of SPEC's 445.gobmk by ~4%, and does not
seem to cause a measurable slowdown in other cases.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=146306&r1=146305&r2=146306&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Dec  9 19:10:13 2011
@@ -4602,6 +4602,14 @@
 /// in Result. If this expression is a glvalue, an lvalue-to-rvalue conversion
 /// will be applied to the result.
 bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const {
+  // Fast-path evaluations of integer literals, since we sometimes see files
+  // containing vast quantities of these.
+  if (const IntegerLiteral *L = dyn_cast<IntegerLiteral>(this)) {
+    Result.Val = APValue(APSInt(L->getValue(),
+                                L->getType()->isUnsignedIntegerType()));
+    return true;
+  }
+
   // FIXME: Evaluating initializers for large arrays can cause performance
   // problems, and we don't use such values yet. Once we have a more efficient
   // array representation, this should be reinstated, and used by CodeGen.





More information about the cfe-commits mailing list