Skip to content

[SPIR-V] Stop re-writing SPIR-V type map #3856

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 2 commits into from
Jun 1, 2021

Conversation

MrSidims
Copy link
Contributor

There is a map used during forward translation. It links LLVM type
and SPIR-V type, that is being generated, LLVM type here is used as
a key. Due to a bug in type mapping (information is below), it's
possible that for a single pointer type in LLVM, the translator
will create 2 physically-indentical SPIR-V pointer types and with
previous implementation of mapType function the map would be changed
during the second type insertion. This patch prevents it, forcing
to reuse the type that was created first, though we would still have
an unused duplication of this type in SPIR-V module.

Please consider following LLVM IR sample:
%struct._ZTS4Args.Args = type { %struct._ZTS6Object.Object addrspace(4)* }
%struct._ZTS6Object.Object = type { i32 (%struct._ZTS6Object.Object addrspace(4), i32) }

Here we have 2 LLVM type declarations. The translator will recursively
go through structure members and then through element types of the
pointer types, creating the appropriate SPIR-V types and mapping them
on LLVM types. Due to a recursive nature of this algorithm, here we will
have '%struct._ZTS6Object.Object addrspace(4)*' be processed twice with
2 SPIR-V type declaration instruction being created.

Signed-off-by: Dmitry Sidorov [email protected]

@MrSidims MrSidims force-pushed the private/MrSidims/spv_pointer_type branch from c00c4dc to 9994c86 Compare May 31, 2021 18:03
@MrSidims
Copy link
Contributor Author

I would prefer to push this patch ASAP not waiting for Khronos review and a pull-down.

There is a map used during forward translation. It links LLVM type
and SPIR-V type, that is being generated, LLVM type here is used as
a key. Due to a bug in type mapping (information is below), it's
possible that for a single pointer type in LLVM, the translator
will create 2 physically-indentical SPIR-V pointer types and with
previous implementation of mapType function the map would be changed
during the second type insertion. This patch prevents it, forcing
to reuse the type that was created first, though we would still have
an unused duplication of this type in SPIR-V module.

Please consider following LLVM IR sample:
%struct._ZTS4Args.Args = type { %struct._ZTS6Object.Object addrspace(4)* }
%struct._ZTS6Object.Object = type { i32 (%struct._ZTS6Object.Object addrspace(4)*, i32)* }

Here we have 2 LLVM type declarations. The translator will recursively
go through structure members and then through element types of the
pointer types, creating the appropriate SPIR-V types and mapping them
on LLVM types. Due to a recursive nature of this algorithm, here we will
have '%struct._ZTS6Object.Object addrspace(4)*' be processed twice with
2 SPIR-V type declaration instruction being created.

Signed-off-by: Dmitry Sidorov <[email protected]>
@MrSidims MrSidims force-pushed the private/MrSidims/spv_pointer_type branch from 9994c86 to 95db1e9 Compare May 31, 2021 18:10
AlexeySotkin
AlexeySotkin previously approved these changes May 31, 2021
@bader
Copy link
Contributor

bader commented May 31, 2021

I would prefer to push this patch ASAP not waiting for Khronos review and a pull-down.

Why?

@MrSidims
Copy link
Contributor Author

I would prefer to push this patch ASAP not waiting for Khronos review and a pull-down.

Why?

There is an assertion firing because of this bug (store instruction validation) and a customer, that uses intel/llvm build wants it be fixed ASAP.

Signed-off-by: Dmitry Sidorov <[email protected]>
Copy link
Contributor

@AlexeySachkov AlexeySachkov left a comment

Choose a reason for hiding this comment

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

@MrSidims, could you please report CI failure - it is not the first time I see that something is wrong on some download steps.

The patch looks good to me - we have KhronosGroup/SPIRV-LLVM-Translator#1048 submitted to track the main problem and this patch seems to be a small, but reasonable step towards proper solution

@MrSidims
Copy link
Contributor Author

MrSidims commented Jun 1, 2021

@MrSidims, could you please report CI failure - it is not the first time I see that something is wrong on some download steps.

The patch looks good to me - we have KhronosGroup/SPIRV-LLVM-Translator#1048 submitted to track the main problem and this patch seems to be a small, but reasonable step towards proper solution

I reported it. Though, while I'm trying to get access to the logs I'm getting a timeout error.

@bader bader merged commit ff16022 into intel:sycl Jun 1, 2021
MrSidims added a commit to MrSidims/llvm that referenced this pull request Jun 2, 2021
It's a follow up change for intel#3856

Signed-off-by: Dmitry Sidorov <[email protected]>
bader pushed a commit that referenced this pull request Jun 3, 2021
It's a follow up change for #3856

Signed-off-by: Dmitry Sidorov <[email protected]>
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.

4 participants