forked from OSchip/llvm-project
[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
This commit is contained in:
parent
e714b98fff
commit
1bf7921374
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]+}}
|
||||
|
|
Loading…
Reference in New Issue