diff options
author | NAKAMURA Takumi <geek4civic@gmail.com> | 2025-01-09 16:27:35 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-09 16:27:35 +0900 |
commit | 61b294aa15e9e2149398a641121fc3e977284a17 (patch) | |
tree | 8bb01ed54067bbdb652e4e80c838fb135e502004 /llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | |
parent | 24a92f509a4e9ebaf5ae431409520d30055ea6fc (diff) | |
download | llvm-61b294aa15e9e2149398a641121fc3e977284a17.zip llvm-61b294aa15e9e2149398a641121fc3e977284a17.tar.gz llvm-61b294aa15e9e2149398a641121fc3e977284a17.tar.bz2 |
Introduce CounterExpressionBuilder::subst(C, Map) (#112698)
This return a counter for each term in the expression replaced by
ReplaceMap.
At the moment, this doesn't update the Map, so Map is marked as `const`.
Diffstat (limited to 'llvm/lib/ProfileData/Coverage/CoverageMapping.cpp')
-rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index e8f60d2..6d6678e 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -135,6 +135,31 @@ Counter CounterExpressionBuilder::subtract(Counter LHS, Counter RHS, return Simplify ? simplify(Cnt) : Cnt; } +Counter CounterExpressionBuilder::subst(Counter C, const SubstMap &Map) { + // Replace C with the value found in Map even if C is Expression. + if (auto I = Map.find(C); I != Map.end()) + return I->second; + + if (!C.isExpression()) + return C; + + auto CE = Expressions[C.getExpressionID()]; + auto NewLHS = subst(CE.LHS, Map); + auto NewRHS = subst(CE.RHS, Map); + + // Reconstruct Expression with induced subexpressions. + switch (CE.Kind) { + case CounterExpression::Add: + C = add(NewLHS, NewRHS); + break; + case CounterExpression::Subtract: + C = subtract(NewLHS, NewRHS); + break; + } + + return C; +} + void CounterMappingContext::dump(const Counter &C, raw_ostream &OS) const { switch (C.getKind()) { case Counter::Zero: |