Skip to content

Commit abb0f8d

Browse files
authored
Revert "JIT: cache the wasm image base in a local" (#132166)
Reverts #131369. This change is subsumed by #132029; now that we shrink global indices down to their minimum size, it actually costs the same (2 bytes) to do `global.get <imageBase>` vs. `local.get <cached image base>`. Measured SPC diff: -105408 bytes (-0.34%)
1 parent e53147e commit abb0f8d

8 files changed

Lines changed: 4 additions & 91 deletions

File tree

src/coreclr/jit/codegen.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,6 @@ class CodeGen final : public CodeGenInterface
621621
void genReserveEpilog(BasicBlock* block);
622622
void genFnProlog();
623623
void genBeginFnProlog();
624-
#ifdef TARGET_WASM
625-
void genInitImageBaseLocal(FuncInfoDsc* func);
626-
#endif
627624
void genFnEpilog(BasicBlock* block);
628625

629626
void genReserveFuncletProlog(BasicBlock* block);

src/coreclr/jit/codegenwasm.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,6 @@ void CodeGen::genBeginFnProlog()
116116
GetEmitter()->emitIns_I_Ty(INS_local_decl, decl.Count, decl.Type, localsCount);
117117
localsCount += decl.Count;
118118
}
119-
120-
genInitImageBaseLocal(func);
121-
}
122-
123-
//------------------------------------------------------------------------
124-
// genInitImageBaseLocal: initialize the wasm local caching the image base, if this
125-
// function has one.
126-
//
127-
// Arguments:
128-
// func - the function or funclet whose prolog is being generated
129-
//
130-
// Notes:
131-
// Emitted in the prolog, which dominates every use. The imageBase global is immutable,
132-
// so the cached value never needs refreshing.
133-
//
134-
void CodeGen::genInitImageBaseLocal(FuncInfoDsc* func)
135-
{
136-
if (func->funWasmImageBaseLocalIndex != UINT_MAX)
137-
{
138-
GetEmitter()->emitImageBaseGlobal();
139-
GetEmitter()->emitIns_I(INS_local_set, EA_PTRSIZE, func->funWasmImageBaseLocalIndex);
140-
}
141119
}
142120

143121
//------------------------------------------------------------------------
@@ -469,8 +447,6 @@ void CodeGen::genFuncletProlog(BasicBlock* block)
469447
localsCount += decl.Count;
470448
}
471449

472-
genInitImageBaseLocal(func);
473-
474450
// All the funclet params are used from their home registers, so nothing
475451
// needs homing here.
476452
//

src/coreclr/jit/compiler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,6 @@ struct FuncInfoDsc
18321832
jitstd::vector<WasmLocalsDecl>* funWasmLocalDecls;
18331833
unsigned funWasmFrameSize;
18341834
unsigned funWasmExnRefLocalIndex = UINT_MAX;
1835-
unsigned funWasmImageBaseLocalIndex = UINT_MAX;
18361835
bool needsUnwindableFrame;
18371836
emitLocation* startLoc;
18381837
emitLocation* endLoc;

src/coreclr/jit/emitwasm.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,34 +192,13 @@ bool emitter::emitInsIsStore(instruction ins)
192192
unreached();
193193
}
194194

195-
//------------------------------------------------------------------------
196-
// emitImageBaseGlobal: Emit the module base onto the stack, reading the imageBase global.
197-
//
198-
void emitter::emitImageBaseGlobal()
199-
{
200-
emitIns_I(INS_global_get, EA_HANDLE_CNS_RELOC,
201-
(cnsval_ssize_t)(size_t)m_compiler->eeGetWasmWellKnownGlobals()->imageBase);
202-
}
203-
204195
//------------------------------------------------------------------------
205196
// emitImageBase: Emit the module base (imageBase global) onto the stack.
206197
//
207-
// Notes:
208-
// When this function caches the image base in a wasm local, read it from there instead. The
209-
// local is initialized in the prolog, which dominates every use.
210-
//
211198
void emitter::emitImageBase()
212199
{
213-
FuncInfoDsc* const func = m_compiler->funCurrentFunc();
214-
215-
if (func->funWasmImageBaseLocalIndex != UINT_MAX)
216-
{
217-
emitIns_I(INS_local_get, EA_PTRSIZE, func->funWasmImageBaseLocalIndex);
218-
}
219-
else
220-
{
221-
emitImageBaseGlobal();
222-
}
200+
emitIns_I(INS_global_get, EA_HANDLE_CNS_RELOC,
201+
(cnsval_ssize_t)(size_t)m_compiler->eeGetWasmWellKnownGlobals()->imageBase);
223202
}
224203

225204
//------------------------------------------------------------------------

src/coreclr/jit/emitwasm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ void emitIns_Lane(instruction ins, uint8_t laneIdx);
3838
void emitIns_MemargLane(instruction ins, emitAttr attr, cnsval_ssize_t offset, uint8_t laneIdx);
3939

