Skip to content

Commit

Permalink
JIT: enable cloning of try regions (#110020)
Browse files Browse the repository at this point in the history
Add a utility to clone a try region and all associated regions.

Test this by enabling duplication of loops with try regions.
  • Loading branch information
AndyAyersMS authored Dec 4, 2024
1 parent f7974ea commit 6144376
Show file tree
Hide file tree
Showing 10 changed files with 2,205 additions and 55 deletions.
38 changes: 37 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,9 @@ class FlowGraphNaturalLoop
bool HasDef(unsigned lclNum);

bool CanDuplicate(INDEBUG(const char** reason));
bool CanDuplicateWithEH(INDEBUG(const char** reason));
void Duplicate(BasicBlock** insertAfter, BlockToBlockMap* map, weight_t weightScale);
void DuplicateWithEH(BasicBlock** insertAfter, BlockToBlockMap* map, weight_t weightScale);

bool MayExecuteBlockMultipleTimesPerIteration(BasicBlock* block);

Expand Down Expand Up @@ -2557,6 +2559,29 @@ struct RelopImplicationInfo
bool reverseSense = false;
};

//------------------------------------------------------------------------
// CloneTryInfo
//
// Describes information needed to clone a try region, and information
// produced by cloning that region
//
struct CloneTryInfo
{
CloneTryInfo(Compiler* comp);

// bbID based traits and vector
//
BitVecTraits Traits;
BitVec Visited;

BlockToBlockMap* Map = nullptr;
jitstd::vector<BasicBlock*>* BlocksToClone = nullptr;
weight_t ProfileScale = 0.0;
unsigned EHIndexShift = 0;
bool AddEdges = false;
bool ScaleOriginalBlockProfile = false;
};

/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Expand Down Expand Up @@ -3001,7 +3026,7 @@ class Compiler

void fgRemoveEHTableEntry(unsigned XTnum);

EHblkDsc* fgAddEHTableEntry(unsigned XTnum);
EHblkDsc* fgTryAddEHTableEntries(unsigned XTnum, unsigned count = 1, bool deferAdding = false);

void fgSortEHTable();

Expand Down Expand Up @@ -5359,6 +5384,10 @@ class Compiler

PhaseStatus fgCloneFinally();

bool fgCanCloneTryRegion(BasicBlock* tryEntry);

BasicBlock* fgCloneTryRegion(BasicBlock* tryEntry, CloneTryInfo& info, BasicBlock** insertAfter = nullptr);

void fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum);

void fgCleanupContinuation(BasicBlock* continuation);
Expand Down Expand Up @@ -12264,6 +12293,13 @@ class EHClauses
assert((m_begin != nullptr) || (m_begin == m_end));
}

EHClauses(Compiler* comp, EHblkDsc* begin)
: m_begin(begin)
, m_end(comp->compHndBBtab + comp->compHndBBtabCount)
{
assert((m_begin != nullptr) || (m_begin == m_end));
}

iterator begin() const
{
return iterator(m_begin);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compmemkind.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ CompMemKindMacro(EarlyProp)
CompMemKindMacro(ZeroInit)
CompMemKindMacro(Pgo)
CompMemKindMacro(MaskConversionOpt)
CompMemKindMacro(TryRegionClone)
//clang-format on

#undef CompMemKindMacro
Loading

0 comments on commit 6144376

Please sign in to comment.