Skip to content
Open
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
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9897,6 +9897,7 @@ class Compiler
void funSetCurrentFunc(unsigned funcIdx);
FuncInfoDsc* funGetFunc(unsigned funcIdx);
unsigned int funGetFuncIdx(BasicBlock* block);
unsigned int bbFuncletRegionOf(BasicBlock* block);
bool bbIsInSameFunclet(BasicBlock* block1, BasicBlock* block2);

// LIVENESS
Expand Down
47 changes: 28 additions & 19 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,36 +860,45 @@ inline unsigned Compiler::funGetFuncIdx(BasicBlock* block)
}

/*****************************************************************************
* Are two blocks physically contained in the same function region (funclet)?
* The main method is region 0. Unlike funGetFuncIdx, this works for an
* arbitrary block (not just a funclet entry), distinguishing a filter
* Return the index of the function region (funclet) that physically contains
* `block`. The main method is region 0. Unlike funGetFuncIdx, this works for
* an arbitrary block (not just a funclet entry), distinguishing a filter
* funclet (FUNC_FILTER) from its filter-handler. Only valid after funclets
* are created.
*
*/
inline bool Compiler::bbIsInSameFunclet(BasicBlock* block1, BasicBlock* block2)
inline unsigned Compiler::bbFuncletRegionOf(BasicBlock* block)
{
assert(fgFuncletsCreated);

auto funcRegionOf = [this](BasicBlock* blk) -> unsigned {
if (!blk->hasHndIndex())
{
return 0;
}
if (!block->hasHndIndex())
{
return 0;
}

EHblkDsc* const eh = ehGetDsc(blk->getHndIndex());
unsigned funcIdx = eh->ebdFuncIndex;
EHblkDsc* const eh = ehGetDsc(block->getHndIndex());
unsigned funcIdx = eh->ebdFuncIndex;

if (eh->HasFilter() && eh->InFilterRegionBBRange(blk))
{
// The filter is the funclet immediately preceding its filter-handler.
funcIdx--;
}
if (eh->HasFilter() && eh->InFilterRegionBBRange(block))
{
// The filter is the funclet immediately preceding its filter-handler.
funcIdx--;
}

return funcIdx;
};
return funcIdx;
}

return funcRegionOf(block1) == funcRegionOf(block2);
/*****************************************************************************
* Are two blocks physically contained in the same function region (funclet)?
* The main method is region 0. Unlike funGetFuncIdx, this works for an
* arbitrary block (not just a funclet entry), distinguishing a filter
* funclet (FUNC_FILTER) from its filter-handler. Only valid after funclets
* are created.
*
*/
inline bool Compiler::bbIsInSameFunclet(BasicBlock* block1, BasicBlock* block2)
{
return bbFuncletRegionOf(block1) == bbFuncletRegionOf(block2);
}
#if HAS_FIXED_REGISTER_SET
//------------------------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions src/coreclr/jit/fgwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,36 @@ PhaseStatus Compiler::fgWasmControlFlow()
order++;
}
}

{
// Verify that each funclet's blocks are contiguous.
//
jitstd::vector<bool> regionClosed(compFuncInfoCount, false, getAllocator(CMK_DebugOnly));
unsigned prevRegion = UINT_MAX;
for (BasicBlock* const block : Blocks())
{
const unsigned region = bbFuncletRegionOf(block);
assert(region < compFuncInfoCount);

if (region != prevRegion)
{
if (prevRegion != UINT_MAX)
{
regionClosed[prevRegion] = true;
}

if (regionClosed[region])
{
JITDUMP("Wasm function region %u is not contiguous: " FMT_BB " re-enters it\n", region,
block->bbNum);
}
assert(!regionClosed[region] &&
"wasm function region (main method / funclet) blocks are not contiguous");

prevRegion = region;
}
}
}
#endif // DEBUG

JITDUMPEXEC(fgDumpWasmControlFlow());
Expand Down
Loading