-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ORC] Refactor executor symbol lookup to use ExecutorSymbolDef (NFC) (#…
…76989) This migrates the dylib manager lookup and related APIs to replace ExecutorAddress with ExecutorSymbolDef so that in the future we can model JITSymbolFlags for these symbols. The current change should be NFC as we are only setting the Exported symbol flag.
- Loading branch information
1 parent
a8cb4f7
commit 40b4ac2
Showing
17 changed files
with
300 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
//===--------- ExecutorSymbolDef.h - (Addr, Flags) pair ---------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Represents a defining location for a symbol in the executing program. | ||
// | ||
// This file was derived from | ||
// llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef ORC_RT_EXECUTOR_SYMBOL_DEF_H | ||
#define ORC_RT_EXECUTOR_SYMBOL_DEF_H | ||
|
||
#include "bitmask_enum.h" | ||
#include "executor_address.h" | ||
#include "simple_packed_serialization.h" | ||
|
||
namespace __orc_rt { | ||
|
||
/// Flags for symbols in the JIT. | ||
class JITSymbolFlags { | ||
public: | ||
using UnderlyingType = uint8_t; | ||
using TargetFlagsType = uint8_t; | ||
|
||
/// These values must be kept in sync with \c JITSymbolFlags in the JIT. | ||
enum FlagNames : UnderlyingType { | ||
None = 0, | ||
HasError = 1U << 0, | ||
Weak = 1U << 1, | ||
Common = 1U << 2, | ||
Absolute = 1U << 3, | ||
Exported = 1U << 4, | ||
Callable = 1U << 5, | ||
MaterializationSideEffectsOnly = 1U << 6, | ||
ORC_RT_MARK_AS_BITMASK_ENUM( // LargestValue = | ||
MaterializationSideEffectsOnly) | ||
}; | ||
|
||
/// Default-construct a JITSymbolFlags instance. | ||
JITSymbolFlags() = default; | ||
|
||
/// Construct a JITSymbolFlags instance from the given flags and target | ||
/// flags. | ||
JITSymbolFlags(FlagNames Flags, TargetFlagsType TargetFlags) | ||
: TargetFlags(TargetFlags), Flags(Flags) {} | ||
|
||
bool operator==(const JITSymbolFlags &RHS) const { | ||
return Flags == RHS.Flags && TargetFlags == RHS.TargetFlags; | ||
} | ||
|
||
/// Get the underlying flags value as an integer. | ||
UnderlyingType getRawFlagsValue() const { | ||
return static_cast<UnderlyingType>(Flags); | ||
} | ||
|
||
/// Return a reference to the target-specific flags. | ||
TargetFlagsType &getTargetFlags() { return TargetFlags; } | ||
|
||
/// Return a reference to the target-specific flags. | ||
const TargetFlagsType &getTargetFlags() const { return TargetFlags; } | ||
|
||
private: | ||
TargetFlagsType TargetFlags = 0; | ||
FlagNames Flags = None; | ||
}; | ||
|
||
/// Represents a defining location for a JIT symbol. | ||
class ExecutorSymbolDef { | ||
public: | ||
ExecutorSymbolDef() = default; | ||
ExecutorSymbolDef(ExecutorAddr Addr, JITSymbolFlags Flags) | ||
: Addr(Addr), Flags(Flags) {} | ||
|
||
const ExecutorAddr &getAddress() const { return Addr; } | ||
|
||
const JITSymbolFlags &getFlags() const { return Flags; } | ||
|
||
friend bool operator==(const ExecutorSymbolDef &LHS, | ||
const ExecutorSymbolDef &RHS) { | ||
return LHS.getAddress() == RHS.getAddress() && | ||
LHS.getFlags() == RHS.getFlags(); | ||
} | ||
|
||
private: | ||
ExecutorAddr Addr; | ||
JITSymbolFlags Flags; | ||
}; | ||
|
||
using SPSJITSymbolFlags = | ||
SPSTuple<JITSymbolFlags::UnderlyingType, JITSymbolFlags::TargetFlagsType>; | ||
|
||
/// SPS serializatior for JITSymbolFlags. | ||
template <> class SPSSerializationTraits<SPSJITSymbolFlags, JITSymbolFlags> { | ||
using FlagsArgList = SPSJITSymbolFlags::AsArgList; | ||
|
||
public: | ||
static size_t size(const JITSymbolFlags &F) { | ||
return FlagsArgList::size(F.getRawFlagsValue(), F.getTargetFlags()); | ||
} | ||
|
||
static bool serialize(SPSOutputBuffer &BOB, const JITSymbolFlags &F) { | ||
return FlagsArgList::serialize(BOB, F.getRawFlagsValue(), | ||
F.getTargetFlags()); | ||
} | ||
|
||
static bool deserialize(SPSInputBuffer &BIB, JITSymbolFlags &F) { | ||
JITSymbolFlags::UnderlyingType RawFlags; | ||
JITSymbolFlags::TargetFlagsType TargetFlags; | ||
if (!FlagsArgList::deserialize(BIB, RawFlags, TargetFlags)) | ||
return false; | ||
F = JITSymbolFlags{static_cast<JITSymbolFlags::FlagNames>(RawFlags), | ||
TargetFlags}; | ||
return true; | ||
} | ||
}; | ||
|
||
using SPSExecutorSymbolDef = SPSTuple<SPSExecutorAddr, SPSJITSymbolFlags>; | ||
|
||
/// SPS serializatior for ExecutorSymbolDef. | ||
template <> | ||
class SPSSerializationTraits<SPSExecutorSymbolDef, ExecutorSymbolDef> { | ||
using DefArgList = SPSExecutorSymbolDef::AsArgList; | ||
|
||
public: | ||
static size_t size(const ExecutorSymbolDef &ESD) { | ||
return DefArgList::size(ESD.getAddress(), ESD.getFlags()); | ||
} | ||
|
||
static bool serialize(SPSOutputBuffer &BOB, const ExecutorSymbolDef &ESD) { | ||
return DefArgList::serialize(BOB, ESD.getAddress(), ESD.getFlags()); | ||
} | ||
|
||
static bool deserialize(SPSInputBuffer &BIB, ExecutorSymbolDef &ESD) { | ||
ExecutorAddr Addr; | ||
JITSymbolFlags Flags; | ||
if (!DefArgList::deserialize(BIB, Addr, Flags)) | ||
return false; | ||
ESD = ExecutorSymbolDef{Addr, Flags}; | ||
return true; | ||
} | ||
}; | ||
|
||
} // End namespace __orc_rt | ||
|
||
#endif // ORC_RT_EXECUTOR_SYMBOL_DEF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
compiler-rt/lib/orc/tests/unit/executor_symbol_def_test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- executor_symbol_def_test.cpp --------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "executor_symbol_def.h" | ||
#include "simple_packed_serialization_utils.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace __orc_rt; | ||
|
||
TEST(ExecutorSymbolDefTest, Serialization) { | ||
blobSerializationRoundTrip<SPSExecutorSymbolDef>(ExecutorSymbolDef{}); | ||
blobSerializationRoundTrip<SPSExecutorSymbolDef>( | ||
ExecutorSymbolDef{ExecutorAddr{0x70}, {JITSymbolFlags::Callable, 9}}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
compiler-rt/lib/orc/tests/unit/simple_packed_serialization_utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===-- simple_packed_serialization_utils.h -------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef ORC_RT_TEST_SIMPLE_PACKED_SERIALIZATION_UTILS_H | ||
#define ORC_RT_TEST_SIMPLE_PACKED_SERIALIZATION_UTILS_H | ||
|
||
#include "simple_packed_serialization.h" | ||
#include "gtest/gtest.h" | ||
|
||
template <typename SPSTagT, typename T> | ||
static void blobSerializationRoundTrip(const T &Value) { | ||
using BST = __orc_rt::SPSSerializationTraits<SPSTagT, T>; | ||
|
||
size_t Size = BST::size(Value); | ||
auto Buffer = std::make_unique<char[]>(Size); | ||
__orc_rt::SPSOutputBuffer OB(Buffer.get(), Size); | ||
|
||
EXPECT_TRUE(BST::serialize(OB, Value)); | ||
|
||
__orc_rt::SPSInputBuffer IB(Buffer.get(), Size); | ||
|
||
T DSValue; | ||
EXPECT_TRUE(BST::deserialize(IB, DSValue)); | ||
|
||
EXPECT_EQ(Value, DSValue) | ||
<< "Incorrect value after serialization/deserialization round-trip"; | ||
} | ||
|
||
#endif // ORC_RT_TEST_SIMPLE_PACKED_SERIALIZATION_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.