LLVM  8.0.1
PassPlugin.cpp
Go to the documentation of this file.
1 //===- lib/Passes/PassPluginLoader.cpp - Load Plugins for New PM Passes ---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/Passes/PassPlugin.h"
12 
13 #include <cstdint>
14 
15 using namespace llvm;
16 
17 Expected<PassPlugin> PassPlugin::Load(const std::string &Filename) {
18  std::string Error;
19  auto Library =
21  if (!Library.isValid())
22  return make_error<StringError>(Twine("Could not load library '") +
23  Filename + "': " + Error,
25 
26  PassPlugin P{Filename, Library};
27  intptr_t getDetailsFn =
28  (intptr_t)Library.SearchForAddressOfSymbol("llvmGetPassPluginInfo");
29 
30  if (!getDetailsFn)
31  // If the symbol isn't found, this is probably a legacy plugin, which is an
32  // error
33  return make_error<StringError>(Twine("Plugin entry point not found in '") +
34  Filename + "'. Is this a legacy plugin?",
36 
37  P.Info = reinterpret_cast<decltype(llvmGetPassPluginInfo) *>(getDetailsFn)();
38 
39  if (P.Info.APIVersion != LLVM_PLUGIN_API_VERSION)
40  return make_error<StringError>(
41  Twine("Wrong API version on plugin '") + Filename + "'. Got version " +
42  Twine(P.Info.APIVersion) + ", supported version is " +
45 
46  if (!P.Info.RegisterPassBuilderCallbacks)
47  return make_error<StringError>(Twine("Empty entry callback in plugin '") +
48  Filename + "'.'",
50 
51  return P;
52 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo()
The public entry point for a pass plugin.
#define P(N)
static Expected< PassPlugin > Load(const std::string &Filename)
Attempts to load a pass plugin from a given file.
Definition: PassPlugin.cpp:17
A loaded pass plugin.
Definition: PassPlugin.h:61
bool isValid() const
Returns true if the object refers to a valid library.
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path.
#define LLVM_PLUGIN_API_VERSION
LLVM_PLUGIN_API_VERSION Identifies the API version understood by this plugin.
Definition: PassPlugin.h:34
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:78