Skip to content
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: Expand flow graph debug checking #99238

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,11 @@ class FlowGraphDominatorTree

static BasicBlock* IntersectDom(BasicBlock* block1, BasicBlock* block2);
public:
const FlowGraphDfsTree* GetDfsTree()
{
return m_dfsTree;
}

BasicBlock* Intersect(BasicBlock* block, BasicBlock* block2);
bool Dominates(BasicBlock* dominator, BasicBlock* dominated);

Expand Down Expand Up @@ -2357,23 +2362,28 @@ class BlockToNaturalLoopMap
// exceptional flow, then CanReach returns false.
class BlockReachabilitySets
{
FlowGraphDfsTree* m_dfsTree;
const FlowGraphDfsTree* m_dfsTree;
BitVec* m_reachabilitySets;

BlockReachabilitySets(FlowGraphDfsTree* dfsTree, BitVec* reachabilitySets)
BlockReachabilitySets(const FlowGraphDfsTree* dfsTree, BitVec* reachabilitySets)
: m_dfsTree(dfsTree)
, m_reachabilitySets(reachabilitySets)
{
}

public:
const FlowGraphDfsTree* GetDfsTree()
{
return m_dfsTree;
}

bool CanReach(BasicBlock* from, BasicBlock* to);

#ifdef DEBUG
void Dump();
#endif

static BlockReachabilitySets* Build(FlowGraphDfsTree* dfsTree);
static BlockReachabilitySets* Build(const FlowGraphDfsTree* dfsTree);
};

enum class FieldKindForVN
Expand Down Expand Up @@ -6095,7 +6105,7 @@ class Compiler
bool fgDebugCheckIncomingProfileData(BasicBlock* block, ProfileChecks checks);
bool fgDebugCheckOutgoingProfileData(BasicBlock* block, ProfileChecks checks);

void fgDebugCheckDfsTree();
void fgDebugCheckFlowGraphAnnotations();

#endif // DEBUG

Expand Down
15 changes: 13 additions & 2 deletions src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4743,10 +4743,17 @@ void Compiler::fgDebugCheckLoops()
}

//------------------------------------------------------------------------------
// fgDebugCheckDfsTree: Checks that the DFS tree matches the current flow graph.
// fgDebugCheckFlowGraphAnnotations: Checks that all flow graph annotations
// that are currently non-null are valid.
//
void Compiler::fgDebugCheckDfsTree()
void Compiler::fgDebugCheckFlowGraphAnnotations()
{
if (m_dfsTree == nullptr)
{
assert((m_loops == nullptr) && (m_domTree == nullptr) && (m_reachabilitySets == nullptr));
return;
}

unsigned count =
fgRunDfs([](BasicBlock* block, unsigned preorderNum) { assert(block->bbPreorderNum == preorderNum); },
[=](BasicBlock* block, unsigned postorderNum) {
Expand All @@ -4756,6 +4763,10 @@ void Compiler::fgDebugCheckDfsTree()
[](BasicBlock* block, BasicBlock* succ) {});

assert(m_dfsTree->GetPostOrderCount() == count);

assert((m_loops == nullptr) || (m_loops->GetDfsTree() == m_dfsTree));
assert((m_domTree == nullptr) || (m_domTree->GetDfsTree() == m_dfsTree));
assert((m_reachabilitySets == nullptr) || (m_reachabilitySets->GetDfsTree() == m_dfsTree));
}

/*****************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6146,7 +6146,7 @@ BlockToNaturalLoopMap* BlockToNaturalLoopMap::Build(FlowGraphNaturalLoops* loops
// This algorithm consumes O(n^2) memory because we're using dense
// bitsets to represent reachability.
//
BlockReachabilitySets* BlockReachabilitySets::Build(FlowGraphDfsTree* dfsTree)
BlockReachabilitySets* BlockReachabilitySets::Build(const FlowGraphDfsTree* dfsTree)
{
Compiler* comp = dfsTree->GetCompiler();
BitVecTraits postOrderTraits = dfsTree->PostOrderTraits();
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/jit/phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ void Phase::PostPhase(PhaseStatus status)
comp->fgDebugCheckLinkedLocals();
}

if (comp->m_dfsTree != nullptr)
{
comp->fgDebugCheckDfsTree();
}
comp->fgDebugCheckFlowGraphAnnotations();
}
#endif // DEBUG
}
Loading