[Mlir-commits] [mlir] EmitC: Add emitc.global and emitc.get_global (#145) (PR #88701)
Marius Brehler
llvmlistbot at llvm.org
Mon Apr 22 05:59:41 PDT 2024
================
@@ -1016,6 +1016,75 @@ def EmitC_VariableOp : EmitC_Op<"variable", []> {
let hasVerifier = 1;
}
+def EmitC_GlobalOp : EmitC_Op<"global", [Symbol]> {
+ let summary = "A global variable";
+ let description = [{
+ The `emitc.global` operation declares or defines a named global variable.
+ The backing memory for the variable is allocated statically and is
+ described by the type of the variable.
+ Optionally, and `initial_value` can be provided.
+ Internal linkage can be specified using the `staticSpecifier` unit attribute
+ and external linkage can be specified using the `externSpecifier` unit attribute.
+ Note that the default linkage without those two keywords depends on whether
+ the target is C or C++ and whether the global variable is `const`.
+ The global variable can also be marked constant using the `constSpecifier`
+ unit attribute. Writing to such constant global variables is
+ undefined.
+
+ The global variable can be accessed by using the `emitc.get_global` to
+ retrieve the value for the global variable.
+
+ Example:
+
+ ```mlir
+ // Global variable with an initial value.
+ emitc.global @x : emitc.array<2xf32> = dense<0.0, 2.0>
+ // External global variable
+ emitc.global extern @x : emitc.array<2xf32>
+ // Constant global variable with internal linkage
+ emitc.global static const @x : i32 = 0
+ ```
+ }];
+
+ let arguments = (ins SymbolNameAttr:$sym_name,
+ TypeAttr:$type,
+ OptionalAttr<EmitC_OpaqueOrTypedAttr>:$initial_value,
+ UnitAttr:$externSpecifier,
+ UnitAttr:$staticSpecifier,
+ UnitAttr:$constSpecifier);
----------------
marbre wrote:
For consistency this could be changed to
```suggestion
UnitAttr:$extern_specifier,
UnitAttr:$static_specifier,
UnitAttr:$const_specifier);
```
https://github.com/llvm/llvm-project/pull/88701
More information about the Mlir-commits
mailing list