Skip to content

[llvm] annotate interfaces in llvm/ExecutionEngine for DLL export #140809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "llvm/Object/Binary.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Target/TargetMachine.h"
Expand Down Expand Up @@ -88,15 +89,15 @@ class ExecutionEngineState {
/// Erase an entry from the mapping table.
///
/// \returns The address that \p ToUnmap was mapped to.
uint64_t RemoveMapping(StringRef Name);
LLVM_ABI uint64_t RemoveMapping(StringRef Name);
};

using FunctionCreator = std::function<void *(const std::string &)>;

/// Abstract interface for implementation execution of LLVM modules,
/// designed to support both interpreter and just-in-time (JIT) compiler
/// implementations.
class ExecutionEngine {
class LLVM_ABI ExecutionEngine {
/// The state object holding the global address mapping, which must be
/// accessed synchronously.
//
Expand Down Expand Up @@ -550,13 +551,13 @@ class EngineBuilder {

public:
/// Default constructor for EngineBuilder.
EngineBuilder();
LLVM_ABI EngineBuilder();

/// Constructor for EngineBuilder.
EngineBuilder(std::unique_ptr<Module> M);
LLVM_ABI EngineBuilder(std::unique_ptr<Module> M);

// Out-of-line since we don't have the def'n of RTDyldMemoryManager here.
~EngineBuilder();
LLVM_ABI ~EngineBuilder();

/// setEngineKind - Controls whether the user wants the interpreter, the JIT,
/// or whichever engine works. This option defaults to EngineKind::Either.
Expand All @@ -571,12 +572,14 @@ class EngineBuilder {
/// to create anything other than MCJIT will cause a runtime error. If create()
/// is called and is successful, the created engine takes ownership of the
/// memory manager. This option defaults to NULL.
EngineBuilder &setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);
LLVM_ABI EngineBuilder &
setMCJITMemoryManager(std::unique_ptr<RTDyldMemoryManager> mcjmm);

EngineBuilder&
LLVM_ABI EngineBuilder &
setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM);

EngineBuilder &setSymbolResolver(std::unique_ptr<LegacyJITSymbolResolver> SR);
LLVM_ABI EngineBuilder &
setSymbolResolver(std::unique_ptr<LegacyJITSymbolResolver> SR);

/// setErrorStr - Set the error string to write to on error. This option
/// defaults to NULL.
Expand Down Expand Up @@ -645,20 +648,19 @@ class EngineBuilder {
this->EmulatedTLS = EmulatedTLS;
}

TargetMachine *selectTarget();
LLVM_ABI TargetMachine *selectTarget();

/// selectTarget - Pick a target either via -march or by guessing the native
/// arch. Add any CPU features specified via -mcpu or -mattr.
TargetMachine *selectTarget(const Triple &TargetTriple,
StringRef MArch,
StringRef MCPU,
const SmallVectorImpl<std::string>& MAttrs);
LLVM_ABI TargetMachine *
selectTarget(const Triple &TargetTriple, StringRef MArch, StringRef MCPU,
const SmallVectorImpl<std::string> &MAttrs);

ExecutionEngine *create() {
return create(selectTarget());
}

ExecutionEngine *create(TargetMachine *TM);
LLVM_ABI ExecutionEngine *create(TargetMachine *TM);
};

// Create wrappers for C Binding types (see CBindingWrapping.h).
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/ExecutionEngine/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#define LLVM_EXECUTIONENGINE_INTERPRETER_H

#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/Support/Compiler.h"

extern "C" void LLVMLinkInInterpreter();
extern "C" LLVM_ABI void LLVMLinkInInterpreter();

namespace {
struct ForceInterpreterLinking {
Expand Down
3 changes: 2 additions & 1 deletion llvm/include/llvm/ExecutionEngine/JITEventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/Compiler.h"
#include <cstdint>

namespace llvm {
Expand All @@ -37,7 +38,7 @@ class ObjectFile;
/// profilers and debuggers that need to know where functions have been emitted.
///
/// The default implementation of each method does nothing.
class JITEventListener {
class LLVM_ABI JITEventListener {
public:
using ObjectKey = uint64_t;

Expand Down
5 changes: 3 additions & 2 deletions llvm/include/llvm/ExecutionEngine/JITLink/EHFrameSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "llvm/ExecutionEngine/JITLink/JITLink.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/TargetParser/Triple.h"

Expand All @@ -36,7 +37,7 @@ class EHFrameCFIBlockInspector {
/// second to PC-begin, third (if present) to LSDA.
///
/// It is illegal to call this function on a block with four or more edges.
static EHFrameCFIBlockInspector FromEdgeScan(Block &B);
LLVM_ABI static EHFrameCFIBlockInspector FromEdgeScan(Block &B);

/// Returns true if this frame is an FDE, false for a CIE.
bool isFDE() const { return CIEEdge != nullptr; }
Expand Down Expand Up @@ -85,7 +86,7 @@ class EHFrameCFIBlockInspector {

/// Returns a pointer to the DWARF eh-frame section if the graph contains a
/// non-empty one, otherwise returns null.
Section *getEHFrameSection(LinkGraph &G);
LLVM_ABI Section *getEHFrameSection(LinkGraph &G);

} // end namespace jitlink
} // end namespace llvm
Expand Down
56 changes: 29 additions & 27 deletions llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/Support/Allocator.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamWriter.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
Expand All @@ -49,7 +50,7 @@ class Section;

/// Base class for errors originating in JIT linker, e.g. missing relocation
/// support.
class JITLinkError : public ErrorInfo<JITLinkError> {
class LLVM_ABI JITLinkError : public ErrorInfo<JITLinkError> {
public:
static char ID;

Expand Down Expand Up @@ -105,7 +106,7 @@ class Edge {

/// Returns the string name of the given generic edge kind, or "unknown"
/// otherwise. Useful for debugging.
const char *getGenericEdgeKindName(Edge::Kind K);
LLVM_ABI const char *getGenericEdgeKindName(Edge::Kind K);

/// Base class for Addressable entities (externals, absolutes, blocks).
class Addressable {
Expand Down Expand Up @@ -389,7 +390,7 @@ inline orc::ExecutorAddr alignToBlock(orc::ExecutorAddr Addr, const Block &B) {
// Returns true if the given blocks contains exactly one valid c-string.
// Zero-fill blocks of size 1 count as valid empty strings. Content blocks
// must end with a zero, and contain no zeros before the end.
bool isCStringBlock(Block &B);
LLVM_ABI bool isCStringBlock(Block &B);

/// Describes symbol linkage. This can be used to resolve definition clashes.
enum class Linkage : uint8_t {
Expand All @@ -401,7 +402,7 @@ enum class Linkage : uint8_t {
using TargetFlagsType = uint8_t;

/// For errors and debugging output.
const char *getLinkageName(Linkage L);
LLVM_ABI const char *getLinkageName(Linkage L);

/// Defines the scope in which this symbol should be visible:
/// Default -- Visible in the public interface of the linkage unit.
Expand All @@ -412,9 +413,9 @@ const char *getLinkageName(Linkage L);
enum class Scope : uint8_t { Default, Hidden, SideEffectsOnly, Local };

/// For debugging output.
const char *getScopeName(Scope S);
LLVM_ABI const char *getScopeName(Scope S);

raw_ostream &operator<<(raw_ostream &OS, const Block &B);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const Block &B);

/// Symbol representation.
///
Expand Down Expand Up @@ -708,10 +709,10 @@ class Symbol {
size_t Size = 0;
};

raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);

void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
StringRef EdgeKindName);
LLVM_ABI void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
StringRef EdgeKindName);

/// Represents an object file section.
class Section {
Expand All @@ -731,7 +732,7 @@ class Section {
using block_iterator = BlockSet::iterator;
using const_block_iterator = BlockSet::const_iterator;

~Section();
LLVM_ABI ~Section();

// Sections are not movable or copyable.
Section(const Section &) = delete;
Expand Down Expand Up @@ -1039,7 +1040,7 @@ class LinkGraph {
LinkGraph &operator=(const LinkGraph &) = delete;
LinkGraph(LinkGraph &&) = delete;
LinkGraph &operator=(LinkGraph &&) = delete;
~LinkGraph();
LLVM_ABI ~LinkGraph();

/// Returns the name of this graph (usually the name of the original
/// underlying MemoryBuffer).
Expand Down Expand Up @@ -1658,11 +1659,11 @@ class LinkGraph {
orc::shared::AllocActions &allocActions() { return AAs; }

/// Dump the graph.
void dump(raw_ostream &OS);
LLVM_ABI void dump(raw_ostream &OS);

private:
std::vector<Block *> splitBlockImpl(std::vector<Block *> Blocks,
SplitBlockCache *Cache);
LLVM_ABI std::vector<Block *> splitBlockImpl(std::vector<Block *> Blocks,
SplitBlockCache *Cache);

// Put the BumpPtrAllocator first so that we don't free any of the underlying
// memory until the Symbol/Addressable destructors have been run.
Expand Down Expand Up @@ -1894,15 +1895,15 @@ struct PassConfiguration {
/// the two types once we have an OrcSupport library.
enum class SymbolLookupFlags { RequiredSymbol, WeaklyReferencedSymbol };

raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LF);
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const SymbolLookupFlags &LF);

/// A map of symbol names to resolved addresses.
using AsyncLookupResult =
DenseMap<orc::SymbolStringPtr, orc::ExecutorSymbolDef>;

/// A function object to call with a resolved symbol map (See AsyncLookupResult)
/// or an error if resolution failed.
class JITLinkAsyncLookupContinuation {
class LLVM_ABI JITLinkAsyncLookupContinuation {
public:
virtual ~JITLinkAsyncLookupContinuation() = default;
virtual void run(Expected<AsyncLookupResult> LR) = 0;
Expand All @@ -1929,7 +1930,7 @@ createLookupContinuation(Continuation Cont) {
}

/// Holds context for a single jitLink invocation.
class JITLinkContext {
class LLVM_ABI JITLinkContext {
public:
using LookupMap = DenseMap<orc::SymbolStringPtr, SymbolLookupFlags>;

Expand Down Expand Up @@ -1995,14 +1996,14 @@ class JITLinkContext {

/// Marks all symbols in a graph live. This can be used as a default,
/// conservative mark-live implementation.
Error markAllSymbolsLive(LinkGraph &G);
LLVM_ABI Error markAllSymbolsLive(LinkGraph &G);

/// Create an out of range error for the given edge in the given block.
Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
const Edge &E);
LLVM_ABI Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
const Edge &E);

Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value, int N,
const Edge &E);
LLVM_ABI Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value,
int N, const Edge &E);

/// Creates a new pointer block in the given section and returns an
/// Anonymous symbol pointing to it.
Expand All @@ -2016,7 +2017,7 @@ using AnonymousPointerCreator =
Symbol *InitialTarget, uint64_t InitialAddend)>;

/// Get target-specific AnonymousPointerCreator
AnonymousPointerCreator getAnonymousPointerCreator(const Triple &TT);
LLVM_ABI AnonymousPointerCreator getAnonymousPointerCreator(const Triple &TT);

/// Create a jump stub that jumps via the pointer at the given symbol and
/// an anonymous symbol pointing to it. Return the anonymous symbol.
Expand All @@ -2026,7 +2027,7 @@ using PointerJumpStubCreator = unique_function<Symbol &(
LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)>;

/// Get target-specific PointerJumpStubCreator
PointerJumpStubCreator getPointerJumpStubCreator(const Triple &TT);
LLVM_ABI PointerJumpStubCreator getPointerJumpStubCreator(const Triple &TT);

/// Base case for edge-visitors where the visitor-list is empty.
inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
Expand Down Expand Up @@ -2063,17 +2064,18 @@ void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs) {
/// Note: The graph does not take ownership of the underlying buffer, nor copy
/// its contents. The caller is responsible for ensuring that the object buffer
/// outlives the graph.
Expected<std::unique_ptr<LinkGraph>>
LLVM_ABI Expected<std::unique_ptr<LinkGraph>>
createLinkGraphFromObject(MemoryBufferRef ObjectBuffer,
std::shared_ptr<orc::SymbolStringPool> SSP);

/// Create a \c LinkGraph defining the given absolute symbols.
std::unique_ptr<LinkGraph>
LLVM_ABI std::unique_ptr<LinkGraph>
absoluteSymbolsLinkGraph(Triple TT, std::shared_ptr<orc::SymbolStringPool> SSP,
orc::SymbolMap Symbols);

/// Link the given graph.
void link(std::unique_ptr<LinkGraph> G, std::unique_ptr<JITLinkContext> Ctx);
LLVM_ABI void link(std::unique_ptr<LinkGraph> G,
std::unique_ptr<JITLinkContext> Ctx);

} // end namespace jitlink
} // end namespace llvm
Expand Down
Loading