diff options
author | Justin Bogner <mail@justinbogner.com> | 2015-04-13 12:23:19 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2015-04-13 12:23:19 +0000 |
commit | 1c21c28b9e0b8c90dbbb23e23be008a258fd6e6b (patch) | |
tree | ba3c7015d6306160748bffa80e7111301b945624 /clang/lib/CodeGen | |
parent | cced470374a43dda437e3413673971bd204eff75 (diff) | |
download | bcm5719-llvm-1c21c28b9e0b8c90dbbb23e23be008a258fd6e6b.tar.gz bcm5719-llvm-1c21c28b9e0b8c90dbbb23e23be008a258fd6e6b.zip |
InstrProf: Simplify getStmtCount by using an Optional
llvm-svn: 234750
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CodeGenPGO.cpp | 10 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenPGO.h | 17 |
2 files changed, 11 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 557828db0d0..cc6ac20dd7b 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/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<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); } diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h index 431c850ef81..c92a0579507 100644 --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/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<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 |