Skip to content

Commit 6144376

Browse files
authored
JIT: enable cloning of try regions (#110020)
Add a utility to clone a try region and all associated regions. Test this by enabling duplication of loops with try regions.
1 parent f7974ea commit 6144376

File tree

10 files changed

+2205
-55
lines changed

10 files changed

+2205
-55
lines changed

src/coreclr/jit/compiler.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,9 @@ class FlowGraphNaturalLoop
22332233
bool HasDef(unsigned lclNum);
22342234

22352235
bool CanDuplicate(INDEBUG(const char** reason));
2236+
bool CanDuplicateWithEH(INDEBUG(const char** reason));
22362237
void Duplicate(BasicBlock** insertAfter, BlockToBlockMap* map, weight_t weightScale);
2238+
void DuplicateWithEH(BasicBlock** insertAfter, BlockToBlockMap* map, weight_t weightScale);
22372239

22382240
bool MayExecuteBlockMultipleTimesPerIteration(BasicBlock* block);
22392241

@@ -2557,6 +2559,29 @@ struct RelopImplicationInfo
25572559
bool reverseSense = false;
25582560
};
25592561

2562+
//------------------------------------------------------------------------
2563+
// CloneTryInfo
2564+
//
2565+
// Describes information needed to clone a try region, and information
2566+
// produced by cloning that region
2567+
//
2568+
struct CloneTryInfo
2569+
{
2570+
CloneTryInfo(Compiler* comp);
2571+
2572+
// bbID based traits and vector
2573+
//
2574+
BitVecTraits Traits;
2575+
BitVec Visited;
2576+
2577+
BlockToBlockMap* Map = nullptr;
2578+
jitstd::vector<BasicBlock*>* BlocksToClone = nullptr;
2579+
weight_t ProfileScale = 0.0;
2580+
unsigned EHIndexShift = 0;
2581+
bool AddEdges = false;
2582+
bool ScaleOriginalBlockProfile = false;
2583+
};
2584+
25602585
/*
25612586
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
25622587
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
@@ -3001,7 +3026,7 @@ class Compiler
30013026

30023027
void fgRemoveEHTableEntry(unsigned XTnum);
30033028

3004-
EHblkDsc* fgAddEHTableEntry(unsigned XTnum);
3029+
EHblkDsc* fgTryAddEHTableEntries(unsigned XTnum, unsigned count = 1, bool deferAdding = false);
30053030

30063031
void fgSortEHTable();
30073032

@@ -5359,6 +5384,10 @@ class Compiler
53595384

53605385
PhaseStatus fgCloneFinally();
53615386

5387+
bool fgCanCloneTryRegion(BasicBlock* tryEntry);
5388+
5389+
BasicBlock* fgCloneTryRegion(BasicBlock* tryEntry, CloneTryInfo& info, BasicBlock** insertAfter = nullptr);
5390+
53625391
void fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum);
53635392

53645393
void fgCleanupContinuation(BasicBlock* continuation);
@@ -12264,6 +12293,13 @@ class EHClauses
1226412293
assert((m_begin != nullptr) || (m_begin == m_end));
1226512294
}
1226612295

12296+
EHClauses(Compiler* comp, EHblkDsc* begin)
12297+
: m_begin(begin)
12298+
, m_end(comp->compHndBBtab + comp->compHndBBtabCount)
12299+
{
12300+
assert((m_begin != nullptr) || (m_begin == m_end));
12301+
}
12302+
1226712303
iterator begin() const
1226812304
{
1226912305
return iterator(m_begin);

src/coreclr/jit/compmemkind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ CompMemKindMacro(EarlyProp)
6565
CompMemKindMacro(ZeroInit)
6666
CompMemKindMacro(Pgo)
6767
CompMemKindMacro(MaskConversionOpt)
68+
CompMemKindMacro(TryRegionClone)
6869
//clang-format on
6970

7071
#undef CompMemKindMacro

0 commit comments

Comments
 (0)