https://github.com/NuriAmari updated https://github.com/llvm/llvm-project/pull/92331
>From 66ddf609c0e77867ec48c17136fb80d1e482041d Mon Sep 17 00:00:00 2001 From: Nuri Amari <nuriam...@fb.com> Date: Wed, 15 May 2024 16:33:03 -0700 Subject: [PATCH 1/2] 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 >From 142174dff7b12827f7af187e4ff08b3e75486923 Mon Sep 17 00:00:00 2001 From: Nuri Amari <nuriam...@fb.com> Date: Fri, 17 May 2024 11:38:16 -0700 Subject: [PATCH 2/2] Address PR Feedback - Adjust test - Unconditionally include ARC pass in ThinLTO pipeline --- clang/lib/CodeGen/BackendUtil.cpp | 3 --- clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll | 2 +- lld/MachO/LTO.cpp | 3 --- llvm/lib/LTO/LTOBackend.cpp | 2 ++ 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 03dd1df281d80..90985c08fe7f8 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1289,9 +1289,6 @@ 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 index 7d0247555b5c8..a2a7b62cb7f93 100644 --- a/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll +++ b/clang/test/CodeGen/thinlto-distributed-objc-contract-pass.ll @@ -12,7 +12,7 @@ target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16 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 + call void (...) @llvm.objc.clang.arc.use(ptr %a, ptr %b) nounwind ret void } diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index 7a9a9223a0322..6527cbb68f249 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -48,9 +48,6 @@ static lto::Config createConfig() { c.CPU = getCPUStr(); c.MAttrs = getMAttrs(); c.DiagHandler = diagnosticHandler; - c.PreCodeGenPassesHook = [](legacy::PassManager &pm) { - pm.add(createObjCARCContractPass()); - }; c.AlwaysEmitRegularLTOObj = !config->ltoObjPath.empty(); diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index d4b89ede2d713..aef3a7575dfdf 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -42,6 +42,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/TargetParser/SubtargetFeature.h" #include "llvm/Transforms/IPO/WholeProgramDevirt.h" +#include "llvm/Transforms/ObjCARC.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include "llvm/Transforms/Utils/FunctionImportUtils.h" #include "llvm/Transforms/Utils/SplitModule.h" @@ -415,6 +416,7 @@ static void codegen(const Config &Conf, TargetMachine *TM, CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII)); CodeGenPasses.add( createImmutableModuleSummaryIndexWrapperPass(&CombinedIndex)); + CodeGenPasses.add(createObjCARCContractPass()); if (Conf.PreCodeGenPassesHook) Conf.PreCodeGenPassesHook(CodeGenPasses); if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits