]> granicus.if.org Git - clang/commitdiff
Add a fast path to the constant evaluator for integer literals. This speeds up
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 10 Dec 2011 01:10:13 +0000 (01:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 10 Dec 2011 01:10:13 +0000 (01:10 +0000)
compilation of some translation units of SPEC's 445.gobmk by ~4%, and does not
seem to cause a measurable slowdown in other cases.

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

lib/AST/ExprConstant.cpp

index 5162c625d163cd910276ae7b8373779b48407199..1ef3605f20642d1f144dc36d5704b0f1a490b96a 100644 (file)
@@ -4602,6 +4602,14 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) {
 /// 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.