/// assignable and destroyable state, but otherwise invalid.
void wipe() {
DomTreeNodes.clear();
- IDoms.clear();
RootNode = nullptr;
}
mutable bool DFSInfoValid = false;
mutable unsigned int SlowQueries = 0;
- DenseMap<NodeT *, NodeT *> IDoms;
-
void reset() {
DomTreeNodes.clear();
- IDoms.clear();
this->Roots.clear();
RootNode = nullptr;
DFSInfoValid = false;
DomTreeNodes(std::move(Arg.DomTreeNodes)),
RootNode(std::move(Arg.RootNode)),
DFSInfoValid(std::move(Arg.DFSInfoValid)),
- SlowQueries(std::move(Arg.SlowQueries)),
- IDoms(std::move(Arg.IDoms)) {
+ SlowQueries(std::move(Arg.SlowQueries)) {
Arg.wipe();
}
RootNode = std::move(RHS.RootNode);
DFSInfoValid = std::move(RHS.DFSInfoValid);
SlowQueries = std::move(RHS.SlowQueries);
- IDoms = std::move(RHS.IDoms);
RHS.wipe();
return *this;
}
unsigned Parent = 0;
unsigned Semi = 0;
NodePtr Label = nullptr;
+ NodePtr IDom = nullptr;
};
std::vector<NodePtr> NumToNode;
DenseMap<NodePtr, InfoRec> NodeToInfo;
+
+ NodeT *getIDom(NodeT *BB) const {
+ auto InfoIt = NodeToInfo.find(BB);
+ if (InfoIt == NodeToInfo.end()) return nullptr;
+
+ return InfoIt->second.IDom;
+ }
};
template <class GraphT>
friend void Calculate(DominatorTreeBaseByGraphTraits<GraphTraits<N>> &DT,
FuncT &F);
- DomTreeNodeBase<NodeT> *getNodeForBlock(NodeT *BB) {
+ DomTreeNodeBase<NodeT> *getNodeForBlock(NodeT *BB,
+ const SemiNCAInfo& SNCAInfo) {
if (DomTreeNodeBase<NodeT> *Node = getNode(BB))
return Node;
// Haven't calculated this node yet? Get or calculate the node for the
// immediate dominator.
- NodeT *IDom = getIDom(BB);
+ NodeT *IDom = SNCAInfo.getIDom(BB);
assert(IDom || DomTreeNodes[nullptr]);
- DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom);
+ DomTreeNodeBase<NodeT> *IDomNode = getNodeForBlock(IDom, SNCAInfo);
// Add a new tree node for this NodeT, and link it as a child of
// IDomNode
llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
}
- NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); }
-
void addRoot(NodeT *BB) { this->Roots.push_back(BB); }
public:
// Initialize IDoms to spanning tree parents.
for (unsigned i = 1; i <= N; ++i) {
const NodePtr V = SNCA.NumToNode[i];
- DT.IDoms[V] = SNCA.NumToNode[SNCA.NodeToInfo[V].Parent];
+ auto &VInfo = SNCA.NodeToInfo[V];
+ VInfo.IDom = SNCA.NumToNode[VInfo.Parent];
}
// Step #2: Calculate the semidominators of all vertices.
// path compression in Eval.
for (unsigned i = 2; i <= N; ++i) {
const NodePtr W = SNCA.NumToNode[i];
- const auto &WInfo = SNCA.NodeToInfo[W];
+ auto &WInfo = SNCA.NodeToInfo[W];
const unsigned SDomNum = SNCA.NodeToInfo[SNCA.NumToNode[WInfo.Semi]].DFSNum;
- NodePtr WIDomCandidate = DT.IDoms[W];
+ NodePtr WIDomCandidate = WInfo.IDom;
while (SNCA.NodeToInfo[WIDomCandidate].DFSNum > SDomNum)
- WIDomCandidate = DT.IDoms[WIDomCandidate];
+ WIDomCandidate = SNCA.NodeToInfo[WIDomCandidate].IDom;
- DT.IDoms[W] = WIDomCandidate;
+ WInfo.IDom = WIDomCandidate;
}
if (DT.Roots.empty()) return;
if (DT.DomTreeNodes[W])
continue; // Haven't calculated this node yet?
- NodePtr ImmDom = DT.getIDom(W);
+ NodePtr ImmDom = SNCA.getIDom(W);
assert(ImmDom || DT.DomTreeNodes[nullptr]);
// Get or calculate the node for the immediate dominator
- DomTreeNodeBase<NodeType> *IDomNode = DT.getNodeForBlock(ImmDom);
+ DomTreeNodeBase<NodeType> *IDomNode = DT.getNodeForBlock(ImmDom, SNCA);
// Add a new tree node for this BasicBlock, and link it as a child of
// IDomNode
llvm::make_unique<DomTreeNodeBase<NodeType>>(W, IDomNode));
}
- // Free temporary memory used to construct idom's
- DT.IDoms.clear();
-
DT.updateDFSNumbers();
}
}