[SIL Utils] Move IndexTrieNode into its own header in Utils. NFC.

Move IndexTrieNode from DeadObjectElimination into its own header. I plan to
use this data structure when diagnosing static violations of exclusive access.
This commit is contained in:
Devin Coughlin
2017-06-14 21:23:14 -07:00
parent 63a9905f43
commit 2896d5b93f
2 changed files with 67 additions and 44 deletions

View File

@@ -36,6 +36,7 @@
#include "swift/SIL/DebugUtils.h"
#include "swift/SIL/InstructionUtils.h"
#include "swift/SILOptimizer/Analysis/ArraySemantic.h"
#include "swift/SILOptimizer/Utils/IndexTrie.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "swift/SILOptimizer/Utils/SILSSAUpdater.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"
@@ -277,50 +278,6 @@ hasUnremovableUsers(SILInstruction *AllocRef, UserList &Users) {
// NonTrivial DeadObject Elimination
//===----------------------------------------------------------------------===//
namespace {
// Trie node representing a sequence of unsigned integer indices.
class IndexTrieNode {
static const unsigned RootIdx = ~0U;
unsigned Index;
llvm::SmallVector<IndexTrieNode*, 8> Children;
public:
IndexTrieNode(): Index(RootIdx) {}
explicit IndexTrieNode(unsigned V): Index(V) {}
IndexTrieNode(IndexTrieNode &) =delete;
IndexTrieNode &operator=(const IndexTrieNode&) =delete;
~IndexTrieNode() {
for (auto *N : Children)
delete N;
}
bool isRoot() const { return Index == RootIdx; }
bool isLeaf() const { return Children.empty(); }
unsigned getIndex() const { return Index; }
IndexTrieNode *getChild(unsigned Idx) {
assert(Idx != RootIdx);
auto I = std::lower_bound(Children.begin(), Children.end(), Idx,
[](IndexTrieNode *a, unsigned i) {
return a->Index < i;
});
if (I != Children.end() && (*I)->Index == Idx)
return *I;
auto *N = new IndexTrieNode(Idx);
Children.insert(I, N);
return N;
}
ArrayRef<IndexTrieNode*> getChildren() const { return Children; }
};
} // end anonymous namespace
namespace {
/// Determine if an object is dead. Compute its original lifetime. Find the
/// lifetime endpoints reached by each store of a refcounted object into the