[ARM] Put some of the TTI costmodel behind hasNeon calls.
[llvm-core.git] / lib / Passes / PassPlugin.cpp
blobceefa25a703b6e38d22d3b8c6d5586c1bbd990a4
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Passes/PassPlugin.h"
10 #include "llvm/Support/raw_ostream.h"
12 #include <cstdint>
14 using namespace llvm;
16 Expected<PassPlugin> PassPlugin::Load(const std::string &Filename) {
17 std::string Error;
18 auto Library =
19 sys::DynamicLibrary::getPermanentLibrary(Filename.c_str(), &Error);
20 if (!Library.isValid())
21 return make_error<StringError>(Twine("Could not load library '") +
22 Filename + "': " + Error,
23 inconvertibleErrorCode());
25 PassPlugin P{Filename, Library};
26 intptr_t getDetailsFn =
27 (intptr_t)Library.SearchForAddressOfSymbol("llvmGetPassPluginInfo");
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?",
34 inconvertibleErrorCode());
36 P.Info = reinterpret_cast<decltype(llvmGetPassPluginInfo) *>(getDetailsFn)();
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 " +
42 Twine(LLVM_PLUGIN_API_VERSION) + ".",
43 inconvertibleErrorCode());
45 if (!P.Info.RegisterPassBuilderCallbacks)
46 return make_error<StringError>(Twine("Empty entry callback in plugin '") +
47 Filename + "'.'",
48 inconvertibleErrorCode());
50 return P;