-
Notifications
You must be signed in to change notification settings - Fork 769
[llvm-spirv] Cherry pick Khronos changes to expand collection of entry point interfaces (PR #1334) #10623
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
Merged
Merged
[llvm-spirv] Cherry pick Khronos changes to expand collection of entry point interfaces (PR #1334) #10623
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 |
---|---|---|
|
@@ -874,9 +874,7 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) { | |
|
||
BM->setName(BF, F->getName().str()); | ||
} | ||
if (isKernel(F)) | ||
BM->addEntryPoint(ExecutionModelKernel, BF->getId()); | ||
else if (F->getLinkage() != GlobalValue::InternalLinkage) | ||
if (!isKernel(F) && F->getLinkage() != GlobalValue::InternalLinkage) | ||
BF->setLinkageType(transLinkageType(F)); | ||
|
||
// Translate OpenCL/SYCL buffer_location metadata if it's attached to the | ||
|
@@ -4898,12 +4896,15 @@ bool LLVMToSPIRVBase::isAnyFunctionReachableFromFunction( | |
return false; | ||
} | ||
|
||
void LLVMToSPIRVBase::collectInputOutputVariables(SPIRVFunction *SF, | ||
Function *F) { | ||
std::vector<SPIRVId> | ||
LLVMToSPIRVBase::collectEntryPointInterfaces(SPIRVFunction *SF, Function *F) { | ||
std::vector<SPIRVId> Interface; | ||
for (auto &GV : M->globals()) { | ||
const auto AS = GV.getAddressSpace(); | ||
if (AS != SPIRAS_Input && AS != SPIRAS_Output) | ||
continue; | ||
SPIRVModule *BM = SF->getModule(); | ||
if (!BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_4)) | ||
if (AS != SPIRAS_Input && AS != SPIRAS_Output) | ||
continue; | ||
|
||
std::unordered_set<const Function *> Funcs; | ||
|
||
|
@@ -4915,9 +4916,14 @@ void LLVMToSPIRVBase::collectInputOutputVariables(SPIRVFunction *SF, | |
} | ||
|
||
if (isAnyFunctionReachableFromFunction(F, Funcs)) { | ||
SF->addVariable(ValueMap[&GV]); | ||
SPIRVWord ModuleVersion = static_cast<SPIRVWord>(BM->getSPIRVVersion()); | ||
if (AS != SPIRAS_Input && AS != SPIRAS_Output && | ||
ModuleVersion < static_cast<SPIRVWord>(VersionNumber::SPIRV_1_4)) | ||
BM->setMinSPIRVVersion(VersionNumber::SPIRV_1_4); | ||
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 now pass Version number directly without converting to SPIRVWord |
||
Interface.push_back(ValueMap[&GV]->getId()); | ||
} | ||
} | ||
return Interface; | ||
} | ||
|
||
void LLVMToSPIRVBase::mutateFuncArgType( | ||
|
@@ -5118,10 +5124,10 @@ void LLVMToSPIRVBase::transFunction(Function *I) { | |
joinFPContract(I, FPContract::ENABLED); | ||
fpContractUpdateRecursive(I, getFPContract(I)); | ||
|
||
bool IsKernelEntryPoint = isKernel(I); | ||
|
||
if (IsKernelEntryPoint) { | ||
collectInputOutputVariables(BF, I); | ||
if (isKernel(I)) { | ||
auto Interface = collectEntryPointInterfaces(BF, I); | ||
BM->addEntryPoint(ExecutionModelKernel, BF->getId(), I->getName().str(), | ||
Interface); | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -248,6 +248,8 @@ class LLVMToSPIRVBase : protected BuiltinCallHelper { | |
const Function *FS, | ||
const std::unordered_set<const Function *> Funcs) const; | ||
void collectInputOutputVariables(SPIRVFunction *SF, Function *F); | ||
std::vector<SPIRVId> collectEntryPointInterfaces(SPIRVFunction *BF, | ||
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. This function declaration was missing in the original patch. |
||
Function *F); | ||
}; | ||
|
||
class LLVMToSPIRVPass : public PassInfoMixin<LLVMToSPIRVPass> { | ||
|
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
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
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
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
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
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
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
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
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,52 @@ | ||
; RUN: llvm-as %s -o %t.bc | ||
|
||
; RUN: llvm-spirv %t.bc -o %t.spv | ||
; RUN: spirv-val --target-env spv1.4 %t.spv | ||
; RUN: llvm-spirv -to-text %t.spv -o %t.from.spv.spt | ||
; RUN: FileCheck < %t.from.spv.spt %s --check-prefix=CHECK-SPIRV | ||
|
||
; RUN: llvm-spirv -spirv-text %t.bc -o %t.from.bc.spt | ||
; RUN: FileCheck < %t.from.bc.spt %s --check-prefix=CHECK-SPIRV | ||
|
||
; CHECK-SPIRV: 7 EntryPoint 6 [[#]] "test" [[#Interface1:]] [[#Interface2:]] | ||
; CHECK-SPIRV: TypeInt [[#TypeInt:]] 32 0 | ||
; CHECK-SPIRV: Constant [[#TypeInt]] [[#Constant1:]] 1 | ||
; CHECK-SPIRV: Constant [[#TypeInt]] [[#Constant2:]] 3 | ||
; CHECK-SPIRV: Variable [[#]] [[#Interface1]] 0 [[#Constant1]] | ||
; CHECK-SPIRV: Variable [[#]] [[#Interface2]] 0 [[#Constant2]] | ||
|
||
; ModuleID = 'source.cpp' | ||
source_filename = "source.cpp" | ||
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" | ||
target triple = "spir" | ||
|
||
@var = dso_local addrspace(2) constant i32 1, align 4 | ||
@var2 = dso_local addrspace(2) constant i32 3, align 4 | ||
@var.const = private unnamed_addr addrspace(2) constant i32 1, align 4 | ||
@var2.const = private unnamed_addr addrspace(2) constant i32 3, align 4 | ||
|
||
; Function Attrs: convergent noinline norecurse nounwind optnone | ||
define dso_local spir_kernel void @test() #0 !kernel_arg_addr_space !2 !kernel_arg_access_qual !2 !kernel_arg_type !2 !kernel_arg_base_type !2 !kernel_arg_type_qual !2 !kernel_arg_host_accessible !2 !kernel_arg_pipe_depth !2 !kernel_arg_pipe_io !2 !kernel_arg_buffer_location !2 { | ||
entry: | ||
%0 = load i32, i32 addrspace(2)* @var.const, align 4 | ||
%1 = load i32, i32 addrspace(2)* @var2.const, align 4 | ||
%mul = mul nsw i32 %0, %1 | ||
%mul1 = mul nsw i32 %mul, 2 | ||
ret void | ||
} | ||
|
||
attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" } | ||
|
||
!opencl.enable.FP_CONTRACT = !{} | ||
!opencl.ocl.version = !{!0} | ||
!opencl.spir.version = !{!0} | ||
!llvm.module.flags = !{!1} | ||
!opencl.used.extensions = !{!2} | ||
!opencl.used.optional.core.features = !{!2} | ||
!opencl.compiler.options = !{!2} | ||
!llvm.ident = !{!3} | ||
|
||
!0 = !{i32 2, i32 0} | ||
!1 = !{i32 7, !"frame-pointer", i32 2} | ||
!2 = !{} | ||
!3 = !{!"Compiler"} |
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
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
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.
We no longer add entry point for function decls.