Skip to content

Commit

Permalink
JIT: Rewrite initial parameter frame layout in terms of new ABI info (#…
Browse files Browse the repository at this point in the history
…101340)

Rewrite `lvaAssignVirtualFrameOffsetsToArgs` to make use of the ABI
information that was already computed as part of ABI classification in
the frontend.
  • Loading branch information
jakobbotsch committed May 8, 2024
1 parent a0eb5f2 commit 562457f
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 621 deletions.
17 changes: 9 additions & 8 deletions src/coreclr/jit/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ regMaskTP ABIPassingSegment::GetRegisterMask() const
// Offset relative to the first stack argument.
//
// Remarks:
// On x86, where arguments are pushed in order and thus come in reverse order
// in the callee, this is the offset to subtract from the top of the stack to
// get the argument's address. By top of the stack is meant esp on entry + 4
// for the return address + total size of stack arguments. In varargs methods
// the varargs cookie contains the information required to allow the
// computation of the total size of stack arguments.
//
// Outside x86 this is the offset to add to the first argument's address.
// On x86, for the managed ABI where arguments are pushed in order and thus
// come in reverse order in the callee, this is the offset to subtract from
// the top of the stack to get the argument's address. By top of the stack is
// meant esp on entry + 4 for the return address + total size of stack
// arguments. In varargs methods the varargs cookie contains the information
// required to allow the computation of the total size of stack arguments.
//
// Outside the managed x86 ABI this is the offset to add to the first
// argument's address.
//
unsigned ABIPassingSegment::GetStackOffset() const
{
Expand Down
47 changes: 44 additions & 3 deletions src/coreclr/jit/abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ struct ClassifierInfo

class X86Classifier
{
RegisterQueue m_regs;
unsigned m_stackArgSize = 0;
const ClassifierInfo& m_info;
RegisterQueue m_regs;
unsigned m_stackArgSize = 0;

public:
X86Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return m_stackArgSize;
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand All @@ -122,11 +128,16 @@ class WinX64Classifier
{
RegisterQueue m_intRegs;
RegisterQueue m_floatRegs;
unsigned m_stackArgSize = 0;
unsigned m_stackArgSize = 32;

public:
WinX64Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return m_stackArgSize;
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand All @@ -142,6 +153,11 @@ class SysVX64Classifier
public:
SysVX64Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return m_stackArgSize;
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand All @@ -158,6 +174,11 @@ class Arm64Classifier
public:
Arm64Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return roundUp(m_stackArgSize, TARGET_POINTER_SIZE);
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand All @@ -182,6 +203,11 @@ class Arm32Classifier
public:
Arm32Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return m_stackArgSize;
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand All @@ -198,6 +224,11 @@ class RiscV64Classifier
public:
RiscV64Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return m_stackArgSize;
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand All @@ -214,6 +245,11 @@ class LoongArch64Classifier
public:
LoongArch64Classifier(const ClassifierInfo& info);

unsigned StackSize()
{
return m_stackArgSize;
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand Down Expand Up @@ -247,6 +283,11 @@ class SwiftABIClassifier
{
}

unsigned StackSize()
{
return m_classifier.StackSize();
}

ABIPassingInformation Classify(Compiler* comp,
var_types type,
ClassLayout* structLayout,
Expand Down
7 changes: 2 additions & 5 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3792,6 +3792,7 @@ class Compiler
unsigned lvaTableCnt; // lvaTable size (>= lvaCount)

ABIPassingInformation* lvaParameterPassingInfo;
unsigned lvaParameterStackSize;

unsigned lvaTrackedCount; // actual # of locals being tracked
unsigned lvaTrackedCountInSizeTUnits; // min # of size_t's sufficient to hold a bit for all the locals being tracked
Expand Down Expand Up @@ -3939,11 +3940,7 @@ class Compiler
void lvaUpdateArgWithInitialReg(LclVarDsc* varDsc);
void lvaUpdateArgsWithInitialReg();
void lvaAssignVirtualFrameOffsetsToArgs();
#ifdef UNIX_AMD64_ABI
int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs, int* callerArgOffset);
#else // !UNIX_AMD64_ABI
int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs);
#endif // !UNIX_AMD64_ABI
bool lvaGetRelativeOffsetToCallerAllocatedSpaceForParameter(unsigned lclNum, int* offset);
void lvaAssignVirtualFrameOffsetsToLocals();
bool lvaParamHasLocalStackSpace(unsigned lclNum);
int lvaAllocLocalAndSetVirtualOffset(unsigned lclNum, unsigned size, int stkOffs);
Expand Down
Loading

0 comments on commit 562457f

Please sign in to comment.