Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceLoopAnalyzer.h - Loop Analysis ------------*- C++ -*-===// | 1 //===- subzero/src/IceLoopAnalyzer.h - Loop Analysis ------------*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 /// | 9 /// |
| 10 /// \file | 10 /// \file |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 public: | 28 public: |
| 29 explicit LoopAnalyzer(Cfg *Func); | 29 explicit LoopAnalyzer(Cfg *Func); |
| 30 | 30 |
| 31 /// Use Tarjan's strongly connected components algorithm to identify outermost | 31 /// Use Tarjan's strongly connected components algorithm to identify outermost |
| 32 /// to innermost loops. By deleting the head of the loop from the graph, inner | 32 /// to innermost loops. By deleting the head of the loop from the graph, inner |
| 33 /// loops can be found. This assumes that the head node is not shared between | 33 /// loops can be found. This assumes that the head node is not shared between |
| 34 /// loops but instead all paths to the head come from 'continue' constructs. | 34 /// loops but instead all paths to the head come from 'continue' constructs. |
| 35 /// | 35 /// |
| 36 /// This only computes the loop nest depth within the function and does not | 36 /// This only computes the loop nest depth within the function and does not |
| 37 /// take into account whether the function was called from within a loop. | 37 /// take into account whether the function was called from within a loop. |
| 38 // TODO(ascull): this currently uses a extension of Tarjan's algorithm with | |
| 39 // is bounded linear. ncbray suggests another algorithm which is linear in | |
| 40 // practice but not bounded linear. I think it also finds dominators. | |
| 41 // http://lenx.100871.net/papers/loop-SAS.pdf | |
| 38 void computeLoopNestDepth(); | 42 void computeLoopNestDepth(); |
| 39 | 43 |
| 40 private: | 44 private: |
| 41 using IndexT = uint32_t; | 45 using IndexT = uint32_t; |
| 42 static constexpr IndexT UndefinedIndex = 0; | 46 static constexpr IndexT UndefinedIndex = 0; |
| 43 static constexpr IndexT FirstDefinedIndex = 1; | 47 static constexpr IndexT FirstDefinedIndex = 1; |
| 44 | 48 |
| 45 // TODO(ascull): classify the other fields | 49 // TODO(ascull): classify the other fields |
| 46 class LoopNode { | 50 class LoopNode { |
| 47 LoopNode() = delete; | 51 LoopNode() = delete; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 IndexT Index; | 85 IndexT Index; |
| 82 IndexT LowLink; | 86 IndexT LowLink; |
| 83 bool OnStack; | 87 bool OnStack; |
| 84 bool Deleted = false; | 88 bool Deleted = false; |
| 85 }; | 89 }; |
| 86 | 90 |
| 87 using LoopNodeList = std::vector<LoopNode, CfgLocalAllocator<LoopNode>>; | 91 using LoopNodeList = std::vector<LoopNode, CfgLocalAllocator<LoopNode>>; |
| 88 using LoopNodePtrList = | 92 using LoopNodePtrList = |
| 89 std::vector<LoopNode *, CfgLocalAllocator<LoopNode *>>; | 93 std::vector<LoopNode *, CfgLocalAllocator<LoopNode *>>; |
| 90 | 94 |
| 91 /// Process the node as part as part of Tarjan's algorithm and return either | 95 /// Process the node as part as part of Tarjan's algorithm and return either a |
| 92 /// a node to recurse into or nullptr when the node has been fully processed. | 96 /// node to recurse into or nullptr when the node has been fully processed. |
| 93 LoopNode *processNode(LoopNode &Node); | 97 LoopNode *processNode(LoopNode &Node); |
| 94 | 98 |
| 95 /// The fuction to analyze for loops. | 99 /// The fuction to analyze for loops. |
|
Jim Stichnoth
2015/09/16 00:01:29
function
ascull
2015/09/16 18:30:09
Done.
| |
| 96 Cfg *const Func; | 100 Cfg *const Func; |
| 97 /// A list of decorated nodes in the same order as Func->getNodes() which | 101 /// A list of decorated nodes in the same order as Func->getNodes() which |
| 98 /// means the node's index will also be valid in this list. | 102 /// means the node's index will also be valid in this list. |
| 99 LoopNodeList AllNodes; | 103 LoopNodeList AllNodes; |
| 100 /// This is used as a replacement for the call stack. | 104 /// This is used as a replacement for the call stack. |
| 101 LoopNodePtrList WorkStack; | 105 LoopNodePtrList WorkStack; |
| 102 /// Track which loop a node belongs to. | 106 /// Track which loop a node belongs to. |
| 103 LoopNodePtrList LoopStack; | 107 LoopNodePtrList LoopStack; |
| 104 /// The index to assign to the next visited node. | 108 /// The index to assign to the next visited node. |
| 105 IndexT NextIndex = FirstDefinedIndex; | 109 IndexT NextIndex = FirstDefinedIndex; |
| 106 /// The number of nodes which have been marked deleted. This is used to track | 110 /// The number of nodes which have been marked deleted. This is used to track |
| 107 /// when the iteration should end. | 111 /// when the iteration should end. |
| 108 LoopNodePtrList::size_type NumDeletedNodes = 0; | 112 LoopNodePtrList::size_type NumDeletedNodes = 0; |
| 109 }; | 113 }; |
| 110 | 114 |
| 111 } // end of namespace Ice | 115 } // end of namespace Ice |
| 112 | 116 |
| 113 #endif // SUBZERO_SRC_ICELOOPANALYZER_H | 117 #endif // SUBZERO_SRC_ICELOOPANALYZER_H |
| OLD | NEW |