[clang] Run ObjCContractPass in Distributed Thin-LTO Pipeline (PR #92331)
Nuri Amari via cfe-commits
cfe-commits at lists.llvm.org
Wed May 15 17:20:37 PDT 2024
https://github.com/NuriAmari created https://github.com/llvm/llvm-project/pull/92331
Prior to this patch, when using -fthinlto-index= the ObjCARCContractPass isn't run prior to CodeGen, and instruction selection fails on IR containing arc intrinstics.
The pass would normally be added here: https://github.com/llvm/llvm-project/blob/c00e012bcf5da384a3e7339dc2e046779b339063/clang/lib/CodeGen/BackendUtil.cpp#L1352 Since because we are using an index file, we return early above after `runThinLTOBackend`:
https://github.com/llvm/llvm-project/blob/c00e012bcf5da384a3e7339dc2e046779b339063/clang/lib/CodeGen/BackendUtil.cpp#L1333-L1339
>From 66ddf609c0e77867ec48c17136fb80d1e482041d Mon Sep 17 00:00:00 2001
From: Nuri Amari <nuriamari at fb.com>
Date: Wed, 15 May 2024 16:33:03 -0700
Subject: [PATCH] Run ObjCContractPass in Distributed Thin-LTO Pipeline
Prior to this patch, when using -fthinlto-index= the
ObjCARCContractPass isn't run prior to CodeGen, and
instruction selection fails on IR containing
arc intrinstics.
---
clang/lib/CodeGen/BackendUtil.cpp | 3 +++
.../thinlto-distributed-objc-contract-pass.ll | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 90985c08fe7f8..03dd1df281d80 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1289,6 +1289,9 @@ static void runThinLTOBackend(
};
break;
default:
+ Conf.PreCodeGenPassesHook = [](legacy::PassManager &Pm) {
+ Pm.add(createObjCARCContractPass());
+ };
Conf.CGFileType = getCodeGenFileType(Action);
break;
}
diff --git a/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
new file mode 100644
index 0000000000000..7d0247555b5c8
--- /dev/null
+++ b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll
@@ -0,0 +1,19 @@
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN: -o %t2.index \
+; RUN: -r=%t.o,_use_arc,px
+
+; RUN: %clang_cc1 -triple x86_64-apple-darwin \
+; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+; RUN: -o %t.native.o -x ir %t.o
+
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-darwin"
+
+define void @use_arc(ptr %a, ptr %b) {
+ call void (...) @llvm.objc.clang.arc.use(i8* %a, i8* %b) nounwind
+ ret void
+}
+
+declare void @llvm.objc.clang.arc.use(...) nounwind
More information about the cfe-commits
mailing list