Add a section attribute to LLVM_GlobalOp, during module translation attribute value is propagated to llvm
Reviewed By: sgrechanik, ftynse, mehdi_amini
Differential Revision: https://reviews.llvm.org/D100947
Linkage:$linkage,
OptionalAttr<AnyAttr>:$value,
DefaultValuedAttr<Confined<I32Attr, [IntNonNegative]>, "0">:$addr_space,
- OptionalAttr<UnnamedAddr>:$unnamed_addr
+ OptionalAttr<UnnamedAddr>:$unnamed_addr,
+ OptionalAttr<StrAttr>:$section
);
let summary = "LLVM dialect global.";
let description = [{
if (GV->hasAtLeastLocalUnnamedAddr())
op.unnamed_addrAttr(UnnamedAddrAttr::get(
context, convertUnnamedAddrFromLLVM(GV->getUnnamedAddr())));
+ if (GV->hasSection())
+ op.sectionAttr(b.getStringAttr(GV->getSection()));
return globals[GV] = op;
}
if (op.unnamed_addr().hasValue())
var->setUnnamedAddr(convertUnnamedAddrToLLVM(*op.unnamed_addr()));
+ if (op.section().hasValue())
+ var->setSection(*op.section());
+
globalsMapping.try_emplace(op, var);
}
// CHECK: llvm.mlir.global private unnamed_addr constant @foo(42 : i64) : i64
llvm.mlir.global private unnamed_addr constant @foo(42 : i64) : i64
+// CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}
+llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}: !llvm.array<10 x i8>
+
// -----
// expected-error @+1 {{requires string attribute 'sym_name'}}
@unnamed_addr = private unnamed_addr constant i64 42
;
+; Section attribute
+;
+
+; CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}
+@sectionvar = internal constant [10 x i8] c"teststring", section ".mysection"
+
+;
; Sequential constants.
;
llvm.mlir.global private unnamed_addr constant @unnamed_addr(42 : i64) : i64
//
+// Section attribute.
+//
+
+// CHECK: @sectionvar = internal constant [10 x i8] c"teststring", section ".mysection"
+llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}: !llvm.array<10 x i8>
+
+//
// Declarations of the allocation functions to be linked against. These are
// inserted before other functions in the module.
//