This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][SPIRVToLLVM] Conversion of SPIR-V variable op
ClosedPublic

Authored by georgemitenkov on Jul 21 2020, 2:15 AM.

Details

Summary

The patch introduces the conversion pattern for function-level
spv.Variable. It is modelled as llvm.alloca op. If initialized, then
additional store instruction is used. Note that there is no initialization
for arrays and structs since constants of these types are not supported in
LLVM dialect yet. Also, at the moment initialisation is only possible via
spv.constant (since spv.GlobalVariable conversion is not implemented
yet).

Diff Detail

Event Timeline

georgemitenkov created this revision.Jul 21 2020, 2:15 AM
georgemitenkov edited the summary of this revision. (Show Details)Jul 21 2020, 3:20 AM
ftynse accepted this revision.Jul 23 2020, 5:24 AM

Just as a warning, memory allocated by alloca is live throughout the execution of a function. In the past, we ran into stack overflows because transforming ops executed in a loop into allocas. If the input code has some scoping, it should be reflected with an AutomaticAllocationScope interface that we can then lower to a stacksave/stackrestore pair (TBD).

Note that there is no initialization for arrays and structs since constants of these types are not supported in LLVM dialect yet.

I think we have array and struct initializers for llvm.mlir.global. It should be possible to port those on llvm.mlir.constant as well. Contributions most welcome!

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
183

Nit: prefer explicit types to auto when it doesn't hamper readability

751

Should this also have a check for supported types and bail out on unsupported types (arrays, structs)?

This revision is now accepted and ready to land.Jul 23 2020, 5:24 AM
georgemitenkov marked 2 inline comments as done.

Addressed comments. Scoping will be dealt with separately.

This revision was automatically updated to reflect the committed changes.