aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/CodeGen/DAGISelHeader.h
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-11-05 04:14:16 +0000
committerDan Gohman <gohman@apple.com>2008-11-05 04:14:16 +0000
commit8be6bbe5bfd50945ac6c5542e0f54a0924a5db8d (patch)
treeabedd58cca5caf54d92b3093da2cc916ae679464 /include/llvm/CodeGen/DAGISelHeader.h
parentfa210d8dd1433d344d430ece5ef3efb629e992cd (diff)
downloadexternal_llvm-8be6bbe5bfd50945ac6c5542e0f54a0924a5db8d.zip
external_llvm-8be6bbe5bfd50945ac6c5542e0f54a0924a5db8d.tar.gz
external_llvm-8be6bbe5bfd50945ac6c5542e0f54a0924a5db8d.tar.bz2
Eliminate the ISel priority queue, which used the topological order for a
priority function. Instead, just iterate over the AllNodes list, which is already in topological order. This eliminates a fair amount of bookkeeping, and speeds up the isel phase by about 15% on many testcases. The impact on most targets is that AddToISelQueue calls can be simply removed. In the x86 target, there are two additional notable changes. The rule-bending AND+SHIFT optimization in MatchAddress that creates new pre-isel nodes during isel is now a little more verbose, but more robust. Instead of either creating an invalid DAG or creating an invalid topological sort, as it has historically done, it can now just insert the new nodes into the node list at a position where they will be consistent with the topological ordering. Also, the address-matching code has logic that checked to see if a node was "already selected". However, when a node is selected, it has all its uses taken away via ReplaceAllUsesWith or equivalent, so it won't recieve any further visits from MatchAddress. This code is now removed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CodeGen/DAGISelHeader.h')
-rw-r--r--include/llvm/CodeGen/DAGISelHeader.h145
1 files changed, 32 insertions, 113 deletions
diff --git a/include/llvm/CodeGen/DAGISelHeader.h b/include/llvm/CodeGen/DAGISelHeader.h
index ec72152..783c567 100644
--- a/include/llvm/CodeGen/DAGISelHeader.h
+++ b/include/llvm/CodeGen/DAGISelHeader.h
@@ -21,15 +21,10 @@
#ifndef LLVM_CODEGEN_DAGISEL_HEADER_H
#define LLVM_CODEGEN_DAGISEL_HEADER_H
-/// ISelQueue - Instruction selector priority queue sorted
-/// in the order of decreasing NodeId() values.
-std::vector<SDNode*> ISelQueue;
-
-/// Keep track of nodes which have already been added to queue.
-unsigned char *ISelQueued;
-
-/// Keep track of nodes which have already been selected.
-unsigned char *ISelSelected;
+/// ISelPosition - Node iterator marking the current position of
+/// instruction selection as it procedes through the topologically-sorted
+/// node list.
+SelectionDAG::allnodes_iterator ISelPosition;
/// IsChainCompatible - Returns true if Chain is Op or Chain does
/// not reach Op.
@@ -46,97 +41,38 @@ static bool IsChainCompatible(SDNode *Chain, SDNode *Op) {
return true;
}
-/// isel_sort - Sorting functions for the selection queue in the
-/// decreasing NodeId order.
-struct isel_sort : public std::binary_function<SDNode*, SDNode*, bool> {
- bool operator()(const SDNode* left, const SDNode* right) const {
- return left->getNodeId() < right->getNodeId();
- }
-};
-
-/// setQueued - marks the node with a given NodeId() as element of the
-/// instruction selection queue.
-inline void setQueued(int Id) {
- ISelQueued[Id / 8] |= 1 << (Id % 8);
-}
-
-/// isSelected - checks if the node with a given NodeId() is
-/// in the instruction selection queue already.
-inline bool isQueued(int Id) {
- return ISelQueued[Id / 8] & (1 << (Id % 8));
-}
-
-/// setSelected - marks the node with a given NodeId() as selected.
-inline void setSelected(int Id) {
- ISelSelected[Id / 8] |= 1 << (Id % 8);
-}
-
-/// isSelected - checks if the node with a given NodeId() is
-/// selected already.
-inline bool isSelected(int Id) {
- return ISelSelected[Id / 8] & (1 << (Id % 8));
-}
-
-/// AddToISelQueue - adds a node to the instruction
-/// selection queue.
-void AddToISelQueue(SDValue N) DISABLE_INLINE {
- int Id = N.getNode()->getNodeId();
- if (Id != -1 && !isQueued(Id)) {
- ISelQueue.push_back(N.getNode());
- std::push_heap(ISelQueue.begin(), ISelQueue.end(), isel_sort());
- setQueued(Id);
+/// ISelUpdater - helper class to handle updates of the
+/// instruciton selection graph.
+class VISIBILITY_HIDDEN ISelUpdater : public SelectionDAG::DAGUpdateListener {
+ SelectionDAG::allnodes_iterator &ISelPosition;
+ bool HadDelete; // Indicate if any deletions were done.
+public:
+ explicit ISelUpdater(SelectionDAG::allnodes_iterator &isp)
+ : ISelPosition(isp) {}
+
+ /// NodeDeleted - remove node from the selection queue.
+ virtual void NodeDeleted(SDNode *N, SDNode *E) {
+ if (ISelPosition == SelectionDAG::allnodes_iterator(N))
+ ++ISelPosition;
}
-}
-
-/// ISelQueueUpdater - helper class to handle updates of the
-/// instruciton selection queue.
-class VISIBILITY_HIDDEN ISelQueueUpdater :
- public SelectionDAG::DAGUpdateListener {
- std::vector<SDNode*> &ISelQueue;
- bool HadDelete; // Indicate if any deletions were done.
- public:
- explicit ISelQueueUpdater(std::vector<SDNode*> &isq)
- : ISelQueue(isq), HadDelete(false) {}
-
- bool hadDelete() const { return HadDelete; }
-
- /// NodeDeleted - remove node from the selection queue.
- virtual void NodeDeleted(SDNode *N, SDNode *E) {
- ISelQueue.erase(std::remove(ISelQueue.begin(), ISelQueue.end(), N),
- ISelQueue.end());
- HadDelete = true;
- }
-
- /// NodeUpdated - Ignore updates for now.
- virtual void NodeUpdated(SDNode *N) {}
- };
-
-/// UpdateQueue - update the instruction selction queue to maintain
-/// the decreasing NodeId() ordering property.
-inline void UpdateQueue(const ISelQueueUpdater &ISQU) {
- if (ISQU.hadDelete())
- std::make_heap(ISelQueue.begin(), ISelQueue.end(),isel_sort());
-}
+ /// NodeUpdated - Ignore updates for now.
+ virtual void NodeUpdated(SDNode *N) {}
+};
/// ReplaceUses - replace all uses of the old node F with the use
/// of the new node T.
void ReplaceUses(SDValue F, SDValue T) DISABLE_INLINE {
- ISelQueueUpdater ISQU(ISelQueue);
- CurDAG->ReplaceAllUsesOfValueWith(F, T, &ISQU);
- setSelected(F.getNode()->getNodeId());
- UpdateQueue(ISQU);
+ ISelUpdater ISU(ISelPosition);
+ CurDAG->ReplaceAllUsesOfValueWith(F, T, &ISU);
}
/// ReplaceUses - replace all uses of the old nodes F with the use
/// of the new nodes T.
void ReplaceUses(const SDValue *F, const SDValue *T,
unsigned Num) DISABLE_INLINE {
- ISelQueueUpdater ISQU(ISelQueue);
- CurDAG->ReplaceAllUsesOfValuesWith(F, T, Num, &ISQU);
- for (unsigned i = 0; i != Num; ++i)
- setSelected(F[i].getNode()->getNodeId());
- UpdateQueue(ISQU);
+ ISelUpdater ISU(ISelPosition);
+ CurDAG->ReplaceAllUsesOfValuesWith(F, T, Num, &ISU);
}
/// ReplaceUses - replace all uses of the old node F with the use
@@ -144,42 +80,30 @@ void ReplaceUses(const SDValue *F, const SDValue *T,
void ReplaceUses(SDNode *F, SDNode *T) DISABLE_INLINE {
unsigned FNumVals = F->getNumValues();
unsigned TNumVals = T->getNumValues();
- ISelQueueUpdater ISQU(ISelQueue);
+ ISelUpdater ISU(ISelPosition);
if (FNumVals != TNumVals) {
for (unsigned i = 0, e = std::min(FNumVals, TNumVals); i < e; ++i)
- CurDAG->ReplaceAllUsesOfValueWith(SDValue(F, i), SDValue(T, i), &ISQU);
+ CurDAG->ReplaceAllUsesOfValueWith(SDValue(F, i), SDValue(T, i), &ISU);
} else {
- CurDAG->ReplaceAllUsesWith(F, T, &ISQU);
+ CurDAG->ReplaceAllUsesWith(F, T, &ISU);
}
- setSelected(F->getNodeId());
- UpdateQueue(ISQU);
}
/// SelectRoot - Top level entry to DAG instruction selector.
/// Selects instructions starting at the root of the current DAG.
void SelectRoot(SelectionDAG &DAG) {
SelectRootInit();
- unsigned NumBytes = (DAGSize + 7) / 8;
- ISelQueued = new unsigned char[NumBytes];
- ISelSelected = new unsigned char[NumBytes];
- memset(ISelQueued, 0, NumBytes);
- memset(ISelSelected, 0, NumBytes);
// Create a dummy node (which is not added to allnodes), that adds
// a reference to the root node, preventing it from being deleted,
// and tracking any changes of the root.
HandleSDNode Dummy(CurDAG->getRoot());
- ISelQueue.push_back(CurDAG->getRoot().getNode());
+ ISelPosition = next(SelectionDAG::allnodes_iterator(CurDAG->getRoot().getNode()));
// Select pending nodes from the instruction selection queue
// until no more nodes are left for selection.
- while (!ISelQueue.empty()) {
- SDNode *Node = ISelQueue.front();
- std::pop_heap(ISelQueue.begin(), ISelQueue.end(), isel_sort());
- ISelQueue.pop_back();
- // Skip already selected nodes.
- if (isSelected(Node->getNodeId()))
- continue;
+ while (ISelPosition != CurDAG->allnodes_begin()) {
+ SDNode *Node = --ISelPosition;
#if 0
DAG.setSubgraphColor(Node, "red");
#endif
@@ -199,16 +123,11 @@ void SelectRoot(SelectionDAG &DAG) {
// If after the replacement this node is not used any more,
// remove this dead node.
if (Node->use_empty()) { // Don't delete EntryToken, etc.
- ISelQueueUpdater ISQU(ISelQueue);
- CurDAG->RemoveDeadNode(Node, &ISQU);
- UpdateQueue(ISQU);
+ ISelUpdater ISU(ISelPosition);
+ CurDAG->RemoveDeadNode(Node, &ISU);
}
}
- delete[] ISelQueued;
- ISelQueued = NULL;
- delete[] ISelSelected;
- ISelSelected = NULL;
CurDAG->setRoot(Dummy.getValue());
}