1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_COMPILER_LOOP_PEELING_H_
6 #define V8_COMPILER_LOOP_PEELING_H_
7
8 #include "src/base/compiler-specific.h"
9 #include "src/common/globals.h"
10 #include "src/compiler/loop-analysis.h"
11
12 namespace v8 {
13 namespace internal {
14 namespace compiler {
15
16 class NodeOriginTable;
17 class SourcePositionTable;
18
19 // Represents the output of peeling a loop, which is basically the mapping
20 // from the body of the loop to the corresponding nodes in the peeled
21 // iteration.
NON_EXPORTED_BASE(ZoneObject)22 class V8_EXPORT_PRIVATE PeeledIteration : public NON_EXPORTED_BASE(ZoneObject) {
23 public:
24 // Maps {node} to its corresponding copy in the peeled iteration, if
25 // the node was part of the body of the loop. Returns {node} otherwise.
26 Node* map(Node* node);
27
28 protected:
29 PeeledIteration() = default;
30 };
31
32 class CommonOperatorBuilder;
33
34 // Implements loop peeling.
35 class V8_EXPORT_PRIVATE LoopPeeler {
36 public:
LoopPeeler(Graph * graph,CommonOperatorBuilder * common,LoopTree * loop_tree,Zone * tmp_zone,SourcePositionTable * source_positions,NodeOriginTable * node_origins)37 LoopPeeler(Graph* graph, CommonOperatorBuilder* common, LoopTree* loop_tree,
38 Zone* tmp_zone, SourcePositionTable* source_positions,
39 NodeOriginTable* node_origins)
40 : graph_(graph),
41 common_(common),
42 loop_tree_(loop_tree),
43 tmp_zone_(tmp_zone),
44 source_positions_(source_positions),
45 node_origins_(node_origins) {}
CanPeel(LoopTree::Loop * loop)46 bool CanPeel(LoopTree::Loop* loop) {
47 return LoopFinder::HasMarkedExits(loop_tree_, loop);
48 }
49 PeeledIteration* Peel(LoopTree::Loop* loop);
50 void PeelInnerLoopsOfTree();
51
52 static void EliminateLoopExits(Graph* graph, Zone* tmp_zone);
53 static void EliminateLoopExit(Node* loop);
54 static const size_t kMaxPeeledNodes = 1000;
55
56 private:
57 Graph* const graph_;
58 CommonOperatorBuilder* const common_;
59 LoopTree* const loop_tree_;
60 Zone* const tmp_zone_;
61 SourcePositionTable* const source_positions_;
62 NodeOriginTable* const node_origins_;
63
64 void PeelInnerLoops(LoopTree::Loop* loop);
65 };
66
67
68 } // namespace compiler
69 } // namespace internal
70 } // namespace v8
71
72 #endif // V8_COMPILER_LOOP_PEELING_H_
73