loop-peeling.h 1.82 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_LOOP_PEELING_H_
#define V8_COMPILER_LOOP_PEELING_H_

8
#include "src/base/compiler-specific.h"
9
#include "src/compiler/loop-analysis.h"
10
#include "src/globals.h"
11 12 13 14 15

namespace v8 {
namespace internal {
namespace compiler {

16 17
class SourcePositionTable;

18 19 20
// Represents the output of peeling a loop, which is basically the mapping
// from the body of the loop to the corresponding nodes in the peeled
// iteration.
21
class V8_EXPORT_PRIVATE PeeledIteration : public NON_EXPORTED_BASE(ZoneObject) {
22 23 24 25 26 27 28 29 30 31 32 33
 public:
  // Maps {node} to its corresponding copy in the peeled iteration, if
  // the node was part of the body of the loop. Returns {node} otherwise.
  Node* map(Node* node);

 protected:
  PeeledIteration() {}
};

class CommonOperatorBuilder;

// Implements loop peeling.
34
class V8_EXPORT_PRIVATE LoopPeeler {
35
 public:
36 37 38 39 40 41 42 43 44 45 46 47
  LoopPeeler(Graph* graph, CommonOperatorBuilder* common, LoopTree* loop_tree,
             Zone* tmp_zone, SourcePositionTable* source_positions)
      : graph_(graph),
        common_(common),
        loop_tree_(loop_tree),
        tmp_zone_(tmp_zone),
        source_positions_(source_positions) {}
  bool CanPeel(LoopTree::Loop* loop);
  PeeledIteration* Peel(LoopTree::Loop* loop);
  void PeelInnerLoopsOfTree();

  static void EliminateLoopExits(Graph* graph, Zone* tmp_zone);
48
  static const size_t kMaxPeeledNodes = 1000;
49 50 51 52 53 54 55 56 57

 private:
  Graph* const graph_;
  CommonOperatorBuilder* const common_;
  LoopTree* const loop_tree_;
  Zone* const tmp_zone_;
  SourcePositionTable* const source_positions_;

  void PeelInnerLoops(LoopTree::Loop* loop);
58 59 60 61 62 63 64 65
};


}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_LOOP_PEELING_H_