machine-operator-reducer.h 3.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright 2014 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_MACHINE_OPERATOR_REDUCER_H_
#define V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_

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

namespace v8 {
namespace internal {
namespace compiler {

// Forward declarations.
16 17 18
class CommonOperatorBuilder;
class JSGraph;

19 20 21

// Performs constant folding and strength reduction on nodes that have
// machine operators.
22
class MachineOperatorReducer final : public Reducer {
23
 public:
24 25
  explicit MachineOperatorReducer(JSGraph* jsgraph);
  ~MachineOperatorReducer();
26

27
  Reduction Reduce(Node* node) override;
28 29

 private:
30
  Node* Float32Constant(volatile float value);
31
  Node* Float64Constant(volatile double value);
32 33
  Node* Int32Constant(int32_t value);
  Node* Int64Constant(int64_t value);
34 35 36
  Node* Uint32Constant(uint32_t value) {
    return Int32Constant(bit_cast<uint32_t>(value));
  }
37 38 39 40
  Node* Word32And(Node* lhs, Node* rhs);
  Node* Word32And(Node* lhs, uint32_t rhs) {
    return Word32And(lhs, Uint32Constant(rhs));
  }
41 42
  Node* Word32Sar(Node* lhs, uint32_t rhs);
  Node* Word32Shr(Node* lhs, uint32_t rhs);
43
  Node* Word32Equal(Node* lhs, Node* rhs);
44 45 46
  Node* Int32Add(Node* lhs, Node* rhs);
  Node* Int32Sub(Node* lhs, Node* rhs);
  Node* Int32Mul(Node* lhs, Node* rhs);
47 48
  Node* Int32Div(Node* dividend, int32_t divisor);
  Node* Uint32Div(Node* dividend, uint32_t divisor);
49 50

  Reduction ReplaceBool(bool value) { return ReplaceInt32(value ? 1 : 0); }
51 52 53
  Reduction ReplaceFloat32(volatile float value) {
    return Replace(Float32Constant(value));
  }
54 55 56
  Reduction ReplaceFloat64(volatile double value) {
    return Replace(Float64Constant(value));
  }
57 58 59
  Reduction ReplaceInt32(int32_t value) {
    return Replace(Int32Constant(value));
  }
60 61 62
  Reduction ReplaceUint32(uint32_t value) {
    return Replace(Uint32Constant(value));
  }
63 64
  Reduction ReplaceInt64(int64_t value) {
    return Replace(Int64Constant(value));
65
  }
66

67
  Reduction ReduceInt32Add(Node* node);
68
  Reduction ReduceInt32Sub(Node* node);
69
  Reduction ReduceInt32Div(Node* node);
70
  Reduction ReduceUint32Div(Node* node);
71
  Reduction ReduceInt32Mod(Node* node);
72
  Reduction ReduceUint32Mod(Node* node);
73
  Reduction ReduceTruncateFloat64ToInt32(Node* node);
74
  Reduction ReduceStore(Node* node);
75
  Reduction ReduceProjection(size_t index, Node* node);
76
  Reduction ReduceWord32Shifts(Node* node);
77
  Reduction ReduceWord32Shl(Node* node);
78
  Reduction ReduceWord32Sar(Node* node);
79
  Reduction ReduceWord32And(Node* node);
80
  Reduction ReduceWord32Or(Node* node);
81 82
  Reduction ReduceFloat64InsertLowWord32(Node* node);
  Reduction ReduceFloat64InsertHighWord32(Node* node);
83
  Reduction ReduceFloat64Compare(Node* node);
84

85 86 87
  Graph* graph() const;
  JSGraph* jsgraph() const { return jsgraph_; }
  CommonOperatorBuilder* common() const;
88
  MachineOperatorBuilder* machine() const;
89 90

  JSGraph* jsgraph_;
91
};
92 93 94 95

}  // namespace compiler
}  // namespace internal
}  // namespace v8
96 97

#endif  // V8_COMPILER_MACHINE_OPERATOR_REDUCER_H_