Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: src/IceLoopAnalyzer.h

Issue 2138443002: Subzero: Loop Invariant Code Motion (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Put invariant detection logic into separate function Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
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 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 39 // is bounded linear. ncbray suggests another algorithm whichis linear in
Jim Stichnoth 2016/07/12 10:51:51 undo this
40 // practice but not bounded linear. I think it also finds dominators. 40 // practice but not bounded linear. I think it also finds dominators.
41 // http://lenx.100871.net/papers/loop-SAS.pdf 41 // http://lenx.100871.net/papers/loop-SAS.pdf
42 void computeLoopNestDepth(); 42 CfgUnorderedMap<SizeT, CfgVector<SizeT>> getLoopInfo() { return Loops; }
43 43
44 private: 44 private:
45 void computeLoopNestDepth();
45 using IndexT = uint32_t; 46 using IndexT = uint32_t;
46 static constexpr IndexT UndefinedIndex = 0; 47 static constexpr IndexT UndefinedIndex = 0;
47 static constexpr IndexT FirstDefinedIndex = 1; 48 static constexpr IndexT FirstDefinedIndex = 1;
48 49
49 // TODO(ascull): classify the other fields 50 // TODO(ascull): classify the other fields
50 class LoopNode { 51 class LoopNode {
51 LoopNode() = delete; 52 LoopNode() = delete;
52 LoopNode operator=(const LoopNode &) = delete; 53 LoopNode operator=(const LoopNode &) = delete;
53 54
54 public: 55 public:
(...skipping 18 matching lines...) Expand all
73 74
74 void setOnStack(bool NewValue = true) { OnStack = NewValue; } 75 void setOnStack(bool NewValue = true) { OnStack = NewValue; }
75 bool isOnStack() const { return OnStack; } 76 bool isOnStack() const { return OnStack; }
76 77
77 void setDeleted() { Deleted = true; } 78 void setDeleted() { Deleted = true; }
78 bool isDeleted() const { return Deleted; } 79 bool isDeleted() const { return Deleted; }
79 80
80 void incrementLoopNestDepth(); 81 void incrementLoopNestDepth();
81 bool hasSelfEdge() const; 82 bool hasSelfEdge() const;
82 83
84 CfgNode *getNode() { return BB; }
85
83 private: 86 private:
84 CfgNode *BB; 87 CfgNode *BB;
85 NodeList::const_iterator Succ; 88 NodeList::const_iterator Succ;
86 IndexT Index; 89 IndexT Index;
87 IndexT LowLink; 90 IndexT LowLink;
88 bool OnStack; 91 bool OnStack;
89 bool Deleted = false; 92 bool Deleted = false;
90 }; 93 };
91 94
92 using LoopNodeList = CfgVector<LoopNode>; 95 using LoopNodeList = CfgVector<LoopNode>;
(...skipping 10 matching lines...) Expand all
103 LoopNodeList AllNodes; 106 LoopNodeList AllNodes;
104 /// This is used as a replacement for the call stack. 107 /// This is used as a replacement for the call stack.
105 LoopNodePtrList WorkStack; 108 LoopNodePtrList WorkStack;
106 /// Track which loop a node belongs to. 109 /// Track which loop a node belongs to.
107 LoopNodePtrList LoopStack; 110 LoopNodePtrList LoopStack;
108 /// The index to assign to the next visited node. 111 /// The index to assign to the next visited node.
109 IndexT NextIndex = FirstDefinedIndex; 112 IndexT NextIndex = FirstDefinedIndex;
110 /// The number of nodes which have been marked deleted. This is used to track 113 /// The number of nodes which have been marked deleted. This is used to track
111 /// when the iteration should end. 114 /// when the iteration should end.
112 LoopNodePtrList::size_type NumDeletedNodes = 0; 115 LoopNodePtrList::size_type NumDeletedNodes = 0;
116 /// Detailed loop information
117 CfgUnorderedMap<SizeT, CfgVector<SizeT>> Loops;
113 }; 118 };
114 119
115 } // end of namespace Ice 120 } // end of namespace Ice
116 121
117 #endif // SUBZERO_SRC_ICELOOPANALYZER_H 122 #endif // SUBZERO_SRC_ICELOOPANALYZER_H
OLDNEW
« src/IceCfg.cpp ('K') | « src/IceClFlags.def ('k') | src/IceLoopAnalyzer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698