[Mlir-commits] [mlir] b65472d - [MLIR] Add and propagate section attribute for LLVM_GlobalOp
Mehdi Amini
llvmlistbot at llvm.org
Tue Apr 27 21:22:55 PDT 2021
Author: Ranjith Kumar H
Date: 2021-04-28T04:15:49Z
New Revision: b65472d66dcc11600bd2093a484e1309533bdfac
URL: https://github.com/llvm/llvm-project/commit/b65472d66dcc11600bd2093a484e1309533bdfac
DIFF: https://github.com/llvm/llvm-project/commit/b65472d66dcc11600bd2093a484e1309533bdfac.diff
LOG: [MLIR] Add and propagate section attribute for LLVM_GlobalOp
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
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Dialect/LLVMIR/global.mlir
mlir/test/Target/LLVMIR/import.ll
mlir/test/Target/LLVMIR/llvmir.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 1ff060a418509..c379dc76ff19c 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -908,7 +908,8 @@ def LLVM_GlobalOp : LLVM_Op<"mlir.global",
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 = [{
diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index e1e57bbc405fd..5b1faee52e3ed 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -490,6 +490,8 @@ GlobalOp Importer::processGlobal(llvm::GlobalVariable *GV) {
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;
}
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 33d439d8afd30..ea4c32cf6a2ed 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -410,6 +410,9 @@ LogicalResult ModuleTranslation::convertGlobals() {
if (op.unnamed_addr().hasValue())
var->setUnnamedAddr(convertUnnamedAddrToLLVM(*op.unnamed_addr()));
+ if (op.section().hasValue())
+ var->setSection(*op.section());
+
globalsMapping.try_emplace(op, var);
}
diff --git a/mlir/test/Dialect/LLVMIR/global.mlir b/mlir/test/Dialect/LLVMIR/global.mlir
index 23f77ab37fe56..a5306c4485d5b 100644
--- a/mlir/test/Dialect/LLVMIR/global.mlir
+++ b/mlir/test/Dialect/LLVMIR/global.mlir
@@ -69,6 +69,9 @@ llvm.mlir.global private local_unnamed_addr constant @local(42 : i64) : i64
// 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'}}
diff --git a/mlir/test/Target/LLVMIR/import.ll b/mlir/test/Target/LLVMIR/import.ll
index c208b7612d417..027bc29b78697 100644
--- a/mlir/test/Target/LLVMIR/import.ll
+++ b/mlir/test/Target/LLVMIR/import.ll
@@ -61,6 +61,13 @@
; CHECK: llvm.mlir.global private unnamed_addr constant @unnamed_addr(42 : i64) : i64
@unnamed_addr = private unnamed_addr constant i64 42
+;
+; Section attribute
+;
+
+; CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}
+ at sectionvar = internal constant [10 x i8] c"teststring", section ".mysection"
+
;
; Sequential constants.
;
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index abaec730ef12f..2b59893d085c9 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -70,6 +70,13 @@ llvm.mlir.global private local_unnamed_addr constant @local_unnamed_addr(42 : i6
// CHECK: @unnamed_addr = private unnamed_addr constant i64 42
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.
More information about the Mlir-commits
mailing list