[llvm] [CodeGen][GC] Skip function without GC in `GCLoweringPass` (PR #84421)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 01:57:30 PST 2024
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/84421
>From e1668c840819c5ff2ebe28424bcd54a9a2abc484 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 8 Mar 2024 10:14:00 +0800
Subject: [PATCH 1/2] [CodeGen][GC] Skip function without GC in
`GCLoweringPass`
---
llvm/lib/CodeGen/GCRootLowering.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/CodeGen/GCRootLowering.cpp b/llvm/lib/CodeGen/GCRootLowering.cpp
index 894ab9a0486a7b..0d82f2bab8960b 100644
--- a/llvm/lib/CodeGen/GCRootLowering.cpp
+++ b/llvm/lib/CodeGen/GCRootLowering.cpp
@@ -81,6 +81,9 @@ class GCMachineCodeAnalysis : public MachineFunctionPass {
PreservedAnalyses GCLoweringPass::run(Function &F,
FunctionAnalysisManager &FAM) {
+ if (!F.hasGC())
+ return PreservedAnalyses::all();
+
auto &Info = FAM.getResult<GCFunctionAnalysis>(F);
bool Changed = DoLowering(F, Info.getStrategy());
>From 28071e020df3e6634e9f75540401c1e365bf508f Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Fri, 8 Mar 2024 14:16:12 +0800
Subject: [PATCH 2/2] add test
---
llvm/test/CodeGen/Generic/gc-lowering.ll | 42 ++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 llvm/test/CodeGen/Generic/gc-lowering.ll
diff --git a/llvm/test/CodeGen/Generic/gc-lowering.ll b/llvm/test/CodeGen/Generic/gc-lowering.ll
new file mode 100644
index 00000000000000..7297db8c105510
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/gc-lowering.ll
@@ -0,0 +1,42 @@
+; RUN: opt -S -passes='require<collector-metadata>,function(gc-lowering)' < %s | FileCheck %s
+
+declare ptr @llvm_gc_allocate(i32)
+declare void @llvm_gc_initialize(i32)
+
+declare void @llvm.gcroot(ptr, ptr)
+declare void @llvm.gcwrite(ptr, ptr, ptr)
+
+define i32 @main() gc "shadow-stack" {
+entry:
+ %A = alloca ptr
+ %B = alloca ptr
+
+ call void @llvm_gc_initialize(i32 1048576) ; Start with 1MB heap
+
+ ;; ptr A;
+ call void @llvm.gcroot(ptr %A, ptr null)
+
+ ;; A = gcalloc(10);
+ %Aptr = call ptr @llvm_gc_allocate(i32 10)
+ store ptr %Aptr, ptr %A
+
+ ;; ptr B;
+ call void @llvm.gcroot(ptr %B, ptr null)
+
+ ;; B = gcalloc(4);
+ %B.upgrd.1 = call ptr @llvm_gc_allocate(i32 8)
+ store ptr %B.upgrd.1, ptr %B
+
+ ;; *B = A;
+ %B.1 = load ptr, ptr %B
+ %A.1 = load ptr, ptr %A
+ call void @llvm.gcwrite(ptr %A.1, ptr %B.upgrd.1, ptr %B.1)
+ ; CHECK: %A.1 = load ptr, ptr %A, align 8
+ ; CHECK-NEXT: store ptr %A.1, ptr %B.1, align 8
+
+ ret i32 0
+}
+
+define void @no_gc() {
+ ret void
+}
More information about the llvm-commits
mailing list