Skip to content

Commit 8fa4501

Browse files
Rename a few LSRAs to RegAllocs
Addressing the factoring TODO.
1 parent 13f6a0c commit 8fa4501

File tree

10 files changed

+51
-46
lines changed

10 files changed

+51
-46
lines changed

src/coreclr/jit/codegencommon.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ void CodeGen::genEmitMachineCode()
21562156
#if TRACK_LSRA_STATS
21572157
if (JitConfig.DisplayLsraStats() == 3)
21582158
{
2159-
compiler->m_pLinearScan->dumpLsraStatsSummary(jitstdout());
2159+
compiler->m_regAlloc->dumpLsraStatsSummary(jitstdout());
21602160
}
21612161
#endif // TRACK_LSRA_STATS
21622162

@@ -4524,7 +4524,7 @@ void CodeGen::genFinalizeFrame()
45244524
// of the first basic block, so load those up. In particular, the determination
45254525
// of whether or not to use block init in the prolog is dependent on the variable
45264526
// locations on entry to the function.
4527-
compiler->m_pLinearScan->recordVarLocationsAtStartOfBB(compiler->fgFirstBB);
4527+
compiler->m_regAlloc->recordVarLocationsAtStartOfBB(compiler->fgFirstBB);
45284528

45294529
genCheckUseBlockInit();
45304530

@@ -5794,7 +5794,7 @@ void CodeGen::genGeneratePrologsAndEpilogs()
57945794

57955795
// Before generating the prolog, we need to reset the variable locations to what they will be on entry.
57965796
// This affects our code that determines which untracked locals need to be zero initialized.
5797-
compiler->m_pLinearScan->recordVarLocationsAtStartOfBB(compiler->fgFirstBB);
5797+
compiler->m_regAlloc->recordVarLocationsAtStartOfBB(compiler->fgFirstBB);
57985798

57995799
// Tell the emitter we're done with main code generation, and are going to start prolog and epilog generation.
58005800

src/coreclr/jit/codegenlinear.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void CodeGen::genCodeForBBlist()
187187
gcInfo.gcRegGCrefSetCur = RBM_NONE;
188188
gcInfo.gcRegByrefSetCur = RBM_NONE;
189189

190-
compiler->m_pLinearScan->recordVarLocationsAtStartOfBB(block);
190+
compiler->m_regAlloc->recordVarLocationsAtStartOfBB(block);
191191

192192
// Updating variable liveness after last instruction of previous block was emitted
193193
// and before first of the current block is emitted

src/coreclr/jit/compiler.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4965,14 +4965,14 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
49654965

49664966
// Assign registers to variables, etc.
49674967

4968-
// Create LinearScan before Lowering, so that Lowering can call LinearScan methods
4969-
// for determining whether locals are register candidates and (for xarch) whether
4968+
// Create the RA before Lowering, so that Lowering can call RA methods for
4969+
// determining whether locals are register candidates and (for xarch) whether
49704970
// a node is a containable memory op.
4971-
m_pLinearScan = getLinearScanAllocator(this);
4971+
m_regAlloc = GetRegisterAllocator(this);
49724972

49734973
// Lower
49744974
//
4975-
m_pLowering = new (this, CMK_LSRA) Lowering(this, m_pLinearScan); // PHASE_LOWERING
4975+
m_pLowering = new (this, CMK_LSRA) Lowering(this, m_regAlloc); // PHASE_LOWERING
49764976
m_pLowering->Run();
49774977

49784978
// Set stack levels and analyze throw helper usage.
@@ -4988,7 +4988,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
49884988
// Now that lowering is completed we can proceed to perform register allocation
49894989
//
49904990
auto linearScanPhase = [this] {
4991-
m_pLinearScan->doLinearScan();
4991+
m_regAlloc->doRegisterAllocation();
49924992
};
49934993
DoPhase(this, PHASE_LINEAR_SCAN, linearScanPhase);
49944994

@@ -5027,7 +5027,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
50275027
#if TRACK_LSRA_STATS
50285028
if (JitConfig.DisplayLsraStats() == 2)
50295029
{
5030-
m_pLinearScan->dumpLsraStatsCsv(jitstdout());
5030+
m_regAlloc->dumpLsraStatsCsv(jitstdout());
50315031
}
50325032
#endif // TRACK_LSRA_STATS
50335033

