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/unittests/ProfileData/CoverageMappingTest.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/unittests/ProfileData/CoverageMappingTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/CoverageMappingTest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index ef14767..46f881e 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -291,6 +291,45 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::tuple<bool, bool>> { } }; +TEST(CoverageMappingTest, expression_subst) { + CounterExpressionBuilder Builder; + CounterExpressionBuilder::SubstMap MapToExpand; + + auto C = [](unsigned ID) { return Counter::getCounter(ID); }; + auto A = [&](Counter LHS, Counter RHS) { return Builder.add(LHS, RHS); }; + // returns {E, N} in clangCodeGen + auto getBranchCounterPair = [&](Counter E, Counter P, Counter N) { + auto Skipped = Builder.subtract(P, E); + MapToExpand[N] = Builder.subst(Skipped, MapToExpand); + }; + + auto E18 = C(5); + auto P18 = C(2); + auto S18 = C(18); + // #18 => (#2 - #5) + getBranchCounterPair(E18, P18, S18); + + auto E22 = S18; + auto P22 = C(0); + auto S22 = C(22); + // #22 => #0 - (#2 - #5) + getBranchCounterPair(E22, P22, S22); + + auto E28 = A(A(C(9), C(11)), C(14)); + auto P28 = S22; + auto S28 = C(28); + // #28 => (((((#0 + #5) - #2) - #9) - #11) - #14) + getBranchCounterPair(E28, P28, S28); + + auto LHS = A(E28, A(S28, S18)); + auto RHS = C(0); + + // W/o subst, LHS cannot be reduced. + ASSERT_FALSE(Builder.subtract(LHS, RHS).isZero()); + // W/ subst, C(18) and C(28) in LHS will be reduced. + ASSERT_TRUE(Builder.subst(Builder.subtract(LHS, RHS), MapToExpand).isZero()); +} + TEST_P(CoverageMappingTest, basic_write_read) { startFunction("func", 0x1234); addCMR(Counter::getCounter(0), "foo", 1, 1, 1, 1); |