Skip to content

Commit

Permalink
Improve Dependency analysis when doing multi-node Instruction Selection
Browse files Browse the repository at this point in the history
Relanding after fixing NodeId Invariant.

Cleanup cycle/validity checks in ISel (IsLegalToFold,
HandleMergeInputChains) and X86 (isFusableLoadOpStore). Now do a full
search for cycles / dependencies pruning the search when topological
property of NodeId allows.

As part of this propogate the NodeId-based cutoffs to narrow
hasPreprocessorHelper searches.

Reviewers: craig.topper, bogner

Subscribers: llvm-commits, hiraditya

Differential Revision: https://reviews.llvm.org/D41293

llvm-svn: 327171
  • Loading branch information
niravhdave committed Mar 9, 2018
1 parent 071699b commit d668f69
Show file tree
Hide file tree
Showing 18 changed files with 594 additions and 996 deletions.
45 changes: 39 additions & 6 deletions llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Expand Up @@ -800,16 +800,44 @@ class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
/// searches to be performed in parallel, caching of results across
/// queries and incremental addition to Worklist. Stops early if N is
/// found but will resume. Remember to clear Visited and Worklists
/// if DAG changes.
/// if DAG changes. MaxSteps gives a maximum number of nodes to visit before
/// giving up. The TopologicalPrune flag signals that positive NodeIds are
/// topologically ordered (Operands have strictly smaller node id) and search
/// can be pruned leveraging this.
static bool hasPredecessorHelper(const SDNode *N,
SmallPtrSetImpl<const SDNode *> &Visited,
SmallVectorImpl<const SDNode *> &Worklist,
unsigned int MaxSteps = 0) {
unsigned int MaxSteps = 0,
bool TopologicalPrune = false) {
SmallVector<const SDNode *, 8> DeferredNodes;
if (Visited.count(N))
return true;

// Node Id's are assigned in three places: As a topological
// ordering (> 0), during legalization (results in values set to
// 0), new nodes (set to -1). If N has a topolgical id then we
// know that all nodes with ids smaller than it cannot be
// successors and we need not check them. Filter out all node
// that can't be matches. We add them to the worklist before exit
// in case of multiple calls. Note that during selection the topological id
// may be violated if a node's predecessor is selected before it. We mark
// this at selection negating the id of unselected successors and
// restricting topological pruning to positive ids.

int NId = N->getNodeId();
// If we Invalidated the Id, reconstruct original NId.
if (NId < -1)
NId = -(NId + 1);

bool Found = false;
while (!Worklist.empty()) {
const SDNode *M = Worklist.pop_back_val();
bool Found = false;
int MId = M->getNodeId();
if (TopologicalPrune && M->getOpcode() != ISD::TokenFactor && (NId > 0) &&
(MId > 0) && (MId < NId)) {
DeferredNodes.push_back(M);
continue;
}
for (const SDValue &OpV : M->op_values()) {
SDNode *Op = OpV.getNode();
if (Visited.insert(Op).second)
Expand All @@ -818,11 +846,16 @@ class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
Found = true;
}
if (Found)
return true;
break;
if (MaxSteps != 0 && Visited.size() >= MaxSteps)
return true;
break;
}
return false;
// Push deferred nodes back on worklist.
Worklist.append(DeferredNodes.begin(), DeferredNodes.end());
// If we bailed early, conservatively return found.
if (MaxSteps != 0 && Visited.size() >= MaxSteps)
return true;
return Found;
}

/// Return true if all the users of N are contained in Nodes.
Expand Down

0 comments on commit d668f69

Please sign in to comment.