blob: 151787106b2b1227e75a9c6fb5fe7ab064e05cdb [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/base/flags.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/compiler/graph-reducer.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/compiler/opcodes.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011
12namespace v8 {
13namespace internal {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014
15// Forward declarations.
16class CompilationDependencies;
17class Factory;
18class TypeCache;
19
20
Ben Murdochb8a8cc12014-11-26 15:28:44 +000021namespace compiler {
22
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023// Forward declarations.
24class CommonOperatorBuilder;
25class JSGraph;
26class JSOperatorBuilder;
27class MachineOperatorBuilder;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028class SimplifiedOperatorBuilder;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040029
30
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031// Lowers JS-level operators to simplified operators based on types.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032class JSTypedLowering final : public AdvancedReducer {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000033 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034 // Flags that control the mode of operation.
35 enum Flag {
36 kNoFlags = 0u,
37 kDeoptimizationEnabled = 1u << 0,
38 kDisableBinaryOpReduction = 1u << 1,
39 };
40 typedef base::Flags<Flag> Flags;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000041
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042 JSTypedLowering(Editor* editor, CompilationDependencies* dependencies,
43 Flags flags, JSGraph* jsgraph, Zone* zone);
44 ~JSTypedLowering() final {}
45
46 Reduction Reduce(Node* node) final;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047
48 private:
49 friend class JSBinopReduction;
50
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051 Reduction ReduceJSAdd(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 Reduction ReduceJSModulus(Node* node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040053 Reduction ReduceJSBitwiseOr(Node* node);
54 Reduction ReduceJSMultiply(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000055 Reduction ReduceJSComparison(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 Reduction ReduceJSLoadNamed(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057 Reduction ReduceJSLoadProperty(Node* node);
58 Reduction ReduceJSStoreProperty(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000059 Reduction ReduceJSInstanceOf(Node* node);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040060 Reduction ReduceJSLoadContext(Node* node);
61 Reduction ReduceJSStoreContext(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062 Reduction ReduceJSEqual(Node* node, bool invert);
63 Reduction ReduceJSStrictEqual(Node* node, bool invert);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040064 Reduction ReduceJSToBoolean(Node* node);
Ben Murdochda12d292016-06-02 14:46:10 +010065 Reduction ReduceJSToInteger(Node* node);
66 Reduction ReduceJSToLength(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067 Reduction ReduceJSToNumberInput(Node* input);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040068 Reduction ReduceJSToNumber(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069 Reduction ReduceJSToStringInput(Node* input);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040070 Reduction ReduceJSToString(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071 Reduction ReduceJSToObject(Node* node);
72 Reduction ReduceJSConvertReceiver(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000073 Reduction ReduceJSCallConstruct(Node* node);
74 Reduction ReduceJSCallFunction(Node* node);
75 Reduction ReduceJSForInDone(Node* node);
76 Reduction ReduceJSForInNext(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077 Reduction ReduceJSForInStep(Node* node);
78 Reduction ReduceSelect(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 Reduction ReduceNumberBinop(Node* node, const Operator* numberOp);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040080 Reduction ReduceInt32Binop(Node* node, const Operator* intOp);
81 Reduction ReduceUI32Shift(Node* node, Signedness left_signedness,
82 const Operator* shift_op);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040083
84 Node* Word32Shl(Node* const lhs, int32_t const rhs);
85
86 Factory* factory() const;
87 Graph* graph() const;
88 JSGraph* jsgraph() const { return jsgraph_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089 Isolate* isolate() const;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040090 JSOperatorBuilder* javascript() const;
91 CommonOperatorBuilder* common() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 SimplifiedOperatorBuilder* simplified() const;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040093 MachineOperatorBuilder* machine() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094 CompilationDependencies* dependencies() const;
95 Flags flags() const { return flags_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097 CompilationDependencies* dependencies_;
98 Flags flags_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099 JSGraph* jsgraph_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400100 Type* shifted_int32_ranges_[4];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101 Type* const true_type_;
102 Type* const false_type_;
103 Type* const the_hole_type_;
104 TypeCache const& type_cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105};
106
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000107DEFINE_OPERATORS_FOR_FLAGS(JSTypedLowering::Flags)
108
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109} // namespace compiler
110} // namespace internal
111} // namespace v8
112
113#endif // V8_COMPILER_JS_TYPED_LOWERING_H_