Index: mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td =================================================================== --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -1237,6 +1237,7 @@ let arguments = (ins DefaultValuedAttr:$linkage, UnitAttr:$dso_local, OptionalAttr:$personality, + OptionalAttr:$garbageCollector, OptionalAttr:$passthrough); let regions = (region AnyRegion:$body); Index: mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -812,6 +812,9 @@ emitWarning(UnknownLoc::get(context), "could not deduce personality, skipping it"); + if (f->hasGC()) + fop.setGarbageCollectorAttr(b.getStringAttr(f->getGC())); + if (f->isDeclaration()) return success(); Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp =================================================================== --- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -797,6 +797,9 @@ 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) { Index: mlir/test/Target/LLVMIR/import.ll =================================================================== --- mlir/test/Target/LLVMIR/import.ll +++ mlir/test/Target/LLVMIR/import.ll @@ -331,6 +331,12 @@ 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 Index: mlir/test/Target/LLVMIR/llvmir.mlir =================================================================== --- mlir/test/Target/LLVMIR/llvmir.mlir +++ mlir/test/Target/LLVMIR/llvmir.mlir @@ -1378,6 +1378,12 @@ // ----- +// 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]+}}