aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Passes
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 10:51:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 10:51:19 +0000
commiteb11fae6d08f479c0799db45860a98af528fa6e7 (patch)
tree44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /include/llvm/Passes
parentb8a2042aa938069e862750553db0e4d82d25822c (diff)
Notes
Diffstat (limited to 'include/llvm/Passes')
-rw-r--r--include/llvm/Passes/PassBuilder.h58
-rw-r--r--include/llvm/Passes/PassPlugin.h114
2 files changed, 151 insertions, 21 deletions
diff --git a/include/llvm/Passes/PassBuilder.h b/include/llvm/Passes/PassBuilder.h
index b699888262537..24a93bc76af5b 100644
--- a/include/llvm/Passes/PassBuilder.h
+++ b/include/llvm/Passes/PassBuilder.h
@@ -19,6 +19,7 @@
#include "llvm/ADT/Optional.h"
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include <vector>
@@ -26,6 +27,7 @@ namespace llvm {
class StringRef;
class AAManager;
class TargetMachine;
+class ModuleSummaryIndex;
/// A struct capturing PGO tunables.
struct PGOOptions {
@@ -47,7 +49,7 @@ struct PGOOptions {
bool SamplePGOSupport;
};
-/// \brief This class provides access to building LLVM's passes.
+/// This class provides access to building LLVM's passes.
///
/// It's members provide the baseline state available to passes during their
/// construction. The \c PassRegistry.def file specifies how to construct all
@@ -58,7 +60,7 @@ class PassBuilder {
Optional<PGOOptions> PGOOpt;
public:
- /// \brief A struct to capture parsed pass pipeline names.
+ /// A struct to capture parsed pass pipeline names.
///
/// A pipeline is defined as a series of names, each of which may in itself
/// recursively contain a nested pipeline. A name is either the name of a pass
@@ -71,7 +73,7 @@ public:
std::vector<PipelineElement> InnerPipeline;
};
- /// \brief ThinLTO phase.
+ /// ThinLTO phase.
///
/// This enumerates the LLVM ThinLTO optimization phases.
enum class ThinLTOPhase {
@@ -83,7 +85,7 @@ public:
PostLink
};
- /// \brief LLVM-provided high-level optimization levels.
+ /// LLVM-provided high-level optimization levels.
///
/// This enumerates the LLVM-provided high-level optimization levels. Each
/// level has a specific goal and rationale.
@@ -173,7 +175,7 @@ public:
Optional<PGOOptions> PGOOpt = None)
: TM(TM), PGOOpt(PGOOpt) {}
- /// \brief Cross register the analysis managers through their proxies.
+ /// Cross register the analysis managers through their proxies.
///
/// This is an interface that can be used to cross register each
// AnalysisManager with all the others analysis managers.
@@ -182,7 +184,7 @@ public:
CGSCCAnalysisManager &CGAM,
ModuleAnalysisManager &MAM);
- /// \brief Registers all available module analysis passes.
+ /// Registers all available module analysis passes.
///
/// This is an interface that can be used to populate a \c
/// ModuleAnalysisManager with all registered module analyses. Callers can
@@ -190,7 +192,7 @@ public:
/// pre-register analyses and this will not override those.
void registerModuleAnalyses(ModuleAnalysisManager &MAM);
- /// \brief Registers all available CGSCC analysis passes.
+ /// Registers all available CGSCC analysis passes.
///
/// This is an interface that can be used to populate a \c CGSCCAnalysisManager
/// with all registered CGSCC analyses. Callers can still manually register any
@@ -198,7 +200,7 @@ public:
/// not override those.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM);
- /// \brief Registers all available function analysis passes.
+ /// Registers all available function analysis passes.
///
/// This is an interface that can be used to populate a \c
/// FunctionAnalysisManager with all registered function analyses. Callers can
@@ -206,7 +208,7 @@ public:
/// pre-register analyses and this will not override those.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM);
- /// \brief Registers all available loop analysis passes.
+ /// Registers all available loop analysis passes.
///
/// This is an interface that can be used to populate a \c LoopAnalysisManager
/// with all registered loop analyses. Callers can still manually register any
@@ -309,8 +311,9 @@ public:
/// only intended for use when attempting to optimize code. If frontends
/// require some transformations for semantic reasons, they should explicitly
/// build them.
- ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level,
- bool DebugLogging = false);
+ ModulePassManager
+ buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
+ const ModuleSummaryIndex *ImportSummary);
/// Build a pre-link, LTO-targeting default optimization pipeline to a pass
/// manager.
@@ -339,13 +342,14 @@ public:
/// require some transformations for semantic reasons, they should explicitly
/// build them.
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
- bool DebugLogging = false);
+ bool DebugLogging,
+ ModuleSummaryIndex *ExportSummary);
/// Build the default `AAManager` with the default alias analysis pipeline
/// registered.
AAManager buildDefaultAAPipeline();
- /// \brief Parse a textual pass pipeline description into a \c
+ /// Parse a textual pass pipeline description into a \c
/// ModulePassManager.
///
/// The format of the textual pass pipeline description looks something like:
@@ -409,7 +413,7 @@ public:
/// returns false.
bool parseAAPipeline(AAManager &AA, StringRef PipelineText);
- /// \brief Register a callback for a default optimizer pipeline extension
+ /// Register a callback for a default optimizer pipeline extension
/// point
///
/// This extension point allows adding passes that perform peephole
@@ -420,7 +424,7 @@ public:
PeepholeEPCallbacks.push_back(C);
}
- /// \brief Register a callback for a default optimizer pipeline extension
+ /// Register a callback for a default optimizer pipeline extension
/// point
///
/// This extension point allows adding late loop canonicalization and
@@ -434,7 +438,7 @@ public:
LateLoopOptimizationsEPCallbacks.push_back(C);
}
- /// \brief Register a callback for a default optimizer pipeline extension
+ /// Register a callback for a default optimizer pipeline extension
/// point
///
/// This extension point allows adding loop passes to the end of the loop
@@ -444,7 +448,7 @@ public:
LoopOptimizerEndEPCallbacks.push_back(C);
}
- /// \brief Register a callback for a default optimizer pipeline extension
+ /// Register a callback for a default optimizer pipeline extension
/// point
///
/// This extension point allows adding optimization passes after most of the
@@ -454,7 +458,7 @@ public:
ScalarOptimizerLateEPCallbacks.push_back(C);
}
- /// \brief Register a callback for a default optimizer pipeline extension
+ /// Register a callback for a default optimizer pipeline extension
/// point
///
/// This extension point allows adding CallGraphSCC passes at the end of the
@@ -465,7 +469,7 @@ public:
CGSCCOptimizerLateEPCallbacks.push_back(C);
}
- /// \brief Register a callback for a default optimizer pipeline extension
+ /// Register a callback for a default optimizer pipeline extension
/// point
///
/// This extension point allows adding optimization passes before the
@@ -476,7 +480,17 @@ public:
VectorizerStartEPCallbacks.push_back(C);
}
- /// \brief Register a callback for parsing an AliasAnalysis Name to populate
+ /// Register a callback for a default optimizer pipeline extension point.
+ ///
+ /// This extension point allows adding optimization once at the start of the
+ /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
+ /// link-time pipelines).
+ void registerPipelineStartEPCallback(
+ const std::function<void(ModulePassManager &)> &C) {
+ PipelineStartEPCallbacks.push_back(C);
+ }
+
+ /// Register a callback for parsing an AliasAnalysis Name to populate
/// the given AAManager \p AA
void registerParseAACallback(
const std::function<bool(StringRef Name, AAManager &AA)> &C) {
@@ -530,7 +544,7 @@ public:
}
/// @}}
- /// \brief Register a callback for a top-level pipeline entry.
+ /// Register a callback for a top-level pipeline entry.
///
/// If the PassManager type is not given at the top level of the pipeline
/// text, this Callback should be used to determine the appropriate stack of
@@ -589,6 +603,8 @@ private:
SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2>
VectorizerStartEPCallbacks;
// Module callbacks
+ SmallVector<std::function<void(ModulePassManager &)>, 2>
+ PipelineStartEPCallbacks;
SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
ModuleAnalysisRegistrationCallbacks;
SmallVector<std::function<bool(StringRef, ModulePassManager &,
diff --git a/include/llvm/Passes/PassPlugin.h b/include/llvm/Passes/PassPlugin.h
new file mode 100644
index 0000000000000..af8f11a7a352e
--- /dev/null
+++ b/include/llvm/Passes/PassPlugin.h
@@ -0,0 +1,114 @@
+//===- llvm/Passes/PassPlugin.h - Public Plugin API -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This defines the public entry point for new-PM pass plugins.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_PASSES_PASSPLUGIN_H
+#define LLVM_PASSES_PASSPLUGIN_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/Error.h"
+#include <cstdint>
+#include <string>
+
+namespace llvm {
+class PassBuilder;
+
+/// \macro LLVM_PLUGIN_API_VERSION
+/// Identifies the API version understood by this plugin.
+///
+/// When a plugin is loaded, the driver will check it's supported plugin version
+/// against that of the plugin. A mismatch is an error. The supported version
+/// will be incremented for ABI-breaking changes to the \c PassPluginLibraryInfo
+/// struct, i.e. when callbacks are added, removed, or reordered.
+#define LLVM_PLUGIN_API_VERSION 1
+
+extern "C" {
+/// Information about the plugin required to load its passes
+///
+/// This struct defines the core interface for pass plugins and is supposed to
+/// be filled out by plugin implementors. LLVM-side users of a plugin are
+/// expected to use the \c PassPlugin class below to interface with it.
+struct PassPluginLibraryInfo {
+ /// The API version understood by this plugin, usually \c
+ /// LLVM_PLUGIN_API_VERSION
+ uint32_t APIVersion;
+ /// A meaningful name of the plugin.
+ const char *PluginName;
+ /// The version of the plugin.
+ const char *PluginVersion;
+
+ /// The callback for registering plugin passes with a \c PassBuilder
+ /// instance
+ void (*RegisterPassBuilderCallbacks)(PassBuilder &);
+};
+}
+
+/// A loaded pass plugin.
+///
+/// An instance of this class wraps a loaded pass plugin and gives access to
+/// its interface defined by the \c PassPluginLibraryInfo it exposes.
+class PassPlugin {
+public:
+ /// Attempts to load a pass plugin from a given file.
+ ///
+ /// \returns Returns an error if either the library cannot be found or loaded,
+ /// there is no public entry point, or the plugin implements the wrong API
+ /// version.
+ static Expected<PassPlugin> Load(const std::string &Filename);
+
+ /// Get the filename of the loaded plugin.
+ StringRef getFilename() const { return Filename; }
+
+ /// Get the plugin name
+ StringRef getPluginName() const { return Info.PluginName; }
+
+ /// Get the plugin version
+ StringRef getPluginVersion() const { return Info.PluginVersion; }
+
+ /// Get the plugin API version
+ uint32_t getAPIVersion() const { return Info.APIVersion; }
+
+ /// Invoke the PassBuilder callback registration
+ void registerPassBuilderCallbacks(PassBuilder &PB) const {
+ Info.RegisterPassBuilderCallbacks(PB);
+ }
+
+private:
+ PassPlugin(const std::string &Filename, const sys::DynamicLibrary &Library)
+ : Filename(Filename), Library(Library), Info() {}
+
+ std::string Filename;
+ sys::DynamicLibrary Library;
+ PassPluginLibraryInfo Info;
+};
+}
+
+/// The public entry point for a pass plugin.
+///
+/// When a plugin is loaded by the driver, it will call this entry point to
+/// obtain information about this plugin and about how to register its passes.
+/// This function needs to be implemented by the plugin, see the example below:
+///
+/// ```
+/// extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+/// llvmGetPassPluginInfo() {
+/// return {
+/// LLVM_PLUGIN_API_VERSION, "MyPlugin", "v0.1", [](PassBuilder &PB) { ... }
+/// };
+/// }
+/// ```
+extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK
+llvmGetPassPluginInfo();
+
+#endif /* LLVM_PASSES_PASSPLUGIN_H */