LLVM  16.0.0git
Classes | Public Types | Public Member Functions | List of all members
llvm::jitlink::LinkGraph Class Reference

#include "llvm/ExecutionEngine/JITLink/JITLink.h"

Classes

class  nested_collection_iterator
 

Public Types

using external_symbol_iterator = ExternalSymbolSet::iterator
 
using section_iterator = pointee_iterator< SectionList::iterator >
 
using const_section_iterator = pointee_iterator< SectionList::const_iterator >
 
using defined_symbol_iterator = nested_collection_iterator< const_section_iterator, Section::symbol_iterator, Symbol *, getSectionSymbols >
 
using const_defined_symbol_iterator = nested_collection_iterator< const_section_iterator, Section::const_symbol_iterator, const Symbol *, getSectionConstSymbols >
 
using block_iterator = nested_collection_iterator< const_section_iterator, Section::block_iterator, Block *, getSectionBlocks >
 
using const_block_iterator = nested_collection_iterator< const_section_iterator, Section::const_block_iterator, const Block *, getSectionConstBlocks >
 
using GetEdgeKindNameFunction = const char *(*)(Edge::Kind)
 
using SplitBlockCache = Optional< SmallVector< Symbol *, 8 > >
 Cache type for the splitBlock function. More...
 

Public Member Functions

 LinkGraph (std::string Name, const Triple &TT, unsigned PointerSize, support::endianness Endianness, GetEdgeKindNameFunction GetEdgeKindName)
 
 LinkGraph (const LinkGraph &)=delete
 
LinkGraphoperator= (const LinkGraph &)=delete
 
 LinkGraph (LinkGraph &&)=delete
 
LinkGraphoperator= (LinkGraph &&)=delete
 
const std::string & getName () const
 Returns the name of this graph (usually the name of the original underlying MemoryBuffer). More...
 
const TriplegetTargetTriple () const
 Returns the target triple for this Graph. More...
 
unsigned getPointerSize () const
 Returns the pointer size for use in this graph. More...
 
support::endianness getEndianness () const
 Returns the endianness of content in this graph. More...
 
const char * getEdgeKindName (Edge::Kind K) const
 
MutableArrayRef< char > allocateBuffer (size_t Size)
 Allocate a mutable buffer of the given size using the LinkGraph's allocator. More...
 
MutableArrayRef< char > allocateContent (ArrayRef< char > Source)
 Allocate a copy of the given string using the LinkGraph's allocator. More...
 
MutableArrayRef< char > allocateString (Twine Source)
 Allocate a copy of the given string using the LinkGraph's allocator. More...
 
SectioncreateSection (StringRef Name, orc::MemProt Prot)
 Create a section with the given name, protection flags, and alignment. More...
 
