• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/compiler/loop-analysis.h"
10 #include "src/globals.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() {}
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) {}
46   bool CanPeel(LoopTree::Loop* loop);
47   PeeledIteration* Peel(LoopTree::Loop* loop);
48   void PeelInnerLoopsOfTree();
49 
50   static void EliminateLoopExits(Graph* graph, Zone* tmp_zone);
51   static const size_t kMaxPeeledNodes = 1000;
52 
53  private:
54   Graph* const graph_;
55   CommonOperatorBuilder* const common_;
56   LoopTree* const loop_tree_;
57   Zone* const tmp_zone_;
58   SourcePositionTable* const source_positions_;
59   NodeOriginTable* const node_origins_;
60 
61   void PeelInnerLoops(LoopTree::Loop* loop);
62 };
63 
64 
65 }  // namespace compiler
66 }  // namespace internal
67 }  // namespace v8
68 
69 #endif  // V8_COMPILER_LOOP_PEELING_H_
70