Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4904,7 +4904,6 @@ class Compiler
bool impIsImplicitTailCallCandidate(
OPCODE curOpcode, const BYTE* codeAddrOfNextOpcode, const BYTE* codeEnd, int prefixFlags, bool isRecursive);

bool impIsClassExact(CORINFO_CLASS_HANDLE classHnd);
bool impCanSkipCovariantStoreCheck(GenTree* value, GenTree* array);

methodPointerInfo* impAllocateMethodPointerInfo(const CORINFO_RESOLVED_TOKEN& token, mdToken tokenConstrained);
Expand Down Expand Up @@ -8011,6 +8010,7 @@ class Compiler
size_t bufferSize = 0);

const char* eeGetClassName(CORINFO_CLASS_HANDLE clsHnd, char* buffer = nullptr, size_t bufferSize = 0);
bool eeIsClassExact(CORINFO_CLASS_HANDLE clsHnd);

void eePrintObjectDescription(const char* prefix, CORINFO_OBJECT_HANDLE handle);
const char* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
Expand Down
36 changes: 36 additions & 0 deletions src/coreclr/jit/eeinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,42 @@ const char* Compiler::eeGetClassName(CORINFO_CLASS_HANDLE clsHnd, char* buffer,
return printer.GetBuffer();
}

//------------------------------------------------------------------------
// eeIsClassExact: check if a class handle can only describe values
// of exactly one class.
//
// Arguments:
// classHnd - handle for class in question
//
// Return value:
// true if class is final and not subject to special casting from
// variance or similar.
//
// Note:
// We are conservative on arrays of primitive types here.
//
bool Compiler::eeIsClassExact(CORINFO_CLASS_HANDLE clsHnd)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this method because Jan already moved it to VM side in #97424

{
DWORD flags = info.compCompHnd->getClassAttribs(clsHnd);
DWORD flagsMask = CORINFO_FLG_FINAL | CORINFO_FLG_VARIANCE | CORINFO_FLG_ARRAY;

if ((flags & flagsMask) == CORINFO_FLG_FINAL)
{
return true;
}
if ((flags & flagsMask) == (CORINFO_FLG_FINAL | CORINFO_FLG_ARRAY))
{
CORINFO_CLASS_HANDLE arrayElementHandle = nullptr;
CorInfoType type = info.compCompHnd->getChildType(clsHnd, &arrayElementHandle);

if ((type == CORINFO_TYPE_CLASS) || (type == CORINFO_TYPE_VALUECLASS))
{
return eeIsClassExact(arrayElementHandle);
}
}
return false;
}

//------------------------------------------------------------------------
// eeGetShortClassName: Returns class name with no instantiation.
//
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14034,7 +14034,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree)

// if both classes are "final" (e.g. System.String[]) we can replace the comparison
// with `true/false` + null check.
if ((objCls != NO_CLASS_HANDLE) && (pIsExact || impIsClassExact(objCls)))
if ((objCls != NO_CLASS_HANDLE) && (pIsExact || eeIsClassExact(objCls)))
{
TypeCompareState tcs = info.compCompHnd->compareTypesForEquality(objCls, clsHnd);
if (tcs != TypeCompareState::May)
Expand Down Expand Up @@ -18585,7 +18585,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
}
else
{
*pIsExact = impIsClassExact(objClass);
*pIsExact = eeIsClassExact(objClass);
}
}

Expand Down
Loading