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).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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)? |
Nit: prefer explicit types to auto when it doesn't hamper readability