//===- mlir/Tools/Plugins/PassPlugin.h - Public Plugin API ----------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This defines the public entry point for pass plugins. // //===----------------------------------------------------------------------===// #ifndef MLIR_TOOLS_PLUGINS_PASSPLUGIN_H #define MLIR_TOOLS_PLUGINS_PASSPLUGIN_H #include "mlir/Support/LLVM.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 mlir { /// \macro MLIR_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 MLIR_PLUGIN_API_VERSION … 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 { … }; } /// 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 { … }; } // namespace mlir /// 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" ::mlir::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK /// mlirGetPassPluginInfo() { /// return { /// MLIR_PLUGIN_API_VERSION, "MyPlugin", "v0.1", []() { ... } /// }; /// } /// ``` extern "C" ::mlir::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK mlirGetPassPluginInfo(); #endif /* MLIR_TOOLS_PLUGINS_PASSPLUGIN_H */