Skip to content

Make Type.IsEnum and Type.GetEnumUnderlyingType intrinsics - #71685

Merged
jkotas merged 59 commits into
dotnet:mainfrom
MichalPetryka:enum-underlyingtype
Nov 11, 2022
Merged

Make Type.IsEnum and Type.GetEnumUnderlyingType intrinsics#71685
jkotas merged 59 commits into
dotnet:mainfrom
MichalPetryka:enum-underlyingtype

Conversation

@MichalPetryka

@MichalPetrykaMichalPetryka commented Jul 5, 2022

Copy link
Copy Markdown
Contributor

Makes Type.IsEnum and Type.GetEnumUnderlyingType intrinsics.

Implements IsKnownConstant for Type.

Optimizes Type.GetTypeCode using IsKnownConstant.

Introduces a JIT helper for checking if a tree is typeof.

Introduces JIT tests checking the generated codegen.

Makes Type.GetTypeCode a JIT intrinsic for primitive types,
enums and strings.
Makes Type.IsEnum use intrinsics instead of IsSubclassOf
Makes Enum.GetUnderlyingType use Type.GetTypeCode
Moves the legacy FCall to InternalGetUnderlyingTypeImpl,
so that the non-intrinsic GetTypeCode can use it.
Introduces JIT tests checking the generated codegen.
@ghostghost added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member labels Jul 5, 2022
@ghost

ghost commented Jul 5, 2022

Copy link
Copy Markdown

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Makes Type.GetTypeCode a JIT intrinsic for primitive types,
enums and strings.

Makes Type.IsEnum use intrinsics instead of IsSubclassOf

Makes Enum.GetUnderlyingType use Type.GetTypeCode

Moves the legacy FCall to InternalGetUnderlyingTypeImpl,
so that the non-intrinsic GetTypeCode can use it.

Introduces JIT tests checking the generated codegen.

Fixes #70483.

Author:MichalPetryka
Assignees:-
Labels:

area-CodeGen-coreclr

Milestone:-

Comment threadsrc/libraries/System.Private.CoreLib/src/System/Type.cs Outdated
Comment threadsrc/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs Outdated
@MichalPetryka

Copy link
Copy Markdown
ContributorAuthor

This PR generates the desired codegen only with #71778.

@MichalPetrykaMichalPetryka changed the title Make Type.GetTypeCode an intrinsicMake Type.GetTypeCode/IsEnum intrinsicsJul 9, 2022
@MichalPetryka
MichalPetryka marked this pull request as ready for review July 9, 2022 17:07
// Return Value:
// Is the tree typeof()
//
bool Compiler::gtIsTypeof(GenTree* tree, CORINFO_CLASS_HANDLE* handle)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like you should try and leverage gtGetTypeProducerKind and/or gtIsTypeHandleToRuntimeTypeHelper here.

@MichalPetrykaMichalPetrykaJul 10, 2022

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

gtGetTypeProducerKind doesn't seem particularly useful here since we don't know the exact type with .GetType() and we don't want to return null types here so I've used gtIsTypeHandleToRuntimeTypeHelper and added tests for NRE with Type.GetTypeFromHandle(default)(which I assume generates the _MAYBENULL helper variant)(actually only __reftype seems to generate it).

@jkotas

Copy link
Copy Markdown
Member

Yes, I think it is okay to have that method in Type.cs.

Nit: I would call the method GetRuntimeTypeCode like what it is called in NativeAOT. It is nicer name than GetTypeCodeInternal.

@AndyAyersMSAndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

JIT/SPMI changes LGTM.

Comment threadsrc/libraries/System.Private.CoreLib/src/System/Type.cs
@vargaz

Copy link
Copy Markdown
Contributor

#77763 will fix the mono failures.

jkotas pushed a commit that referenced this pull request Nov 3, 2022
@jkotas

Copy link
Copy Markdown
Member

@MichalPetryka Could you please merge from main and resolve the conflicts?

@MichalPetryka

MichalPetryka commented Nov 3, 2022

