From: Justin Bogner Date: Mon, 13 Jan 2014 21:24:18 +0000 (+0000) Subject: CodeGen: Introduce CodeGenPGO::setCurrentRegionUnreachable X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1361b32e7934a5cfaffffa2bad75c25bba08e88;p=clang CodeGen: Introduce CodeGenPGO::setCurrentRegionUnreachable There are a number of places where we do PGO.setCurrentRegionCount(0) directly after an unconditional branch. Give this operation a name so that it's clearer why we're doing this. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199138 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 4bdd032a2b..d312177446 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -2184,7 +2184,7 @@ void CodeGenFunction::EmitNoreturnRuntimeCallOrInvoke(llvm::Value *callee, call->setCallingConv(getRuntimeCC()); Builder.CreateUnreachable(); } - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } /// Emits a call or invoke instruction to the given nullary runtime diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index ade6ac9185..a9c691ea0c 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -404,14 +404,14 @@ void CodeGenFunction::EmitGotoStmt(const GotoStmt &S) { EmitStopPoint(&S); EmitBranchThroughCleanup(getJumpDestForLabel(S.getLabel())); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) { if (const LabelDecl *Target = S.getConstantTarget()) { EmitBranchThroughCleanup(getJumpDestForLabel(Target)); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); return; } @@ -428,7 +428,7 @@ void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) { cast(IndGotoBB->begin())->addIncoming(V, CurBB); EmitBranch(IndGotoBB); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } void CodeGenFunction::EmitIfStmt(const IfStmt &S) { @@ -847,7 +847,7 @@ void CodeGenFunction::EmitReturnOfRValue(RValue RV, QualType Ty) { /*init*/ true); } EmitBranchThroughCleanup(ReturnBlock); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } /// EmitReturnStmt - Note that due to GCC extensions, this can have an operand @@ -920,7 +920,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) { cleanupScope.ForceCleanup(); EmitBranchThroughCleanup(ReturnBlock); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) { @@ -950,7 +950,7 @@ void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) { if (BC.CountBreak) BC.LoopCnt->getBreakCounter().beginRegion(Builder); EmitBranchThroughCleanup(BC.BreakBlock); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) { @@ -967,7 +967,7 @@ void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) { // non-local exits in PGO instrumentation. BC.LoopCnt->getContinueCounter().beginRegion(Builder); EmitBranchThroughCleanup(BC.ContinueBlock); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); } /// EmitCaseStmtRange - If case statement range is not too big then @@ -1438,7 +1438,7 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) { // Clear the insertion point to indicate we are in unreachable code. Builder.ClearInsertionPoint(); - PGO.setCurrentRegionCount(0); + PGO.setCurrentRegionUnreachable(); // All break statements jump to NextBlock. If BreakContinueStack is non-empty // then reuse last ContinueBlock and that block's counter. diff --git a/lib/CodeGen/CodeGenPGO.h b/lib/CodeGen/CodeGenPGO.h index 0a0699067b..a459e42d29 100644 --- a/lib/CodeGen/CodeGenPGO.h +++ b/lib/CodeGen/CodeGenPGO.h @@ -74,6 +74,10 @@ public: /// of changes to the most recent counter from control flow and non-local /// exits. void setCurrentRegionCount(uint64_t Count) { CurrentRegionCount = Count; } + /// Indicate that the current region is never reached, and thus should have a + /// counter value of zero. This is important so that subsequent regions can + /// correctly track their parent counts. + void setCurrentRegionUnreachable() { setCurrentRegionCount(0); } /// Calculate branch weights appropriate for PGO data llvm::MDNode *createBranchWeights(uint64_t TrueCount, uint64_t FalseCount);