From: Justin Bogner Date: Mon, 13 Jan 2014 21:24:22 +0000 (+0000) Subject: CodeGen: Rename adjustFallThroughCount -> adjustForControlFlow X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a92b70b61f43d59a8fa4c17808de5cab36f95e9;p=clang CodeGen: Rename adjustFallThroughCount -> adjustForControlFlow adjustFallThroughCount isn't a good name, and the documentation was even worse. This commit attempts to clarify what it's for and when to use it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199139 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 940022bddd..4f0c221450 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2680,7 +2680,7 @@ EmitConditionalOperatorLValue(const AbstractConditionalOperator *expr) { eval.begin(*this); LValue lhs = EmitLValue(expr->getTrueExpr()); eval.end(*this); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); if (!lhs.isSimple()) return EmitUnsupportedLValue(expr, "conditional operator"); @@ -2694,7 +2694,7 @@ EmitConditionalOperatorLValue(const AbstractConditionalOperator *expr) { eval.begin(*this); LValue rhs = EmitLValue(expr->getFalseExpr()); eval.end(*this); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); if (!rhs.isSimple()) return EmitUnsupportedLValue(expr, "conditional operator"); rhsBlock = Builder.GetInsertBlock(); diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 1a6274e828..3395bd7d33 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -903,7 +903,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { CGF.EmitBlock(LHSBlock); Cnt.beginRegion(Builder); Visit(E->getTrueExpr()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); eval.end(CGF); assert(CGF.HaveInsertPoint() && "expression evaluation ended with no IP!"); @@ -919,7 +919,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { CGF.EmitBlock(RHSBlock); Cnt.beginElseRegion(); Visit(E->getFalseExpr()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); eval.end(CGF); CGF.EmitBlock(ContBlock); diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp index 145d94620e..938b0b331d 100644 --- a/lib/CodeGen/CGExprComplex.cpp +++ b/lib/CodeGen/CGExprComplex.cpp @@ -760,7 +760,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { CGF.EmitBlock(LHSBlock); Cnt.beginRegion(Builder); ComplexPairTy LHS = Visit(E->getTrueExpr()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); LHSBlock = Builder.GetInsertBlock(); CGF.EmitBranch(ContBlock); eval.end(CGF); @@ -769,7 +769,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { CGF.EmitBlock(RHSBlock); Cnt.beginElseRegion(); ComplexPairTy RHS = Visit(E->getFalseExpr()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); RHSBlock = Builder.GetInsertBlock(); CGF.EmitBlock(ContBlock); eval.end(CGF); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index a38c69494c..a4e0eeb9f0 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -2934,7 +2934,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CGF.EmitBlock(RHSBlock); Cnt.beginRegion(Builder); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); eval.end(CGF); // Reaquire the RHS block, as there may be subblocks inserted. @@ -3017,7 +3017,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) { CGF.EmitBlock(RHSBlock); Cnt.beginRegion(Builder); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); eval.end(CGF); @@ -3171,7 +3171,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); Value *LHS = Visit(lhsExpr); eval.end(CGF); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); LHSBlock = Builder.GetInsertBlock(); Builder.CreateBr(ContBlock); @@ -3181,7 +3181,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); Value *RHS = Visit(rhsExpr); eval.end(CGF); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); RHSBlock = Builder.GetInsertBlock(); CGF.EmitBlock(ContBlock); diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index a9c691ea0c..79db418486 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -480,7 +480,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { RunCleanupsScope ThenScope(*this); EmitStmt(S.getThen()); } - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); EmitBranch(ContBlock); // Emit the 'else' code if present. @@ -494,7 +494,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { RunCleanupsScope ElseScope(*this); EmitStmt(Else); } - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); // There is no need to emit line number for unconditional branch. if (getDebugInfo()) Builder.SetCurrentDebugLocation(llvm::DebugLoc()); @@ -569,7 +569,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S) { Cnt.beginRegion(Builder); EmitStmt(S.getBody()); } - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); BreakContinueStack.pop_back(); @@ -612,7 +612,7 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S) { RunCleanupsScope BodyScope(*this); EmitStmt(S.getBody()); } - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); BreakContinueStack.pop_back(); @@ -732,7 +732,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S) { EmitBlock(Continue.getBlock()); EmitStmt(S.getInc()); } - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); BreakContinueStack.pop_back(); @@ -815,7 +815,7 @@ void CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S) { // If there is an increment, emit it next. EmitBlock(Continue.getBlock()); EmitStmt(S.getInc()); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); BreakContinueStack.pop_back(); diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 564ea11a8f..a6ed8cb47e 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -928,7 +928,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, eval.begin(*this); EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock, TrueCount); eval.end(*this); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); Cnt.applyAdjustmentsToRegion(); return; @@ -974,7 +974,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr(const Expr *Cond, EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock, RHSCount); eval.end(*this); - Cnt.adjustFallThroughCount(); + Cnt.adjustForControlFlow(); Cnt.applyAdjustmentsToRegion(); return; diff --git a/lib/CodeGen/CodeGenPGO.h b/lib/CodeGen/CodeGenPGO.h index a459e42d29..2d1193bab0 100644 --- a/lib/CodeGen/CodeGenPGO.h +++ b/lib/CodeGen/CodeGenPGO.h @@ -200,15 +200,15 @@ public: PGO->setCurrentRegionCount(RegionCount); } - /// Control may either enter or leave the region, so the count at the end may - /// be different from the start. Call this to track that adjustment without - /// modifying the current count. Must not be called before one of beginRegion - /// or beginElseRegion. - void adjustFallThroughCount() { + /// Adjust for non-local control flow after emitting a subexpression or + /// substatement. This must be called to account for constructs such as gotos, + /// labels, and returns, so that we can ensure that our region's count is + /// correct in the code that follows. + void adjustForControlFlow() { Adjust += PGO->getCurrentRegionCount() - RegionCount; } /// Commit all adjustments to the current region. This should be called after - /// all blocks that adjust the fallthrough count have been emitted. + /// all blocks that adjust for control flow count have been emitted. void applyAdjustmentsToRegion() { PGO->setCurrentRegionCount(ParentCount + Adjust); }