diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-28 19:48:30 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-28 19:48:30 +0000 |
commit | 80d4b55db94db2172a04617d1a80feca6bbcea5c (patch) | |
tree | 04bad08faed06c04c4580572a8de2b877768a108 /lib/CodeGen | |
parent | 0e743b1582d53d3ebb2074da881e00bfb759f250 (diff) |
Small refactoring and simplification of constant evaluation and some of its
clients. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147318 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 1 | ||||
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 16 | ||||
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 16 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 1 |
5 files changed, 20 insertions, 26 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 2a467b59bc..3e5a6772eb 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -16,7 +16,6 @@ #include "CodeGenModule.h" #include "CGObjCRuntime.h" #include "clang/Basic/TargetInfo.h" -#include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/Basic/TargetBuiltins.h" diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index af6d25d363..f48157f48c 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1107,18 +1107,18 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) { CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); CollectVTableInfo(CXXDecl, Unit, EltTys); } - + // Collect static variables with initializers. for (RecordDecl::decl_iterator I = RD->decls_begin(), E = RD->decls_end(); I != E; ++I) if (const VarDecl *V = dyn_cast<VarDecl>(*I)) { - if (const Expr *Init = V->getInit()) { - Expr::EvalResult Result; - if (Init->EvaluateAsRValue(Result, CGM.getContext()) && - Result.Val.isInt()) { - llvm::ConstantInt *CI - = llvm::ConstantInt::get(CGM.getLLVMContext(), Result.Val.getInt()); - + llvm::SmallVector<PartialDiagnosticAt, 8> Notes; + if (V->getInit() && V->evaluateValue(Notes)) { + APValue *Value = V->getEvaluatedValue(); + if (Value && Value->isInt()) { + llvm::ConstantInt *CI + = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt()); + // Create the descriptor for static variable. llvm::DIFile VUnit = getOrCreateFile(V->getLocation()); StringRef VName = V->getName(); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index e7620af24d..c2aec36ee8 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -801,13 +801,13 @@ Value *ScalarExprEmitter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { return Builder.CreateShuffleVector(V1, V2, SV, "shuffle"); } Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) { - Expr::EvalResult Result; - if (E->EvaluateAsRValue(Result, CGF.getContext()) && Result.Val.isInt()) { + llvm::APSInt Value; + if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects)) { if (E->isArrow()) CGF.EmitScalarExpr(E->getBase()); else EmitLValue(E->getBase()); - return Builder.getInt(Result.Val.getInt()); + return Builder.getInt(Value); } // Emit debug info for aggregate now, if it was delayed to reduce @@ -1466,9 +1466,9 @@ Value *ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *E) { Value *ScalarExprEmitter::VisitOffsetOfExpr(OffsetOfExpr *E) { // Try folding the offsetof to a constant. - Expr::EvalResult EvalResult; - if (E->EvaluateAsRValue(EvalResult, CGF.getContext())) - return Builder.getInt(EvalResult.Val.getInt()); + llvm::APSInt Value; + if (E->EvaluateAsInt(Value, CGF.getContext())) + return Builder.getInt(Value); // Loop over the components of the offsetof to compute the value. unsigned n = E->getNumComponents(); @@ -1589,9 +1589,7 @@ ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr( // If this isn't sizeof(vla), the result must be constant; use the constant // folding logic so we don't have to duplicate it here. - Expr::EvalResult Result; - E->EvaluateAsRValue(Result, CGF.getContext()); - return Builder.getInt(Result.Val.getInt()); + return Builder.getInt(E->EvaluateKnownConstInt(CGF.getContext())); } Value *ScalarExprEmitter::VisitUnaryReal(const UnaryOperator *E) { diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 0a5efe03be..62d18ea8ee 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -18,7 +18,6 @@ #include "CGDebugInfo.h" #include "CGException.h" #include "clang/Basic/TargetInfo.h" -#include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" @@ -520,15 +519,14 @@ bool CodeGenFunction:: ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APInt &ResultInt) { // FIXME: Rename and handle conversion of other evaluatable things // to bool. - Expr::EvalResult Result; - if (!Cond->EvaluateAsRValue(Result, getContext()) || !Result.Val.isInt() || - Result.HasSideEffects) + llvm::APSInt Int; + if (!Cond->EvaluateAsInt(Int, getContext())) return false; // Not foldable, not integer or not fully evaluatable. - + if (CodeGenFunction::ContainsLabel(Cond)) return false; // Contains a label. - - ResultInt = Result.Val.getInt(); + + ResultInt = Int; return true; } diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index f6b05c8c0f..105cfbec82 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -43,7 +43,6 @@ namespace llvm { } namespace clang { - class APValue; class ASTContext; class BlockDecl; class CXXDestructorDecl; |