and remove the JITSymbolFlags header.
llvm-svn: 277766
#ifndef LLVM_EXECUTIONENGINE_JITSYMBOL_H
#define LLVM_EXECUTIONENGINE_JITSYMBOL_H
-#include "llvm/ExecutionEngine/JITSymbolFlags.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
#include <functional>
namespace llvm {
+class GlobalValue;
+
+namespace object {
+ class BasicSymbolRef;
+}
+
/// @brief Represents an address in the target process's address space.
typedef uint64_t JITTargetAddress;
+/// @brief Flags for symbols in the JIT.
+class JITSymbolFlags {
+public:
+
+ typedef uint8_t UnderlyingType;
+
+ enum FlagNames : UnderlyingType {
+ None = 0,
+ Weak = 1U << 0,
+ Common = 1U << 1,
+ Absolute = 1U << 2,
+ Exported = 1U << 3
+ };
+
+ /// @brief Default-construct a JITSymbolFlags instance.
+ JITSymbolFlags() : Flags(None) {}
+
+ /// @brief Construct a JITSymbolFlags instance from the given flags.
+ JITSymbolFlags(FlagNames Flags) : Flags(Flags) {}
+
+ /// @brief Returns true is the Weak flag is set.
+ bool isWeak() const {
+ return (Flags & Weak) == Weak;
+ }
+
+ /// @brief Returns true is the Weak flag is set.
+ bool isCommon() const {
+ return (Flags & Common) == Common;
+ }
+
+ /// @brief Returns true is the Weak flag is set.
+ bool isExported() const {
+ return (Flags & Exported) == Exported;
+ }
+
+ operator UnderlyingType&() { return Flags; }
+
+ /// Construct a JITSymbolFlags value based on the flags of the given global
+ /// value.
+ static JITSymbolFlags fromGlobalValue(const GlobalValue &GV);
+
+ /// Construct a JITSymbolFlags value based on the flags of the given libobject
+ /// symbol.
+ static JITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol);
+
+private:
+ UnderlyingType Flags;
+};
+
/// @brief Represents a symbol that has been evaluated to an address already.
-class JITEvaluatedSymbol : public JITSymbolBase {
+class JITEvaluatedSymbol {
public:
/// @brief Create a 'null' symbol.
JITEvaluatedSymbol(std::nullptr_t)
- : JITSymbolBase(JITSymbolFlags::None), Address(0) {}
+ : Address(0) {}
/// @brief Create a symbol for the given address and flags.
JITEvaluatedSymbol(JITTargetAddress Address, JITSymbolFlags Flags)
- : JITSymbolBase(Flags), Address(Address) {}
+ : Address(Address), Flags(Flags) {}
/// @brief An evaluated symbol converts to 'true' if its address is non-zero.
explicit operator bool() const { return Address != 0; }
/// @brief Return the address of this symbol.
JITTargetAddress getAddress() const { return Address; }
+ /// @brief Return the flags for this symbol.
+ JITSymbolFlags getFlags() const { return Flags; }
+
private:
JITTargetAddress Address;
+ JITSymbolFlags Flags;
};
/// @brief Represents a symbol in the JIT.
-class JITSymbol : public JITSymbolBase {
+class JITSymbol {
public:
typedef std::function<JITTargetAddress()> GetAddressFtor;
/// @brief Create a 'null' symbol that represents failure to find a symbol
/// definition.
JITSymbol(std::nullptr_t)
- : JITSymbolBase(JITSymbolFlags::None), CachedAddr(0) {}
+ : CachedAddr(0) {}
/// @brief Create a symbol for a definition with a known address.
JITSymbol(JITTargetAddress Addr, JITSymbolFlags Flags)
- : JITSymbolBase(Flags), CachedAddr(Addr) {}
+ : CachedAddr(Addr), Flags(Flags) {}
/// @brief Construct a JITSymbol from a JITEvaluatedSymbol.
JITSymbol(JITEvaluatedSymbol Sym)
- : JITSymbolBase(Sym.getFlags()), CachedAddr(Sym.getAddress()) {}
+ : CachedAddr(Sym.getAddress()), Flags(Sym.getFlags()) {}
/// @brief Create a symbol for a definition that doesn't have a known address
/// yet.
/// user can materialize the definition at any time by calling the getAddress
/// method.
JITSymbol(GetAddressFtor GetAddress, JITSymbolFlags Flags)
- : JITSymbolBase(Flags), GetAddress(std::move(GetAddress)), CachedAddr(0) {}
+ : GetAddress(std::move(GetAddress)), CachedAddr(0), Flags(Flags) {}
/// @brief Returns true if the symbol exists, false otherwise.
explicit operator bool() const { return CachedAddr || GetAddress; }
return CachedAddr;
}
+ JITSymbolFlags getFlags() const { return Flags; }
+
private:
GetAddressFtor GetAddress;
JITTargetAddress CachedAddr;
+ JITSymbolFlags Flags;
};
/// \brief Symbol resolution.
+++ /dev/null
-//===------ JITSymbolFlags.h - Flags for symbols in the JIT -----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Symbol flags for symbols in the JIT (e.g. weak, exported).
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
-#define LLVM_EXECUTIONENGINE_JITSYMBOLFLAGS_H
-
-#include "llvm/IR/GlobalValue.h"
-#include "llvm/Object/SymbolicFile.h"
-
-namespace llvm {
-
-/// @brief Flags for symbols in the JIT.
-enum class JITSymbolFlags : char {
- None = 0,
- Weak = 1U << 0,
- Common = 1U << 1,
- Exported = 1U << 2
-};
-
-inline JITSymbolFlags operator|(JITSymbolFlags LHS, JITSymbolFlags RHS) {
- typedef std::underlying_type<JITSymbolFlags>::type UT;
- return static_cast<JITSymbolFlags>(
- static_cast<UT>(LHS) | static_cast<UT>(RHS));
-}
-
-inline JITSymbolFlags& operator |=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
- LHS = LHS | RHS;
- return LHS;
-}
-
-inline JITSymbolFlags operator&(JITSymbolFlags LHS, JITSymbolFlags RHS) {
- typedef std::underlying_type<JITSymbolFlags>::type UT;
- return static_cast<JITSymbolFlags>(
- static_cast<UT>(LHS) & static_cast<UT>(RHS));
-}
-
-inline JITSymbolFlags& operator &=(JITSymbolFlags &LHS, JITSymbolFlags RHS) {
- LHS = LHS & RHS;
- return LHS;
-}
-
-/// @brief Base class for symbols in the JIT.
-class JITSymbolBase {
-public:
- JITSymbolBase(JITSymbolFlags Flags) : Flags(Flags) {}
-
- JITSymbolFlags getFlags() const { return Flags; }
-
- bool isWeak() const {
- return (Flags & JITSymbolFlags::Weak) == JITSymbolFlags::Weak;
- }
-
- bool isCommon() const {
- return (Flags & JITSymbolFlags::Common) == JITSymbolFlags::Common;
- }
-
- bool isExported() const {
- return (Flags & JITSymbolFlags::Exported) == JITSymbolFlags::Exported;
- }
-
- static JITSymbolFlags flagsFromGlobalValue(const GlobalValue &GV) {
- JITSymbolFlags Flags = JITSymbolFlags::None;
- if (GV.hasWeakLinkage())
- Flags |= JITSymbolFlags::Weak;
- if (GV.hasCommonLinkage())
- Flags |= JITSymbolFlags::Common;
- if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
- Flags |= JITSymbolFlags::Exported;
- return Flags;
- }
-
- static JITSymbolFlags
- flagsFromObjectSymbol(const object::BasicSymbolRef &Symbol) {
- JITSymbolFlags Flags = JITSymbolFlags::None;
- if (Symbol.getFlags() & object::BasicSymbolRef::SF_Weak)
- Flags |= JITSymbolFlags::Weak;
- if (Symbol.getFlags() & object::BasicSymbolRef::SF_Common)
- Flags |= JITSymbolFlags::Common;
- if (Symbol.getFlags() & object::BasicSymbolRef::SF_Exported)
- Flags |= JITSymbolFlags::Exported;
- return Flags;
- }
-
-private:
- JITSymbolFlags Flags;
-};
-
-} // end namespace llvm
-
-#endif
auto CCInfo = CompileCallbackMgr.getCompileCallback();
StubInits[mangle(F.getName(), DL)] =
std::make_pair(CCInfo.getAddress(),
- JITSymbolBase::flagsFromGlobalValue(F));
+ JITSymbolFlags::fromGlobalValue(F));
CCInfo.setCompileAction([this, &LD, LMH, &F]() {
return this->extractAndCompile(LD, LMH, F);
});
auto StubTargetAddr =
static_cast<JITTargetAddress>(reinterpret_cast<uintptr_t>(StubAddr));
auto StubSymbol = JITSymbol(StubTargetAddr, I->second.second);
- if (ExportedStubsOnly && !StubSymbol.isExported())
+ if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
return nullptr;
return StubSymbol;
}
// (a StringRef) may go away before the lambda is executed.
// FIXME: Use capture-init when we move to C++14.
std::string PName = Name;
- JITSymbolFlags Flags = JITSymbolBase::flagsFromGlobalValue(*GV);
+ JITSymbolFlags Flags = JITSymbolFlags::fromGlobalValue(*GV);
auto GetAddress =
[this, ExportedSymbolsOnly, PName, &B]() -> JITTargetAddress {
if (this->EmitState == Emitting)
auto SymEntry = SymbolTable.find(Name);
if (SymEntry == SymbolTable.end())
return nullptr;
- if (!SymEntry->second.isExported() && ExportedSymbolsOnly)
+ if (!SymEntry->second.getFlags().isExported() && ExportedSymbolsOnly)
return nullptr;
if (!Finalized)
return JITSymbol(getSymbolMaterializer(Name),
consumeError(SymbolName.takeError());
continue;
}
- auto Flags = JITSymbol::flagsFromObjectSymbol(Symbol);
+ auto Flags = JITSymbolFlags::fromObjectSymbol(Symbol);
SymbolTable.insert(
std::make_pair(*SymbolName, JITEvaluatedSymbol(0, Flags)));
}
auto Key = I->second.first;
auto Flags = I->second.second;
auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
- if (ExportedStubsOnly && !StubSymbol.isExported())
+ if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
return nullptr;
return StubSymbol;
}
ExecutionEngine.cpp
ExecutionEngineBindings.cpp
GDBRegistrationListener.cpp
+ JITSymbol.cpp
SectionMemoryManager.cpp
TargetSelect.cpp
--- /dev/null
+//===----------- JITSymbol.cpp - JITSymbol class implementation -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// JITSymbol class implementation plus helper functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/Object/SymbolicFile.h"
+
+using namespace llvm;
+
+JITSymbolFlags llvm::JITSymbolFlags::fromGlobalValue(const GlobalValue &GV) {
+ JITSymbolFlags Flags = JITSymbolFlags::None;
+ if (GV.hasWeakLinkage())
+ Flags |= JITSymbolFlags::Weak;
+ if (GV.hasCommonLinkage())
+ Flags |= JITSymbolFlags::Common;
+ if (!GV.hasLocalLinkage() && !GV.hasHiddenVisibility())
+ Flags |= JITSymbolFlags::Exported;
+ return Flags;
+}
+
+JITSymbolFlags
+llvm::JITSymbolFlags::fromObjectSymbol(const object::BasicSymbolRef &Symbol) {
+ JITSymbolFlags Flags = JITSymbolFlags::None;
+ if (Symbol.getFlags() & object::BasicSymbolRef::SF_Weak)
+ Flags |= JITSymbolFlags::Weak;
+ if (Symbol.getFlags() & object::BasicSymbolRef::SF_Common)
+ Flags |= JITSymbolFlags::Common;
+ if (Symbol.getFlags() & object::BasicSymbolRef::SF_Exported)
+ Flags |= JITSymbolFlags::Exported;
+ return Flags;
+}
}
if (auto Sym = Resolver.findSymbolInLogicalDylib(Name)) {
- if (!Sym.isCommon()) {
+ if (!Sym.getFlags().isCommon()) {
DEBUG(dbgs() << "\tSkipping common symbol '" << Name
<< "' in favor of stronger definition.\n");
continue;
};
/// @brief Symbol info for RuntimeDyld.
-class SymbolTableEntry : public JITSymbolBase {
+class SymbolTableEntry {
public:
SymbolTableEntry()
- : JITSymbolBase(JITSymbolFlags::None), Offset(0), SectionID(0) {}
+ : Offset(0), SectionID(0) {}
SymbolTableEntry(unsigned SectionID, uint64_t Offset, JITSymbolFlags Flags)
- : JITSymbolBase(Flags), Offset(Offset), SectionID(SectionID) {}
+ : Offset(Offset), SectionID(SectionID), Flags(Flags) {}
unsigned getSectionID() const { return SectionID; }
uint64_t getOffset() const { return Offset; }
+ JITSymbolFlags getFlags() const { return Flags; }
+
private:
uint64_t Offset;
unsigned SectionID;
+ JITSymbolFlags Flags;
};
typedef StringMap<SymbolTableEntry> RTDyldSymbolTable;