redundancy-elimination.h 2.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2016 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_REDUNDANCY_ELIMINATION_H_
#define V8_COMPILER_REDUNDANCY_ELIMINATION_H_

#include "src/compiler/graph-reducer.h"

namespace v8 {
namespace internal {
namespace compiler {

14
class V8_EXPORT_PRIVATE RedundancyElimination final : public AdvancedReducer {
15 16 17
 public:
  RedundancyElimination(Editor* editor, Zone* zone);
  ~RedundancyElimination() final;
18 19
  RedundancyElimination(const RedundancyElimination&) = delete;
  RedundancyElimination& operator=(const RedundancyElimination&) = delete;
20

21 22
  const char* reducer_name() const override { return "RedundancyElimination"; }

23 24 25 26 27 28 29 30 31 32 33 34 35
  Reduction Reduce(Node* node) final;

 private:
  struct Check {
    Check(Node* node, Check* next) : node(node), next(next) {}
    Node* node;
    Check* next;
  };

  class EffectPathChecks final {
   public:
    static EffectPathChecks* Copy(Zone* zone, EffectPathChecks const* checks);
    static EffectPathChecks const* Empty(Zone* zone);
36
    bool Equals(EffectPathChecks const* that) const;
37 38 39 40
    void Merge(EffectPathChecks const* that);

    EffectPathChecks const* AddCheck(Zone* zone, Node* node) const;
    Node* LookupCheck(Node* node) const;
41
    Node* LookupBoundsCheckFor(Node* node) const;
42 43

   private:
44 45
    friend Zone;

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    EffectPathChecks(Check* head, size_t size) : head_(head), size_(size) {}

    // We keep track of the list length so that we can find the longest
    // common tail easily.
    Check* head_;
    size_t size_;
  };

  class PathChecksForEffectNodes final {
   public:
    explicit PathChecksForEffectNodes(Zone* zone) : info_for_node_(zone) {}
    EffectPathChecks const* Get(Node* node) const;
    void Set(Node* node, EffectPathChecks const* checks);

   private:
    ZoneVector<EffectPathChecks const*> info_for_node_;
  };

  Reduction ReduceCheckNode(Node* node);
  Reduction ReduceEffectPhi(Node* node);
66
  Reduction ReduceSpeculativeNumberComparison(Node* node);
67
  Reduction ReduceSpeculativeNumberOperation(Node* node);
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  Reduction ReduceStart(Node* node);
  Reduction ReduceOtherNode(Node* node);

  Reduction TakeChecksFromFirstEffect(Node* node);
  Reduction UpdateChecks(Node* node, EffectPathChecks const* checks);

  Zone* zone() const { return zone_; }

  PathChecksForEffectNodes node_checks_;
  Zone* const zone_;
};

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

#endif  // V8_COMPILER_REDUNDANCY_ELIMINATION_H_