src/coreclr/jit/compiler.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,19 +1363,22 @@ enum class PhaseStatus : unsigned
13631363
};
13641364

13651365
// interface to hide linearscan implementation from rest of compiler
1366-
class LinearScanInterface
1366+
class RegAllocInterface
13671367
{
13681368
public:
1369-
virtual PhaseStatus doLinearScan() = 0;
1369+
virtual PhaseStatus doRegisterAllocation() = 0;
13701370
virtual void recordVarLocationsAtStartOfBB(BasicBlock* bb) = 0;
13711371
virtual bool willEnregisterLocalVars() const = 0;
13721372
#if TRACK_LSRA_STATS
13731373
virtual void dumpLsraStatsCsv(FILE* file) = 0;
13741374
virtual void dumpLsraStatsSummary(FILE* file) = 0;
13751375
#endif // TRACK_LSRA_STATS
1376+
1377+
virtual bool isRegCandidate(LclVarDsc* varDsc) = 0;
1378+
virtual bool isContainableMemoryOp(GenTree* node) = 0;
13761379
};
13771380

1378-
LinearScanInterface* getLinearScanAllocator(Compiler* comp);
1381+
RegAllocInterface* GetRegisterAllocator(Compiler* comp);
13791382

13801383
// This enumeration names the phases into which we divide compilation. The phases should completely
13811384
// partition a compilation.
@@ -5572,7 +5575,7 @@ class Compiler
55725575

55735576
bool backendRequiresLocalVarLifetimes()
55745577
{
5575-
return !opts.MinOpts() || m_pLinearScan->willEnregisterLocalVars();
5578+
return !opts.MinOpts() || m_regAlloc->willEnregisterLocalVars();
55765579
}
55775580

55785581
void fgLocalVarLiveness();
@@ -8230,8 +8233,8 @@ class Compiler
82308233
bool rpMustCreateEBPFrame(INDEBUG(const char** wbReason));
82318234

82328235
private:
8233-
Lowering* m_pLowering = nullptr; // Lowering; needed to Lower IR that's added or modified after Lowering.
8234-
LinearScanInterface* m_pLinearScan = nullptr; // Linear Scan allocator
8236+
Lowering* m_pLowering = nullptr; // Lowering; needed to Lower IR that's added or modified after Lowering.
8237+
RegAllocInterface* m_regAlloc = nullptr; // Register allocator
82358238

82368239
public:
82378240
ArrayStack<ParameterRegisterLocalMapping>* m_paramRegLocalMappings = nullptr;

