File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,14 @@ llvm.func @func() attributes {
105
105
If the attribute is not known to LLVM IR, it will be attached as a string
106
106
attribute.
107
107
108
+ #### Linkage
109
+
110
+ An LLVM IR dialect function has a linkage attribute derived from LLVM IR
111
+ [ linkage types] ( https://llvm.org/docs/LangRef.html#linkage-types ) . Linkage is
112
+ specified by the same keyword as in LLVM IR and is located between ` llvm.func `
113
+ and the symbol name. If no linkage keyword is present, ` external ` linkage is
114
+ assumed by default.
115
+
108
116
### LLVM IR operations
109
117
110
118
The following operations are currently supported. The semantics of these
@@ -423,6 +431,21 @@ llvm.mlir.global constant @int_gep() : !llvm<"i32*"> {
423
431
}
424
432
```
425
433
434
+ Similarly to functions, globals have a linkage attribute. In the custom syntax,
435
+ this attribute is placed between ` llvm.mlir.global ` and the optional ` constant `
436
+ keyword. If the attribute is omitted, ` external ` linkage is assumed by default.
437
+
438
+ Examples:
439
+
440
+ ``` mlir
441
+ // A constant with internal linkage will not participate in linking.
442
+ llvm.mlir.global internal constant @cst(42 : i32) : !llvm.i32
443
+
444
+ // By default, "external" linkage is assumed and the global participates in
445
+ // symbol resolution at link-time.
446
+ llvm.mlir.global @glob(0 : f32) : !llvm.float
447
+ ```
448
+
426
449
#### ` llvm.mlir.null `
427
450
428
451
Unlike LLVM IR, MLIR does not have first-class null pointers. They must be
Original file line number Diff line number Diff line change @@ -1010,15 +1010,17 @@ static ParseResult parseOptionalLLVMKeyword(OpAsmParser &parser,
1010
1010
return success ();
1011
1011
}
1012
1012
1013
- // operation ::= `llvm.mlir.global` linkage `constant`? `@` identifier
1013
+ // operation ::= `llvm.mlir.global` linkage? `constant`? `@` identifier
1014
1014
// `(` attribute? `)` attribute-list? (`:` type)? region?
1015
1015
//
1016
1016
// The type can be omitted for string attributes, in which case it will be
1017
1017
// inferred from the value of the string as [strlen(value) x i8].
1018
1018
static ParseResult parseGlobalOp (OpAsmParser &parser, OperationState &result) {
1019
1019
if (failed (parseOptionalLLVMKeyword<Linkage>(parser, result,
1020
1020
getLinkageAttrName ())))
1021
- return parser.emitError (parser.getCurrentLocation (), " expected linkage" );
1021
+ result.addAttribute (getLinkageAttrName (),
1022
+ parser.getBuilder ().getI64IntegerAttr (
1023
+ static_cast <int64_t >(LLVM::Linkage::External)));
1022
1024
1023
1025
if (succeeded (parser.parseOptionalKeyword (" constant" )))
1024
1026
result.addAttribute (" constant" , parser.getBuilder ().getUnitAttr ());
Original file line number Diff line number Diff line change 1
1
// RUN: mlir-opt -split-input-file -verify-diagnostics %s | FileCheck %s
2
2
3
+ // CHECK: llvm.mlir.global external @default_external
4
+ llvm.mlir.global @default_external () : !llvm.i64
5
+
6
+ // CHECK: llvm.mlir.global external constant @default_external_constant
7
+ llvm.mlir.global constant @default_external_constant (42 ) : !llvm.i64
8
+
3
9
// CHECK: llvm.mlir.global internal @global(42 : i64) : !llvm.i64
4
10
llvm.mlir.global internal @global (42 : i64 ) : !llvm.i64
5
11
You can’t perform that action at this time.
0 commit comments