1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[ORC] Tidy up JITSymbolFlags to remove the need for some explicit static_casts.

Removes the implicit conversion to the underlying type for
JITSymbolFlags::FlagNames and replaces it with some bitwise and comparison
operators.

llvm-svn: 341282
This commit is contained in:
Lang Hames 2018-09-02 01:28:26 +00:00
parent 864546a86b
commit 2bc712fec3
5 changed files with 46 additions and 19 deletions

View File

@ -23,6 +23,7 @@
#include <set>
#include <string>
#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
@ -54,7 +55,8 @@ public:
Exported = 1U << 4,
Callable = 1U << 5,
Lazy = 1U << 6,
Materializing = 1U << 7
Materializing = 1U << 7,
LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue = */ Materializing)
};
static JITSymbolFlags stripTransientFlags(JITSymbolFlags Orig) {
@ -72,6 +74,26 @@ public:
JITSymbolFlags(FlagNames Flags, TargetFlagsType TargetFlags)
: Flags(Flags), TargetFlags(TargetFlags) {}
/// Implicitly convert to bool. Returs true if any flag is set.
explicit operator bool() const { return Flags != None || TargetFlags != 0; }
/// Compare for equality.
bool operator==(const JITSymbolFlags &RHS) const {
return Flags == RHS.Flags && TargetFlags == RHS.TargetFlags;
}
/// Bitwise AND-assignment for FlagNames.
JITSymbolFlags& operator&=(const FlagNames &RHS) {
Flags &= RHS;
return *this;
}
/// Bitwise OR-assignment for FlagNames.
JITSymbolFlags& operator|=(const FlagNames &RHS) {
Flags |= RHS;
return *this;
}
/// Return true if there was an error retrieving this symbol.
bool hasError() const {
return (Flags & HasError) == HasError;
@ -113,11 +135,8 @@ public:
/// Returns true if the given symbol is known to be callable.
bool isCallable() const { return (Flags & Callable) == Callable; }
/// Implicitly convert to the underlying flags type.
operator UnderlyingType&() { return Flags; }
/// Implicitly convert to the underlying flags type.
operator const UnderlyingType&() const { return Flags; }
/// 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; }
@ -135,10 +154,24 @@ public:
fromObjectSymbol(const object::SymbolRef &Symbol);
private:
UnderlyingType Flags = None;
FlagNames Flags = None;
TargetFlagsType TargetFlags = 0;
};
inline JITSymbolFlags operator&(const JITSymbolFlags &LHS,
const JITSymbolFlags::FlagNames &RHS) {
JITSymbolFlags Tmp = LHS;
Tmp &= RHS;
return Tmp;
}
inline JITSymbolFlags operator|(const JITSymbolFlags &LHS,
const JITSymbolFlags::FlagNames &RHS) {
JITSymbolFlags Tmp = LHS;
Tmp |= RHS;
return Tmp;
}
/// ARM-specific JIT symbol flags.
/// FIXME: This should be moved into a target-specific header.
class ARMJITSymbolFlags {

View File

@ -87,8 +87,7 @@ class SerializationTraits<ChannelT, JITSymbolFlags> {
public:
static Error serialize(ChannelT &C, const JITSymbolFlags &Flags) {
return serializeSeq(C, static_cast<JITSymbolFlags::UnderlyingType>(Flags),
Flags.getTargetFlags());
return serializeSeq(C, Flags.getRawFlagsValue(), Flags.getTargetFlags());
}
static Error deserialize(ChannelT &C, JITSymbolFlags &Flags) {

View File

@ -1158,8 +1158,7 @@ void JITDylib::emit(const SymbolFlagsMap &Emitted) {
assert(DependantJD.Symbols.count(DependantName) &&
"Dependant has no entry in the Symbols table");
auto &DependantSym = DependantJD.Symbols[DependantName];
DependantSym.setFlags(static_cast<JITSymbolFlags::FlagNames>(
DependantSym.getFlags() & ~JITSymbolFlags::Materializing));
DependantSym.setFlags(DependantSym.getFlags() & ~JITSymbolFlags::Materializing);
DependantJD.MaterializingInfos.erase(DependantMII);
}
}
@ -1177,8 +1176,7 @@ void JITDylib::emit(const SymbolFlagsMap &Emitted) {
assert(Symbols.count(Name) &&
"Symbol has no entry in the Symbols table");
auto &Sym = Symbols[Name];
Sym.setFlags(static_cast<JITSymbolFlags::FlagNames>(
Sym.getFlags() & ~JITSymbolFlags::Materializing));
Sym.setFlags(Sym.getFlags() & ~JITSymbolFlags::Materializing);
MaterializingInfos.erase(MII);
}
}

View File

@ -533,8 +533,7 @@ TEST_F(CoreAPIsStandardTest, AddAndMaterializeLazySymbol) {
TEST_F(CoreAPIsStandardTest, TestBasicWeakSymbolMaterialization) {
// Test that weak symbols are materialized correctly when we look them up.
BarSym.setFlags(static_cast<JITSymbolFlags::FlagNames>(BarSym.getFlags() |
JITSymbolFlags::Weak));
BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
bool BarMaterialized = false;
auto MU1 = llvm::make_unique<SimpleMaterializationUnit>(

View File

@ -19,8 +19,7 @@ class LegacyAPIsStandardTest : public CoreAPIsBasedStandardTest {};
namespace {
TEST_F(LegacyAPIsStandardTest, TestLambdaSymbolResolver) {
BarSym.setFlags(static_cast<JITSymbolFlags::FlagNames>(BarSym.getFlags() |
JITSymbolFlags::Weak));
BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
cantFail(JD.define(absoluteSymbols({{Foo, FooSym}, {Bar, BarSym}})));
@ -73,8 +72,7 @@ TEST_F(LegacyAPIsStandardTest, TestLambdaSymbolResolver) {
TEST_F(LegacyAPIsStandardTest, LegacyLookupHelpersFn) {
bool BarMaterialized = false;
BarSym.setFlags(static_cast<JITSymbolFlags::FlagNames>(BarSym.getFlags() |
JITSymbolFlags::Weak));
BarSym.setFlags(BarSym.getFlags() | JITSymbolFlags::Weak);
auto LegacyLookup = [&](const std::string &Name) -> JITSymbol {
if (Name == "foo")