]> granicus.if.org Git - clang/commitdiff
InstrProf: Simplify getStmtCount by using an Optional
authorJustin Bogner <mail@justinbogner.com>
Mon, 13 Apr 2015 12:23:19 +0000 (12:23 +0000)
committerJustin Bogner <mail@justinbogner.com>
Mon, 13 Apr 2015 12:23:19 +0000 (12:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234750 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenPGO.cpp
lib/CodeGen/CodeGenPGO.h

index 557828db0d025ce763c17488ac1e4b59e404d937..cc6ac20dd7b4b6832685f63eff5a928a4aef87ae 100644 (file)
@@ -880,12 +880,10 @@ llvm::MDNode *CodeGenPGO::createLoopWeights(const Stmt *Cond,
   if (!haveRegionCounts())
     return nullptr;
   uint64_t LoopCount = Cnt.getCount();
-  uint64_t CondCount = 0;
-  bool Found = getStmtCount(Cond, CondCount);
-  assert(Found && "missing expected loop condition count");
-  (void)Found;
-  if (CondCount == 0)
+  Optional<uint64_t> CondCount = getStmtCount(Cond);
+  assert(CondCount.hasValue() && "missing expected loop condition count");
+  if (*CondCount == 0)
     return nullptr;
   return createBranchWeights(LoopCount,
-                             std::max(CondCount, LoopCount) - LoopCount);
+                             std::max(*CondCount, LoopCount) - LoopCount);
 }
index 431c850ef81ea26342d5503c427bf36f92897622..c92a0579507a827ecb59db0ff9e9060a21751fc3 100644 (file)
@@ -69,23 +69,20 @@ public:
 
   /// Check if an execution count is known for a given statement. If so, return
   /// true and put the value in Count; else return false.
-  bool getStmtCount(const Stmt *S, uint64_t &Count) {
+  Optional<uint64_t> getStmtCount(const Stmt *S) {
     if (!StmtCountMap)
-      return false;
-    llvm::DenseMap<const Stmt*, uint64_t>::const_iterator
-      I = StmtCountMap->find(S);
+      return None;
+    auto I = StmtCountMap->find(S);
     if (I == StmtCountMap->end())
-      return false;
-    Count = I->second;
-    return true;
+      return None;
+    return I->second;
   }
 
   /// If the execution count for the current statement is known, record that
   /// as the current count.
   void setCurrentStmt(const Stmt *S) {
-    uint64_t Count;
-    if (getStmtCount(S, Count))
-      setCurrentRegionCount(Count);
+    if (auto Count = getStmtCount(S))
+      setCurrentRegionCount(*Count);
   }
 
   /// Calculate branch weights appropriate for PGO data