Skip to content

Commit

Permalink
Remove IsClass and IsPrimitive
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Dec 27, 2019
1 parent 75d5c84 commit a6f6f13
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ CorJitResult __stdcall interceptor_ICJC::compileMethod(ICorJitInfo*
our_ICorJitInfo.getBuiltinClass(CLASSID_STRING);
our_ICorJitInfo.getBuiltinClass(CLASSID_ARGUMENT_HANDLE);
our_ICorJitInfo.getBuiltinClass(CLASSID_RUNTIME_TYPE);
our_ICorJitInfo.getBuiltinClass(CLASSID_ENUM);
our_ICorJitInfo.getBuiltinClass(CLASSID___CANON);

#ifdef fatMC
// to build up a fat mc
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/src/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,6 @@ enum CorInfoClassId
CLASSID_STRING,
CLASSID_ARGUMENT_HANDLE,
CLASSID_RUNTIME_TYPE,
CLASSID_ENUM,
CLASSID___CANON,
};

enum CorInfoInline
Expand Down
63 changes: 7 additions & 56 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4015,15 +4015,12 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
break;
}

case NI_System_Type_get_IsClass:
case NI_System_Type_get_IsPrimitive:
case NI_System_Type_get_IsValueType:
{
// Optimize things like
// Optimize
//
// ldtoken [Type]
// call Type.GetTypeFromHandle (which is replaced with CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE)
// call Type.IsValueType (also IsClass and IsPrimitive)
// call Type.IsValueType
//
// to `true` or `false`
// e.g. `typeof(int).IsValueType` => `true`
Expand All @@ -4033,51 +4030,13 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE))
{
CORINFO_CLASS_HANDLE hClass = gtGetHelperArgClassHandle(call->gtCallArgs->GetNode());
if (hClass == NO_CLASS_HANDLE || hClass == info.compCompHnd->getBuiltinClass(CLASSID___CANON))
if (hClass != NO_CLASS_HANDLE)
{
// Ignore System.__Canon
break;
}

BOOL isValueType = eeIsValueClass(hClass);
CorInfoType cit = info.compCompHnd->getTypeForPrimitiveValueClass(hClass);
if (ni == NI_System_Type_get_IsPrimitive)
{
if (isValueType && (cit >= CORINFO_TYPE_BOOL) && (cit <= CORINFO_TYPE_DOUBLE))
{
// Enums are not primitive types
BOOL isEnum = info.compCompHnd->getBuiltinClass(CLASSID_ENUM) ==
info.compCompHnd->getParentType(hClass);
retNode = gtNewIconNode(!isEnum ? 1 : 0);
}
else
{
retNode = gtNewIconNode(0);
}
}
else if (ni == NI_System_Type_get_IsClass)
{
// Pointers are also classes (e.g. typeof(int*).IsClass is true)
if (isValueType && (cit != CORINFO_TYPE_PTR))
{
retNode = gtNewIconNode(0);
}
else
{
BOOL isInterface = info.compCompHnd->getClassAttribs(hClass) & CORINFO_FLG_INTERFACE;
retNode = gtNewIconNode(isInterface ? 0 : 1);
}
retNode = gtNewIconNode((eeIsValueClass(hClass) &&
// pointers are not value types (e.g. typeof(int*).IsValueType is false)
info.compCompHnd->getTypeForPrimitiveValueClass(hClass) != CORINFO_TYPE_PTR) ? 1 : 0);
impPopStack(); // drop CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE call
}
else if (ni == NI_System_Type_get_IsValueType)
{
retNode = gtNewIconNode((isValueType && (cit != CORINFO_TYPE_PTR)) ? 1 : 0);
}
else
{
assert(false);
}
// drop CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE call
impPopStack();
}
}
break;
Expand Down Expand Up @@ -4380,14 +4339,6 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
{
result = NI_System_Type_get_IsValueType;
}
else if (strcmp(methodName, "get_IsClass") == 0)
{
result = NI_System_Type_get_IsClass;
}
else if (strcmp(methodName, "get_IsPrimitive") == 0)
{
result = NI_System_Type_get_IsPrimitive;
}
}
}
#if defined(_TARGET_XARCH_) // We currently only support BSWAP on x86
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/src/jit/namedintrinsiclist.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ enum NamedIntrinsic : unsigned short
NI_System_Buffers_Binary_BinaryPrimitives_ReverseEndianness,
NI_System_GC_KeepAlive,
NI_System_Type_get_IsValueType,
NI_System_Type_get_IsClass,
NI_System_Type_get_IsPrimitive,

#ifdef FEATURE_HW_INTRINSICS
NI_IsSupported_True,
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,12 +1689,6 @@ private CorInfoInitClassResult initClass(CORINFO_FIELD_STRUCT_* field, CORINFO_M
TypeDesc typeOfRuntimeType = _compilation.GetTypeOfRuntimeType();
return typeOfRuntimeType != null ? ObjectToHandle(typeOfRuntimeType) : null;

case CorInfoClassId.CLASSID_ENUM:
return ObjectToHandle(_compilation.TypeSystemContext.GetWellKnownType(WellKnownType.Enum));

case CorInfoClassId.CLASSID___CANON:
return ObjectToHandle(_compilation.TypeSystemContext.GetWellKnownType(WellKnownType.__Canon));

default:
throw new NotImplementedException();
}
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ public enum CorInfoClassId
CLASSID_STRING,
CLASSID_ARGUMENT_HANDLE,
CLASSID_RUNTIME_TYPE,
CLASSID_ENUM,
CLASSID___CANON,
}
public enum CorInfoInline
{
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/src/tools/Common/TypeSystem/Common/TypeDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ internal void SetWellKnownType(WellKnownType wellKnownType)
flags = TypeFlags.ValueType;
break;

// Should WellKnownType.__Canon be handled here?

default:
throw new ArgumentException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ public enum WellKnownType

TypedReference,
ByReferenceOfT,
__Canon,
}
}
6 changes: 0 additions & 6 deletions src/coreclr/src/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4310,12 +4310,6 @@ CORINFO_CLASS_HANDLE CEEInfo::getBuiltinClass(CorInfoClassId classId)
case CLASSID_RUNTIME_TYPE:
result = CORINFO_CLASS_HANDLE(g_pRuntimeTypeClass);
break;
case CLASSID_ENUM:
result = CORINFO_CLASS_HANDLE(g_pEnumClass);
break;
case CLASSID___CANON:
result = CORINFO_CLASS_HANDLE(g_pCanonMethodTableClass);
break;
default:
_ASSERTE(!"NYI: unknown classId");
break;
Expand Down
Loading

0 comments on commit a6f6f13

Please sign in to comment.