[lld] b4e000e - [LLD][MachO] Enable plugin support for LTO (#115690)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 15:02:02 PST 2024


Author: Tom Lin
Date: 2024-11-22T15:01:59-08:00
New Revision: b4e000e6005bd0f11240133aa335efcbb8424a23

URL: https://github.com/llvm/llvm-project/commit/b4e000e6005bd0f11240133aa335efcbb8424a23
DIFF: https://github.com/llvm/llvm-project/commit/b4e000e6005bd0f11240133aa335efcbb8424a23.diff

LOG: [LLD][MachO] Enable plugin support for LTO (#115690)

Add new CLI options for feature parity with ELF w.r.t pass plugins.
Most of the changes are ported directly from
https://github.com/llvm/llvm-project/commit/0c86198b279a98c8550fde318b59ed3ca0ca5045.
With this change, it is now possible to load and run external pass
plugins during the LTO phase.

Added: 
    lld/test/MachO/ltopasses-extension.ll

Modified: 
    lld/MachO/Config.h
    lld/MachO/Driver.cpp
    lld/MachO/LTO.cpp
    lld/MachO/Options.td

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index 41bcd58acc27f7..a03561be925a85 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -166,6 +166,7 @@ struct Configuration {
   llvm::StringRef installName;
   llvm::StringRef clientName;
   llvm::StringRef mapFile;
+  llvm::StringRef ltoNewPmPasses;
   llvm::StringRef ltoObjPath;
   llvm::StringRef thinLTOJobs;
   llvm::StringRef umbrella;
@@ -239,6 +240,7 @@ struct Configuration {
   SymtabPresence localSymbolsPresence = SymtabPresence::All;
   SymbolPatterns localSymbolPatterns;
   llvm::SmallVector<llvm::StringRef, 0> mllvmOpts;
+  llvm::SmallVector<llvm::StringRef, 0> passPlugins;
 
   bool zeroModTime = true;
   bool generateUuid = true;

diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 53b4372435ab54..4f39613ac17dec 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1741,6 +1741,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
     config->umbrella = arg->getValue();
   }
   config->ltoObjPath = args.getLastArgValue(OPT_object_path_lto);
+  config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
   config->thinLTOCacheDir = args.getLastArgValue(OPT_cache_path_lto);
   config->thinLTOCachePolicy = getLTOCachePolicy(args);
   config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
@@ -2110,6 +2111,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
       config->mllvmOpts.emplace_back(arg->getValue());
     }
 
+    config->passPlugins = args::getStrings(args, OPT_load_pass_plugins);
+
     createSyntheticSections();
     createSyntheticSymbols();
     addSynthenticMethnames();

diff  --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp
index 28f5290edb58e3..2eeca44ecbb3c4 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -44,6 +44,9 @@ static lto::Config createConfig() {
   c.Options.EmitAddrsig = config->icfLevel == ICFLevel::safe;
   for (StringRef C : config->mllvmOpts)
     c.MllvmArgs.emplace_back(C.str());
+  for (StringRef pluginFn : config->passPlugins)
+    c.PassPlugins.push_back(std::string(pluginFn));
+  c.OptPipeline = std::string(config->ltoNewPmPasses);
   c.CodeModel = getCodeModelFromCMModel();
   c.CPU = getCPUStr();
   c.MAttrs = getMAttrs();

diff  --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index 739d1da15d4660..d453ea3b9e11d9 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -162,6 +162,12 @@ def no_objc_category_merging : Flag<["-"], "no_objc_category_merging">,
     Group<grp_lld>;
 def lto_debug_pass_manager: Flag<["--"], "lto-debug-pass-manager">,
     HelpText<"Debug new pass manager">, Group<grp_lld>;
+def lto_newpm_passes: Joined<["--"], "lto-newpm-passes=">,
+    HelpText<"Passes to run during LTO">, Group<grp_lld>;
+def load_pass_plugins : Separate<["--"], "load-pass-plugin">, Group<grp_lld>;
+def load_pass_plugins_eq : Joined<["--"], "load-pass-plugin=">,
+    Alias<!cast<Separate>(load_pass_plugins)>,
+    HelpText<"Load passes from plugin library">, Group<grp_lld>;
 def codegen_data_generate_path : Separate<["--"], "codegen-data-generate-path">, Group<grp_lld>;
 def codegen_data_generate_path_eq : Joined<["--"], "codegen-data-generate-path=">,
     Alias<!cast<Separate>(codegen_data_generate_path)>, MetaVarName<"<cgdata>">,

diff  --git a/lld/test/MachO/ltopasses-extension.ll b/lld/test/MachO/ltopasses-extension.ll
new file mode 100644
index 00000000000000..300f03d4cfdb6d
--- /dev/null
+++ b/lld/test/MachO/ltopasses-extension.ll
@@ -0,0 +1,13 @@
+; REQUIRES: x86, plugins, examples
+
+; RUN: opt -module-summary %s -o %t.o
+; RUN: %lld -dylib -%loadnewpmbye --lto-newpm-passes="goodbye" -mllvm %loadbye -mllvm -wave-goodbye %t.o -o /dev/null 2>&1 | FileCheck %s
+; CHECK: Bye
+
+target triple = "x86_64-apple-macosx10.15.0"
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+ at junk = global i32 0
+
+define ptr @somefunk() {
+  ret ptr @junk
+}


        


More information about the llvm-commits mailing list