From de0fe07eef6419bfa253b47e594f070c31cdbff2 Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 15 Aug 2017 21:42:52 +0000 Subject: Extract IRGen's constant-emitter into its own helper class and clean up the interface. The ultimate goal here is to make it easier to do some more interesting things in constant emission, like emit constant initializers that have ignorable side-effects, or doing the majority of an initialization in-place and then patching up the last few things with calls. But for now this is mostly just a refactoring. llvm-svn: 310964 --- clang/lib/CodeGen/CGExpr.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CGExpr.cpp') diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index cd7911a6046b..0217efb9fb4f 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -20,6 +20,7 @@ #include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "ConstantEmitter.h" #include "TargetInfo.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" @@ -356,7 +357,7 @@ static Address createReferenceTemporary(CodeGenFunction &CGF, if (CGF.CGM.getCodeGenOpts().MergeAllConstants && (Ty->isArrayType() || Ty->isRecordType()) && CGF.CGM.isTypeConstant(Ty, true)) - if (llvm::Constant *Init = CGF.CGM.EmitConstantExpr(Inner, Ty, &CGF)) { + if (auto Init = ConstantEmitter(CGF).tryEmitAbstract(Inner, Ty)) { if (auto AddrSpace = CGF.getTarget().getConstantAddressSpace()) { auto AS = AddrSpace.getValue(); auto *GV = new llvm::GlobalVariable( @@ -1318,7 +1319,8 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) { return ConstantEmission(); // Emit as a constant. - llvm::Constant *C = CGM.EmitConstantValue(result.Val, resultType, this); + auto C = ConstantEmitter(*this).emitAbstract(refExpr->getLocation(), + result.Val, resultType); // Make sure we emit a debug reference to the global variable. // This should probably fire even for @@ -2283,7 +2285,9 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { !(E->refersToEnclosingVariableOrCapture() && CapturedStmtInfo && LocalDeclMap.count(VD))) { llvm::Constant *Val = - CGM.EmitConstantValue(*VD->evaluateValue(), VD->getType(), this); + ConstantEmitter(*this).emitAbstract(E->getLocation(), + *VD->evaluateValue(), + VD->getType()); assert(Val && "failed to emit reference constant expression"); // FIXME: Eventually we will want to emit vector element references. -- cgit v1.2.3