LLVM  13.0.0git
PassPlugin.cpp
Go to the documentation of this file.
1 //===- lib/Passes/PassPluginLoader.cpp - Load Plugins for New PM Passes ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
11 
12 #include <cstdint>
13 
14 using namespace llvm;
15 
16 Expected<PassPlugin> PassPlugin::Load(const std::string &Filename) {
17  std::string Error;
18  auto Library =
20  if (!Library.isValid())
21  return make_error<StringError>(Twine("Could not load library '") +
22  Filename + "': " + Error,
24 
25  PassPlugin P{Filename, Library};
26  intptr_t getDetailsFn =
27  (intptr_t)Library.SearchForAddressOfSymbol("llvmGetPassPluginInfo");
28 
29  if (!getDetailsFn)
30  // If the symbol isn't found, this is probably a legacy plugin, which is an
31  // error
32  return make_error<StringError>(Twine("Plugin entry point not found in '") +
33  Filename + "'. Is this a legacy plugin?",
35 
36  P.Info = reinterpret_cast<decltype(llvmGetPassPluginInfo) *>(getDetailsFn)();
37 
38  if (P.Info.APIVersion != LLVM_PLUGIN_API_VERSION)
39  return make_error<StringError>(
40  Twine("Wrong API version on plugin '") + Filename + "'. Got version " +
41  Twine(P.Info.APIVersion) + ", supported version is " +
44 
45  if (!P.Info.RegisterPassBuilderCallbacks)
46  return make_error<StringError>(Twine("Empty entry callback in plugin '") +
47  Filename + "'.'",
49 
50  return P;
51 }
llvm
Definition: AllocatorList.h:23
intptr_t
LLVM_PLUGIN_API_VERSION
#define LLVM_PLUGIN_API_VERSION
\macro LLVM_PLUGIN_API_VERSION Identifies the API version understood by this plugin.
Definition: PassPlugin.h:33
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::PassPlugin
A loaded pass plugin.
Definition: PassPlugin.h:60
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::PassPlugin::Load
static Expected< PassPlugin > Load(const std::string &Filename)
Attempts to load a pass plugin from a given file.
Definition: PassPlugin.cpp:16
llvm::sys::DynamicLibrary::getPermanentLibrary
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path.
Definition: DynamicLibrary.cpp:146
llvm::sys::DynamicLibrary::SearchForAddressOfSymbol
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
Definition: DynamicLibrary.cpp:177
llvm::sys::DynamicLibrary::isValid
bool isValid() const
Returns true if the object refers to a valid library.
Definition: DynamicLibrary.h:49
llvmGetPassPluginInfo
::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK llvmGetPassPluginInfo()
The public entry point for a pass plugin.
PassPlugin.h
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
raw_ostream.h