Skip to content

Commit b4f794e

Browse files
committed
[COFF] Enable new passmanager plugin support for LTO
1 parent b4f0fc2 commit b4f794e

File tree

7 files changed

+60
-4
lines changed

7 files changed

+60
-4
lines changed

lld/COFF/Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ struct Configuration {
151151
llvm::SmallString<128> pdbPath;
152152
llvm::SmallString<128> pdbSourcePath;
153153
std::vector<llvm::StringRef> argv;
154+
std::vector<std::string> passPlugins;
155+
llvm::StringRef ltoNewPmPasses;
154156

155157
// Symbols in this set are considered as live by the garbage collector.
156158
std::vector<Symbol *> gcroot;

lld/COFF/Driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
19451945
}
19461946
}
19471947

1948+
if (args.hasArg(OPT_load_pass_plugins))
1949+
config->passPlugins = args.getAllArgValues(OPT_load_pass_plugins);
1950+
1951+
config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
1952+
19481953
if (!icfLevel)
19491954
icfLevel = doGC ? ICFLevel::All : ICFLevel::None;
19501955
config->doGC = doGC;

lld/COFF/LTO.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ lto::Config BitcodeCompiler::createConfig() {
102102
c.Options.MCOptions.AsmVerbose = true;
103103
}
104104

105+
for (const std::string& pluginFn : ctx.config.passPlugins)
106+
c.PassPlugins.push_back(pluginFn);
107+
108+
// Set up a custom pipeline if we've been asked to.
109+
c.OptPipeline = std::string(ctx.config.ltoNewPmPasses);
110+
105111
if (!ctx.config.saveTempsArgs.empty())
106112
checkError(c.addSaveTemps(std::string(ctx.config.outputFile) + ".",
107113
/*UseInputModulePath*/ true,

lld/COFF/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ def map_info : P<"mapinfo", "Include the specified information in a map file">;
328328
def print_search_paths : F<"print-search-paths">;
329329
def summary : F<"summary">;
330330

331+
def load_pass_plugins: P<"load-pass-plugin", "Load passes from plugin library">;
332+
def lto_newpm_passes: P<"lto-newpm-passes", "Passes to run during LTO">;
333+
331334
//==============================================================================
332335
// The flags below do nothing. They are defined only for link.exe compatibility.
333336
//==============================================================================

llvm/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name
5959
# Must go after `project(..)`.
6060
include(GNUInstallDirs)
6161

62+
if (LLVM_EXPORT_SYMBOLS_FOR_PLUGINS)
63+
add_definitions(-DEXPORT_SYMBOLS)
64+
endif()
65+
6266
# This C++ standard is required to build LLVM.
6367
set(LLVM_REQUIRED_CXX_STANDARD 17)
6468

llvm/include/llvm/IR/Analysis.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@
1414

1515
#include "llvm/ADT/SmallPtrSet.h"
1616

17+
#ifdef _WIN32
18+
#define DLL_EXPORT __declspec(dllexport)
19+
#else
20+
#define DLL_EXPORT
21+
#endif
22+
23+
#ifdef _WIN32
24+
#define DLL_IMPORT __declspec(dllimport)
25+
#else
26+
#define DLL_IMPORT
27+
#endif
28+
29+
#ifdef EXPORT_SYMBOLS
30+
#define DLL_API DLL_EXPORT
31+
#else
32+
#define DLL_API DLL_IMPORT
33+
#endif
34+
1735
namespace llvm {
1836

1937
class Function;
@@ -51,7 +69,7 @@ template <typename IRUnitT> class AllAnalysesOn {
5169
static AnalysisSetKey *ID() { return &SetKey; }
5270

5371
private:
54-
static AnalysisSetKey SetKey;
72+
DLL_API static AnalysisSetKey SetKey;
5573
};
5674

5775
template <typename IRUnitT> AnalysisSetKey AllAnalysesOn<IRUnitT>::SetKey;
@@ -300,7 +318,7 @@ class PreservedAnalyses {
300318

301319
private:
302320
/// A special key used to indicate all analyses.
303-
static AnalysisSetKey AllAnalysesKey;
321+
DLL_API static AnalysisSetKey AllAnalysesKey;
304322

305323
/// The IDs of analyses and analysis sets that are preserved.
306324
SmallPtrSet<void *, 2> PreservedIDs;

llvm/include/llvm/IR/PassManager.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@
5454
#include <utility>
5555
#include <vector>
5656

57+
#ifdef _WIN32
58+
#define DLL_EXPORT __declspec(dllexport)
59+
#else
60+
#define DLL_EXPORT
61+
#endif
62+
63+
#ifdef _WIN32
64+
#define DLL_IMPORT __declspec(dllimport)
65+
#else
66+
#define DLL_IMPORT
67+
#endif
68+
69+
#ifdef EXPORT_SYMBOLS
70+
#define DLL_API DLL_EXPORT
71+
#else
72+
#define DLL_API DLL_IMPORT
73+
#endif
74+
5775
namespace llvm {
5876

5977
class Function;
@@ -507,7 +525,7 @@ template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager {
507525
}
508526

509527
/// Get an analysis result, running the pass if necessary.
510-
ResultConceptT &getResultImpl(AnalysisKey *ID, IRUnitT &IR,
528+
DLL_API ResultConceptT &getResultImpl(AnalysisKey *ID, IRUnitT &IR,
511529
ExtraArgTs... ExtraArgs);
512530

513531
/// Get a cached analysis result or return null.
@@ -634,7 +652,7 @@ class InnerAnalysisManagerProxy
634652
friend AnalysisInfoMixin<
635653
InnerAnalysisManagerProxy<AnalysisManagerT, IRUnitT>>;
636654

637-
static AnalysisKey Key;
655+
DLL_API static AnalysisKey Key;
638656

639657
AnalysisManagerT *InnerAM;
640658
};

0 commit comments

Comments
 (0)