25 I((InitList && End) ? InitList->getNumOperands() : 0) {
29 assert(InitList == Other.InitList &&
"Incomparable iterators.");
34 return !(*
this == Other);
50 assert(CS &&
"Unrecognized type in llvm.global_ctors/llvm.global_dtors");
57 if (
Function *
F = dyn_cast_or_null<Function>(FuncC)) {
60 }
else if (
ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(FuncC)) {
62 FuncC = dyn_cast_or_null<ConstantExpr>(CE->getOperand(0));
73 if (Data && !isa<GlobalValue>(Data))
95 JD.getExecutionSession(),
96 (*CtorDtors.
begin()).Func->getParent()->getDataLayout());
98 for (
const auto &CtorDtor : CtorDtors) {
99 assert(CtorDtor.Func && CtorDtor.Func->hasName() &&
100 "Ctor/Dtor function must be named to be runnable under the JIT");
103 if (CtorDtor.Func->hasLocalLinkage()) {
108 if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) {
109 dbgs() <<
" Skipping because why now?\n";
113 CtorDtorsByPriority[CtorDtor.Priority].push_back(
114 Mangle(CtorDtor.Func->getName()));
119 using CtorDtorTy = void (*)();
123 for (
auto &KV : CtorDtorsByPriority) {
124 for (
auto &
Name : KV.second) {
127 assert(Added &&
"Ctor/Dtor names clashed");
131 auto &ES = JD.getExecutionSession();
132 if (
auto CtorDtorMap =
135 for (
auto &KV : CtorDtorsByPriority) {
136 for (
auto &
Name : KV.second) {
137 assert(CtorDtorMap->count(
Name) &&
"No entry for Name");
138 auto CtorDtor =
reinterpret_cast<CtorDtorTy
>(
139 static_cast<uintptr_t
>((*CtorDtorMap)[
Name].getAddress()));
145 return CtorDtorMap.takeError();
147 CtorDtorsByPriority.clear();
153 auto& CXXDestructorDataPairs = DSOHandleOverride;
154 for (
auto &
P : CXXDestructorDataPairs)
156 CXXDestructorDataPairs.clear();
162 auto& CXXDestructorDataPairs =
164 CXXDestructorDataPairs.push_back(std::make_pair(Destructor, Arg));
171 RuntimeInterposes[Mangle(
"__dso_handle")] =
174 RuntimeInterposes[Mangle(
"__cxa_atexit")] =
183 : Dylib(
std::move(Dylib)), Allow(
std::move(Allow)),
201 bool HasGlobalPrefix = (GlobalPrefix !=
'\0');
203 for (
auto &
Name : Names) {
207 if (Allow && !Allow(
Name))
210 if (HasGlobalPrefix && (*Name).front() != GlobalPrefix)
213 std::string Tmp((*Name).data() + (HasGlobalPrefix ? 1 : 0), (*Name).size());
217 static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(Addr)),
225 if (!NewSymbols.
empty())
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
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.
This class represents lattice values for constants.
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. ...
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
Externally visible function.
std::vector< CXXDestructorDataPair > CXXDestructorDataPairList
Error enable(JITDylib &JD, MangleAndInterner &Mangler)
void(*)(void *) DestructorPtr
CtorDtorIterator & operator++()
Pre-increment iterator.
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols, VModuleKey K=VModuleKey())
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
std::vector< std::pair< JITDylib *, bool > > JITDylibSearchList
A list of (JITDylib*, bool) pairs.
Error define(std::unique_ptr< MaterializationUnitType > &&MU)
Define all symbols provided by the materialization unit to be part of this JITDylib.
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 add(iterator_range< CtorDtorIterator > CtorDtors)
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.
std::function< bool(SymbolStringPtr)> SymbolPredicate
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< DynamicLibrarySearchGenerator > Load(const char *FileName, const DataLayout &DL, SymbolPredicate Allow=SymbolPredicate())
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(const ValueT &V)
SymbolNameSet operator()(JITDylib &JD, const SymbolNameSet &Names)
static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path.
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)
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
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.
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 Constant * getInitializer(Constant *C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
DynamicLibrarySearchGenerator(sys::DynamicLibrary Dylib, const DataLayout &DL, SymbolPredicate Allow=SymbolPredicate())
Create a DynamicLibrarySearchGenerator that searches for symbols in the given sys::DynamicLibrary.
A range adaptor for a pair of iterators.
ConstantArray - Constant Array Declarations.
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
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)
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Element operator*() const
Dereference iterator.
Lightweight error class with error context and mandatory checking.
bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
A symbol table that supports asynchoronous symbol queries.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...