Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ class LclVarDsc
}

unsigned lvExactSize() const;
unsigned lvSymbolicSize() const;

unsigned lvSlotNum; // original slot # (if remapped)

Expand Down Expand Up @@ -4208,6 +4209,7 @@ class Compiler

unsigned lvaLclStackHomeSize(unsigned varNum);
unsigned lvaLclExactSize(unsigned varNum);
unsigned lvaLclSymbolicSize(unsigned varNum);

bool lvaHaveManyLocals(float percent = 1.0f) const;

Expand Down
13 changes: 12 additions & 1 deletion src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,11 @@ extern const BYTE genTypeStSzs[TYP_COUNT];
template <class T>
inline unsigned genTypeStSz(T value)
{
#ifdef TARGET_ARM64
// The size of these types cannot be evaluated in static contexts.
noway_assert(TypeGet(value) != TYP_SIMD);
noway_assert(TypeGet(value) != TYP_MASK);
#endif
assert((unsigned)TypeGet(value) < ArrLen(genTypeStSzs));

return genTypeStSzs[TypeGet(value)];
Expand Down Expand Up @@ -3436,6 +3441,12 @@ inline bool Compiler::fgIsBigOffset(size_t offset)
//
inline bool Compiler::IsValidLclAddr(unsigned lclNum, unsigned offset)
{
#ifdef TARGET_ARM64
if (varTypeHasUnknownSize(lvaGetDesc(lclNum)))
{
return false;
}
#endif
return (offset < UINT16_MAX) && (offset < lvaLclExactSize(lclNum));
}

Expand Down Expand Up @@ -4699,7 +4710,7 @@ GenTree::VisitResult GenTree::VisitLocalDefs(Compiler* comp, TVisitor visitor)
{
if (OperIs(GT_STORE_LCL_VAR))
{
unsigned size = comp->lvaLclExactSize(AsLclVarCommon()->GetLclNum());
unsigned size = comp->lvaLclSymbolicSize(AsLclVarCommon()->GetLclNum());
return visitor(LocalDef(AsLclVarCommon(), /* isEntire */ true, 0, size));
}
if (OperIs(GT_STORE_LCL_FLD))
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18921,6 +18921,8 @@ bool GenTree::IsFieldAddr(Compiler* comp, GenTree** pBaseAddr, FieldSeq** pFldSe
bool Compiler::gtStoreDefinesField(
LclVarDsc* fieldVarDsc, ssize_t offset, unsigned size, ssize_t* pFieldStoreOffset, unsigned* pFieldStoreSize)
{
assert(size != SIZE_UNKNOWN);

ssize_t fieldOffset = fieldVarDsc->lvFldOffset;
unsigned fieldSize = genTypeSize(fieldVarDsc); // No TYP_STRUCT field locals.

Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,15 @@ unsigned Compiler::lvaLclExactSize(unsigned varNum)
return lvaGetDesc(varNum)->lvExactSize();
}

// Return the size of the local variable, allowing the possibility for the local
// to have an unknown size. Returns the size of the local variable in bytes, or
// SIZE_UNKNOWN.
unsigned Compiler::lvaLclSymbolicSize(unsigned varNum)
{
assert(varNum < lvaCount);
return lvaGetDesc(varNum)->lvSymbolicSize();
}

// LclVarDsc "less" comparer used to compare the weight of two locals, when optimizing for small code.
class LclVarDsc_SmallCode_Less
{
Expand Down Expand Up @@ -3237,6 +3246,21 @@ void Compiler::lvaSortByRefCount()
// stack slot size.
//
unsigned LclVarDsc::lvExactSize() const
{
assert(!varTypeHasUnknownSize(lvType));
unsigned size = lvSymbolicSize();
assert(size != SIZE_UNKNOWN);
return size;
}

//------------------------------------------------------------------------
// lvSymbolicSize: Get the symbolic size of the type of this local.
//
// Return Value:
// Size in bytes, or SIZE_UNKNOWN. Always non-zero, but not necessarily
// a multiple of the stack slot size.
//
unsigned LclVarDsc::lvSymbolicSize() const
{
return (lvType == TYP_STRUCT) ? GetLayout()->GetSize() : genTypeSize(lvType);
}
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4068,7 +4068,8 @@ void CSE_Heuristic::Initialize()
}
#endif // TARGET_X86

if (onStack)
// TODO-SVE: What are the consequences of excluding Vector<T> here?
if (onStack && !varTypeHasUnknownSize(varDsc))
{
frameSize += m_pCompiler->lvaLclStackHomeSize(lclNum);
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/regalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ void Compiler::raMarkStkVars()

noway_assert((varDsc->lvType != TYP_UNDEF) && (varDsc->lvType != TYP_VOID) && (varDsc->lvType != TYP_UNKNOWN));
#if FEATURE_FIXED_OUT_ARGS
noway_assert((lclNum == lvaOutgoingArgSpaceVar) || (lvaLclStackHomeSize(lclNum) != 0));
noway_assert((lclNum == lvaOutgoingArgSpaceVar) || varTypeHasUnknownSize(varDsc) ||
(lvaLclStackHomeSize(lclNum) != 0));
#else // FEATURE_FIXED_OUT_ARGS
noway_assert(lvaLclStackHomeSize(lclNum) != 0);
noway_assert(varTypeHasUnknownSize(varDsc) || lvaLclStackHomeSize(lclNum) != 0);
#endif // FEATURE_FIXED_OUT_ARGS

varDsc->lvOnFrame = true; // Our prediction is that the final home for this local variable will be in the
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6165,7 +6165,7 @@ void Compiler::fgValueNumberLocalStore(GenTree* storeNode,

if (defSsaNum != SsaConfig::RESERVED_SSA_NUM)
{
unsigned lclSize = lvaLclExactSize(defLclNum);
unsigned lclSize = lvaLclSymbolicSize(defLclNum);

ValueNumPair newLclValue;
if (vnStore->LoadStoreIsEntire(lclSize, defOffset, defSize))
Expand Down Expand Up @@ -12116,7 +12116,7 @@ void Compiler::fgValueNumberStore(GenTree* store)
case GT_STORE_LCL_VAR:
{
GenTreeLclVarCommon* lcl = store->AsLclVarCommon();
fgValueNumberLocalStore(store, lcl, 0, lvaLclExactSize(lcl->GetLclNum()), valueVNPair,
fgValueNumberLocalStore(store, lcl, 0, lvaLclSymbolicSize(lcl->GetLclNum()), valueVNPair,
/* normalize */ false);
}
break;
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/jit/vartype.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ enum var_types_register
#define TYP_U_IMPL TYP_UINT
#endif

#define SIZE_UNKNOWN UINT8_MAX

/*****************************************************************************/

const extern BYTE varTypeClassification[TYP_COUNT];
Expand Down Expand Up @@ -379,6 +381,21 @@ inline bool varTypeIsValidHfaType(T vt)
}
}

//------------------------------------------------------------------------
// varTypeHasUnknownSize: Determine whether the type has an unknown size
//
// Arguments:
// vt - the type of interest
//
// Return Value:
// Returns true iff the type has size equal to SIZE_UNKNOWN
//
template <class T>
inline bool varTypeHasUnknownSize(T vt)
{
return genTypeSize(TypeGet(vt)) == SIZE_UNKNOWN;
}

/*****************************************************************************/
#endif // _VARTYPE_H_
/*****************************************************************************/
Loading