diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-07 01:58:44 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-03-07 01:58:44 +0000 |
| commit | 8c029611a6714624878cfd72ecbba8ab968773ea (patch) | |
| tree | 017f2d6bb9a8ff048aae0c316b2d09e24a731347 /clang/lib/CodeGen | |
| parent | 4a280ff48fd6194d5fe06df21b057d30af93a386 (diff) | |
| download | bcm5719-llvm-8c029611a6714624878cfd72ecbba8ab968773ea.tar.gz bcm5719-llvm-8c029611a6714624878cfd72ecbba8ab968773ea.zip | |
Don't even try to directly emit the value of a DeclRefExpr if that declaration
is not usable in a constant expression. ~2.5% speedup on 403.gcc / combine.c.
llvm-svn: 152193
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index d5ef402d229..8ed36aac5f1 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -214,6 +214,14 @@ public: // l-values. Value *VisitDeclRefExpr(DeclRefExpr *E) { + VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()); + if (!VD && !isa<EnumConstantDecl>(E->getDecl())) + return EmitLoadOfLValue(E); + if (VD && !VD->isUsableInConstantExpressions()) + return EmitLoadOfLValue(E); + + // This is an enumerator or a variable which is usable in constant + // expressions. Try to emit its value instead. Expr::EvalResult Result; bool IsReferenceConstant = false; QualType EvalTy = E->getType(); @@ -232,10 +240,11 @@ public: llvm::Constant *C = CGF.CGM.EmitConstantValue(Result.Val, EvalTy, &CGF); // Make sure we emit a debug reference to the global variable. - if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { + if (VD) { if (!CGF.getContext().DeclMustBeEmitted(VD)) CGF.EmitDeclRefExprDbgValue(E, C); - } else if (isa<EnumConstantDecl>(E->getDecl())) { + } else { + assert(isa<EnumConstantDecl>(E->getDecl())); CGF.EmitDeclRefExprDbgValue(E, C); } |

