From: Volodymyr Sapsai Date: Thu, 1 Nov 2018 21:57:05 +0000 (+0000) Subject: [CodeGen] Move `emitConstant` from ScalarExprEmitter to CodeGenFunction. NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2597e7eac63e1aec05fd6a8cc58bdad3e125bd86;p=clang [CodeGen] Move `emitConstant` from ScalarExprEmitter to CodeGenFunction. NFC. The goal is to use `emitConstant` in more places. Didn't move `ComplexExprEmitter::emitConstant` because it returns a different type. Reviewers: rjmccall, ahatanak Reviewed By: rjmccall Subscribers: dexonsmith, erik.pilkington, cfe-commits Differential Revision: https://reviews.llvm.org/D53725 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345897 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 738263c906..0fd19c9578 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1491,6 +1491,16 @@ CodeGenFunction::tryEmitAsConstant(const MemberExpr *ME) { return ConstantEmission(); } +llvm::Value *CodeGenFunction::emitScalarConstant( + const CodeGenFunction::ConstantEmission &Constant, Expr *E) { + assert(Constant && "not a constant"); + if (Constant.isReference()) + return EmitLoadOfLValue(Constant.getReferenceLValue(*this, E), + E->getExprLoc()) + .getScalarVal(); + return Constant.getValue(); +} + llvm::Value *CodeGenFunction::EmitLoadOfScalar(LValue lvalue, SourceLocation Loc) { return EmitLoadOfScalar(lvalue.getAddress(), lvalue.isVolatile(), diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 7b024a015c..c77f1bab5b 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -466,19 +466,10 @@ public: return CGF.getOrCreateOpaqueRValueMapping(E).getScalarVal(); } - Value *emitConstant(const CodeGenFunction::ConstantEmission &Constant, - Expr *E) { - assert(Constant && "not a constant"); - if (Constant.isReference()) - return EmitLoadOfLValue(Constant.getReferenceLValue(CGF, E), - E->getExprLoc()); - return Constant.getValue(); - } - // l-values. Value *VisitDeclRefExpr(DeclRefExpr *E) { if (CodeGenFunction::ConstantEmission Constant = CGF.tryEmitAsConstant(E)) - return emitConstant(Constant, E); + return CGF.emitScalarConstant(Constant, E); return EmitLoadOfLValue(E); } @@ -1714,7 +1705,7 @@ Value *ScalarExprEmitter::VisitConvertVectorExpr(ConvertVectorExpr *E) { Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) { if (CodeGenFunction::ConstantEmission Constant = CGF.tryEmitAsConstant(E)) { CGF.EmitIgnoredExpr(E->getBase()); - return emitConstant(Constant, E); + return CGF.emitScalarConstant(Constant, E); } else { llvm::APSInt Value; if (E->EvaluateAsInt(Value, CGF.getContext(), Expr::SE_AllowSideEffects)) { diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index d5de0a0473..f6b76294ae 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -3524,6 +3524,7 @@ public: ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr); ConstantEmission tryEmitAsConstant(const MemberExpr *ME); + llvm::Value *emitScalarConstant(const ConstantEmission &Constant, Expr *E); RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot = AggValueSlot::ignored());