blob: 68ce74e6245396b3501ca0ce48d6ca057be1d32c [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 Murdochb8a8cc12014-11-26 15:28:44 +000065 Reduction ReduceJSToNumberInput(Node* input);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040066 Reduction ReduceJSToNumber(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067 Reduction ReduceJSToStringInput(Node* input);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040068 Reduction ReduceJSToString(Node* node);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069 Reduction ReduceJSToObject(Node* node);
70 Reduction ReduceJSConvertReceiver(Node* node);
71 Reduction ReduceJSCreate(Node* node);
72 Reduction ReduceJSCreateArguments(Node* node);
73 Reduction ReduceJSCreateArray(Node* node);
74 Reduction ReduceJSCreateClosure(Node* node);
75 Reduction ReduceJSCreateIterResultObject(Node* node);
76 Reduction ReduceJSCreateLiteralArray(Node* node);
77 Reduction ReduceJSCreateLiteralObject(Node* node);
78 Reduction ReduceJSCreateFunctionContext(Node* node);
79 Reduction ReduceJSCreateWithContext(Node* node);
80 Reduction ReduceJSCreateCatchContext(Node* node);
81 Reduction ReduceJSCreateBlockContext(Node* node);
82 Reduction ReduceJSCallConstruct(Node* node);
83 Reduction ReduceJSCallFunction(Node* node);
84 Reduction ReduceJSForInDone(Node* node);
85 Reduction ReduceJSForInNext(Node* node);
86 Reduction ReduceJSForInPrepare(Node* node);
87 Reduction ReduceJSForInStep(Node* node);
88 Reduction ReduceSelect(Node* node);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000089 Reduction ReduceNumberBinop(Node* node, const Operator* numberOp);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040090 Reduction ReduceInt32Binop(Node* node, const Operator* intOp);
91 Reduction ReduceUI32Shift(Node* node, Signedness left_signedness,
92 const Operator* shift_op);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093 Reduction ReduceNewArray(Node* node, Node* length, int capacity,
94 Handle<AllocationSite> site);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040095
96 Node* Word32Shl(Node* const lhs, int32_t const rhs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097 Node* AllocateArguments(Node* effect, Node* control, Node* frame_state);
98 Node* AllocateRestArguments(Node* effect, Node* control, Node* frame_state,
99 int start_index);
100 Node* AllocateAliasedArguments(Node* effect, Node* control, Node* frame_state,
101 Node* context, Handle<SharedFunctionInfo>,
102 bool* has_aliased_arguments);
103 Node* AllocateElements(Node* effect, Node* control,
104 ElementsKind elements_kind, int capacity,
105 PretenureFlag pretenure);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400106
107 Factory* factory() const;
108 Graph* graph() const;
109 JSGraph* jsgraph() const { return jsgraph_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110 Isolate* isolate() const;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400111 JSOperatorBuilder* javascript() const;
112 CommonOperatorBuilder* common() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113 SimplifiedOperatorBuilder* simplified() const;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400114 MachineOperatorBuilder* machine() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000115 CompilationDependencies* dependencies() const;
116 Flags flags() const { return flags_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000117
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118 // Limits up to which context allocations are inlined.
119 static const int kFunctionContextAllocationLimit = 16;
120 static const int kBlockContextAllocationLimit = 16;
121
122 CompilationDependencies* dependencies_;
123 Flags flags_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000124 JSGraph* jsgraph_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400125 Type* shifted_int32_ranges_[4];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000126 Type* const true_type_;
127 Type* const false_type_;
128 Type* const the_hole_type_;
129 TypeCache const& type_cache_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130};
131
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000132DEFINE_OPERATORS_FOR_FLAGS(JSTypedLowering::Flags)
133
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134} // namespace compiler
135} // namespace internal
136} // namespace v8
137
138#endif // V8_COMPILER_JS_TYPED_LOWERING_H_