[llvm] r344565 - [ORC] Switch to DenseMap/DenseSet for ORC symbol map/set types.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 15 15:27:03 PDT 2018
Author: lhames
Date: Mon Oct 15 15:27:02 2018
New Revision: 344565
URL: http://llvm.org/viewvc/llvm-project?rev=344565&view=rev
Log:
[ORC] Switch to DenseMap/DenseSet for ORC symbol map/set types.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
llvm/trunk/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h
llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h?rev=344565&r1=344564&r2=344565&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Core.h Mon Oct 15 15:27:02 2018
@@ -20,10 +20,7 @@
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
-#include <list>
-#include <map>
#include <memory>
-#include <set>
#include <vector>
#define DEBUG_TYPE "orc"
@@ -44,18 +41,18 @@ using VModuleKey = uint64_t;
/// A set of symbol names (represented by SymbolStringPtrs for
// efficiency).
-using SymbolNameSet = std::set<SymbolStringPtr>;
+using SymbolNameSet = DenseSet<SymbolStringPtr>;
/// A map from symbol names (as SymbolStringPtrs) to JITSymbols
/// (address/flags pairs).
-using SymbolMap = std::map<SymbolStringPtr, JITEvaluatedSymbol>;
+using SymbolMap = DenseMap<SymbolStringPtr, JITEvaluatedSymbol>;
/// A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
-using SymbolFlagsMap = std::map<SymbolStringPtr, JITSymbolFlags>;
+using SymbolFlagsMap = DenseMap<SymbolStringPtr, JITSymbolFlags>;
/// A base class for materialization failures that allows the failing
/// symbols to be obtained for logging.
-using SymbolDependenceMap = std::map<JITDylib *, SymbolNameSet>;
+using SymbolDependenceMap = DenseMap<JITDylib *, SymbolNameSet>;
/// A list of JITDylib pointers.
using JITDylibList = std::vector<JITDylib *>;
@@ -339,7 +336,7 @@ struct SymbolAliasMapEntry {
};
/// A map of Symbols to (Symbol, Flags) pairs.
-using SymbolAliasMap = std::map<SymbolStringPtr, SymbolAliasMapEntry>;
+using SymbolAliasMap = DenseMap<SymbolStringPtr, SymbolAliasMapEntry>;
/// A materialization unit for symbol aliases. Allows existing symbols to be
/// aliased with alternate flags.
@@ -489,7 +486,7 @@ public:
JITDylib &Parent, const SymbolNameSet &Names)>;
using AsynchronousSymbolQuerySet =
- std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
+ std::set<std::shared_ptr<AsynchronousSymbolQuery>>;
JITDylib(const JITDylib &) = delete;
JITDylib &operator=(const JITDylib &) = delete;
@@ -609,7 +606,7 @@ private:
};
using UnmaterializedInfosMap =
- std::map<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
+ DenseMap<SymbolStringPtr, std::shared_ptr<UnmaterializedInfo>>;
struct MaterializingInfo {
AsynchronousSymbolQueryList PendingQueries;
@@ -618,7 +615,7 @@ private:
bool IsEmitted = false;
};
- using MaterializingInfosMap = std::map<SymbolStringPtr, MaterializingInfo>;
+ using MaterializingInfosMap = DenseMap<SymbolStringPtr, MaterializingInfo>;
using LookupImplActionFlags = enum {
None = 0,
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h?rev=344565&r1=344564&r2=344565&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/SymbolStringPool.h Mon Oct 15 15:27:02 2018
@@ -14,6 +14,7 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H
#define LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include <atomic>
#include <mutex>
@@ -49,10 +50,13 @@ private:
/// Pointer to a pooled string representing a symbol name.
class SymbolStringPtr {
friend class SymbolStringPool;
+ friend struct DenseMapInfo<SymbolStringPtr>;
friend bool operator==(const SymbolStringPtr &LHS,
const SymbolStringPtr &RHS);
friend bool operator<(const SymbolStringPtr &LHS, const SymbolStringPtr &RHS);
+ static SymbolStringPool::PoolMapEntry Tombstone;
+
public:
SymbolStringPtr() = default;
SymbolStringPtr(const SymbolStringPtr &Other)
@@ -142,6 +146,29 @@ inline bool SymbolStringPool::empty() co
}
} // end namespace orc
+
+template <>
+struct DenseMapInfo<orc::SymbolStringPtr> {
+
+ static orc::SymbolStringPtr getEmptyKey() {
+ return orc::SymbolStringPtr();
+ }
+
+ static orc::SymbolStringPtr getTombstoneKey() {
+ return orc::SymbolStringPtr(&orc::SymbolStringPtr::Tombstone);
+ }
+
+ static unsigned getHashValue(orc::SymbolStringPtr V) {
+ uintptr_t IV = reinterpret_cast<uintptr_t>(V.S);
+ return unsigned(IV) ^ unsigned(IV >> 9);
+ }
+
+ static bool isEqual(const orc::SymbolStringPtr &LHS,
+ const orc::SymbolStringPtr &RHS) {
+ return LHS.S == RHS.S;
+ }
+};
+
} // end namespace llvm
#endif // LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H
Modified: llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp?rev=344565&r1=344564&r2=344565&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/Core.cpp Mon Oct 15 15:27:02 2018
@@ -134,6 +134,8 @@ struct PrintSymbolMapElemsMatchingCLOpts
namespace llvm {
namespace orc {
+ SymbolStringPool::PoolMapEntry SymbolStringPtr::Tombstone(0);
+
char FailedToMaterialize::ID = 0;
char SymbolsNotFound::ID = 0;
char SymbolsCouldNotBeRemoved::ID = 0;
@@ -575,20 +577,22 @@ void ReExportsMaterializationUnit::mater
SymbolNameSet QuerySymbols;
SymbolAliasMap QueryAliases;
- for (auto I = RequestedAliases.begin(), E = RequestedAliases.end();
- I != E;) {
- auto Tmp = I++;
-
+ // Collect as many aliases as we can without including a chain.
+ for (auto &KV : RequestedAliases) {
// Chain detected. Skip this symbol for this round.
- if (&SrcJD == &TgtJD && (QueryAliases.count(Tmp->second.Aliasee) ||
- RequestedAliases.count(Tmp->second.Aliasee)))
+ if (&SrcJD == &TgtJD && (QueryAliases.count(KV.second.Aliasee) ||
+ RequestedAliases.count(KV.second.Aliasee)))
continue;
- ResponsibilitySymbols.insert(Tmp->first);
- QuerySymbols.insert(Tmp->second.Aliasee);
- QueryAliases[Tmp->first] = std::move(Tmp->second);
- RequestedAliases.erase(Tmp);
+ ResponsibilitySymbols.insert(KV.first);
+ QuerySymbols.insert(KV.second.Aliasee);
+ QueryAliases[KV.first] = std::move(KV.second);
}
+
+ // Remove the aliases collected this round from the RequestedAliases map.
+ for (auto &KV : QueryAliases)
+ RequestedAliases.erase(KV.first);
+
assert(!QuerySymbols.empty() && "Alias cycle detected!");
auto QueryInfo = std::make_shared<OnResolveInfo>(
@@ -1172,10 +1176,9 @@ void JITDylib::lodgeQueryImpl(
std::shared_ptr<AsynchronousSymbolQuery> &Q, SymbolNameSet &Unresolved,
JITDylib *MatchNonExportedInJD, bool MatchNonExported,
std::vector<std::unique_ptr<MaterializationUnit>> &MUs) {
- for (auto I = Unresolved.begin(), E = Unresolved.end(); I != E;) {
- auto TmpI = I++;
- auto Name = *TmpI;
+ std::vector<SymbolStringPtr> ToRemove;
+ for (auto Name : Unresolved) {
// Search for the name in Symbols. Skip it if not found.
auto SymI = Symbols.find(Name);
if (SymI == Symbols.end())
@@ -1188,9 +1191,9 @@ void JITDylib::lodgeQueryImpl(
if (!MatchNonExported && MatchNonExportedInJD != this)
continue;
- // If we matched against Name in JD, remove it frome the Unresolved set and
- // add it to the added set.
- Unresolved.erase(TmpI);
+ // If we matched against Name in JD, mark it to be removed from the Unresolved
+ // set.
+ ToRemove.push_back(Name);
// If the symbol has an address then resolve it.
if (SymI->second.getAddress() != 0)
@@ -1235,6 +1238,10 @@ void JITDylib::lodgeQueryImpl(
MI.PendingQueries.push_back(Q);
Q->addQueryDependence(*this, Name);
}
+
+ // Remove any symbols that we found.
+ for (auto &Name : ToRemove)
+ Unresolved.erase(Name);
}
SymbolNameSet JITDylib::legacyLookup(std::shared_ptr<AsynchronousSymbolQuery> Q,
@@ -1294,19 +1301,17 @@ JITDylib::lookupImpl(std::shared_ptr<Asy
std::vector<std::unique_ptr<MaterializationUnit>> &MUs,
SymbolNameSet &Unresolved) {
LookupImplActionFlags ActionFlags = None;
+ std::vector<SymbolStringPtr> ToRemove;
- for (auto I = Unresolved.begin(), E = Unresolved.end(); I != E;) {
- auto TmpI = I++;
- auto Name = *TmpI;
+ for (auto Name : Unresolved) {
// Search for the name in Symbols. Skip it if not found.
auto SymI = Symbols.find(Name);
if (SymI == Symbols.end())
continue;
- // If we found Name, remove it frome the Unresolved set and add it
- // to the dependencies set.
- Unresolved.erase(TmpI);
+ // If we found Name, mark it to be removed from the Unresolved set.
+ ToRemove.push_back(Name);
// If the symbol has an address then resolve it.
if (SymI->second.getAddress() != 0) {
@@ -1357,6 +1362,10 @@ JITDylib::lookupImpl(std::shared_ptr<Asy
Q->addQueryDependence(*this, Name);
}
+ // Remove any marked symbols from the Unresolved set.
+ for (auto &Name : ToRemove)
+ Unresolved.erase(Name);
+
return ActionFlags;
}
Modified: llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp?rev=344565&r1=344564&r2=344565&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp Mon Oct 15 15:27:02 2018
@@ -167,13 +167,13 @@ int LocalCXXRuntimeOverridesBase::CXAAtE
Error LocalCXXRuntimeOverrides2::enable(JITDylib &JD,
MangleAndInterner &Mangle) {
- SymbolMap RuntimeInterposes(
- {{Mangle("__dso_handle"),
- JITEvaluatedSymbol(toTargetAddress(&DSOHandleOverride),
- JITSymbolFlags::Exported)},
- {Mangle("__cxa_atexit"),
- JITEvaluatedSymbol(toTargetAddress(&CXAAtExitOverride),
- JITSymbolFlags::Exported)}});
+ SymbolMap RuntimeInterposes;
+ RuntimeInterposes[Mangle("__dso_handle")] =
+ JITEvaluatedSymbol(toTargetAddress(&DSOHandleOverride),
+ JITSymbolFlags::Exported);
+ RuntimeInterposes[Mangle("__cxa_atexit")] =
+ JITEvaluatedSymbol(toTargetAddress(&CXAAtExitOverride),
+ JITSymbolFlags::Exported);
return JD.define(absoluteSymbols(std::move(RuntimeInterposes)));
}
More information about the llvm-commits
mailing list