llvm.org GIT mirror llvm / 8fb9cfe
[SelectionDAG] Force cycle detection in AssignTopologicalOrder before aborting DAG cycle detection is only enabled with ENABLE_EXPENSIVE_CHECKS. However we can run it just before we would crash in order to provide more informative diagnostics. Now in addition to the "Overran sorted position" message we also get the Node printed if a cycle was detected. Tested by building several configs: Debug+Assert, Debug+Assert+Check (this is ENABLE_EXPENSIVE_CHECKS), Release+Assert and Release. Also tried that the AssignTopologicalOrder assert produces the expected results. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209977 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 5 years ago
3 changed file(s) with 24 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
150150 };
151151
152152 class SelectionDAG;
153 void checkForCycles(const SelectionDAG *DAG);
153 void checkForCycles(const SelectionDAG *DAG, bool force = false);
154154
155155 /// SelectionDAG class - This is used to represent a portion of an LLVM function
156156 /// in a low-level Data Dependence DAG representation suitable for instruction
4848 template struct simplify_type;
4949 template struct ilist_traits;
5050
51 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr);
51 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
52 bool force = false);
5253
5354 /// SDVTList - This represents a list of ValueType's that has been intern'd by
5455 /// a SelectionDAG. Instances of this simple value class are returned by
60016001 SDNode *S = ++I;
60026002 dbgs() << "Overran sorted position:\n";
60036003 S->dumprFull(this); dbgs() << "\n";
6004 dbgs() << "Checking if this is due to cycles\n";
6005 checkForCycles(this, true);
60046006 #endif
60056007 llvm_unreachable(nullptr);
60066008 }
65866588 return true;
65876589 }
65886590
6589 #ifdef XDEBUG
6591 #ifndef NDEBUG
65906592 static void checkForCyclesHelper(const SDNode *N,
65916593 SmallPtrSet &Visited,
65926594 SmallPtrSet &Checked,
66136615 #endif
66146616
66156617 void llvm::checkForCycles(const llvm::SDNode *N,
6616 const llvm::SelectionDAG *DAG) {
6618 const llvm::SelectionDAG *DAG,
6619 bool force) {
6620 #ifndef NDEBUG
6621 bool check = force;
66176622 #ifdef XDEBUG
6618 assert(N && "Checking nonexistent SDNode");
6619 SmallPtrSet visited;
6620 SmallPtrSet checked;
6621 checkForCyclesHelper(N, visited, checked, DAG);
6622 #endif
6623 }
6624
6625 void llvm::checkForCycles(const llvm::SelectionDAG *DAG) {
6626 checkForCycles(DAG->getRoot().getNode(), DAG);
6627 }
6623 check = true;
6624 #endif // XDEBUG
6625 if (check) {
6626 assert(N && "Checking nonexistent SDNode");
6627 SmallPtrSet visited;
6628 SmallPtrSet checked;
6629 checkForCyclesHelper(N, visited, checked, DAG);
6630 }
6631 #endif // !NDEBUG
6632 }
6633
6634 void llvm::checkForCycles(const llvm::SelectionDAG *DAG, bool force) {
6635 checkForCycles(DAG->getRoot().getNode(), DAG, force);
6636 }