Skip to content

Commit b435b40

Browse files
authored
[Wasm RyuJIT] Wasm control flow basics (#121417)
Determine how to emit Wasm control flow from the JIT's control flow graph. Relies on loop-aware RPO to determine the block order. Currently only handles the main method. Assumes irreducible loops have been fixed upstream (which is not yet guaranteed; bails out if not so). Doesn't actually do any emission, just prints a textual description in the JIT dump (along with a dot markup version). Uses only LOOP and BLOCK. Tries to limit the extent of BLOCK. Run for now as an optional phase even if not targeting Wasm, to do some stress testing. Contributes to #121178
1 parent c84d65d commit b435b40

File tree

7 files changed

+879
-0
lines changed

7 files changed

+879
-0
lines changed

src/coreclr/jit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ set( JIT_SOURCES
115115
fgprofile.cpp
116116
fgprofilesynthesis.cpp
117117
fgstmt.cpp
118+
fgwasm.cpp
118119
flowgraph.cpp
119120
forwardsub.cpp
120121
gcinfo.cpp

src/coreclr/jit/compiler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5016,6 +5016,16 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
50165016
DoPhase(this, PHASE_ALIGN_LOOPS, &Compiler::placeLoopAlignInstructions);
50175017
#endif
50185018

5019+
#ifdef DEBUG
5020+
// Optionally, simulate generating wasm control flow
5021+
// (eventually this will become part of the wasm target)
5022+
//
5023+
if (JitConfig.JitWasmControlFlow() > 0)
5024+
{
5025+
DoPhase(this, PHASE_WASM_CONTROL_FLOW, &Compiler::fgWasmControlFlow);
5026+
}
5027+
#endif
5028+
50195029
// The common phase checks and dumps are no longer relevant past this point.
50205030
//
50215031
activePhaseChecks = PhaseChecks::CHECK_NONE;

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6237,6 +6237,8 @@ class Compiler
62376237

62386238
PhaseStatus fgFindOperOrder();
62396239

6240+
PhaseStatus fgWasmControlFlow();
6241+
62406242
// method that returns if you should split here
62416243
typedef bool(fgSplitPredicate)(GenTree* tree, GenTree* parent, fgWalkData* data);
62426244

src/coreclr/jit/compmemkind.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ CompMemKindMacro(MaskConversionOpt)
6868
CompMemKindMacro(TryRegionClone)
6969
CompMemKindMacro(Async)
7070
CompMemKindMacro(RangeCheckCloning)
71+
CompMemKindMacro(WasmCfgLowering)
7172
//clang-format on
7273

7374
#undef CompMemKindMacro

src/coreclr/jit/compphases.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ CompPhaseNameMacro(PHASE_RATIONALIZE, "Rationalize IR",
122122
CompPhaseNameMacro(PHASE_REPAIR_PROFILE_POST_MORPH, "Repair profile post-morph", false, -1, false)
123123
CompPhaseNameMacro(PHASE_REPAIR_PROFILE_PRE_LAYOUT, "Repair profile pre-layout", false, -1, false)
124124

125+
CompPhaseNameMacro(PHASE_WASM_CONTROL_FLOW, "Wasm control flow", false, -1, false)
126+
125127
CompPhaseNameMacro(PHASE_ASYNC, "Transform async", false, -1, true)
126128
CompPhaseNameMacro(PHASE_LCLVARLIVENESS, "Local var liveness", true, -1, false)
127129
CompPhaseNameMacro(PHASE_LCLVARLIVENESS_INIT, "Local var liveness init", false, PHASE_LCLVARLIVENESS, false)

0 commit comments

Comments
 (0)