1 // Copyright 2014 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_JS_TYPED_LOWERING_H_
6 #define V8_COMPILER_JS_TYPED_LOWERING_H_
7 
8 #include "src/compiler/graph-reducer.h"
9 #include "src/compiler/js-graph.h"
10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/node.h"
12 #include "src/compiler/simplified-operator.h"
13 
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17 
18 // Lowers JS-level operators to simplified operators based on types.
19 class JSTypedLowering FINAL : public Reducer {
20  public:
JSTypedLowering(JSGraph * jsgraph)21   explicit JSTypedLowering(JSGraph* jsgraph)
22       : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {}
23   virtual ~JSTypedLowering();
24 
25   virtual Reduction Reduce(Node* node) OVERRIDE;
26 
jsgraph()27   JSGraph* jsgraph() { return jsgraph_; }
graph()28   Graph* graph() { return jsgraph_->graph(); }
zone()29   Zone* zone() { return jsgraph_->zone(); }
30 
31  private:
32   friend class JSBinopReduction;
33 
34   Reduction ReplaceEagerly(Node* old, Node* node);
ReplaceWith(Node * node)35   Reduction ReplaceWith(Node* node) { return Reducer::Replace(node); }
36   Reduction ReduceJSAdd(Node* node);
37   Reduction ReduceJSComparison(Node* node);
38   Reduction ReduceJSLoadProperty(Node* node);
39   Reduction ReduceJSStoreProperty(Node* node);
40   Reduction ReduceJSEqual(Node* node, bool invert);
41   Reduction ReduceJSStrictEqual(Node* node, bool invert);
42   Reduction ReduceJSToNumberInput(Node* input);
43   Reduction ReduceJSToStringInput(Node* input);
44   Reduction ReduceJSToBooleanInput(Node* input);
45   Reduction ReduceNumberBinop(Node* node, const Operator* numberOp);
46   Reduction ReduceI32Binop(Node* node, bool left_signed, bool right_signed,
47                            const Operator* intOp);
48   Reduction ReduceI32Shift(Node* node, bool left_signed,
49                            const Operator* shift_op);
50 
javascript()51   JSOperatorBuilder* javascript() { return jsgraph_->javascript(); }
common()52   CommonOperatorBuilder* common() { return jsgraph_->common(); }
simplified()53   SimplifiedOperatorBuilder* simplified() { return &simplified_; }
machine()54   MachineOperatorBuilder* machine() { return jsgraph_->machine(); }
55 
56   JSGraph* jsgraph_;
57   SimplifiedOperatorBuilder simplified_;
58 };
59 
60 }  // namespace compiler
61 }  // namespace internal
62 }  // namespace v8
63 
64 #endif  // V8_COMPILER_JS_TYPED_LOWERING_H_
65