4040
void emitImageBase();
41-
void emitImageBaseGlobal();
4241
void emitAddressConstant(void* address);
4342
void emitFuncletAddressConstant(cnsval_ssize_t funcletId);
4443
void emitDataOffsetConstant(UNATIVE_OFFSET dataOffs);

src/coreclr/jit/flowgraph.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,9 +3159,8 @@ PhaseStatus Compiler::fgCreateFunclets()
31593159
funcInfo[i].funFramePointerReg = REG_NA;
31603160
#endif
31613161
#ifdef TARGET_WASM
3162-
funcInfo[i].funWasmLocalDecls = nullptr;
3163-
funcInfo[i].funWasmExnRefLocalIndex = UINT_MAX;
3164-
funcInfo[i].funWasmImageBaseLocalIndex = UINT_MAX;
3162+
funcInfo[i].funWasmLocalDecls = nullptr;
3163+
funcInfo[i].funWasmExnRefLocalIndex = UINT_MAX;
31653164
#endif
31663165
}
31673166
#endif

src/coreclr/jit/regallocwasm.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,6 @@ void WasmRegAlloc::CollectReferencesForBlock(BasicBlock* block)
431431
//
432432
void WasmRegAlloc::CollectReferencesForNode(GenTree* node)
433433
{
434-
// Track how many times this funclet will materialize the image base, so we can
435-
// decide below whether to cache it in a wasm local.
436-
//
437-
if (node->IsCnsIntOrI() && node->IsIconHandle() && node->AsIntConCommon()->ImmedValNeedsReloc(m_compiler))
438-
{
439-
m_perFuncletData[m_currentFunclet]->m_imageBaseUses++;
440-
}
441-
442434
switch (node->OperGet())
443435
{
444436
case GT_NULLCHECK:
@@ -1109,21 +1101,6 @@ void WasmRegAlloc::ResolveReferences()
11091101
unreached();
11101102
}
11111103

1112-
// Decide up front whether to cache the image base in a wasm local, so the local can be
1113-
// declared as part of an existing group rather than one of its own.
1114-
//
1115-
// Each use costs 6 bytes as a `global.get` (the global index is a padded relocation) and
1116-
// 2 bytes as a `local.get`, against 8 bytes to initialize the local in the prolog. So
1117-
// three uses is the first count that wins.
1118-
//
1119-
PhysicalRegBank& imageBaseBank = virtToPhysRegMap[static_cast<unsigned>(TypeToWasmValueType(TYP_I_IMPL))];
1120-
const bool cacheImageBase = data->m_imageBaseUses >= 3;
1121-
1122-
if (cacheImageBase)
1123-
{
1124-
imageBaseBank.DeclaredCount++;
1125-
}
1126-
11271104
for (WasmValueType type = WasmValueType::First; type < WasmValueType::Count; ++type)
11281105
{
11291106
PhysicalRegBank& physRegs = virtToPhysRegMap[static_cast<unsigned>(type)];
@@ -1132,14 +1109,6 @@ void WasmRegAlloc::ResolveReferences()
11321109
indexBase += physRegs.DeclaredCount;
11331110
}
11341111

1135-
// Reserve the last slot of the bank for the image base. The allocator below only ever
1136-
// hands out the slots the virtual registers need, so it never reaches this one.
1137-
//
1138-
if (cacheImageBase)
1139-
{
1140-
funcInfo->funWasmImageBaseLocalIndex = imageBaseBank.IndexBase + imageBaseBank.DeclaredCount - 1;
1141-
}
1142-
11431112
// Allocate all our virtual registers to physical ones.
11441113
//
11451114
auto allocPhysReg = [&](regNumber virtReg, LclVarDsc* varDsc) {

src/coreclr/jit/regallocwasm.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class WasmRegAlloc : public RegAllocInterface
9292
, m_fpReg(REG_NA)
9393
, m_lastVirtualRegRefsCount(0)
9494
, m_virtualRegRefs(nullptr)
95-
, m_imageBaseUses(0)
9695
, m_physicalRegAssignments(comp->lvaTrackedCount, REG_STK, comp->getAllocator(CMK_LSRA))
9796
{
9897
}
@@ -112,10 +111,6 @@ class WasmRegAlloc : public RegAllocInterface
112111
unsigned m_lastVirtualRegRefsCount;
113112
VirtualRegReferences* m_virtualRegRefs;
114113

115-
// Count of nodes in this funclet that will materialize the image base.
116-
//
117-
unsigned m_imageBaseUses;
118-
119114
// Map from local tracked index to phys reg for that local, in this funclet.
120115
//
121116
jitstd::vector<regNumber> m_physicalRegAssignments;

0 commit comments

Comments
 (0)