Copy link
Copy Markdown
ContributorAuthor

@jkotasDone. Seems like ThunkGenerator fails after the merge?

@jkotas

Copy link
Copy Markdown
Member

Seems like ThunkGenerator fails after the merge?

Do you have #77715 ?

@MichalPetryka

Copy link
Copy Markdown
ContributorAuthor

Seems like ThunkGenerator fails after the merge?

Do you have #77715 ?

Yes. For context:

src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(37,18): error SA1400: Element 'TypeReplacement' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(103,18): error SA1400: Element 'Parameter' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(117,18): error SA1400: Element 'FunctionDecl' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(167,18): error SA1400: Element 'Program' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(169,14): error SA1400: Element 'ParseMode' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(84,34): error SA1400: Element '_instructionSets' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(85,41): error SA1400: Element '_implications' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(86,35): error SA1400: Element '_instructionSetsGroups' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(87,45): error SA1400: Element '_64bitVariants' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(88,39): error SA1400: Element '_r2rNamesByName' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(89,39): error SA1400: Element '_r2rNamesByNumber' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(90,27): error SA1400: Element '_architectures' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(91,42): error SA1400: Element '_architectureJitNames' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(92,42): error SA1400: Element '_architectureVectorInstructionSetJitNames' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(93,25): error SA1400: Element '_64BitArchitectures' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(94,36): error SA1400: Element '_64BitVariantArchitectureJitNameSuffix' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(96,19): error SA1400: Element 'FlagsFieldCount' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(16,22): error SA1400: Element 'InstructionSetInfo' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(61,23): error SA1400: Element 'InstructionSetGroup' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(63,22): error SA1400: Element 'InstructionSetImplication' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(176,42): error SA1400: Element 'ParseInput' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(261,21): error SA1400: Element 'WriteAutogeneratedHeader' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(29,27): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(49,26): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(51,26): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(53,31): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(98,14): error SA1400: Element 'ArchitectureEncountered' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(109,14): error SA1400: Element 'ValidateArchitectureEncountered' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(138,37): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(153,41): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(371,21): error SA1400: Element 'WriteNativeWrapperInterface' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(273,21): error SA1400: Element 'WriteManagedThunkInterface' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(421,21): error SA1400: Element 'WriteAPI_Names' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(333,26): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(240,22): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(242,36): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(435,21): error SA1400: Element 'API_Wrapper_Generic_Core' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(519,21): error SA1400: Element 'API_Wrapper_Generic' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(529,21): error SA1400: Element 'API_Wrapper' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(598,21): error SA1400: Element 'SPMI_ShimCounter_ICorJitInfo' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(551,21): error SA1400: Element 'SPMI_ICorJitInfoImpl' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(616,21): error SA1400: Element 'SPMI_ShimSimple_ICorJitInfo' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\Program.cs(634,21): error SA1400: Element 'Main' should declare an access modifier [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(1027,25): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
src\coreclr\tools\Common\JitInterface\ThunkGenerator\InstructionSetGenerator.cs(709,57): error SA1121: Use built-in type alias [L:\dotnet\runtime\src\coreclr\tools\Common\JitInterface\ThunkGenerator\ThunkGenerator.csproj]
Fix the build errors and run again.

@jkotas

Copy link
Copy Markdown
Member

#77816

@MichalPetryka

Copy link
Copy Markdown
ContributorAuthor

For now I've worked around it by disabling TreatWarningsAsErrors in the generator.

@MichalPetryka

Copy link
Copy Markdown
ContributorAuthor

@jkotas Is there anything left to be done here on my part?

Comment threadsrc/libraries/System.Private.CoreLib/src/System/Enum.cs Outdated

@jkotasjkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM once the CI is green. Thank you!

@jkotas
jkotas merged commit 16b28c7 into dotnet:mainNov 11, 2022
@ghostghost locked as resolved and limited conversation to collaborators Dec 11, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@MichalPetryka@EgorBo@danmoseley@jkotas@vargaz@am11@AndyAyersMS@kasperk81@JulieLeeMSFT