Go to the documentation of this file.
13 #ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
14 #define LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
33 #include <system_error>
74 :
Target(&
Target), Offset(Offset), Addend(Addend), K(K) {}
108 : Address(Address), IsDefined(IsDefined), IsAbsolute(
false) {}
111 : Address(Address), IsDefined(
false), IsAbsolute(
true) {
112 assert(!(IsDefined && IsAbsolute) &&
113 "Block cannot be both defined and absolute");
127 bool isDefined()
const {
return static_cast<bool>(IsDefined); }
128 bool isAbsolute()
const {
return static_cast<bool>(IsAbsolute); }
131 void setAbsolute(
bool IsAbsolute) {
132 assert(!IsDefined &&
"Cannot change the Absolute flag on a defined block");
133 this->IsAbsolute = IsAbsolute;
160 "Alignment offset cannot exceed alignment");
162 "Alignment offset exceeds maximum");
177 "Alignment offset cannot exceed alignment");
179 "Alignment offset exceeds maximum");
196 "Alignment offset cannot exceed alignment");
198 "Alignment offset exceeds maximum");
233 assert(
Data &&
"Block does not contain content");
260 assert(
Data &&
"Block does not contain content");
270 assert(MutableContent.
data() &&
"Setting null content");
299 "Alignment offset can't exceed alignment");
316 return make_range(Edges.begin(), Edges.end());
321 return make_range(Edges.begin(), Edges.end());
341 static constexpr
uint64_t MaxAlignmentOffset = (1ULL << 56) - 1;
343 void setSection(
Section &Parent) { this->Parent = &Parent; }
346 const char *
Data =
nullptr;
348 std::vector<Edge> Edges;
353 uint64_t Delta = (
B.getAlignmentOffset() -
Addr) %
B.getAlignment();
418 assert(SymStorage &&
"Storage cannot be null");
419 assert(!
Name.empty() &&
"Common symbol name cannot be empty");
421 "Cannot create common symbol from undefined block");
423 "Common symbol size should match underlying block size");
424 auto *Sym =
reinterpret_cast<Symbol *
>(SymStorage);
429 static Symbol &constructExternal(
void *SymStorage, Addressable &
Base,
432 assert(SymStorage &&
"Storage cannot be null");
434 "Cannot create external symbol from defined block");
435 assert(!
Name.empty() &&
"External symbol name cannot be empty");
436 auto *Sym =
reinterpret_cast<Symbol *
>(SymStorage);
441 static Symbol &constructAbsolute(
void *SymStorage, Addressable &
Base,
444 assert(SymStorage &&
"Storage cannot be null");
446 "Cannot create absolute symbol from a defined block");
447 auto *Sym =
reinterpret_cast<Symbol *
>(SymStorage);
452 static Symbol &constructAnonDef(
void *SymStorage, Block &
Base,
456 assert(SymStorage &&
"Storage cannot be null");
458 "Symbol extends past end of block");
459 auto *Sym =
reinterpret_cast<Symbol *
>(SymStorage);
465 static Symbol &constructNamedDef(
void *SymStorage, Block &
Base,
468 Scope S,
bool IsLive,
bool IsCallable) {
469 assert(SymStorage &&
"Storage cannot be null");
471 "Symbol extends past end of block");
472 assert(!
Name.empty() &&
"Name cannot be empty");
473 auto *Sym =
reinterpret_cast<Symbol *
>(SymStorage);
496 "Anonymous symbol has non-local scope");
507 assert(
Base &&
"Attempt to access null symbol");
508 return Base->isDefined();
514 assert(
Base &&
"Attempting to access null symbol");
519 void setLive(
bool IsLive) { this->IsLive = IsLive; }
525 void setCallable(
bool IsCallable) { this->IsCallable = IsCallable; }
529 assert(
Base &&
"Attempt to access null symbol");
530 return !
Base->isDefined() && !
Base->isAbsolute();
535 assert(
Base &&
"Attempt to access null symbol");
536 return Base->isAbsolute();
541 assert(
Base &&
"Cannot get underlying addressable for null symbol");
547 assert(
Base &&
"Cannot get underlying addressable for null symbol");
553 assert(
Base &&
"Cannot get block for null symbol");
554 assert(
Base->isDefined() &&
"Not a defined symbol");
555 return static_cast<Block &
>(*Base);
560 assert(
Base &&
"Cannot get block for null symbol");
561 assert(
Base->isDefined() &&
"Not a defined symbol");
562 return static_cast<const Block &
>(*Base);
576 assert(
Base &&
"Cannot set size for null Symbol");
578 "Non-zero size can only be set for defined symbols");
580 "Symbol size cannot extend past the end of its containing block");
605 "Linkage can only be applied to defined named symbols");
606 this->L =
static_cast<uint8_t
>(L);
615 "Can not set anonymous symbol to non-local scope");
617 "Invalid visibility for symbol type");
618 this->S =
static_cast<uint8_t
>(
S);
623 assert(!
A.isDefined() && !
A.isAbsolute() &&
624 "Attempting to make external with defined or absolute block");
633 assert(!
A.isDefined() &&
A.isAbsolute() &&
634 "Attempting to make absolute with defined or external block");
639 void setBlock(Block &
B) {
Base = &
B; }
642 assert(NewOffset <= MaxOffset &&
"Offset out of range");
646 static constexpr
uint64_t MaxOffset = (1ULL << 59) - 1;
650 Addressable *
Base =
nullptr;
661 void printEdge(raw_ostream &OS,
const Block &
B,
const Edge &
E,
662 StringRef EdgeKindName);
670 :
Name(
Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
736 assert(!Symbols.
count(&Sym) &&
"Symbol is already in this section");
740 void removeSymbol(
Symbol &Sym) {
741 assert(Symbols.
count(&Sym) &&
"symbol is not in this section");
745 void addBlock(Block &
B) {
746 assert(!Blocks.
count(&
B) &&
"Block is already in this section");
750 void removeBlock(Block &
B) {
751 assert(Blocks.
count(&
B) &&
"Block is not in this section");
755 void transferContentTo(
Section &DstSection) {
756 if (&DstSection ==
this)
758 for (
auto *
S : Symbols)
759 DstSection.addSymbol(*
S);
760 for (
auto *
B : Blocks)
761 DstSection.addBlock(*
B);
782 First = Last = *Sec.
blocks().begin();
791 assert((!Last || First) &&
"First can not be null if end is non-null");
795 assert((First || !Last) &&
"Last can not be null if start is non-null");
799 assert((First || !Last) &&
"Last can not be null if start is non-null");
815 Block *First =
nullptr;
816 Block *Last =
nullptr;
821 using SectionList = std::vector<std::unique_ptr<Section>>;
825 template <
typename... ArgTs>
838 template <
typename... ArgTs>
Block &createBlock(ArgTs &&...
Args) {
841 B->getSection().addBlock(*
B);
845 void destroyBlock(
Block &
B) {
850 void destroySymbol(
Symbol &
S) {
870 getSectionConstSymbols(
Section &
S) {
880 template <
typename OuterItrT,
typename InnerItrT,
typename T,
882 typename OuterItrT::reference)>
885 nested_collection_iterator<OuterItrT, InnerItrT, T, getInnerRange>,
886 std::forward_iterator_tag, T> {
891 : OuterI(OuterI), OuterE(OuterE),
892 InnerI(getInnerBegin(OuterI, OuterE)) {
893 moveToNonEmptyInnerOrEnd();
897 return (OuterI ==
RHS.OuterI) && (InnerI ==
RHS.InnerI);
901 assert(InnerI != getInnerRange(*OuterI).end() &&
"Dereferencing end?");
907 moveToNonEmptyInnerOrEnd();
912 static InnerItrT getInnerBegin(OuterItrT OuterI, OuterItrT OuterE) {
913 return OuterI != OuterE ? getInnerRange(*OuterI).begin() : InnerItrT();
916 void moveToNonEmptyInnerOrEnd() {
917 while (OuterI != OuterE && InnerI == getInnerRange(*OuterI).end()) {
919 InnerI = getInnerBegin(OuterI, OuterE);
923 OuterItrT OuterI, OuterE;
935 getSectionConstSymbols>;
944 getSectionConstBlocks>;
951 : Name(
std::
move(Name)), TT(TT), PointerSize(PointerSize),
952 Endianness(Endianness), GetEdgeKindName(
std::
move(GetEdgeKindName)) {}
961 const std::string &
getName()
const {
return Name; }
977 return {Allocator.
Allocate<
char>(Size), Size};
998 auto SourceStr =
Source.toStringRef(TmpBuffer);
999 auto *AllocatedBuffer = Allocator.
Allocate<
char>(SourceStr.size());
1007 [&](std::unique_ptr<Section> &Sec) {
1008 return Sec->getName() == Name;
1009 }) == Sections.end() &&
1010 "Duplicate section name");
1011 std::unique_ptr<Section> Sec(
new Section(Name, Prot, Sections.size()));
1013 return *Sections.back();
1020 return createBlock(Parent,
Content, Address, Alignment, AlignmentOffset);
1029 return createBlock(Parent, MutableContent, Address, Alignment,
1037 return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
1090 return Sym->
getName() == Name;
1092 "Duplicate external symbol");
1093 auto &Sym = Symbol::constructExternal(
1096 ExternalSymbols.
insert(&Sym);
1106 return Sym->
getName() == Name;
1108 "Duplicate absolute symbol");
1109 auto &Sym = Symbol::constructAbsolute(Allocator.
Allocate<
Symbol>(),
1110 createAddressable(Address), Name,
1111 Size, L,
S, IsLive);
1112 AbsoluteSymbols.
insert(&Sym);
1122 return Sym->
getName() == Name;
1124 "Duplicate defined symbol");
1125 auto &Sym = Symbol::constructCommon(
1127 createBlock(
Section, Size, Address, Alignment, 0), Name, Size,
S,
1138 Offset, Size, IsCallable, IsLive);
1139 Content.getSection().addSymbol(Sym);
1149 return Sym->
getName() == Name;
1151 "Duplicate defined symbol");
1154 Name, Size, L,
S, IsLive, IsCallable);
1155 Content.getSection().addSymbol(Sym);
1170 if (
S.getName() == Name)
1212 "Sym is not in the absolute symbols set");
1214 AbsoluteSymbols.
erase(&Sym);
1219 Sec.removeSymbol(Sym);
1222 ExternalSymbols.
insert(&Sym);
1237 "Sym is not in the absolute symbols set");
1239 ExternalSymbols.
erase(&Sym);
1245 Sec.removeSymbol(Sym);
1246 Sym.makeAbsolute(createAddressable(Address));
1248 AbsoluteSymbols.
insert(&Sym);
1259 "Symbol is not in the absolutes set");
1260 AbsoluteSymbols.
erase(&Sym);
1263 "Symbol is not in the externals set");
1264 ExternalSymbols.
erase(&Sym);
1268 Sym.setOffset(Offset);
1273 Content.getSection().addSymbol(Sym);
1274 destroyAddressable(OldBase);
1290 Sym.setBlock(DestBlock);
1291 Sym.setOffset(NewOffset);
1292 if (ExplicitNewSize)
1293 Sym.
setSize(*ExplicitNewSize);
1295 auto RemainingBlockSize = DestBlock.
getSize() - NewOffset;
1296 if (Sym.
getSize() > RemainingBlockSize)
1297 Sym.
setSize(RemainingBlockSize);
1299 if (&DestBlock.
getSection() != &OldSection) {
1300 OldSection.removeSymbol(Sym);
1313 auto &OldSection =
B.getSection();
1314 if (&OldSection == &NewSection)
1317 for (
auto *
S : OldSection.symbols())
1318 if (&
S->getBlock() == &
B)
1319 AttachedSymbols.push_back(
S);
1320 for (
auto *
S : AttachedSymbols) {
1321 OldSection.removeSymbol(*
S);
1322 NewSection.addSymbol(*
S);
1324 OldSection.removeBlock(
B);
1325 NewSection.addBlock(
B);
1334 bool PreserveSrcSection =
false) {
1335 if (&DstSection == &SrcSection)
1337 for (
auto *
B : SrcSection.
blocks())
1338 B->setSection(DstSection);
1339 SrcSection.transferContentTo(DstSection);
1340 if (!PreserveSrcSection)
1347 "Sym is not an external symbol");
1348 assert(ExternalSymbols.
count(&Sym) &&
"Symbol is not in the externals set");
1349 ExternalSymbols.
erase(&Sym);
1352 [&](
Symbol *AS) {
return AS->Base == &
Base; }) ==
1353 ExternalSymbols.
end() &&
1354 "Base addressable still in use");
1356 destroyAddressable(
Base);
1362 "Sym is not an absolute symbol");
1364 "Symbol is not in the absolute symbols set");
1365 AbsoluteSymbols.
erase(&Sym);
1368 [&](
Symbol *AS) {
return AS->Base == &
Base; }) ==
1369 ExternalSymbols.
end() &&
1370 "Base addressable still in use");
1372 destroyAddressable(
Base);
1387 return &Sym->getBlock() == &B;
1389 "Block still has symbols attached");
1390 B.getSection().removeBlock(
B);
1397 auto I =
llvm::find_if(Sections, [&Sec](
const std::unique_ptr<Section> &
S) {
1398 return S.get() == &Sec;
1400 assert(
I != Sections.end() &&
"Section does not appear in this graph");
1421 unsigned PointerSize;
1424 SectionList Sections;
1425 ExternalSymbolSet ExternalSymbols;
1426 ExternalSymbolSet AbsoluteSymbols;
1452 template <
typename PredFn = decltype(includeAllBlocks)>
1457 auto I = AddrToBlock.upper_bound(
B.getAddress());
1461 if (
I != AddrToBlock.end()) {
1462 if (
B.getAddress() +
B.getSize() >
I->second->getAddress())
1463 return overlapError(
B, *
I->second);
1468 if (
I != AddrToBlock.begin()) {
1469 auto &PrevBlock = *std::prev(
I)->second;
1470 if (PrevBlock.getAddress() + PrevBlock.getSize() >
B.getAddress())
1471 return overlapError(
B, PrevBlock);
1474 AddrToBlock.insert(
I, std::make_pair(
B.getAddress(), &
B));
1486 template <
typename BlockPtrRange,
1489 for (
auto *
B : Blocks)
1498 template <
typename BlockPtrRange>
1500 for (
auto *
B : Blocks)
1511 auto I = AddrToBlock.find(
Addr);
1512 if (
I == AddrToBlock.end())
1520 auto I = AddrToBlock.upper_bound(
Addr);
1521 if (
I == AddrToBlock.begin())
1523 auto *
B = std::prev(
I)->second;
1524 if (Addr < B->getAddress() +
B->getSize())
1532 auto ExistingBlockEnd =
1534 return make_error<JITLinkError>(
1537 NewBlockEnd.getValue()) +
1540 ExistingBlockEnd.getValue()));
1553 AddrToSymbols[Sym.
getAddress()].push_back(&Sym);
1557 template <
typename SymbolPtrCollection>
1559 for (
auto *Sym : Symbols)
1566 auto I = AddrToSymbols.find(
Addr);
1567 if (
I == AddrToSymbols.end())
1573 std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
1657 virtual void anchor();
1661 template <
typename Continuation>
1662 std::unique_ptr<JITLinkAsyncLookupContinuation>
1674 return std::make_unique<Impl>(
std::move(Cont));
1702 std::unique_ptr<JITLinkAsyncLookupContinuation> LC) = 0;
1759 template <
typename VisitorT,
typename... VisitorTs>
1761 VisitorTs &&...Vs) {
1762 if (!V.visitEdge(
G,
B,
E))
1772 template <
typename... VisitorTs>
1776 std::vector<Block *> Worklist(
G.blocks().begin(),
G.blocks().end());
1778 for (
auto *
B : Worklist)
1779 for (
auto &
E :
B->edges())
1792 void link(std::unique_ptr<LinkGraph>
G, std::unique_ptr<JITLinkContext> Ctx);
1797 #endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
size_t edges_size() const
Return the size of the edges list.
Represents an address in the executor process.
const_iterator begin() const
Iterates over (Address, Block*) pairs in ascending order of address.
StringRef getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
void link(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
Link the given graph.
pointee_iterator< SectionList::iterator > section_iterator
This is an optimization pass for GlobalISel generic memory operations.
@ Standard
Standard memory should be deallocated when the deallocate method is called for the finalized allocati...
SymbolLookupFlags
Flags for symbol lookup.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void setAlignmentOffset(uint64_t AlignmentOffset)
Set the alignment offset for this content.
void setCallable(bool IsCallable)
Set this symbol's callable bit.
void removeDefinedSymbol(Symbol &Sym)
Removes defined symbols. Does not remove the underlying block.
void transferBlock(Block &B, Section &NewSection)
Transfers the given Block and all Symbols pointing to it to the given Section.
A function object to call with a resolved symbol map (See AsyncLookupResult) or an error if resolutio...
iterator_range< external_symbol_iterator > absolute_symbols()
Target - Wrapper for Target specific information.
MutableArrayRef< char > getMutableContent(LinkGraph &G)
Get mutable content for this block.
bool isDefined() const
Returns true if this Symbol has content (potentially) defined within this object file (i....
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
bool isRelocation() const
EdgeVector::const_iterator const_edge_iterator
orc::ExecutorAddr getStart() const
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromObject(MemoryBufferRef ObjectBuffer)
Create a LinkGraph from the given object buffer.
static ErrorSuccess success()
Create a success value.
SymbolSet::const_iterator const_symbol_iterator
void addEdge(const Edge &E)
Add an edge by copying an existing one.
A map of addresses to Symbols.
iterator_range< const_edge_iterator > edges() const
Returns the list of edges attached to this content.
const Addressable & getAddressable() const
Return the addressable that thsi symbol points to.
LinkGraph & operator=(const LinkGraph &)=delete
Triple - Helper class for working with autoconf configuration names.
void mergeSections(Section &DstSection, Section &SrcSection, bool PreserveSrcSection=false)
Move all blocks and symbols from the source section to the destination section.
void removeAbsoluteSymbol(Symbol &Sym)
Remove an absolute symbol. Also removes the underlying Addressable.
SymbolSet::iterator symbol_iterator
uint64_t getValue() const
An Addressable with content and edges.
MemProt getMemProt() const
Returns the protection flags for this section.
const char * getEdgeKindName(Edge::Kind K) const
virtual bool shouldAddDefaultTargetPasses(const Triple &TT) const
Called by JITLink prior to linking to determine whether default passes for the target should be added...
const SymbolVector * getSymbolsAt(orc::ExecutorAddr Addr) const
Returns the list of symbols that start at the given address, or nullptr if no such symbols exist.
Section * findSectionByName(StringRef Name)
Returns the section with the given name if it exists, otherwise returns null.
const Block & getBlock() const
Return the Block for this Symbol (Symbol must be defined).
OutputIt copy(R &&Range, OutputIt Out)
orc::ExecutorAddrRange getRange() const
static void makeAbsolute(SmallVectorImpl< char > &Path)
Make Path absolute.
Manages allocations of JIT memory.
orc::ExecutorAddr getEnd() const
Tagged union holding either a T or a Error.
nested_collection_iterator(OuterItrT OuterI, OuterItrT OuterE)
Section & operator=(const Section &)=delete
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
std::pair< iterator, bool > insert(const ValueT &V)
void setLive(bool IsLive)
Set this symbol's live bit.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
void removeSection(Section &Sec)
Remove a section.
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
orc::ExecutorAddrRange getRange() const
Returns the address range of this defined addressable.
Symbol & addAnonymousSymbol(Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, bool IsCallable, bool IsLive)
Add an anonymous symbol.
Block * getBlockCovering(orc::ExecutorAddr Addr) const
Returns the block covering the given address, or nullptr if no such block exists.
Block & createContentBlock(Section &Parent, ArrayRef< char > Content, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a content block.
void removeBlock(Block &B)
Remove a block.
EdgeVector::iterator edge_iterator
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Error addBlocks(BlockPtrRange &&Blocks, PredFn Pred=includeAllBlocks)
Add a range of blocks to the map.
JITLinkError(Twine ErrMsg)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Block * getFirstBlock() const
bool isDefined() const
Returns true if this is a defined addressable, in which case you can downcast this to a Block.
iterator_range< const_block_iterator > blocks() const
raw_ostream & operator<<(raw_ostream &OS, const Block &B)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void transferDefinedSymbol(Symbol &Sym, Block &DestBlock, orc::ExecutorAddrDiff NewOffset, Optional< orc::ExecutorAddrDiff > ExplicitNewSize)
Transfer a defined symbol from one block to another.
void addSymbols(SymbolPtrCollection &&Symbols)
Add all symbols in a given range to the SymbolAddressMap.
Addressable(orc::ExecutorAddr Address, bool IsDefined)
Symbol()=default
Create a null Symbol.
(vector float) vec_cmpeq(*A, *B) C
support::endianness getEndianness() const
Returns the endianness of content in this graph.
uint64_t getAlignmentOffset() const
Get the alignment offset for this content.
bool isZeroFill() const
Returns true if this is a zero-fill block.
virtual ~JITLinkAsyncLookupContinuation()=default
orc::ExecutorAddrDiff getSize() const
Returns the size of this symbol.
bool isSymbolZeroFill() const
Returns true if this symbol is backed by a zero-fill block.
const char *(*)(Edge::Kind) GetEdgeKindNameFunction
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
BlockSet::iterator block_iterator
AddrToBlockMap::const_iterator const_iterator
uint64_t ExecutorAddrDiff
This class implements an extremely fast bulk output stream that can only output to a stream.
bool isCallable() const
Returns true is this symbol is callable.
MemProt
Describes Read/Write/Exec permissions for memory.
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
Represents an address range in the exceutor process.
void setSize(orc::ExecutorAddrDiff Size)
Set the size of this symbol.
bool isLive() const
Returns true if this symbol is live (i.e.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
const char * getScopeName(Scope S)
For debugging output.
virtual Error modifyPassConfig(LinkGraph &G, PassConfiguration &Config)
Called by JITLink to modify the pass pipeline prior to linking.
iterator_range< external_symbol_iterator > external_symbols()
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Symbol & operator=(const Symbol &)=delete
void addBlocksWithoutChecking(BlockPtrRange &&Blocks)
Add a range of blocks to the map without checking for overlap with existing blocks.
LinkGraphPassList PrePrunePasses
Pre-prune passes.
iterator_range< defined_symbol_iterator > defined_symbols()
void dump(raw_ostream &OS)
Dump the graph.
static bool includeNonNull(const Block &B)
A block predicate that always includes blocks with non-null addresses.
Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
pointee_iterator< SectionList::const_iterator > const_section_iterator
const std::string & getName() const
Returns the name of this graph (usually the name of the original underlying MemoryBuffer).
ConstIterator const_iterator
ExternalSymbolSet::iterator external_symbol_iterator
void setName(StringRef Name)
Rename this symbol.
Enables easy lookup of blocks by addresses.
Allocate memory in an ever growing pool, as if by bump-pointer.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
bool isExternal() const
Returns true if the underlying addressable is an unresolved external.
MutableArrayRef< char > allocateContent(ArrayRef< char > Source)
Allocate a copy of the given string using the LinkGraph's allocator.
orc::ExecutorAddr getAddress() const
Returns the address of this symbol.
uint64_t getAlignment() const
Get the alignment for this content.
std::map< orc::ExecutorAddr, Block * > AddrToBlockMap
nested_collection_iterator< const_section_iterator, Section::block_iterator, Block *, getSectionBlocks > block_iterator
nested_collection_iterator< const_section_iterator, Section::symbol_iterator, Symbol *, getSectionSymbols > defined_symbol_iterator
JITLinkContext(const JITLinkDylib *JD)
Create a JITLinkContext.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Symbol & addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size, Linkage L)
Add an external symbol.
iterator_range< const_defined_symbol_iterator > defined_symbols() const
unsigned getPointerSize() const
Returns the pointer size for use in this graph.
AddendT getAddend() const
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Addressable & getAddressable()
Return the addressable that this symbol points to.
ArrayRef< char > getContent() const
Get the content for this block. Block must not be a zero-fill block.
std::vector< LinkGraphPassFunction > LinkGraphPassList
A list of LinkGraph passes.
Addressable & operator=(const Addressable &)=default
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
MemDeallocPolicy getMemDeallocPolicy() const
Get the deallocation policy for this section.
bool hasName() const
Returns true if this symbol has a name.
void visitEdge(LinkGraph &G, Block *B, Edge &E)
Base case for edge-visitors where the visitor-list is empty.
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
LinkGraphPassList PreFixupPasses
Pre-fixup passes.
print Print MemDeps of function
orc::shared::AllocActions & allocActions()
Accessor for the AllocActions object for this graph.
void setMemProt(MemProt Prot)
Set the protection flags for this section.
void makeAbsolute(Symbol &Sym, orc::ExecutorAddr Address)
Make the given symbol an absolute with the given address (must not already be absolute).
iterator_range< symbol_iterator > symbols()
Returns an iterator over the symbols defined in this section.
Base class for user error types.
void setMutableContent(MutableArrayRef< char > MutableContent)
Set mutable content for this block.
void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs)
For each edge in the given graph, apply a list of visitors to the edge, stopping when the first visit...
edge_iterator removeEdge(edge_iterator I)
Remove the edge pointed to by the given iterator.
Block & splitBlock(Block &B, size_t SplitIndex, SplitBlockCache *Cache=nullptr)
Splits block B at the given index which must be greater than zero.
DenseMap< StringRef, SymbolLookupFlags > LookupMap
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
LinkGraphPassList PostFixupPasses
Post-fixup passes.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
Block * getLastBlock() const
void makeExternal(Symbol &Sym)
Make the given symbol external (must not already be external).
Symbol & addAbsoluteSymbol(StringRef Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Add an absolute symbol.
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1.
std::unique_ptr< JITLinkAsyncLookupContinuation > createLookupContinuation(Continuation Cont)
Create a lookup continuation from a function object.
StringRef - Represent a constant reference to a string, i.e.
void setAddress(orc::ExecutorAddr Address)
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
orc::ExecutorAddr getAddress() const
virtual Error notifyResolved(LinkGraph &G)=0
Called by JITLink once all defined symbols in the graph have been assigned their final memory locatio...
Represents fixups and constraints in the LinkGraph.
nested_collection_iterator()=default
void removeExternalSymbol(Symbol &Sym)
Removes an external symbol. Also removes the underlying Addressable.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B, const Edge &E)
Create an out of range error for the given edge in the given block.
virtual void lookup(const LookupMap &Symbols, std::unique_ptr< JITLinkAsyncLookupContinuation > LC)=0
Called by JITLink to resolve external symbols.
Holds context for a single jitLink invocation.
SectionOrdinal getOrdinal() const
Returns the ordinal for this section.
Linkage
Describes symbol linkage.
BlockSet::const_iterator const_block_iterator
void setLinkage(Linkage L)
Set the linkage for this Symbol.
nested_collection_iterator< const_section_iterator, Section::const_symbol_iterator, const Symbol *, getSectionConstSymbols > const_defined_symbol_iterator
BlockAddressMap()=default
iterator_range< block_iterator > blocks()
Returns an iterator over the blocks defined in this section.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
virtual JITLinkMemoryManager & getMemoryManager()=0
Return the MemoryManager to be used for this link.
Base class for errors originating in JIT linker, e.g.
const Triple & getTargetTriple() const
Returns the target triple for this Graph.
virtual LinkGraphPassFunction getMarkLivePass(const Triple &TT) const
Returns the mark-live pass to be used for this link.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool edges_empty() const
Returns true if the list of edges is empty.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
Represents an object file section.
void setOffset(OffsetT Offset)
Represents a finalized allocation.
MutableArrayRef< char > allocateBuffer(size_t Size)
Allocate a mutable buffer of the given size using the LinkGraph's allocator.
Lightweight error class with error context and mandatory checking.
StringRef getName() const
Returns the name of this section.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
void setContent(ArrayRef< char > Content)
Set the content for this block.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
iterator_range< edge_iterator > edges()
Return the list of edges attached to this content.
MemDeallocPolicy
Describes a memory deallocation policy for memory to be allocated by a JITLinkMemoryManager.
SectionList::size_type sections_size() const
size_t getSize() const
Returns the size of this defined addressable.
void setMemDeallocPolicy(MemDeallocPolicy MDP)
Set the deallocation policy for this section.
const std::string & getErrorMessage() const
void setTarget(Symbol &Target)
iterator_range< const_symbol_iterator > symbols() const
Returns an iterator over the symbols defined in this section.
virtual void notifyFailed(Error Err)=0
Notify this context that linking failed.
orc::ExecutorAddrDiff getOffset() const
Returns the offset for this symbol within the underlying addressable.
void addSymbol(Symbol &Sym)
Add a symbol to the SymbolAddressMap.
MutableArrayRef< char > getAlreadyMutableContent()
Get mutable content for this block.
BlockSet::size_type blocks_size() const
Returns the number of blocks in this section.
iterator_range< const_block_iterator > blocks() const
Returns an iterator over the blocks defined in this section.
const JITLinkDylib * getJITLinkDylib() const
Return the JITLinkDylib that this link is targeting, if any.
Section & createSection(StringRef Name, MemProt Prot)
Create a section with the given name, protection flags, and alignment.
virtual ~JITLinkContext()
Destroy a JITLinkContext.
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
orc::ExecutorAddrDiff getSize() const
std::vector< Edge > EdgeVector
orc::ExecutorAddr getFixupAddress(const Edge &E) const
Returns the address of the fixup for the given edge, which is equal to this block's address plus the ...
LinkGraphPassList PostAllocationPasses
Post-allocation passes.
size_t size() const
size - Get the array size.
Base class for Addressable entities (externals, absolutes, blocks).
Symbol & addCommonSymbol(StringRef Name, Scope S, Section &Section, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, uint64_t Alignment, bool IsLive)
Convenience method for adding a weak zero-fill symbol.
A range adaptor for a pair of iterators.
LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize, support::endianness Endianness, GetEdgeKindNameFunction GetEdgeKindName)
static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
OffsetT getOffset() const
void makeDefined(Symbol &Sym, Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Turn an absolute or external symbol into a defined one by attaching it to a block.
bool operator==(const nested_collection_iterator &RHS) const
bool erase(const ValueT &V)
iterator_range< block_iterator > blocks()
bool isAbsolute() const
Returns true if the underlying addressable is an absolute symbol.
const char * getLinkageName(Linkage L)
For errors and debugging output.
SymbolSet::size_type symbols_size() const
Return the number of symbols in this section.
iterator_range< section_iterator > sections()
LinkGraphPassList PostPrunePasses
Post-prune passes.
Symbol & addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, StringRef Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive)
Add a named symbol.
Addressable(orc::ExecutorAddr Address)
An iterator type that allows iterating over the pointees via some other iterator.
Symbol & getTarget() const
virtual void notifyFinalized(JITLinkMemoryManager::FinalizedAlloc Alloc)=0
Called by JITLink to notify the context that the object has been finalized (i.e.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
std::function< Error(LinkGraph &)> LinkGraphPassFunction
A function for mutating LinkGraphs.
Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value, int N, const Edge &E)
nested_collection_iterator operator++()
uint64_t alignToBlock(uint64_t Addr, Block &B)
virtual void run(Expected< AsyncLookupResult > LR)=0
Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend)
const_iterator end() const
SectionRange(const Section &Sec)
Scope getScope() const
Get the visibility for this Symbol.
ArrayRef< char > getSymbolContent() const
Returns the content in the underlying block covered by this symbol.
Block & createMutableContentBlock(Section &Parent, MutableArrayRef< char > MutableContent, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a content block with initially mutable data.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
void addBlockWithoutChecking(Block &B)
Add a block to the map without checking for overlap with existing blocks.
LLVM Value Representation.
void setAlignment(uint64_t Alignment)
Set the alignment for this content.
Kind getRelocation() const
MutableArrayRef< char > allocateString(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator.
Block * getBlockAt(orc::ExecutorAddr Addr) const
Returns the block starting at the given address, or nullptr if no such block exists.
orc::ExecutorAddrRange getRange() const
Returns the address range of this symbol.
static bool includeAllBlocks(const Block &B)
A block predicate that always adds all blocks.
void Deallocate(const void *Ptr, size_t Size, size_t)
Section & getSection() const
Return the parent section for this block.
Error addBlock(Block &B, PredFn Pred=includeAllBlocks)
Add a block to the map.
void setAddend(AddendT Addend)
Block & createZeroFillBlock(Section &Parent, orc::ExecutorAddrDiff Size, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a zero-fill block.
void setScope(Scope S)
Set the visibility for this Symbol.
nested_collection_iterator< const_section_iterator, Section::const_block_iterator, const Block *, getSectionConstBlocks > const_block_iterator
bool isContentMutable() const
Returns true if this block's content is mutable.
Block & operator=(const Block &)=delete
Linkage getLinkage() const
Get the linkage for this Symbol.