[llvm] r341282 - [ORC] Tidy up JITSymbolFlags to remove the need for some explicit static_casts.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 1 18:28:26 PDT 2018
Author: lhames
Date: Sat Sep 1 18:28:26 2018
New Revision: 341282
URL: http://llvm.org/viewvc/llvm-project?rev=341282&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h
llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
llvm/trunk/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h?rev=341282&r1=341281&r2=341282&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/JITSymbol.h Sat Sep 1 18:28:26 2018
@@ -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 {
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h?rev=341282&r1=341281&r2=341282&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h Sat Sep 1 18:28:26 2018
@@ -87,8 +87,7 @@ class SerializationTraits<ChannelT, JITS
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) {
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=341282&r1=341281&r2=341282&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Sat Sep 1 18:28:26 2018
@@ -1158,8 +1158,7 @@ void JITDylib::emit(const SymbolFlagsMap
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
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);
}
}
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp?rev=341282&r1=341281&r2=341282&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp Sat Sep 1 18:28:26 2018
@@ -533,8 +533,7 @@ TEST_F(CoreAPIsStandardTest, AddAndMater
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>(
Modified: llvm/trunk/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp?rev=341282&r1=341281&r2=341282&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/Orc/LegacyAPIInteropTest.cpp Sat Sep 1 18:28:26 2018
@@ -19,8 +19,7 @@ class LegacyAPIsStandardTest : public Co
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, TestLambd
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")
More information about the llvm-commits
mailing list