-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JIT: Add post-phase validation of DFS tree #95682
Changes from all commits
d27e91b
52860b7
0055faa
b6583a0
170b2c2
8d2fbda
2a4d841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4664,43 +4664,17 @@ void Compiler::fgDebugCheckSsa() | |
assert(fgSsaPassesCompleted > 0); | ||
assert(fgDomsComputed); | ||
|
||
// This class visits the flow graph the same way the SSA builder does. | ||
// In particular it may skip over blocks that SSA did not rename. | ||
// | ||
class SsaCheckDomTreeVisitor : public NewDomTreeVisitor<SsaCheckDomTreeVisitor> | ||
{ | ||
SsaCheckVisitor& m_checkVisitor; | ||
|
||
public: | ||
SsaCheckDomTreeVisitor(Compiler* compiler, SsaCheckVisitor& checkVisitor) | ||
: NewDomTreeVisitor(compiler), m_checkVisitor(checkVisitor) | ||
{ | ||
} | ||
|
||
void PreOrderVisit(BasicBlock* block) | ||
{ | ||
m_checkVisitor.SetBlock(block); | ||
|
||
for (Statement* const stmt : block->Statements()) | ||
{ | ||
m_checkVisitor.WalkTree(stmt->GetRootNodePointer(), nullptr); | ||
} | ||
} | ||
}; | ||
|
||
// Visit the blocks that SSA initially renamed | ||
// | ||
SsaCheckVisitor scv(this); | ||
SsaCheckDomTreeVisitor visitor(this, scv); | ||
visitor.WalkTree(fgSsaDomTree); | ||
|
||
// Also visit any blocks added after SSA was built | ||
// | ||
for (BasicBlock* const block : Blocks()) | ||
SsaCheckVisitor scv(this); | ||
for (unsigned i = 0; i < m_dfsTree->GetPostOrderCount(); i++) | ||
{ | ||
if (block->bbNum > fgDomBBcount) | ||
BasicBlock* block = m_dfsTree->GetPostOrder()[i]; | ||
scv.SetBlock(block); | ||
|
||
for (Statement* const stmt : block->Statements()) | ||
{ | ||
visitor.PreOrderVisit(block); | ||
scv.WalkTree(stmt->GetRootNodePointer(), nullptr); | ||
} | ||
} | ||
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. I've removed this since |
||
|
||
|
@@ -5136,5 +5110,20 @@ void Compiler::fgDebugCheckLoopTable() | |
assert(preHeaderCount == 0); | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// fgDebugCheckDfsTree: Checks that the DFS tree matches the current flow graph. | ||
// | ||
void Compiler::fgDebugCheckDfsTree() | ||
{ | ||
unsigned count = | ||
fgRunDfs([](BasicBlock* block, unsigned preorderNum) { assert(block->bbPreorderNum == preorderNum); }, | ||
[=](BasicBlock* block, unsigned postorderNum) { | ||
assert(block->bbNewPostorderNum == postorderNum); | ||
assert(m_dfsTree->GetPostOrder()[postorderNum] == block); | ||
}); | ||
|
||
assert(m_dfsTree->GetPostOrderCount() == count); | ||
} | ||
|
||
/*****************************************************************************/ | ||
#endif // DEBUG |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6438,7 +6438,32 @@ PhaseStatus Compiler::fgDfsBlocksAndRemove() | |
} | ||
#endif | ||
|
||
fgRemoveUnreachableBlocks([=](BasicBlock* block) { return !m_dfsTree->Contains(block); }); | ||
// The DFS we run is not precise around call-finally, so | ||
// `fgRemoveUnreachableBlocks` can expose newly unreachable blocks | ||
// that we did not uncover during the DFS. If we did remove any | ||
// call-finally blocks then iterate to closure. This is a very rare | ||
// case. | ||
while (true) | ||
{ | ||
bool anyCallFinallyPairs = false; | ||
fgRemoveUnreachableBlocks([=, &anyCallFinallyPairs](BasicBlock* block) { | ||
if (!m_dfsTree->Contains(block)) | ||
{ | ||
anyCallFinallyPairs |= block->isBBCallAlwaysPair(); | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
if (!anyCallFinallyPairs) | ||
{ | ||
break; | ||
} | ||
|
||
m_dfsTree = fgComputeDfs(); | ||
} | ||
Comment on lines
+6441
to
+6465
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. Sadly even with the more precise EH treatment we do not get around this issue, so I've had to add this iteration to closure to make sure the validation passes in cases where removing a callfinally/always pair results in new unreachable blocks (without the validation it would just result in a bit conservative behavior -- considering some blocks reachable that aren't). I only saw one assertion in all of our collections, so at least TP wise it does not seem like an issue. |
||
|
||
status = PhaseStatus::MODIFIED_EVERYTHING; | ||
} | ||
|
||
|
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.
@AndyAyersMS The SSA checker is dependent on SSA's dominator tree, which is stale after RBO, so I'm also setting
fgSsaValid = false
infgInvalidateDfsTree
. It means we no longer check after CSEs, but I suppose that's not a big issue since RBO is really the last user.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.
(Seems like the SSA checker could be switched to iterate the post order of the DFS as well)
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.
Ok by me -- at one point I wanted to keep the SSA checked properties viable longer, but I don't recall why.