BlockcreateContentBlock (Section &Parent, ArrayRef< char > Content, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
 Create a content block. More...
 
BlockcreateMutableContentBlock (Section &Parent, MutableArrayRef< char > MutableContent, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
 Create a content block with initially mutable data. More...
 
BlockcreateZeroFillBlock (Section &Parent, orc::ExecutorAddrDiff Size, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
 Create a zero-fill block. More...
 
BlocksplitBlock (Block &B, size_t SplitIndex, SplitBlockCache *Cache=nullptr)
 Splits block B at the given index which must be greater than zero. More...
 
SymboladdExternalSymbol (StringRef Name, orc::ExecutorAddrDiff Size, bool IsWeaklyReferenced)
 Add an external symbol. More...
 
SymboladdAbsoluteSymbol (StringRef Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
 Add an absolute symbol. More...
 
SymboladdAnonymousSymbol (Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, bool IsCallable, bool IsLive)
 Add an anonymous symbol. More...
 
SymboladdDefinedSymbol (Block &Content, orc::ExecutorAddrDiff Offset, StringRef Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive)
 Add a named symbol. More...
 
iterator_range< section_iteratorsections ()
 
SectionList::size_type sections_size () const
 
SectionfindSectionByName (StringRef Name)
 Returns the section with the given name if it exists, otherwise returns null. More...
 
iterator_range< block_iteratorblocks ()
 
iterator_range< const_block_iteratorblocks () const
 
iterator_range< external_symbol_iteratorexternal_symbols ()
 
iterator_range< external_symbol_iteratorabsolute_symbols ()
 
iterator_range< defined_symbol_iteratordefined_symbols ()
 
iterator_range< const_defined_symbol_iteratordefined_symbols () const
 
void makeExternal (Symbol &Sym)
 Make the given symbol external (must not already be external). More...
 
void makeAbsolute (Symbol &Sym, orc::ExecutorAddr Address)
 Make the given symbol an absolute with the given address (must not already be absolute). More...
 
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. More...
 
void transferDefinedSymbol (Symbol &Sym, Block &DestBlock, orc::ExecutorAddrDiff NewOffset, Optional< orc::ExecutorAddrDiff > ExplicitNewSize)
 Transfer a defined symbol from one block to another. More...
 
void transferBlock (Block &B, Section &NewSection)
 Transfers the given Block and all Symbols pointing to it to the given Section. More...
 
void mergeSections (Section &DstSection, Section &SrcSection, bool PreserveSrcSection=false)
 Move all blocks and symbols from the source section to the destination section. More...
 
void removeExternalSymbol (Symbol &Sym)
 Removes an external symbol. Also removes the underlying Addressable. More...
 
void removeAbsoluteSymbol (Symbol &Sym)
 Remove an absolute symbol. Also removes the underlying Addressable. More...
 
void removeDefinedSymbol (Symbol &Sym)
 Removes defined symbols. Does not remove the underlying block. More...
 
void removeBlock (Block &B)
 Remove a block. More...
 
void removeSection (Section &Sec)
 Remove a section. More...
 
orc::shared::AllocActionsallocActions ()
 Accessor for the AllocActions object for this graph. More...
 
void dump (raw_ostream &OS)
 Dump the graph. More...
 

Detailed Description

Definition at line 820 of file JITLink.h.

Member Typedef Documentation

◆ block_iterator

Definition at line 940 of file JITLink.h.

◆ const_block_iterator

Definition at line 945 of file JITLink.h.

◆ const_defined_symbol_iterator

Definition at line 936 of file JITLink.h.

◆ const_section_iterator

Definition at line 879 of file JITLink.h.

◆ defined_symbol_iterator

Definition at line 931 of file JITLink.h.

◆ external_symbol_iterator

Definition at line 876 of file JITLink.h.

◆ GetEdgeKindNameFunction

Definition at line 947 of file JITLink.h.

◆ section_iterator

Definition at line 878 of file JITLink.h.

◆ SplitBlockCache

Cache type for the splitBlock function.

Definition at line 1042 of file JITLink.h.

Constructor & Destructor Documentation

◆ LinkGraph() [1/3]

llvm::jitlink::LinkGraph::LinkGraph ( std::string  Name,
const Triple TT,
unsigned  PointerSize,
support::endianness  Endianness,
GetEdgeKindNameFunction  GetEdgeKindName 
)
inline

Definition at line 949 of file JITLink.h.

◆ LinkGraph() [2/3]

llvm::jitlink::LinkGraph::LinkGraph ( const LinkGraph )
delete

◆ LinkGraph() [3/3]

llvm::jitlink::LinkGraph::LinkGraph ( LinkGraph &&  )
delete

Member Function Documentation

◆ absolute_symbols()

iterator_range<external_symbol_iterator> llvm::jitlink::LinkGraph::absolute_symbols ( )
inline

◆ addAbsoluteSymbol()

Symbol& llvm::jitlink::LinkGraph::addAbsoluteSymbol ( StringRef  Name,
orc::ExecutorAddr  Address,
orc::ExecutorAddrDiff  Size,
Linkage  L,
Scope  S,
bool  IsLive 
)
inline

◆ addAnonymousSymbol()

Symbol& llvm::jitlink::LinkGraph::addAnonymousSymbol ( Block Content,
orc::ExecutorAddrDiff  Offset,
orc::ExecutorAddrDiff  Size,
bool  IsCallable,
bool  IsLive 
)
inline

Add an anonymous symbol.

Definition at line 1118 of file JITLink.h.

References Allocator, and Content.

◆ addDefinedSymbol()

Symbol& llvm::jitlink::LinkGraph::addDefinedSymbol ( Block Content,
orc::ExecutorAddrDiff  Offset,
StringRef  Name,
orc::ExecutorAddrDiff  Size,
Linkage  L,
Scope  S,
bool  IsCallable,
bool  IsLive 
)
inline

Add a named symbol.

Definition at line 1128 of file JITLink.h.

References Allocator, assert(), Content, llvm::count_if(), defined_symbols(), llvm::jitlink::Symbol::getName(), llvm::jitlink::Local, and S.

◆ addExternalSymbol()

Symbol& llvm::jitlink::LinkGraph::addExternalSymbol ( StringRef  Name,
orc::ExecutorAddrDiff  Size,
bool  IsWeaklyReferenced 
)
inline

Add an external symbol.

Some formats (e.g. ELF) allow Symbols to have sizes. For Symbols whose size is not known, you should substitute '0'. The IsWeaklyReferenced argument determines whether the symbol must be present during lookup: Externals that are strongly referenced must be found or an error will be emitted. Externals that are weakly referenced are permitted to be undefined, in which case they are assigned an address of 0.

Definition at line 1088 of file JITLink.h.

References Allocator, assert(), llvm::count_if(), llvm::jitlink::Symbol::getName(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), and llvm::jitlink::Strong.

◆ allocActions()

orc::shared::AllocActions& llvm::jitlink::LinkGraph::allocActions ( )
inline

Accessor for the AllocActions object for this graph.

This can be used to register allocation action calls prior to finalization.

Accessing this object after finalization will result in undefined behavior.

Definition at line 1394 of file JITLink.h.

Referenced by llvm::jitlink::BasicLayout::graphAllocActions().

◆ allocateBuffer()

MutableArrayRef<char> llvm::jitlink::LinkGraph::allocateBuffer ( size_t  Size)
inline

Allocate a mutable buffer of the given size using the LinkGraph's allocator.

Definition at line 977 of file JITLink.h.

References Allocator.

◆ allocateContent()

MutableArrayRef<char> llvm::jitlink::LinkGraph::allocateContent ( ArrayRef< char >  Source)
inline

Allocate a copy of the given string using the LinkGraph's allocator.

This can be useful when renaming symbols or adding new content to the graph.

Definition at line 984 of file JITLink.h.

References Allocator, llvm::copy(), and llvm::Sched::Source.

◆ allocateString()

MutableArrayRef<char> llvm::jitlink::LinkGraph::allocateString ( Twine  Source)
inline

Allocate a copy of the given string using the LinkGraph's allocator.

This can be useful when renaming symbols or adding new content to the graph.

Note: This Twine-based overload requires an extra string copy and an extra heap allocation for large strings. The ArrayRef<char> overload should be preferred where possible.

Definition at line 997 of file JITLink.h.

References Allocator, llvm::copy(), and llvm::Sched::Source.

◆ blocks() [1/2]

iterator_range<block_iterator> llvm::jitlink::LinkGraph::blocks ( )
inline

◆ blocks() [2/2]

iterator_range<const_block_iterator> llvm::jitlink::LinkGraph::blocks ( ) const
inline

Definition at line 1163 of file JITLink.h.

References llvm::make_range().

◆ createContentBlock()

Block& llvm::jitlink::LinkGraph::createContentBlock ( Section Parent,
ArrayRef< char >  Content,
orc::ExecutorAddr  Address,
uint64_t  Alignment,
uint64_t  AlignmentOffset 
)
inline

Create a content block.

Definition at line 1018 of file JITLink.h.

References Content.

◆ createMutableContentBlock()

Block& llvm::jitlink::LinkGraph::createMutableContentBlock ( Section Parent,
MutableArrayRef< char >  MutableContent,
orc::ExecutorAddr  Address,
uint64_t  Alignment,
uint64_t  AlignmentOffset 
)
inline

Create a content block with initially mutable data.

Definition at line 1025 of file JITLink.h.

◆ createSection()

Section& llvm::jitlink::LinkGraph::createSection ( StringRef  Name,
orc::MemProt  Prot 
)
inline

Create a section with the given name, protection flags, and alignment.

Definition at line 1006 of file JITLink.h.

References assert(), move, and llvm::none_of().

◆ createZeroFillBlock()

Block& llvm::jitlink::LinkGraph::createZeroFillBlock ( Section Parent,
orc::ExecutorAddrDiff  Size,
orc::ExecutorAddr  Address,
uint64_t  Alignment,
uint64_t  AlignmentOffset 
)
inline

Create a zero-fill block.

Definition at line 1035 of file JITLink.h.

◆ defined_symbols() [1/2]

iterator_range<defined_symbol_iterator> llvm::jitlink::LinkGraph::defined_symbols ( )
inline

Definition at line 1176 of file JITLink.h.

References llvm::make_range().

Referenced by addDefinedSymbol().

◆ defined_symbols() [2/2]

iterator_range<const_defined_symbol_iterator> llvm::jitlink::LinkGraph::defined_symbols ( ) const
inline

Definition at line 1181 of file JITLink.h.

References llvm::make_range().

◆ dump()

void llvm::jitlink::LinkGraph::dump ( raw_ostream OS)

Dump the graph.

Definition at line 230 of file JITLink.cpp.

References LHS, RHS, and llvm::sort().

◆ external_symbols()

iterator_range<external_symbol_iterator> llvm::jitlink::LinkGraph::external_symbols ( )
inline

◆ findSectionByName()

Section* llvm::jitlink::LinkGraph::findSectionByName ( StringRef  Name)
inline

Returns the section with the given name if it exists, otherwise returns null.

Definition at line 1151 of file JITLink.h.

References S, and sections().

◆ getEdgeKindName()

const char* llvm::jitlink::LinkGraph::getEdgeKindName ( Edge::Kind  K) const
inline

◆ getEndianness()

support::endianness llvm::jitlink::LinkGraph::getEndianness ( ) const
inline

Returns the endianness of content in this graph.

Definition at line 971 of file JITLink.h.

◆ getName()

const std::string& llvm::jitlink::LinkGraph::getName ( ) const
inline

Returns the name of this graph (usually the name of the original underlying MemoryBuffer).

Definition at line 962 of file JITLink.h.

Referenced by llvm::orc::GDBJITDebugInfoRegistrationPlugin::modifyPassConfig().

◆ getPointerSize()

unsigned llvm::jitlink::LinkGraph::getPointerSize ( ) const
inline

Returns the pointer size for use in this graph.

Definition at line 968 of file JITLink.h.

◆ getTargetTriple()

const Triple& llvm::jitlink::LinkGraph::getTargetTriple ( ) const
inline

Returns the target triple for this Graph.

Definition at line 965 of file JITLink.h.

Referenced by llvm::orc::GDBJITDebugInfoRegistrationPlugin::modifyPassConfig().

◆ makeAbsolute()

void llvm::jitlink::LinkGraph::makeAbsolute ( Symbol Sym,
orc::ExecutorAddr  Address 
)
inline

Make the given symbol an absolute with the given address (must not already be absolute).

The symbol's size, linkage, and callability, and liveness will be left unchanged, and its offset will be reset to 0.

If the symbol was external then its scope will be set to local, otherwise it will be left unchanged.

Definition at line 1218 of file JITLink.h.

References assert(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::erase(), llvm::jitlink::Symbol::getAddressable(), llvm::jitlink::Symbol::getBlock(), llvm::jitlink::Symbol::getOffset(), llvm::jitlink::Block::getSection(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), llvm::jitlink::Symbol::isAbsolute(), llvm::jitlink::Symbol::isDefined(), llvm::jitlink::Symbol::isExternal(), llvm::jitlink::Local, and llvm::jitlink::Symbol::setScope().

◆ makeDefined()

void llvm::jitlink::LinkGraph::makeDefined ( Symbol Sym,
Block Content,
orc::ExecutorAddrDiff  Offset,
orc::ExecutorAddrDiff  Size,
Linkage  L,
Scope  S,
bool  IsLive 
)
inline

◆ makeExternal()

void llvm::jitlink::LinkGraph::makeExternal ( Symbol Sym)
inline

◆ mergeSections()

void llvm::jitlink::LinkGraph::mergeSections ( Section DstSection,
Section SrcSection,
bool  PreserveSrcSection = false 
)
inline

Move all blocks and symbols from the source section to the destination section.

If PreserveSrcSection is true (or SrcSection and DstSection are the same) then SrcSection is preserved, otherwise it is removed (the default).

Definition at line 1320 of file JITLink.h.

References B, llvm::jitlink::Section::blocks(), and removeSection().

◆ operator=() [1/2]

LinkGraph& llvm::jitlink::LinkGraph::operator= ( const LinkGraph )
delete

◆ operator=() [2/2]

LinkGraph& llvm::jitlink::LinkGraph::operator= ( LinkGraph &&  )
delete

◆ removeAbsoluteSymbol()

void llvm::jitlink::LinkGraph::removeAbsoluteSymbol ( Symbol Sym)
inline

◆ removeBlock()

void llvm::jitlink::LinkGraph::removeBlock ( Block B)
inline

Remove a block.

The block reference is defunct after calling this function and should no longer be used.

Definition at line 1369 of file JITLink.h.

References assert(), B, and llvm::none_of().

◆ removeDefinedSymbol()

void llvm::jitlink::LinkGraph::removeDefinedSymbol ( Symbol Sym)
inline

Removes defined symbols. Does not remove the underlying block.

Definition at line 1361 of file JITLink.h.

References assert(), llvm::jitlink::Symbol::getBlock(), llvm::jitlink::Block::getSection(), and llvm::jitlink::Symbol::isDefined().

◆ removeExternalSymbol()

void llvm::jitlink::LinkGraph::removeExternalSymbol ( Symbol Sym)
inline

◆ removeSection()

void llvm::jitlink::LinkGraph::removeSection ( Section Sec)
inline

Remove a section.

The section reference is defunct after calling this function and should no longer be used.

Definition at line 1381 of file JITLink.h.

References assert(), llvm::find_if(), I, and S.

Referenced by mergeSections().

◆ sections()

iterator_range<section_iterator> llvm::jitlink::LinkGraph::sections ( )
inline

◆ sections_size()

SectionList::size_type llvm::jitlink::LinkGraph::sections_size ( ) const
inline

Definition at line 1147 of file JITLink.h.

◆ splitBlock()

Block & llvm::jitlink::LinkGraph::splitBlock ( Block B,
size_t  SplitIndex,
SplitBlockCache Cache = nullptr 
)

Splits block B at the given index which must be greater than zero.

If SplitIndex == B.getSize() then this function is a no-op and returns B. If SplitIndex < B.getSize() then this function returns a new block covering the range [ 0, SplitIndex ), and B is modified to cover the range [ SplitIndex, B.size() ).

The optional Cache parameter can be used to speed up repeated calls to splitBlock for a single block. If the value is None the cache will be treated as uninitialized and splitBlock will populate it. Otherwise it is assumed to contain the list of Symbols pointing at B, sorted in descending order of offset.

Notes:

  1. splitBlock must be used with care. Splitting a block may cause incoming edges to become invalid if the edge target subexpression points outside the bounds of the newly split target block (E.g. an edge 'S + 10 : Pointer64' where S points to a newly split block whose size is less than 10). No attempt is made to detect invalidation of incoming edges, as in general this requires context that the LinkGraph does not have. Clients are responsible for ensuring that splitBlock is not used in a way that invalidates edges.
  2. The newly introduced block will have a new ordinal which will be higher than any other ordinals in the section. Clients are responsible for re-assigning block ordinals to restore a compatible order if needed.
  3. The cache is not automatically updated if new symbols are introduced between calls to splitBlock. Any newly introduced symbols may be added to the cache manually (descending offset order must be preserved), or the cache can be set to None and rebuilt by splitBlock on the next call.

Definition at line 150 of file JITLink.cpp.

References assert(), B, I, LHS, llvm::None, RHS, and llvm::sort().

◆ transferBlock()

void llvm::jitlink::LinkGraph::transferBlock ( Block B,
Section NewSection 
)
inline

Transfers the given Block and all Symbols pointing to it to the given Section.

No attempt is made to check compatibility of the source and destination sections. Blocks may be moved between sections with incompatible permissions (e.g. from data to text). The client is responsible for ensuring that this is safe.

Definition at line 1299 of file JITLink.h.

References B, and S.

◆ transferDefinedSymbol()

void llvm::jitlink::LinkGraph::transferDefinedSymbol ( Symbol Sym,
Block DestBlock,
orc::ExecutorAddrDiff  NewOffset,
Optional< orc::ExecutorAddrDiff ExplicitNewSize 
)
inline

Transfer a defined symbol from one block to another.

The symbol's offset within DestBlock is set to NewOffset.

If ExplicitNewSize is given as None then the size of the symbol will be checked and auto-truncated to at most the size of the remainder (from the given offset) of the size of the new block.

All other symbol attributes are unchanged.

Definition at line 1273 of file JITLink.h.

References llvm::jitlink::Symbol::getBlock(), llvm::jitlink::Block::getSection(), llvm::jitlink::Block::getSize(), llvm::jitlink::Symbol::getSize(), and llvm::jitlink::Symbol::setSize().


The documentation for this class was generated from the following files: