-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[SPIRV] Add support for CodeSectionINTEL storage class in legalizer #167961
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
Open
sarnex
wants to merge
2
commits into
llvm:main
Choose a base branch
from
sarnex:legalizer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−14
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,17 +84,19 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) { | |
| const LLT p6 = LLT::pointer(6, PSize); // SPV_INTEL_usm_storage_classes (Host) | ||
| const LLT p7 = LLT::pointer(7, PSize); // Input | ||
| const LLT p8 = LLT::pointer(8, PSize); // Output | ||
| const LLT p9 = | ||
| LLT::pointer(9, PSize); // CodeSectionINTEL, SPV_INTEL_function_pointers | ||
| const LLT p10 = LLT::pointer(10, PSize); // Private | ||
| const LLT p11 = LLT::pointer(11, PSize); // StorageBuffer | ||
| const LLT p12 = LLT::pointer(12, PSize); // Uniform | ||
|
|
||
| // TODO: remove copy-pasting here by using concatenation in some way. | ||
| auto allPtrsScalarsAndVectors = { | ||
| p0, p1, p2, p3, p4, p5, p6, p7, p8, | ||
| p10, p11, p12, s1, s8, s16, s32, s64, v2s1, | ||
| v2s8, v2s16, v2s32, v2s64, v3s1, v3s8, v3s16, v3s32, v3s64, | ||
| v4s1, v4s8, v4s16, v4s32, v4s64, v8s1, v8s8, v8s16, v8s32, | ||
| v8s64, v16s1, v16s8, v16s16, v16s32, v16s64}; | ||
| p0, p1, p2, p3, p4, p5, p6, p7, p8, | ||
| p9, p10, p11, p12, s1, s8, s16, s32, s64, | ||
| v2s1, v2s8, v2s16, v2s32, v2s64, v3s1, v3s8, v3s16, v3s32, | ||
| v3s64, v4s1, v4s8, v4s16, v4s32, v4s64, v8s1, v8s8, v8s16, | ||
| v8s32, v8s64, v16s1, v16s8, v16s16, v16s32, v16s64}; | ||
|
|
||
| auto allVectors = {v2s1, v2s8, v2s16, v2s32, v2s64, v3s1, v3s8, | ||
| v3s16, v3s32, v3s64, v4s1, v4s8, v4s16, v4s32, | ||
|
|
@@ -121,10 +123,10 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) { | |
| s16, s32, s64, v2s16, v2s32, v2s64, v3s16, v3s32, v3s64, | ||
| v4s16, v4s32, v4s64, v8s16, v8s32, v8s64, v16s16, v16s32, v16s64}; | ||
|
|
||
| auto allFloatAndIntScalarsAndPtrs = {s8, s16, s32, s64, p0, p1, p2, p3, | ||
| p4, p5, p6, p7, p8, p10, p11, p12}; | ||
| auto allFloatAndIntScalarsAndPtrs = {s8, s16, s32, s64, p0, p1, p2, p3, p4, | ||
| p5, p6, p7, p8, p9, p10, p11, p12}; | ||
|
|
||
| auto allPtrs = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p10, p11, p12}; | ||
| auto allPtrs = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12}; | ||
|
|
||
| bool IsExtendedInts = | ||
| ST.canUseExtension( | ||
|
|
@@ -177,15 +179,22 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) { | |
| getActionDefinitionsBuilder(G_UNMERGE_VALUES).alwaysLegal(); | ||
|
|
||
| getActionDefinitionsBuilder({G_MEMCPY, G_MEMMOVE}) | ||
| .unsupportedIf(LegalityPredicates::any(typeIs(0, p9), typeIs(1, p9))) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need the |
||
| .legalIf(all(typeInSet(0, allPtrs), typeInSet(1, allPtrs))); | ||
|
|
||
| getActionDefinitionsBuilder(G_MEMSET).legalIf( | ||
| all(typeInSet(0, allPtrs), typeInSet(1, allIntScalars))); | ||
| getActionDefinitionsBuilder(G_MEMSET) | ||
| .unsupportedIf(typeIs(0, p9)) | ||
| .legalIf(all(typeInSet(0, allPtrs), typeInSet(1, allIntScalars))); | ||
|
|
||
| getActionDefinitionsBuilder(G_ADDRSPACE_CAST) | ||
| .unsupportedIf( | ||
| LegalityPredicates::any(all(typeIs(0, p9), typeIsNot(1, p9)), | ||
| all(typeIsNot(0, p9), typeIs(1, p9)))) | ||
| .legalForCartesianProduct(allPtrs, allPtrs); | ||
|
|
||
| getActionDefinitionsBuilder({G_LOAD, G_STORE}).legalIf(typeInSet(1, allPtrs)); | ||
| getActionDefinitionsBuilder({G_LOAD, G_STORE}) | ||
| .unsupportedIf(typeIs(1, p9)) | ||
| .legalIf(typeInSet(1, allPtrs)); | ||
|
|
||
| getActionDefinitionsBuilder({G_SMIN, G_SMAX, G_UMIN, G_UMAX, G_ABS, | ||
| G_BITREVERSE, G_SADDSAT, G_UADDSAT, G_SSUBSAT, | ||
|
|
@@ -247,9 +256,12 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) { | |
|
|
||
| // ST.canDirectlyComparePointers() for pointer args is supported in | ||
| // legalizeCustom(). | ||
| getActionDefinitionsBuilder(G_ICMP).customIf( | ||
| all(typeInSet(0, allBoolScalarsAndVectors), | ||
| typeInSet(1, allPtrsScalarsAndVectors))); | ||
| getActionDefinitionsBuilder(G_ICMP) | ||
| .unsupportedIf(LegalityPredicates::any( | ||
| all(typeIs(0, p9), typeInSet(1, allPtrs), typeIsNot(1, p9)), | ||
| all(typeInSet(0, allPtrs), typeIsNot(0, p9), typeIs(1, p9)))) | ||
| .customIf(all(typeInSet(0, allBoolScalarsAndVectors), | ||
| typeInSet(1, allPtrsScalarsAndVectors))); | ||
|
|
||
| getActionDefinitionsBuilder(G_FCMP).legalIf( | ||
| all(typeInSet(0, allBoolScalarsAndVectors), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ; RUN: not llc --global-isel %s -filetype=null 2>&1 | FileCheck %s | ||
| target triple = "spirv64" | ||
|
|
||
| define void @addrspacecast(ptr addrspace(9) %a) { | ||
| ; CHECK: unable to legalize instruction: %{{.*}}:pid(p4) = G_ADDRSPACE_CAST %{{.*}}:pid(p9) | ||
| %res1 = addrspacecast ptr addrspace(9) %a to ptr addrspace(4) | ||
| ret void | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ; RUN: not llc --global-isel %s -filetype=null 2>&1 | FileCheck %s | ||
| target triple = "spirv64" | ||
|
|
||
| define void @do_load(ptr addrspace(9) %a) { | ||
| ; CHECK: unable to legalize instruction: %{{.*}}:iid(s32) = G_LOAD %{{.*}}:pid(p9) | ||
| %val = load i32, ptr addrspace(9) %a | ||
| ret void | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ; RUN: not llc --global-isel %s -filetype=null 2>&1 | FileCheck %s | ||
| target triple = "spirv64" | ||
|
|
||
| define void @memcpy(ptr addrspace(9) %a) { | ||
| ; CHECK: unable to legalize instruction: G_MEMCPY %{{.*}}:pid(p9), %{{.*}}:pid(p0), %{{.*}}:iid(s64), 0 | ||
| call void @llvm.memcpy.p9.p0.i64(ptr addrspace(9) %a, ptr null, i32 1, i1 0) | ||
| ret void | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ; RUN: not llc --global-isel %s -filetype=null 2>&1 | FileCheck %s | ||
| target triple = "spirv64" | ||
|
|
||
| define void @memset(ptr addrspace(9) %a) { | ||
| ; CHECK: unable to legalize instruction: G_MEMSET %{{.*}}:pid(p9), %{{.*}}:iid(s8), %{{.*}}:iid(s64) | ||
| call void @llvm.memset.p9.i32(ptr addrspace(9) %a, i8 0, i32 1, i1 0) | ||
| ret void | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ; RUN: not llc --global-isel %s -filetype=null 2>&1 | FileCheck %s | ||
| target triple = "spirv64" | ||
|
|
||
| define void @do_store(ptr addrspace(9) %a) { | ||
| ; CHECK: unable to legalize instruction: G_STORE %{{.*}}:iid(s32), %{{.*}}:pid(p9) | ||
| store i32 5, ptr addrspace(9) %a | ||
| ret void | ||
| } |
27 changes: 27 additions & 0 deletions
27
llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_function_pointers/fp_cmp.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| ; RUN: llc -verify-machineinstrs -O0 --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s | ||
| ; TODO: %if spirv-tools %{ llc -O0 %s -o - -filetype=obj | spirv-val %} | ||
|
|
||
| ; CHECK-DAG: OpCapability FunctionPointersINTEL | ||
| ; CHECK: OpExtension "SPV_INTEL_function_pointers" | ||
|
|
||
| ; CHECK: OpName %[[F1:.*]] "f1" | ||
| ; CHECK: OpName %[[ARG:.*]] "arg" | ||
|
|
||
| ; CHECK: %[[TyBool:.*]] = OpTypeBool | ||
|
|
||
| ; CHECK: %[[F1Ptr:.*]] = OpConstantFunctionPointerINTEL %{{.*}} %[[F1]] | ||
|
|
||
| ; CHECK: OpPtrEqual %[[TyBool]] %[[F1Ptr]] %[[ARG]] | ||
|
|
||
| target triple = "spirv64" | ||
|
|
||
| define spir_func void @f1() addrspace(9) { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| define spir_func i1 @foo(ptr addrspace(9) %arg) addrspace(9) { | ||
| entry: | ||
| %a = icmp eq ptr addrspace(9) @f1, %arg | ||
| ret i1 %a | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be an address space enum somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have an enum but we do have a mapping between the storage class operand and LLVM addrspace, if I were to use that here the code would look like
I'm not sure that's much better but if you prefer this way I'm happy to implement it.