mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-09 13:33:17 +00:00
make ComputeTopDownOrdering significantly faster and use less stack space
by making it non-recursive git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37629 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f50cd749e1
commit
e10e6f7a36
@ -302,24 +302,45 @@ SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag)
|
|||||||
"Too many value types for ValueTypeActions to hold!");
|
"Too many value types for ValueTypeActions to hold!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ComputeTopDownOrdering - Add the specified node to the Order list if it has
|
/// ComputeTopDownOrdering - Compute a top-down ordering of the dag, where Order
|
||||||
/// not been visited yet and if all of its operands have already been visited.
|
/// contains all of a nodes operands before it contains the node.
|
||||||
static void ComputeTopDownOrdering(SDNode *N, SmallVector<SDNode*, 64> &Order,
|
static void ComputeTopDownOrdering(SelectionDAG &DAG,
|
||||||
DenseMap<SDNode*, unsigned> &Visited) {
|
SmallVector<SDNode*, 64> &Order) {
|
||||||
if (++Visited[N] != N->getNumOperands())
|
|
||||||
return; // Haven't visited all operands yet
|
DenseMap<SDNode*, unsigned> Visited;
|
||||||
|
std::vector<SDNode*> Worklist;
|
||||||
|
Worklist.reserve(128);
|
||||||
|
|
||||||
Order.push_back(N);
|
// Compute ordering from all of the leaves in the graphs, those (like the
|
||||||
|
// entry node) that have no operands.
|
||||||
if (N->hasOneUse()) { // Tail recurse in common case.
|
for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
|
||||||
ComputeTopDownOrdering(*N->use_begin(), Order, Visited);
|
E = DAG.allnodes_end(); I != E; ++I) {
|
||||||
return;
|
if (I->getNumOperands() == 0) {
|
||||||
|
Visited[I] = 0 - 1U;
|
||||||
|
Worklist.push_back(I);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we have N in, add anything that uses it if all of their operands
|
while (!Worklist.empty()) {
|
||||||
// are now done.
|
SDNode *N = Worklist.back();
|
||||||
for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end(); UI != E;++UI)
|
Worklist.pop_back();
|
||||||
ComputeTopDownOrdering(*UI, Order, Visited);
|
|
||||||
|
if (++Visited[N] != N->getNumOperands())
|
||||||
|
continue; // Haven't visited all operands yet
|
||||||
|
|
||||||
|
Order.push_back(N);
|
||||||
|
|
||||||
|
// Now that we have N in, add anything that uses it if all of their operands
|
||||||
|
// are now done.
|
||||||
|
for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
|
||||||
|
UI != E; ++UI)
|
||||||
|
Worklist.push_back(*UI);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(Order.size() == Visited.size() &&
|
||||||
|
Order.size() ==
|
||||||
|
(unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) &&
|
||||||
|
"Error: DAG is cyclic!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -333,24 +354,8 @@ void SelectionDAGLegalize::LegalizeDAG() {
|
|||||||
// practice however, this causes us to run out of stack space on large basic
|
// practice however, this causes us to run out of stack space on large basic
|
||||||
// blocks. To avoid this problem, compute an ordering of the nodes where each
|
// blocks. To avoid this problem, compute an ordering of the nodes where each
|
||||||
// node is only legalized after all of its operands are legalized.
|
// node is only legalized after all of its operands are legalized.
|
||||||
DenseMap<SDNode*, unsigned> Visited;
|
|
||||||
SmallVector<SDNode*, 64> Order;
|
SmallVector<SDNode*, 64> Order;
|
||||||
|
ComputeTopDownOrdering(DAG, Order);
|
||||||
// Compute ordering from all of the leaves in the graphs, those (like the
|
|
||||||
// entry node) that have no operands.
|
|
||||||
for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
|
|
||||||
E = DAG.allnodes_end(); I != E; ++I) {
|
|
||||||
if (I->getNumOperands() == 0) {
|
|
||||||
Visited[I] = 0 - 1U;
|
|
||||||
ComputeTopDownOrdering(I, Order, Visited);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(Order.size() == Visited.size() &&
|
|
||||||
Order.size() ==
|
|
||||||
(unsigned)std::distance(DAG.allnodes_begin(), DAG.allnodes_end()) &&
|
|
||||||
"Error: DAG is cyclic!");
|
|
||||||
Visited.clear();
|
|
||||||
|
|
||||||
for (unsigned i = 0, e = Order.size(); i != e; ++i)
|
for (unsigned i = 0, e = Order.size(); i != e; ++i)
|
||||||
HandleOp(SDOperand(Order[i], 0));
|
HandleOp(SDOperand(Order[i], 0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user