Skip to content

Commit 6dd237e

Browse files
jakobbotschmichaelgsharp
authored andcommitted
JIT: Rewrite initial parameter frame layout in terms of new ABI info (dotnet#101340)
Rewrite `lvaAssignVirtualFrameOffsetsToArgs` to make use of the ABI information that was already computed as part of ABI classification in the frontend.
1 parent 84baab8 commit 6dd237e

File tree

5 files changed

+234
-621
lines changed

5 files changed

+234
-621
lines changed

src/coreclr/jit/abi.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ regMaskTP ABIPassingSegment::GetRegisterMask() const
7171
// Offset relative to the first stack argument.
7272
//
7373
// Remarks:
74-
// On x86, where arguments are pushed in order and thus come in reverse order
75-
// in the callee, this is the offset to subtract from the top of the stack to
76-
// get the argument's address. By top of the stack is meant esp on entry + 4
77-
// for the return address + total size of stack arguments. In varargs methods
78-
// the varargs cookie contains the information required to allow the
79-
// computation of the total size of stack arguments.
80-
//
81-
// Outside x86 this is the offset to add to the first argument's address.
74+
// On x86, for the managed ABI where arguments are pushed in order and thus
75+
// come in reverse order in the callee, this is the offset to subtract from
76+
// the top of the stack to get the argument's address. By top of the stack is
77+
// meant esp on entry + 4 for the return address + total size of stack
78+
// arguments. In varargs methods the varargs cookie contains the information
79+
// required to allow the computation of the total size of stack arguments.
80+
//
81+
// Outside the managed x86 ABI this is the offset to add to the first
82+
// argument's address.
8283
//
8384
unsigned ABIPassingSegment::GetStackOffset() const
8485
{

src/coreclr/jit/abi.h

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,18 @@ struct ClassifierInfo
106106

107107
class X86Classifier
108108
{
109-
RegisterQueue m_regs;
110-
unsigned m_stackArgSize = 0;
109+
const ClassifierInfo& m_info;
110+
RegisterQueue m_regs;
111+
unsigned m_stackArgSize = 0;
111112

112113
public:
113114
X86Classifier(const ClassifierInfo& info);
114115

116+
unsigned StackSize()
117+
{
118+
return m_stackArgSize;
119+
}
120+
115121
ABIPassingInformation Classify(Compiler* comp,
116122
var_types type,
117123
ClassLayout* structLayout,
@@ -122,11 +128,16 @@ class WinX64Classifier
122128
{
123129
RegisterQueue m_intRegs;
124130
RegisterQueue m_floatRegs;
125-
unsigned m_stackArgSize = 0;
131+
unsigned m_stackArgSize = 32;
126132

127133
public:
128134
WinX64Classifier(const ClassifierInfo& info);
129135

136+
unsigned StackSize()
137+
{
138+
return m_stackArgSize;
139+
}
140+
130141
ABIPassingInformation Classify(Compiler* comp,
131142
var_types type,
132143
ClassLayout* structLayout,
@@ -142,6 +153,11 @@ class SysVX64Classifier
142153
public:
143154
SysVX64Classifier(const ClassifierInfo& info);
144155

156+
unsigned StackSize()
157+
{
158+
return m_stackArgSize;
159+
}
160+
145161
ABIPassingInformation Classify(Compiler* comp,
146162
var_types type,
147163
ClassLayout* structLayout,
@@ -158,6 +174,11 @@ class Arm64Classifier
158174
public:
159175
Arm64Classifier(const ClassifierInfo& info);
160176

177+
unsigned StackSize()
178+
{
179+
return roundUp(m_stackArgSize, TARGET_POINTER_SIZE);
180+
}
181+
161182
ABIPassingInformation Classify(Compiler* comp,
162183
var_types type,
163184
ClassLayout* structLayout,
@@ -182,6 +203,11 @@ class Arm32Classifier
182203
public:
183204
Arm32Classifier(const ClassifierInfo& info);
184205

206+
unsigned StackSize()
207+
{
208+
return m_stackArgSize;
209+
}
210+
185211
ABIPassingInformation Classify(Compiler* comp,
186212
var_types type,
187213
ClassLayout* structLayout,
@@ -198,6 +224,11 @@ class RiscV64Classifier
198224
public:
199225
RiscV64Classifier(const ClassifierInfo& info);
200226

227+
unsigned StackSize()
228+
{
229+
return m_stackArgSize;
230+
}
231+
201232
ABIPassingInformation Classify(Compiler* comp,
202233
var_types type,
203234
ClassLayout* structLayout,
@@ -214,6 +245,11 @@ class LoongArch64Classifier
214245
public:
215246
LoongArch64Classifier(const ClassifierInfo& info);
216247

248+
unsigned StackSize()
249+
{
250+
return m_stackArgSize;
251+
}
252+
217253
ABIPassingInformation Classify(Compiler* comp,
218254
var_types type,
219255
ClassLayout* structLayout,
@@ -247,6 +283,11 @@ class SwiftABIClassifier
247283
{
248284
}
249285

286+
unsigned StackSize()
287+
{
288+
return m_classifier.StackSize();
289+
}
290+
250291
ABIPassingInformation Classify(Compiler* comp,
251292
var_types type,
252293
ClassLayout* structLayout,

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,6 +3792,7 @@ class Compiler
37923792
unsigned lvaTableCnt; // lvaTable size (>= lvaCount)
37933793

37943794
ABIPassingInformation* lvaParameterPassingInfo;
3795+
unsigned lvaParameterStackSize;
37953796

37963797
unsigned lvaTrackedCount; // actual # of locals being tracked
37973798
unsigned lvaTrackedCountInSizeTUnits; // min # of size_t's sufficient to hold a bit for all the locals being tracked
@@ -3939,11 +3940,7 @@ class Compiler
39393940
void lvaUpdateArgWithInitialReg(LclVarDsc* varDsc);
39403941
void lvaUpdateArgsWithInitialReg();
39413942
void lvaAssignVirtualFrameOffsetsToArgs();
3942-
#ifdef UNIX_AMD64_ABI
3943-
int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs, int* callerArgOffset);
3944-
#else // !UNIX_AMD64_ABI
3945-
int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs);
3946-
#endif // !UNIX_AMD64_ABI
3943+
bool lvaGetRelativeOffsetToCallerAllocatedSpaceForParameter(unsigned lclNum, int* offset);
39473944
void lvaAssignVirtualFrameOffsetsToLocals();
39483945
bool lvaParamHasLocalStackSpace(unsigned lclNum);
39493946
int lvaAllocLocalAndSetVirtualOffset(unsigned lclNum, unsigned size, int stkOffs);

0 commit comments

Comments
 (0)