src/coreclr/jit/lower.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2929
class Lowering final : public Phase
3030
{
3131
public:
32-
inline Lowering(Compiler* compiler, LinearScanInterface* lsra)
32+
inline Lowering(Compiler* compiler, RegAllocInterface* regAlloc)
3333
: Phase(compiler, PHASE_LOWERING)
3434
, vtableCallTemp(BAD_VAR_NUM)
3535
#ifdef TARGET_ARM64
3636
, m_blockIndirs(compiler->getAllocator(CMK_ArrayStack))
3737
#endif
3838
{
39-
m_lsra = (LinearScan*)lsra;
40-
assert(m_lsra);
39+
m_regAlloc = static_cast<RegAllocImpl*>(regAlloc);
40+
assert(m_regAlloc != nullptr);
4141
}
4242
virtual PhaseStatus DoPhase() override;
4343

4444
// This variant of LowerRange is called from outside of the main Lowering pass,
4545
// so it creates its own instance of Lowering to do so.
4646
void LowerRange(BasicBlock* block, LIR::ReadOnlyRange& range)
4747
{
48-
Lowering lowerer(comp, m_lsra);
48+
Lowering lowerer(comp, m_regAlloc);
4949
lowerer.m_block = block;
5050

5151
lowerer.LowerRange(range);
@@ -489,7 +489,7 @@ class Lowering final : public Phase
489489
// Return true if 'node' is a containable memory op.
490490
bool IsContainableMemoryOp(GenTree* node) const
491491
{
492-
return m_lsra->isContainableMemoryOp(node);
492+
return m_regAlloc->isContainableMemoryOp(node);
493493
}
494494

495495
// Return true if 'childNode' is a containable memory op by its size relative to the 'parentNode'.
@@ -594,14 +594,14 @@ class Lowering final : public Phase
594594
// do an expensive check here. For non-candidates it is not harmful to set lvDoNotEnregister.
595595
if (varDsc->lvTracked && !varDsc->lvDoNotEnregister)
596596
{
597-
assert(!m_lsra->isRegCandidate(varDsc));
597+
assert(!m_regAlloc->isRegCandidate(varDsc));
598598
comp->lvaSetVarDoNotEnregister(lclNum DEBUG_ARG(DoNotEnregisterReason::LocalField));
599599
}
600600
}
601601

602602
void RequireOutgoingArgSpace(GenTree* node, unsigned numBytes);
603603

604-
LinearScan* m_lsra;
604+
RegAllocImpl* m_regAlloc;
605605
unsigned vtableCallTemp; // local variable we use as a temp for vtable calls
606606
mutable SideEffectSet m_scratchSideEffects; // SideEffectSet used for IsSafeToContainMem and isRMWIndirCandidate
607607
BasicBlock* m_block;

src/coreclr/jit/lsra.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3636
That is, the destination register is one of the sources. In this case, we must not use the same register for
3737
the non-RMW operand as for the destination.
3838

39-
Overview (doLinearScan):
39+
Overview (doRegisterAllocation):
4040
- Walk all blocks, building intervals and RefPositions (buildIntervals)
4141
- Allocate registers (allocateRegisters)
4242
- Annotate nodes with register assignments (resolveRegisters)
@@ -824,7 +824,7 @@ void LinearScan::dumpOutVarToRegMap(BasicBlock* block)
824824

825825
#endif // DEBUG
826826

827-
LinearScanInterface* getLinearScanAllocator(Compiler* comp)
827+
RegAllocInterface* GetRegisterAllocator(Compiler* comp)
828828
{
829829
return new (comp, CMK_LSRA) LinearScan(comp);
830830
}
@@ -1314,15 +1314,15 @@ BasicBlock* LinearScan::getNextBlock()
13141314
}
13151315

