From: Justin Bogner Date: Mon, 13 Apr 2015 12:23:19 +0000 (+0000) Subject: InstrProf: Simplify getStmtCount by using an Optional X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7d930cc59db208489d79ab38219aa9f847eba26;p=clang InstrProf: Simplify getStmtCount by using an Optional git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234750 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 557828db0d..cc6ac20dd7 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -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 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); } diff --git a/lib/CodeGen/CodeGenPGO.h b/lib/CodeGen/CodeGenPGO.h index 431c850ef8..c92a057950 100644 --- a/lib/CodeGen/CodeGenPGO.h +++ b/lib/CodeGen/CodeGenPGO.h @@ -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 getStmtCount(const Stmt *S) { if (!StmtCountMap) - return false; - llvm::DenseMap::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