Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Type.IsEnum and Type.GetEnumUnderlyingType intrinsics #71685

Merged
merged 59 commits into from
Nov 11, 2022

Conversation

MichalPetryka
Copy link
Contributor

@MichalPetryka MichalPetryka commented Jul 5, 2022

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.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 5, 2022
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 5, 2022
@ghost
Copy link

ghost commented Jul 5, 2022

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: -

@MichalPetryka
Copy link
Contributor Author

This PR generates the desired codegen only with #71778.

@MichalPetryka MichalPetryka changed the title Make Type.GetTypeCode an intrinsic Make Type.GetTypeCode/IsEnum intrinsics Jul 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
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.

Copy link
Contributor Author

@MichalPetryka MichalPetryka Jul 10, 2022

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
Member

jkotas commented Nov 1, 2022

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.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

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

JIT/SPMI changes LGTM.

@vargaz
Copy link
Contributor

vargaz commented Nov 2, 2022

#77763 will fix the mono failures.

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

jkotas commented Nov 3, 2022

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

@MichalPetryka
Copy link
Contributor Author

MichalPetryka commented Nov 3, 2022

@jkotas Done. Seems like ThunkGenerator fails after the merge?

@jkotas
Copy link
Member

jkotas commented Nov 3, 2022

Seems like ThunkGenerator fails after the merge?

Do you have #77715 ?

@MichalPetryka
Copy link
Contributor Author

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
Member

jkotas commented Nov 3, 2022

#77816

@MichalPetryka
Copy link
Contributor Author

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

@MichalPetryka
Copy link
Contributor Author

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

Copy link
Member

@jkotas jkotas left a comment

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:main Nov 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants