23 : TT(
std::move(TT)) {}
35 return make_error<StringError>(std::string(
"Unknown arch: ") + Arch,
46 Options, RM, CM, OptLevel,
true);
48 return make_error<StringError>(
"Could not allocate target machine",
51 return std::unique_ptr<TargetMachine>(
TM);
55 const std::vector<std::string> &FeatureVec) {
56 for (
const auto &
F : FeatureVec)
64 I((InitList && End) ? InitList->getNumOperands() : 0) {
68 assert(InitList == Other.InitList &&
"Incomparable iterators.");
73 return !(*
this == Other);
89 assert(CS &&
"Unrecognized type in llvm.global_ctors/llvm.global_dtors");
96 if (
Function *
F = dyn_cast_or_null<Function>(FuncC)) {
99 }
else if (
ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(FuncC)) {
101 FuncC = dyn_cast_or_null<ConstantExpr>(CE->getOperand(0));
112 if (Data && !isa<GlobalValue>(Data))
130 if (CtorDtors.
begin() == CtorDtors.
end())
134 V.getExecutionSession(),
135 (*CtorDtors.
begin()).Func->getParent()->getDataLayout());
137 for (
const auto &CtorDtor : CtorDtors) {
138 assert(CtorDtor.Func && CtorDtor.Func->hasName() &&
139 "Ctor/Dtor function must be named to be runnable under the JIT");
141 if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) {
142 dbgs() <<
" Skipping because why now?\n";
146 CtorDtorsByPriority[CtorDtor.Priority].push_back(
147 Mangle(CtorDtor.Func->getName()));
152 using CtorDtorTy = void (*)();
156 for (
auto &KV : CtorDtorsByPriority) {
157 for (
auto &
Name : KV.second) {
158 auto Added = Names.insert(
Name).second;
160 assert(Added &&
"Ctor/Dtor names clashed");
164 if (
auto CtorDtorMap =
lookup({&V}, std::move(Names))) {
165 for (
auto &KV : CtorDtorsByPriority) {
166 for (
auto &
Name : KV.second) {
167 assert(CtorDtorMap->count(
Name) &&
"No entry for Name");
168 auto CtorDtor =
reinterpret_cast<CtorDtorTy
>(
169 static_cast<uintptr_t
>((*CtorDtorMap)[
Name].getAddress()));
175 return CtorDtorMap.takeError();
177 CtorDtorsByPriority.clear();
183 auto& CXXDestructorDataPairs = DSOHandleOverride;
184 for (
auto &
P : CXXDestructorDataPairs)
186 CXXDestructorDataPairs.clear();
192 auto& CXXDestructorDataPairs =
194 CXXDestructorDataPairs.push_back(std::make_pair(Destructor, Arg));
200 {{Mangle(
"__dso_handle"),
203 {Mangle(
"__cxa_atexit"),
212 : Dylib(
std::move(Dylib)), Allow(
std::move(Allow)),
220 bool HasGlobalPrefix = (GlobalPrefix !=
'\0');
222 for (
auto &
Name : Names) {
223 if (!Allow(
Name) || (*Name).empty())
226 if (HasGlobalPrefix && (*Name).front() != GlobalPrefix)
229 std::string Tmp((*Name).data() + (HasGlobalPrefix ? 1 : 0), (*Name).size());
233 static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Addr)),
241 if (!NewSymbols.empty())
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
SymbolNameSet operator()(VSO &V, const SymbolNameSet &Names)
std::enable_if< std::is_convertible< typename std::decay< UniquePtrToMaterializationUnit >::type, std::unique_ptr< MaterializationUnit > >::value, Error >::type define(UniquePtrToMaterializationUnit &&MU)
Define all symbols provided by the materialization unit to be part of the given VSO.
A parsed version of the target data layout string in and methods for querying it. ...
Accessor for an element of the global_ctors/global_dtors array.
Compute iterated dominance frontiers using a linear time algorithm.
bool operator==(const CtorDtorIterator &Other) const
Test iterators for equality.
A Module instance is used to store all the information related to an LLVM module. ...
A symbol table that supports asynchoronous symbol queries.
std::string getString() const
Returns features as a string.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
std::map< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
std::vector< CXXDestructorDataPair > CXXDestructorDataPairList
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
void(*)(void *) DestructorPtr
CtorDtorIterator & operator++()
Pre-increment iterator.
Mangles symbol names then uniques them in the context of an ExecutionSession.
void * getAddressOfSymbol(const char *symbolName)
Searches through the library for the symbol symbolName.
Tagged union holding either a T or a Error.
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
A constant value that is initialized with an expression using other constant values.
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
CtorDtorIterator(const GlobalVariable *GV, bool End)
Construct an iterator instance.
Value * getOperand(unsigned i) const
static Expected< JITTargetMachineBuilder > detectHost()
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
The instances of the Type class are immutable: once they are created, they are never changed...
Error enable(VSO &V, MangleAndInterner &Mangler)
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
JITTargetMachineBuilder(Triple TT)
std::function< bool(SymbolStringPtr)> SymbolPredicate
JITTargetMachineBuilder & addFeatures(const std::vector< std::string > &FeatureVec)
std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast_or_null(const Y &Val)
Triple - Helper class for working with autoconf configuration names.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static ErrorSuccess success()
Create a success value.
unsigned getNumOperands() const
static int CXAAtExitOverride(DestructorPtr Destructor, void *Arg, void *DSOHandle)
This is the shared class of boolean and integer constants.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
This iterator provides a convenient way to iterate over the elements of an llvm.global_ctors/llvm.global_dtors instance.
Module.h This file contains the declarations for the Module class.
static ArchType getArchTypeForLLVMName(StringRef Str)
getArchTypeForLLVMName - The canonical type for the given LLVM architecture name (e.g., "x86").
Expected< SymbolMap > lookup(const VSOList &VSOs, SymbolNameSet Names)
Look up the given names in the given VSOs.
static Constant * getInitializer(Constant *C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
A range adaptor for a pair of iterators.
ConstantArray - Constant Array Declarations.
void add(iterator_range< CtorDtorIterator > CtorDtors)
const std::string & getTriple() const
Represents a symbol that has been evaluated to an address already.
void runDestructors()
Run any destructors recorded by the overriden __cxa_atexit function (CXAAtExitOverride).
amdgpu Simplify well known AMD library false Value Value * Arg
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Element operator*() const
Dereference iterator.
Lightweight error class with error context and mandatory checking.
DynamicLibraryFallbackGenerator(sys::DynamicLibrary Dylib, const DataLayout &DL, SymbolPredicate Allow)
bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
std::set< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
A utility class for building TargetMachines for JITs.