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

Update translation of kernel metadata to work with new metadata format. #2

Open
wants to merge 48 commits into
base: master
Choose a base branch
from

Conversation

AlexeySotkin
Copy link
Owner

Clang 4.0 and higher produces kernel argument metadata attached to a
kernel:
'define spir_kernel void @foo(..) #0 !kernel_arg_addr_space !1 ... {}'
'!1 = !{i32 1, i32 1}'

The patch updates SPIRVWriter to use metadata in this format.

'Old' format:
'!0 = !{void (float addrspace(1), ...) @foo, !1, ...}'
'!1 = !{!"kernel_arg_addr_space", i32 1, ...}'
is no longer supported.

Also changing translation of !opencl.used.extension metadata to
OpSourceExtension instead of translation to OpExtension

AlexeySotkin and others added 22 commits November 23, 2018 13:29
Image type may be represented in llvm IR in two forms:
- OpenCL form, for example, '%opencl.image2d_ro_t',
- SPIRV form, for example, '%spirv.Image._void_1_0_0_0_0_0_0',
but in both cases it is the same image type and it should be mapped to
one SPIR-V type.
'cl_intel_subgroup' extension allows to use sub_group_barrier() built-in
with OpenCL 1.2/2.0. It requires to translate this built-in to
reqular (core) SPIR-V instruction OpControlBarrier.

Note: currently clag generates nothing representing vendor extensions
like 'cl_intel_subgroup'. So, SPIR-V translator doesn't check that the
extensions was enabled. It assumes that if a built-in or a type which
belong to one of supported extension used in the IR, this extensions is
enabled.
Fix translation of sampler initialization function
Update test for sampled image with the current version of LLVM IR
The patch changes mangling rules for types with qualifiers from SPIR1.2
to the latest version of Itanium mangling used in clang, which includes
* change in order of qualifiers: first mangles address space, then
  CVR-qualifiers,
* change in substitution rules: private address space is mangled to an
  empty string, but pointee type + private address space is supposed to
  be a substitutable entity even private address space is the only
  qualifier the pointer type has.
A sampler initialized with 0 value is introduced by
cl_intel_device_side_avc_motion_estimation extension.
…tor.

Instead of default enum initialization of "memory_order_*" constants
in SPIRV generator I declared them with specific values. It makes
declaration of these constants in SPIRV generator consistent with
corresponding constants produced by Clang avoiding any inconsistence.

Change-Id: Ida3b373475c248675e1f6adac3b682263a334420
* Change SPIR-V Writer/Reader to consume/produce LLVM IR with blocks and
device side enqueue built-ins as it is produced by clang
* Improve function pointers removal related to OpenCL 2.0 blocks
* Improve tests
* Fix translation of literal structs
…onosGroup#53)

* Adding asserts to prevent possible dereference of a null pointer
* Adding return statements after llvm_unreachable
Removed LIT_SITE_CFG_IN_FOOTER as in llvm repo as in llvm
https://reviews.llvm.org/D51357
Starting from version 3.8 clang generates unmangled names for pipe built-ins.
Plus reflect changes in LLVM IR introduced by https://reviews.llvm.org/D46015.
There are two separate types for read only and write only pipes:
opencl.pipe_ro_t and opencl.pipe_wo_t instead of opencl.pipe_t.

Changes:
* Update SPIRVWriter to consume LLVM IR with non-mangled pipe built-ins.

* Align SPIRV Translator to consume and produce new pipe types. Old ones are no
longer supported.

* Change translation flow to not to convert new pipe types to
spirv-friendly format (like spirv.Pipe._0 or spirv.Pipe._1) before translation.
Spirv-friendly format for pipes is still supported for consuming or producing.
When llvm-spirv is built out of LLVM tree there might be two cases:
- SPIR-V library linked statically. This this case linker and loader are
  able to handle LLVM symbols correctly.
- SPIR-V library linked dynamically. LLVM_LINK_COMPONENTS is ignored as
  all LLVM components is supposed to be linked into libLLVM.so and we
  should explicitly link with SPIR-V library.

If we build llvm-spirv tool in LLVM tree explicit link with SPIR-V
library might lead to multiple symbol definition (e.g. SPIR-V library
linked with libLLVM.so as LLVM component and with llmv-spirv tool via
explicit target_link_library command).
LLVM lifetime intrinsics accept only i8* pointers + size as object
descriptors, so typical pattern for local variables is
alloca+bitcast+lifetime instructions.
SPIR-V translator tries store original type into lifetime instruction
looking though bitcast. It also removes bitcast from the SPIR-V file and
tries to recover it during SPIR-V conversion.
This patch simplifies the translation by keeping bitcast instruction and
fixes assertion of lifetime intrinsics for 8-bit objects.
Some atomic instructions allow only integer result type
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.