13161316
//------------------------------------------------------------------------
1317-
// doLinearScan: The main method for register allocation.
1317+
// doRegisterAllocation: The main method for register allocation.
13181318
//
13191319
// Arguments:
13201320
// None
13211321
//
13221322
// Return Value:
13231323
// Suitable phase status
13241324
//
1325-
PhaseStatus LinearScan::doLinearScan()
1325+
PhaseStatus LinearScan::doRegisterAllocation()
13261326
{
13271327
// Check to see whether we have any local variables to enregister.
13281328
// We initialize this in the constructor based on opt settings,

src/coreclr/jit/lsra.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
622622
// to the next RefPosition in code order
623623
// THIS IS THE OPTION CURRENTLY BEING PURSUED
624624

625-
class LinearScan : public LinearScanInterface
625+
class LinearScan : public RegAllocInterface
626626
{
627627
friend class RefPosition;
628628
friend class Interval;
@@ -634,7 +634,7 @@ class LinearScan : public LinearScanInterface
634634
LinearScan(Compiler* theCompiler);
635635

636636
// This is the main driver
637-
virtual PhaseStatus doLinearScan();
637+
virtual PhaseStatus doRegisterAllocation();
638638

639639
static bool isSingleRegister(SingleTypeRegSet regMask)
640640
{
@@ -983,9 +983,9 @@ class LinearScan : public LinearScanInterface
983983

984984
public:
985985
// Used by Lowering when considering whether to split Longs, as well as by identifyCandidates().
986-
bool isRegCandidate(LclVarDsc* varDsc);
986+
virtual bool isRegCandidate(LclVarDsc* varDsc);
987987

988-
bool isContainableMemoryOp(GenTree* node);
988+
virtual bool isContainableMemoryOp(GenTree* node);
989989

990990
private:
991991
// Determine which locals are candidates for allocation
@@ -2199,6 +2199,8 @@ class LinearScan : public LinearScanInterface
21992199
}
22002200
};
22012201

2202+
using RegAllocImpl = LinearScan;
2203+
22022204
/*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
22032205
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
22042206
XX XX

src/coreclr/jit/regalloc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ enum CanDoubleAlign
2525
DEFAULT_DOUBLE_ALIGN = CAN_DOUBLE_ALIGN
2626
};
2727
#endif
28-
2928
#endif // REGALLOC_H_

src/coreclr/jit/regallocwasm.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,48 @@
88

99
#include "regallocwasm.h"
1010

11-
LinearScanInterface* getLinearScanAllocator(Compiler* compiler)
11+
RegAllocInterface* GetRegisterAllocator(Compiler* compiler)
1212
{
13-
return new (compiler->getAllocator(CMK_LSRA)) LinearScan(compiler);
13+
return new (compiler->getAllocator(CMK_LSRA)) WasmRegAlloc(compiler);
1414
}
1515

16-
LinearScan::LinearScan(Compiler* compiler)
16+
WasmRegAlloc::WasmRegAlloc(Compiler* compiler)
1717
: m_compiler(compiler)
1818
{
1919
}
2020

21-
PhaseStatus LinearScan::doLinearScan()
21+
PhaseStatus WasmRegAlloc::doRegisterAllocation()
2222
{
2323
m_compiler->codeGen->setFramePointerUsed(false);
2424
return PhaseStatus::MODIFIED_NOTHING;
2525
}
2626

27-
void LinearScan::recordVarLocationsAtStartOfBB(BasicBlock* bb)
27+
void WasmRegAlloc::recordVarLocationsAtStartOfBB(BasicBlock* bb)
2828
{
2929
}
3030

31-
bool LinearScan::willEnregisterLocalVars() const
31+
bool WasmRegAlloc::willEnregisterLocalVars() const
3232
{
3333
return m_compiler->compEnregLocals();
3434
}
3535

3636
#if TRACK_LSRA_STATS
37-
void LinearScan::dumpLsraStatsCsv(FILE* file)
37+
void WasmRegAlloc::dumpLsraStatsCsv(FILE* file)
3838
{
3939
}
4040

41-
void LinearScan::dumpLsraStatsSummary(FILE* file)
41+
void WasmRegAlloc::dumpLsraStatsSummary(FILE* file)
4242
{
4343
}
4444
#endif // TRACK_LSRA_STATS
4545

46-
bool LinearScan::isRegCandidate(LclVarDsc* varDsc)
46+
bool WasmRegAlloc::isRegCandidate(LclVarDsc* varDsc)
4747
{
4848
NYI_WASM("isRegCandidate");
4949
return false;
5050
}
5151

52-
bool LinearScan::isContainableMemoryOp(GenTree* node)
52+
bool WasmRegAlloc::isContainableMemoryOp(GenTree* node)
5353
{
5454
NYI_WASM("isContainableMemoryOp");
5555
return false;

src/coreclr/jit/regallocwasm.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
#pragma once
55

6-
// TODO-WASM-Factoring: rename the abstractions related to register allocation to make them less LSRA-specific.
7-
class LinearScan : public LinearScanInterface
6+
class WasmRegAlloc : public RegAllocInterface
87
{
98
Compiler* m_compiler;
109

1110
public:
12-
LinearScan(Compiler* compiler);
11+
WasmRegAlloc(Compiler* compiler);
1312

14-
virtual PhaseStatus doLinearScan();
13+
virtual PhaseStatus doRegisterAllocation();
1514
virtual void recordVarLocationsAtStartOfBB(BasicBlock* bb);
1615
virtual bool willEnregisterLocalVars() const;
1716
#if TRACK_LSRA_STATS
@@ -22,3 +21,5 @@ class LinearScan : public LinearScanInterface
2221
bool isRegCandidate(LclVarDsc* varDsc);
2322
bool isContainableMemoryOp(GenTree* node);
2423
};
24+
25+
using RegAllocImpl = WasmRegAlloc;

0 commit comments

Comments
 (0)