Page MenuHomePhabricator

[MLIR][SPIRVToLLVM] Conversion for global and addressof

Authored by georgemitenkov on Jul 27 2020, 2:52 AM.



Inital conversion of spv._address_of and spv.globalVariable.
In SPIR-V, the global returns a pointer, whereas in LLVM dialect the global
holds an actual value. This difference is handled by spv._address_of and
llvm.mlir.addressofops that both return a pointer. Moreover, only current
invocation is in conversion's scope.

Diff Detail

Event Timeline

georgemitenkov created this revision.Jul 27 2020, 2:52 AM
antiagainst requested changes to this revision.Jul 28 2020, 6:38 PM
antiagainst added inline comments.

considered as


I think External is not correct for Private storage class. Private storage class can only be accessed by the current module so it should map to LLVM private linkage?

This revision now requires changes to proceed.Jul 28 2020, 6:38 PM
georgemitenkov marked an inline comment as done.Jul 29 2020, 6:28 AM
georgemitenkov added inline comments.

@antiagainst That's right! What about other storage classes?
Based on SPIR-V spec:

By default, functions and global variables are private to a module and cannot be accessed by other modules. However, a module may be written to export or import functions and global (module scope) variables. Imported functions and global variable definitions are resolved at linkage time. A module is considered to be partially linked if it depends on imported values. Within a module, imported or exported values are decorated using the Linkage Attributes Decoration.

This means that Private linkage should be the default for all, and it is the linkage decoration that specifies if the variable is Import/Export?

georgemitenkov marked an inline comment as done.

Fixed a typo and handled linkage properly.

mravishankar added inline comments.Aug 3 2020, 11:36 PM

Comment is misleading. The SPIR-V spec returns an SSA value. In SPIR-V dialect GlobalVariable is a Symbol. Not sure what LLVM dialect holds an actual value means though. AFAIK, the LLVM global variable and SPIR-V global variable are the same and the address of act the same way?


I am confused why input is chosen as a constant. I might be missing something here (or maybe just the naming is throwing me off), but Input seems to be more like a Global Variable that is externally defined and used internally (I dont know off the top of my head if there is a further qualifier that makes it externally defined but not modified within an LLVM module). SPIR-V constants map more directly to LLVM constants.


Please group all the CHECK comments together. Its easier to read that way.

mravishankar requested changes to this revision.Aug 3 2020, 11:37 PM
This revision now requires changes to proceed.Aug 3 2020, 11:37 PM
georgemitenkov marked an inline comment as done.Aug 4 2020, 2:42 AM
georgemitenkov added inline comments.

spv._address_of acts the same way indeed. What I meant here is that spv.globalVariable's type is a pointer, whereas op's type is the pointee's type.
Hence we need to do this before type conversion


to later build


It is still a LLVM global but just with a constant flag. Based on LLVM dialect spec, if the global value is a constant, storing into it is not allowed. I think that by "is a constant" it means that it has a constant attribute.
Since Input variables are

read-only, and cannot have initializers

per SPIR-V spec, we add constant attribute to

Put CHECK statements in one block.

mravishankar accepted this revision.Aug 4 2020, 10:09 AM
mravishankar added inline comments.

THanks for the clarification! That makes sense to me.


THanks. Super Nit, typically I have seen


instead. But this is as good.

georgemitenkov marked 2 inline comments as done.Aug 6 2020, 7:27 AM
georgemitenkov marked an inline comment as done.Aug 6 2020, 7:30 AM
antiagainst accepted this revision.Aug 11 2020, 8:58 AM

Sorry for the delay! For future patches, please feel free to land once you've gotten Mahesh's approval; no need to wait for mine.

This revision is now accepted and ready to land.Aug 11 2020, 8:58 AM