-
Notifications
You must be signed in to change notification settings - Fork 234
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
[SPV-IR] Fix SPIRV builtin variable/call translation #1133
Conversation
The workitem builtin calls are first transformed to global variables as preprocessing in LLVMToSPIRV. Also move the "SPV-IR builtin call <-> OCL builtin call" translation to SPIRVToOCL. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
Signed-off-by: Yilong Guo <yilong.guo@intel.com>
@AlexeySachkov @AlexeySotkin @Fznamznon @MrSidims Please take a look, thanks :) |
@Fznamznon could you please take a look? |
// e.g. load i32, i32* @__spirv_BuiltInGlobalLinearId, align 4 | ||
// If the desired format is global variables, we don't have to lower them | ||
// as calls. | ||
if (!lowerBuiltinVariablesToCalls(M)) |
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.
While we don't have an option to control output format, do we need another call to lowerBuiltinVariablesToCalls
from SPIRToOCL passes?
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.
Yes. I added for both SPIRVToOCL12
and SPIRVToOCL20
.
lowerBuiltinVariablesToCalls
is called at the start of SPIRVToOCL
(as preprocessing), to make sure all work item builtins are used as calls, so that visitCallSPIRVBuiltin
can convert them with a simple lookup.
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.
Yes, I understand that, thanks.
I see that lowerBuiltinVariablesToCalls
is also called at the end of SPIRVReader, I guess it already makes SPIRVReader to produce calls to work item built-ins (instead of variables use). After that all that is left to do in SPIRVToOCL passes is to change built-in names in visitCallSPIRVBuiltin.
But lowerBuiltinVariablesToCalls
is called again at the beginning of SPIRVToOCL pass. Do we really need this second call, or I just misunderstood something? (Sorry If I did).
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.
I guess a comment on line 3328 "// TODO: add an option to control the builtin format in SPV-IR." explains why lowerBuiltinVariablesToCalls
is being called twice and foresees a time when it actually won't be a case . BTW, why do we need to call lowerBuiltinVariablesToCalls
in the reader in the first place? I'd prefer to always have GV-like built-ins in SPV-IR, or I just don't have enough data?
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.
I guess a comment on line 3328 "// TODO: add an option to control the builtin format in SPV-IR." explains why lowerBuiltinVariablesToCalls is being called twice and foresees a time when it actually won't be a case .
Yes, as I already mentioned in my first comment, while we don't have an option, can we make only one call?
BTW, why do we need to call lowerBuiltinVariablesToCalls in the reader in the first place? I'd prefer to always have GV-like built-ins in SPV-IR
The thing is, we already have users that use calls, so we don't want to break their workflow.
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.
Yes, as I already mentioned in my first comment, while we don't have an option, can we make only one call?
Sorry I didn't make it clear. The thing is, we have users that use the SPIRVToOCL
pass independently, translating SPV-IR into OCL-IR. And for these users, the SPIRVToOCL
pass may receive SPV-IR of both formats (builtin calls / variables) as input. For example, clang is still emitting builtin-variable-based SPV-IR.
So I think this call in SPIRVToOCL
is probably unavoidable, at least for the current stage :(
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.
Ah, I understand. Thank you.
lib/SPIRV/SPIRVUtil.cpp
Outdated
void transWorkItemBuiltinsToVariables(Module *M) { | ||
LLVM_DEBUG(dbgs() << "Enter transWorkItemBuiltinsToVariables\n"); | ||
std::vector<Function *> WorkList; | ||
for (auto &I : *M) { |
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.
Why I
and not F
? If I understand correctly, here we iterate over functions and not over instructions
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.
Done. A leftover during copy/paste :P
We don't translate OCL work item builtins directly to SPIRV builtin variables anymore. Splitting into two steps instead: 1. First translate OCL work item builtins to SPV-IR builtin calls in OCLToSPIRV. For example: @_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i) 2. Then SPV-IR builtin calls are transformed to variables in LLVMToSPIRV, via transWorkItemBuiltinCallsToVariables(). For example: @_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i We also benefit from this change that builtin-call-based SPV-IR can be recognized by the translator, as builtin calls will be converted to variables finally in LLVMToSPIRV. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
A gentle ping. |
lib/SPIRV/SPIRVWriter.cpp
Outdated
std::string BuiltinVarName = | ||
std::string(kSPIRVName::Prefix) + SPIRVBuiltInNameMap::map(BVKind); |
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.
Don't we have variable's name in DemangledName
already?
I assume DemangledName
is not fully demangled, right?
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.
Thanks, done! Eliminated BVKind
as well!
lib/SPIRV/SPIRVWriter.cpp
Outdated
Type *GVType = | ||
IsVec ? FixedVectorType::get(F.getReturnType(), 3) : F.getReturnType(); | ||
auto *BV = new GlobalVariable( | ||
*M, GVType, true, GlobalValue::ExternalLinkage, nullptr, BuiltinVarName, |
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.
NIT
*M, GVType, true, GlobalValue::ExternalLinkage, nullptr, BuiltinVarName, | |
*M, GVType, /*isConstant=*/ true, GlobalValue::ExternalLinkage, nullptr, BuiltinVarName, |
It would be great to add comments explaining what constant values mean https://llvm.org/docs/CodingStandards.html#comment-formatting .
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.
Done.
lib/SPIRV/SPIRVWriter.cpp
Outdated
auto *BV = new GlobalVariable( | ||
*M, GVType, true, GlobalValue::ExternalLinkage, nullptr, BuiltinVarName, | ||
0, GlobalVariable::NotThreadLocal, SPIRAS_Input); | ||
for (auto UI = F.user_begin(), UE = F.user_end(); UI != UE; ++UI) { |
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.
NIT
for (auto UI = F.user_begin(), UE = F.user_end(); UI != UE; ++UI) { | |
for (auto *U : F->users()) { |
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.
Thanks, done.
else if (auto *F = dyn_cast<Function>(V)) | ||
F->eraseFromParent(); |
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.
NIT: that would be weird if something git into ToRemove and it is not a call or a function, right?
else if (auto *F = dyn_cast<Function>(V)) | |
F->eraseFromParent(); | |
else if (auto *F = dyn_cast<Function>(V)) | |
F->eraseFromParent(); | |
else | |
llvm_unreachable("Unexpected value to remove!"); |
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.
Done.
if (!F.isDeclaration()) | ||
continue; | ||
StringRef DemangledName; | ||
if (!oclIsBuiltin(F.getName(), DemangledName)) |
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.
I guess it is expected that a function named oclIsBuiltin returns true for SPV-IR as well? Maybe we should rename it?
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.
Yes. I think we better do it (renaming oclIsBuiltin()
) in a separate PR to avoid irrelevant changes.
lib/SPIRV/SPIRVWriter.cpp
Outdated
/// Transforms SPR-IR work-item builtin calls to SPIRV builtin variables. | ||
/// e.g. | ||
/// SPR-IR: @_Z33__spirv_BuiltInGlobalInvocationIdi(i) | ||
/// is transformed as: | ||
/// x = load GlobalInvocationId; extract x, i | ||
/// e.g. | ||
/// SPR-IR: @_Z22__spirv_BuiltInWorkDimi() | ||
/// is transformed as: | ||
/// load WorkDim |
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 usually call this representation SPV-IR, right?
/// Transforms SPR-IR work-item builtin calls to SPIRV builtin variables. | |
/// e.g. | |
/// SPR-IR: @_Z33__spirv_BuiltInGlobalInvocationIdi(i) | |
/// is transformed as: | |
/// x = load GlobalInvocationId; extract x, i | |
/// e.g. | |
/// SPR-IR: @_Z22__spirv_BuiltInWorkDimi() | |
/// is transformed as: | |
/// load WorkDim | |
/// Transforms SPV-IR work-item builtin calls to SPIRV builtin variables. | |
/// e.g. | |
/// SPV-IR: @_Z33__spirv_BuiltInGlobalInvocationIdi(i) | |
/// is transformed as: | |
/// x = load GlobalInvocationId; extract x, i | |
/// e.g. | |
/// SPV-IR: @_Z22__spirv_BuiltInWorkDim() | |
/// is transformed as: | |
/// load WorkDim |
(also corrected mangling).
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.
Typo fixed.
lib/SPIRV/SPIRVWriter.cpp
Outdated
/// load WorkDim | ||
bool LLVMToSPIRVBase::transWorkItemBuiltinCallsToVariables() { | ||
LLVM_DEBUG(dbgs() << "Enter transWorkItemBuiltinCallsToVariables\n"); | ||
// Store instructions and functions need to be removed. |
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.
// Store instructions and functions need to be removed. | |
// Store instructions and functions that need to be removed. |
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.
Thanks, done.
// e.g. load i32, i32* @__spirv_BuiltInGlobalLinearId, align 4 | ||
// If the desired format is global variables, we don't have to lower them | ||
// as calls. | ||
if (!lowerBuiltinVariablesToCalls(M)) |
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.
Yes, I understand that, thanks.
I see that lowerBuiltinVariablesToCalls
is also called at the end of SPIRVReader, I guess it already makes SPIRVReader to produce calls to work item built-ins (instead of variables use). After that all that is left to do in SPIRVToOCL passes is to change built-in names in visitCallSPIRVBuiltin.
But lowerBuiltinVariablesToCalls
is called again at the beginning of SPIRVToOCL pass. Do we really need this second call, or I just misunderstood something? (Sorry If I did).
Signed-off-by: Yilong Guo <yilong.guo@intel.com>
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.
Thank you!
KhronosGroup#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation.
KhronosGroup#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation.
KhronosGroup#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation.
KhronosGroup#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation.
* Update SPIR-V friendly IR doc according to recent changes #1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation. * Apply suggestions from code review Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` ### LLVM --> SPIRV translation: We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` ### SPIRV --> LLVM translation: We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…up#1153) * Update SPIR-V friendly IR doc according to recent changes KhronosGroup#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation. * Apply suggestions from code review Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…up#1153) * Update SPIR-V friendly IR doc according to recent changes KhronosGroup#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation. * Apply suggestions from code review Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
* Update SPIR-V friendly IR doc according to recent changes #1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation. * Apply suggestions from code review Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
* Update SPIR-V friendly IR doc according to recent changes KhronosGroup/SPIRV-LLVM-Translator#1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation. * Apply suggestions from code review Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Original commit: KhronosGroup/SPIRV-LLVM-Translator@168cb23
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133.
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` ### LLVM --> SPIRV translation: We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` ### SPIRV --> LLVM translation: We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
* Update SPIR-V friendly IR doc according to recent changes #1133 added full support for SPIR-V friendly IR with SPIR-V built-in variables mapped to calls. This commit adds info to the doc about the new supported representation. * Apply suggestions from code review Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com> Co-authored-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
…p#1180) The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR KhronosGroup#1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
…nslation (KhronosGroup#1133) 'master' -> 'xmain-web' (KhronosGroup#3) CONFLICT (content): Merge conflict in lib/SPIRV/SPIRVInternal.h commit bafc886 Author: Yilong Guo <yilong.guo@intel.com> Date: Tue Aug 3 15:25:57 2021 +0800 [SPV-IR] Fix SPIRV builtin variable/call translation (KhronosGroup#1133) This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` ### LLVM --> SPIRV translation: We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` ### SPIRV --> LLVM translation: We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com Change-Id: Ie361b71607ba37677d7634f33f55e7286cee673f
…hronosGroup#1133) This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
…1133) This PR fixes the translation of SPIRV builtin variables/calls. The translator now is able to recognize builtin-call-based SPV-IR input. e.g. `call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)` We first translate OCL work item builtins to SPV-IR builtin calls in `OCLToSPIRV`. For example: `@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)` SPV-IR builtin calls are transformed to variables in `LLVMToSPIRV`. This step is shared by all source inputs (SPV-IR, OCL-IR). For example: `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> x = load GlobalInvocationId; extract x, i` We lower SPIRV builtin variables into calls in `SPIRVToLLVM` so that SPV-IR has builtin function calls (instead of variables) by default. Builtin calls in SPV-IR can be then translated into OpenCL builtin calls, in `SPIRVToOCL`. e.g. `@_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)` `SPIRVToOCL` is also capable of lower SPIRV builtin variables into calls as preprocessing, so that this pass can be used by users independently to translate SPV-IR into OCL-IR. Signed-off-by: Yilong Guo yilong.guo@intel.com
This PR fixes the translation of SPIRV builtin variables/calls. The translator
now is able to recognize builtin-call-based SPV-IR input.
e.g. call spir_func i64 @_Z33__spirv_BuiltinGlobalInvocationIdi(i32 1)
LLVM --> SPIRV translation:
We first translate OCL work item builtins to SPV-IR builtin calls in
OCLToSPIRV. For example:
@_Z13get_global_idj(i) -> @_Z33__spirv_BuiltinGlobalInvocationIdi(i)
SPV-IR builtin calls are transformed to variables in LLVMToSPIRV. This
step is shared by all source inputs (SPV-IR, OCL-IR). For example:
@_Z33__spirv_BuiltinGlobalInvocationIdi(i) ->
x = load GlobalInvocationId; extract x, i
SPIRV --> LLVM translation:
We lower SPIRV builtin variables into calls in SPIRVToLLVM so that SPV-IR
has builtin function calls (instead of variables) by default.
Builtin calls in SPV-IR can be then translated into OpenCL builtin calls,
in SPIRVToOCL.
e.g. @_Z33__spirv_BuiltinGlobalInvocationIdi(i) -> @_Z13get_global_idj(i)
SPIRVToOCL is also capable of lower SPIRV builtin variables into calls as
preprocessing, so that this pass can be used by users independently to
translate SPV-IR into OCL-IR.
Signed-off-by: Yilong Guo yilong.guo@intel.com