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

[SPV-IR] Fix SPIRV builtin variable/call translation #1133

Merged
merged 4 commits into from
Aug 3, 2021

Conversation

Nuullll
Copy link
Contributor

@Nuullll Nuullll commented Jul 28, 2021

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:

    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)

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

    1. We lower SPIRV builtin variables into calls in SPIRVToLLVM so that SPV-IR
      has builtin function calls (instead of variables) by default.

    2. 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)

    3. 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

Nuullll added 2 commits July 28, 2021 20:51
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>
@Nuullll
Copy link
Contributor Author

Nuullll commented Jul 29, 2021

@AlexeySachkov @AlexeySotkin @Fznamznon @MrSidims Please take a look, thanks :)

@AlexeySotkin
Copy link
Contributor

@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))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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).

Copy link
Contributor

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?

Copy link
Contributor

@Fznamznon Fznamznon Aug 2, 2021

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

void transWorkItemBuiltinsToVariables(Module *M) {
LLVM_DEBUG(dbgs() << "Enter transWorkItemBuiltinsToVariables\n");
std::vector<Function *> WorkList;
for (auto &I : *M) {
Copy link
Contributor

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

Copy link
Contributor Author

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>
@Nuullll Nuullll requested a review from AlexeySachkov July 30, 2021 06:29
@Nuullll
Copy link
Contributor Author

Nuullll commented Aug 2, 2021

A gentle ping.

Comment on lines 2074 to 2075
std::string BuiltinVarName =
std::string(kSPIRVName::Prefix) + SPIRVBuiltInNameMap::map(BVKind);
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Type *GVType =
IsVec ? FixedVectorType::get(F.getReturnType(), 3) : F.getReturnType();
auto *BV = new GlobalVariable(
*M, GVType, true, GlobalValue::ExternalLinkage, nullptr, BuiltinVarName,
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT

Suggested change
*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 .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT

Suggested change
for (auto UI = F.user_begin(), UE = F.user_end(); UI != UE; ++UI) {
for (auto *U : F->users()) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

Comment on lines +2107 to +2108
else if (auto *F = dyn_cast<Function>(V))
F->eraseFromParent();
Copy link
Contributor

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?

Suggested change
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!");

Copy link
Contributor Author

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))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 2046 to 2054
/// 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
Copy link
Contributor

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?

Suggested change
/// 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typo fixed.

/// load WorkDim
bool LLVMToSPIRVBase::transWorkItemBuiltinCallsToVariables() {
LLVM_DEBUG(dbgs() << "Enter transWorkItemBuiltinCallsToVariables\n");
// Store instructions and functions need to be removed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Store instructions and functions need to be removed.
// Store instructions and functions that need to be removed.

Copy link
Contributor Author

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))
Copy link
Contributor

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>
Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

Thank you!

@Nuullll Nuullll changed the title [SPV-IR] Handle builtin-call based SPV-IR input [SPV-IR] Fix SPIRV builtin variable/call translation Aug 3, 2021
@AlexeySachkov AlexeySachkov merged commit bafc886 into KhronosGroup:master Aug 3, 2021
Fznamznon added a commit to Fznamznon/SPIRV-LLVM-Translator that referenced this pull request Aug 13, 2021
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.
Fznamznon added a commit to Fznamznon/SPIRV-LLVM-Translator that referenced this pull request Aug 13, 2021
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.
Fznamznon added a commit to Fznamznon/SPIRV-LLVM-Translator that referenced this pull request Aug 13, 2021
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.
Fznamznon added a commit to Fznamznon/SPIRV-LLVM-Translator that referenced this pull request Aug 13, 2021
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.
AlexeySotkin pushed a commit that referenced this pull request Aug 16, 2021
* 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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Aug 17, 2021
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
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Aug 17, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Aug 17, 2021
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
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Aug 17, 2021
…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>
AlexeySachkov pushed a commit that referenced this pull request Aug 18, 2021
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
AlexeySachkov pushed a commit that referenced this pull request Aug 18, 2021
* 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>
vmaksimo pushed a commit to vmaksimo/llvm that referenced this pull request Aug 23, 2021
* 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
Nuullll added a commit to Nuullll/SPIRV-LLVM-Translator that referenced this pull request Aug 26, 2021
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.
AlexeySotkin pushed a commit that referenced this pull request Aug 27, 2021
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
AlexeySotkin pushed a commit that referenced this pull request Aug 27, 2021
* 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>
MrSidims pushed a commit that referenced this pull request Sep 1, 2021
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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
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
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
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
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
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
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
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
aratajew pushed a commit to aratajew/SPIRV-LLVM-Translator that referenced this pull request Dec 14, 2021
…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>
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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>
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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>
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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>
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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>
MrSidims pushed a commit that referenced this pull request Dec 20, 2021
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>
Quetzonarch pushed a commit to Quetzonarch/SPIRV-LLVM-Translator that referenced this pull request Jul 13, 2022
…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>
vmaksimo pushed a commit to vmaksimo/SPIRV-LLVM-Translator that referenced this pull request Sep 1, 2022
…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
stanleygambarin pushed a commit to stanleygambarin/SPIRV-LLVM-Translator that referenced this pull request Jan 28, 2023
…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
MrSidims pushed a commit that referenced this pull request Jan 28, 2023
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants