Hi.
I need to define global variable, say ‘%global1’, that is produced as result of an operation but is ‘global’ i.e. in a module outside function scope. When I search in mlir I get references to ‘llvm.mlir.global’ as an example (using addresof). But I am unable to understand how to do it for myself (because I am not familiar with mlir’s llvm). But could someone give me some useful pointers
Thanks
The way we usually model this is by defining an operation that defines a “symbol”, that is a name by which it can be referred to. It requires the parent op to define a “symbol table” (through a trait). Then such operation can be looked up by name.
This is how func
operates for example.
So this won’t work with an SSA value (you asked about %global1
), it needs another mechanism. Here is more about it: Symbols and Symbol Tables - MLIR
May be define a global variable using memref.global
and write to it by using memref.get_global
and then writing to the result memref in some init function?
Thanks Mehdi/Rahul. Will have a look and come back if stuck