Skip to content

Commit

Permalink
Delete "lvPromotedStruct" (dotnet#74702)
Browse files Browse the repository at this point in the history
In all cases where it was used, "lvPromoted" is a better check.
  • Loading branch information
SingleAccretion committed Sep 9, 2022
1 parent fbb2ec3 commit 31001a3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3612,7 +3612,7 @@ GenTree* Compiler::optCopyAssertionProp(AssertionDsc* curAssertion,
//
if (tree->OperIs(GT_LCL_FLD))
{
if (copyVarDsc->IsEnregisterableLcl() || copyVarDsc->lvPromotedStruct())
if (copyVarDsc->IsEnregisterableLcl() || copyVarDsc->lvPromoted)
{
return nullptr;
}
Expand Down
18 changes: 1 addition & 17 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,23 +981,7 @@ class LclVarDsc
lvStkOffs = offset;
}

unsigned lvExactSize; // (exact) size of the type in bytes

// Is this a promoted struct?
// This method returns true only for structs (including SIMD structs), not for
// locals that are split on a 32-bit target.
// It is only necessary to use this:
// 1) if only structs are wanted, and
// 2) if Lowering has already been done.
// Otherwise lvPromoted is valid.
bool lvPromotedStruct()
{
#if !defined(TARGET_64BIT)
return (lvPromoted && !varTypeIsLong(lvType));
#else // defined(TARGET_64BIT)
return lvPromoted;
#endif // defined(TARGET_64BIT)
}
unsigned lvExactSize; // (exact) size of a STRUCT/SIMD/BLK local in bytes.

unsigned lvSize() const;

Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/decomposelongs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,18 +2131,28 @@ void DecomposeLongs::PromoteLongVars()
m_compiler->lvaGrabTemp(false DEBUGARG(bufp)); // Lifetime of field locals might span multiple BBs, so
// they are long lifetime temps.

varDsc = m_compiler->lvaGetDesc(lclNum);
LclVarDsc* fieldVarDsc = m_compiler->lvaGetDesc(varNum);
fieldVarDsc->lvType = TYP_INT;
fieldVarDsc->lvExactSize = genTypeSize(TYP_INT);
fieldVarDsc->lvIsStructField = true;
fieldVarDsc->lvFldOffset = (unsigned char)(index * genTypeSize(TYP_INT));
fieldVarDsc->lvFldOrdinal = (unsigned char)index;
fieldVarDsc->lvParentLcl = lclNum;

// Currently we do not support enregistering incoming promoted aggregates with more than one field.
if (isParam)
{
fieldVarDsc->lvIsParam = true;
m_compiler->lvaSetVarDoNotEnregister(varNum DEBUGARG(DoNotEnregisterReason::LongParamField));

#if FEATURE_MULTIREG_ARGS
if (varDsc->lvIsRegArg)
{
fieldVarDsc->lvIsRegArg = 1; // Longs are never split.
fieldVarDsc->SetArgReg((index == 0) ? varDsc->GetArgReg() : varDsc->GetOtherArgReg());
}
#endif // FEATURE_MULTIREG_ARGS
}
}
}
Expand Down
39 changes: 8 additions & 31 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4926,7 +4926,7 @@ void Compiler::lvaComputeRefCounts(bool isRecompute, bool setSlotNumbers)
//
// This was formerly done during RCS_EARLY counting,
// and we did not used to reset counts like we do now.
if (varDsc->lvIsStructField)
if (varDsc->lvIsStructField && varTypeIsStruct(lvaGetDesc(varDsc->lvParentLcl)))
{
varDsc->incRefCnts(BB_UNITY_WEIGHT, this);
}
Expand Down Expand Up @@ -5740,7 +5740,7 @@ void Compiler::lvaUpdateArgsWithInitialReg()
{
LclVarDsc* varDsc = lvaGetDesc(lclNum);

if (varDsc->lvPromotedStruct())
if (varDsc->lvPromoted)
{
for (unsigned fieldVarNum = varDsc->lvFieldLclStart;
fieldVarNum < varDsc->lvFieldLclStart + varDsc->lvFieldCnt; ++fieldVarNum)
Expand Down Expand Up @@ -6041,7 +6041,7 @@ int Compiler::lvaAssignVirtualFrameOffsetToArg(unsigned lclNum,
// For struct promoted parameters we need to set the offsets for the field lclVars.
//
// For a promoted struct we also assign the struct fields stack offset
if (varDsc->lvPromotedStruct())
if (varDsc->lvPromoted)
{
unsigned firstFieldNum = varDsc->lvFieldLclStart;
int offset = varDsc->GetStackOffset();
Expand Down Expand Up @@ -6345,17 +6345,7 @@ int Compiler::lvaAssignVirtualFrameOffsetToArg(unsigned lclNum,
// For a dependent promoted struct we also assign the struct fields stack offset
CLANG_FORMAT_COMMENT_ANCHOR;

#if !defined(TARGET_64BIT)
if ((varDsc->TypeGet() == TYP_LONG) && varDsc->lvPromoted)
{
noway_assert(varDsc->lvFieldCnt == 2);
fieldVarNum = varDsc->lvFieldLclStart;
lvaTable[fieldVarNum].SetStackOffset(varDsc->GetStackOffset());
lvaTable[fieldVarNum + 1].SetStackOffset(varDsc->GetStackOffset() + genTypeSize(TYP_INT));
}
else
#endif // !defined(TARGET_64BIT)
if (varDsc->lvPromotedStruct())
if (varDsc->lvPromoted)
{
unsigned firstFieldNum = varDsc->lvFieldLclStart;
for (unsigned i = 0; i < varDsc->lvFieldCnt; i++)
Expand Down Expand Up @@ -7105,10 +7095,10 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
// Reserve the stack space for this variable
stkOffs = lvaAllocLocalAndSetVirtualOffset(lclNum, lvaLclSize(lclNum), stkOffs);
#if defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64)
// If we have an incoming register argument that has a struct promoted field
// then we need to copy the lvStkOff (the stack home) from the reg arg to the field lclvar
// If we have an incoming register argument that has a promoted field then we
// need to copy the lvStkOff (the stack home) from the reg arg to the field lclvar
//
if (varDsc->lvIsRegArg && varDsc->lvPromotedStruct())
if (varDsc->lvIsRegArg && varDsc->lvPromoted)
{
unsigned firstFieldNum = varDsc->lvFieldLclStart;
for (unsigned i = 0; i < varDsc->lvFieldCnt; i++)
Expand All @@ -7117,20 +7107,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
fieldVarDsc->SetStackOffset(varDsc->GetStackOffset() + fieldVarDsc->lvFldOffset);
}
}
#ifdef TARGET_ARM
// If we have an incoming register argument that has a promoted long
// then we need to copy the lvStkOff (the stack home) from the reg arg to the field lclvar
//
else if (varDsc->lvIsRegArg && varDsc->lvPromoted)
{
assert(varTypeIsLong(varDsc) && (varDsc->lvFieldCnt == 2));

unsigned fieldVarNum = varDsc->lvFieldLclStart;
lvaTable[fieldVarNum].SetStackOffset(varDsc->GetStackOffset());
lvaTable[fieldVarNum + 1].SetStackOffset(varDsc->GetStackOffset() + 4);
}
#endif // TARGET_ARM
#endif // TARGET_ARM64 || TARGET_LOONGARCH64
#endif // defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64)
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2044,11 +2044,6 @@ void LinearScan::UpdateRegStateForStructArg(LclVarDsc* argDsc)
// The argument is live on entry to the function
// (or is untracked and therefore assumed live)
//
// Notes:
// This relies on a method in regAlloc.cpp that is shared between LSRA
// and regAlloc. It is further abstracted here because regState is updated
// separately for tracked and untracked variables in LSRA.
//
void LinearScan::updateRegStateForArg(LclVarDsc* argDsc)
{
#if defined(UNIX_AMD64_ABI) || defined(TARGET_LOONGARCH64)
Expand Down Expand Up @@ -2204,7 +2199,7 @@ void LinearScan::buildIntervals()
RefPosition* pos = newRefPosition(interval, MinLocation, RefTypeParamDef, nullptr, mask);
pos->setRegOptional(true);
}
else if (varTypeIsStruct(argDsc->lvType))
else if (argDsc->lvPromoted)
{
for (unsigned fieldVarNum = argDsc->lvFieldLclStart;
fieldVarNum < argDsc->lvFieldLclStart + argDsc->lvFieldCnt; ++fieldVarNum)
Expand Down Expand Up @@ -2236,7 +2231,7 @@ void LinearScan::buildIntervals()
{
LclVarDsc* argDsc = compiler->lvaGetDesc(argNum);

if (argDsc->lvPromotedStruct())
if (argDsc->lvPromoted)
{
for (unsigned fieldVarNum = argDsc->lvFieldLclStart;
fieldVarNum < argDsc->lvFieldLclStart + argDsc->lvFieldCnt; ++fieldVarNum)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/rationalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void Rationalizer::RewriteSIMDIndir(LIR::Use& use)

comp->lvaSetVarDoNotEnregister(lclNum DEBUGARG(DoNotEnregisterReason::LocalField));
}
if (varDsc->lvPromotedStruct())
if (varDsc->lvPromoted)
{
comp->lvaSetVarDoNotEnregister(lclNum DEBUGARG(DoNotEnregisterReason::BlockOp));
}
Expand Down

0 comments on commit 31001a3

Please sign in to comment.