[Mlir-commits] [mlir] 1bf7921 - [mlir][LLVM] Add support for adding a garbage collector to a LLVM function
Markus Böck
llvmlistbot at llvm.org
Fri Feb 11 01:24:01 PST 2022
Author: Markus Böck
Date: 2022-02-11T10:23:51+01:00
New Revision: 1bf792137478ddbe036b2c04c64985d11ba33d63
URL: https://github.com/llvm/llvm-project/commit/1bf792137478ddbe036b2c04c64985d11ba33d63
DIFF: https://github.com/llvm/llvm-project/commit/1bf792137478ddbe036b2c04c64985d11ba33d63.diff
LOG: [mlir][LLVM] Add support for adding a garbage collector to a LLVM function
This patch simply adds an optional garbage collector attribute to LLVMFuncOp which maps 1:1 to the "gc" property of functions in LLVM.
Differential Revision: https://reviews.llvm.org/D119492
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
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 7dae79047b1bc..d9883f33086e8 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1237,6 +1237,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
let arguments = (ins DefaultValuedAttr<Linkage, "Linkage::External">:$linkage,
UnitAttr:$dso_local,
OptionalAttr<FlatSymbolRefAttr>:$personality,
+ OptionalAttr<StrAttr>:$garbageCollector,
OptionalAttr<ArrayAttr>:$passthrough);
let regions = (region AnyRegion:$body);
diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index 7b42f40f5ae6f..5415905c517dc 100644
--- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
+++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
@@ -812,6 +812,9 @@ LogicalResult Importer::processFunction(llvm::Function *f) {
emitWarning(UnknownLoc::get(context),
"could not deduce personality, skipping it");
+ if (f->hasGC())
+ fop.setGarbageCollectorAttr(b.getStringAttr(f->getGC()));
+
if (f->isDeclaration())
return success();
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 75d04e1648688..544af4cf48c5c 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -797,6 +797,9 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
llvmFunc->setPersonalityFn(pfunc);
}
+ if (auto gc = func.getGarbageCollector())
+ llvmFunc->setGC(gc->str());
+
// First, create all blocks so we can jump to them.
llvm::LLVMContext &llvmContext = llvmFunc->getContext();
for (auto &bb : func) {
diff --git a/mlir/test/Target/LLVMIR/import.ll b/mlir/test/Target/LLVMIR/import.ll
index a8884bdd91a34..c1deb500d1cf5 100644
--- a/mlir/test/Target/LLVMIR/import.ll
+++ b/mlir/test/Target/LLVMIR/import.ll
@@ -331,6 +331,12 @@ define i32 @invokeLandingpad() personality i8* bitcast (i32 (...)* @__gxx_person
ret i32 0
}
+; CHECK-LABEL: @hasGCFunction
+; CHECK-SAME: garbageCollector = "statepoint-example"
+define void @hasGCFunction() gc "statepoint-example" {
+ ret void
+}
+
;CHECK-LABEL: @useFreezeOp
define i32 @useFreezeOp(i32 %x) {
;CHECK: %{{[0-9]+}} = llvm.freeze %{{[0-9a-z]+}} : i32
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 644d480404043..ef369714d94f1 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1378,6 +1378,12 @@ llvm.func @invoke_phis() -> i32 attributes { personality = @__gxx_personality_v0
// -----
+// CHECK-LABEL: @hasGCFunction
+// CHECK-SAME: gc "statepoint-example"
+llvm.func @hasGCFunction() attributes { garbageCollector = "statepoint-example" } {
+ llvm.return
+}
+
// CHECK-LABEL: @callFreezeOp
llvm.func @callFreezeOp(%x : i32) {
// CHECK: freeze i32 %{{[0-9]+}}
More information about the Mlir-commits
mailing list