]> granicus.if.org Git - clang/commitdiff
CodeGen: Introduce CodeGenPGO::setCurrentRegionUnreachable
authorJustin Bogner <mail@justinbogner.com>
Mon, 13 Jan 2014 21:24:18 +0000 (21:24 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 13 Jan 2014 21:24:18 +0000 (21:24 +0000)
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

lib/CodeGen/CGCall.cpp
lib/CodeGen/CGStmt.cpp
lib/CodeGen/CodeGenPGO.h

index 4bdd032a2b9cb80e66fe10bfa620340899dfa6f3..d31217744635c485c3c794be87315633e270dd86 100644 (file)
@@ -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
index ade6ac91852e0a4124beb0b655102027dde10f39..a9c691ea0cd9faad8b8015168f0c79fc8a54b7dc 100644 (file)
@@ -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<llvm::PHINode>(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.
index 0a0699067b12b5baddecb12ac71409b9641bf404..a459e42d2998e31678babe5e2c55910963bec903 100644 (file)
@@ -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);