-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Coverage] Make additional counters available for BranchRegion. NFC. #120930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chapuni
wants to merge
62
commits into
main
Choose a base branch
from
users/chapuni/cov/single/nextcount
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
618e639
Introduce CounterExpressionBuilder::replace(C, Map)
chapuni fc697f0
[Coverage] Introduce `getBranchCounterPair()`. NFC.
chapuni e4172ca
Introduce the type `CounterPair` for RegionCounterMap
chapuni 12abd89
Merge branches 'users/chapuni/cov/single/getpair', 'users/chapuni/cov…
chapuni 5e46059
[Coverage] Make additional counters available for BranchRegion. NFC.
chapuni ad13691
Rewind changes for folding
chapuni 209ea4c
Update comments
chapuni f0afd04
Use initializer statements
chapuni d4518a4
Merge branches 'users/chapuni/cov/single/getpair' and 'users/chapuni/…
chapuni 05df8df
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/cha…
chapuni be516fa
`first` may be cancelled.
chapuni 03cfce1
CGF::markStmtAsUsed
chapuni afc8481
CGF.markStmtMaybeUsed for binop
chapuni 58feee3
Merge branch 'main' into users/chapuni/cov/single/getpair
chapuni ab84f17
Introduce skeleton getSwitchImplicitDefaultCounter()
chapuni 804d330
Merge branches 'users/chapuni/cov/single/pair' and 'users/chapuni/cov…
chapuni 2c29f5d
Merge branch 'users/chapuni/cov/single/nextcount-base' into HEAD
chapuni a460885
Update getSwitchImplicitDefaultCounter
chapuni 0285394
Don't allocate second if SkipExpr isn't Expr.
chapuni ce7c17d
Merge branch 'main' into users/chapuni/cov/single/pair
chapuni 631bc35
Merge branch 'main' into users/chapuni/cov/single/replace
chapuni ed700c2
s/replace/subst/
chapuni 9d3c3b0
Merge branch 'main' into users/chapuni/cov/single/getpair
chapuni dbcf896
getSwitchImplicitDefaultCounterPair
chapuni 2cb6395
Merge branch 'users/chapuni/cov/single/pair' into users/chapuni/cov/s…
chapuni 702a72e
Merge branch 'users/chapuni/cov/single/getpair' into users/chapuni/co…
chapuni 36465dc
Merge branch 'users/chapuni/cov/single/replace' into users/chapuni/co…
chapuni 2413b83
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/cha…
chapuni c0785e9
Fold either in switchcase
chapuni bd1d96b
Introduce CounterMappingRegion::isBranch(). NFC.
chapuni 19edcd3
Merge branch 'main' into users/chapuni/cov/single/getpair
chapuni 4e41b99
Introduce BranchCounterPair
chapuni 63dbfb3
Merge branch 'main' into users/chapuni/cov/single/pair
chapuni 306d77f
void verifyCounterMap() const
chapuni a4f05c7
Introduce the dedicated class CounterPair instead of std::pair
chapuni 1f18ab9
Merge branches 'users/chapuni/cov/single/getpair' and 'users/chapuni/…
chapuni b7ae558
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/cha…
chapuni f6c5f40
Catch up the merge
chapuni aca86d4
Introduce {UseExecPath, UseSkipPath} instead of {false, true}
chapuni 28c568a
Add a test
chapuni d92a9d9
Prune redundant logic
chapuni 93fb420
Merge branch 'users/chapuni/cov/single/replace' into users/chapuni/co…
chapuni 6f8681c
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/cha…
chapuni 82f2e92
Expand RHS of MapToExpand. This will prevent recursion.
chapuni b90fdf6
Append an explanation in the comment
chapuni d854fb1
Rewind switch DefaultCase. (to #113112)
chapuni bac2967
Enable addCounters
chapuni 6bae87d
Get rid of structual bindings
chapuni c8edf58
Flatten with getBranchCounterPair(SkipCntForOld)
chapuni ec6892d
Merge branch 'users/chapuni/cov/single/getpair' into users/chapuni/co…
chapuni 9b99dde
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/cha…
chapuni f2ba219
Update comments
chapuni 97015cb
Decorate the mock
chapuni 9a40d20
Will be pruned after the migration of SingleByte.
chapuni b548e71
Add comments
chapuni 13fbcde
Merge branch 'main' into users/chapuni/cov/single/replace
chapuni 789eeab
Merge branch 'main' into users/chapuni/cov/single/getpair
chapuni 8683882
Merge branch 'users/chapuni/cov/single/replace' into users/chapuni/co…
chapuni de5756c
Merge branch 'main' into users/chapuni/cov/single/pair
chapuni 6d16b1c
Merge branch 'users/chapuni/cov/single/getpair' into users/chapuni/co…
chapuni 0aa930a
Merge branch 'users/chapuni/cov/single/pair' into users/chapuni/cov/s…
chapuni fea7da1
Merge branch 'users/chapuni/cov/single/nextcount-base' into users/cha…
chapuni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -884,6 +884,9 @@ struct CounterCoverageMappingBuilder | |
/// The map of statements to count values. | ||
llvm::DenseMap<const Stmt *, CounterPair> &CounterMap; | ||
|
||
CounterExpressionBuilder::SubstMap MapToExpand; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MapToExpand could use a doxygen comment explaining what it is |
||
unsigned NextCounterNum; | ||
|
||
MCDC::State &MCDCState; | ||
|
||
/// A stack of currently live regions. | ||
|
@@ -958,7 +961,8 @@ struct CounterCoverageMappingBuilder | |
BranchCounterPair | ||
getBranchCounterPair(const Stmt *S, Counter ParentCnt, | ||
std::optional<Counter> SkipCntForOld = std::nullopt) { | ||
Counter ExecCnt = getRegionCounter(S); | ||
auto &TheMap = CounterMap[S]; | ||
auto ExecCnt = Counter::getCounter(TheMap.Executed); | ||
|
||
// The old behavior of SingleByte is unaware of Branches. | ||
// Will be pruned after the migration of SingleByte. | ||
|
@@ -968,13 +972,44 @@ struct CounterCoverageMappingBuilder | |
return {ExecCnt, *SkipCntForOld}; | ||
} | ||
|
||
return {ExecCnt, Builder.subtract(ParentCnt, ExecCnt)}; | ||
BranchCounterPair Counters = {ExecCnt, | ||
Builder.subtract(ParentCnt, ExecCnt)}; | ||
|
||
if (!llvm::EnableSingleByteCoverage || !Counters.Skipped.isExpression()) { | ||
assert( | ||
!TheMap.Skipped.hasValue() && | ||
"SkipCnt shouldn't be allocated but refer to an existing counter."); | ||
return Counters; | ||
} | ||
|
||
// Assign second if second is not assigned yet. | ||
if (!TheMap.Skipped.hasValue()) | ||
TheMap.Skipped = NextCounterNum++; | ||
|
||
// Replace an expression (ParentCnt - ExecCnt) with SkipCnt. | ||
Counter SkipCnt = Counter::getCounter(TheMap.Skipped); | ||
MapToExpand[SkipCnt] = Builder.subst(Counters.Skipped, MapToExpand); | ||
Counters.Skipped = SkipCnt; | ||
return Counters; | ||
} | ||
|
||
bool IsCounterEqual(Counter OutCount, Counter ParentCount) { | ||
if (OutCount == ParentCount) | ||
return true; | ||
|
||
// Try comaparison with pre-replaced expressions. | ||
// | ||
// For example, getBranchCounterPair(#0) returns {#1, #0 - #1}. | ||
// The sum of the pair should be equivalent to the Parent, #0. | ||
// OTOH when (#0 - #1) is replaced with the new counter #2, | ||
// The sum is (#1 + #2). If the reverse substitution #2 => (#0 - #1) | ||
// can be applied, the sum can be transformed to (#1 + (#0 - #1)). | ||
// To apply substitutions to both hand expressions, transform (LHS - RHS) | ||
// and check isZero. | ||
if (Builder.subst(Builder.subtract(OutCount, ParentCount), MapToExpand) | ||
.isZero()) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
|
@@ -1188,12 +1223,14 @@ struct CounterCoverageMappingBuilder | |
/// and add it to the function's SourceRegions. | ||
/// Returns Counter that corresponds to SC. | ||
Counter createSwitchCaseRegion(const SwitchCase *SC, Counter ParentCount) { | ||
Counter TrueCnt = getRegionCounter(SC); | ||
Counter FalseCnt = (llvm::EnableSingleByteCoverage | ||
? Counter::getZero() // Folded | ||
: subtractCounters(ParentCount, TrueCnt)); | ||
// Push region onto RegionStack but immediately pop it (which adds it to | ||
// the function's SourceRegions) because it doesn't apply to any other | ||
// source other than the SwitchCase. | ||
Counter TrueCnt = getRegionCounter(SC); | ||
popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), | ||
subtractCounters(ParentCount, TrueCnt))); | ||
popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), FalseCnt)); | ||
return TrueCnt; | ||
} | ||
|
||
|
@@ -1460,7 +1497,8 @@ struct CounterCoverageMappingBuilder | |
llvm::DenseMap<const Stmt *, CounterPair> &CounterMap, | ||
MCDC::State &MCDCState, SourceManager &SM, const LangOptions &LangOpts) | ||
: CoverageMappingBuilder(CVM, SM, LangOpts), CounterMap(CounterMap), | ||
MCDCState(MCDCState), MCDCBuilder(CVM.getCodeGenModule(), MCDCState) {} | ||
NextCounterNum(CounterMap.size()), MCDCState(MCDCState), | ||
MCDCBuilder(CVM.getCodeGenModule(), MCDCState) {} | ||
|
||
/// Write the mapping data to the output stream | ||
void write(llvm::raw_ostream &OS) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doxygen comment would be useful here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the meaning of "exec counter" and "skip counter" defined anywhere? if not, it would be good to do that here.