Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 8 | #include "src/base/flags.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/compiler/graph-reducer.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 10 | #include "src/compiler/opcodes.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 14 | |
| 15 | // Forward declarations. |
| 16 | class CompilationDependencies; |
| 17 | class Factory; |
| 18 | class TypeCache; |
| 19 | |
| 20 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 21 | namespace compiler { |
| 22 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | // Forward declarations. |
| 24 | class CommonOperatorBuilder; |
| 25 | class JSGraph; |
| 26 | class JSOperatorBuilder; |
| 27 | class MachineOperatorBuilder; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 28 | class SimplifiedOperatorBuilder; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 29 | |
| 30 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 31 | // Lowers JS-level operators to simplified operators based on types. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 32 | class JSTypedLowering final : public AdvancedReducer { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 33 | public: |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 34 | // 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 41 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 42 | JSTypedLowering(Editor* editor, CompilationDependencies* dependencies, |
| 43 | Flags flags, JSGraph* jsgraph, Zone* zone); |
| 44 | ~JSTypedLowering() final {} |
| 45 | |
| 46 | Reduction Reduce(Node* node) final; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | friend class JSBinopReduction; |
| 50 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | Reduction ReduceJSAdd(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 52 | Reduction ReduceJSModulus(Node* node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 53 | Reduction ReduceJSBitwiseOr(Node* node); |
| 54 | Reduction ReduceJSMultiply(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | Reduction ReduceJSComparison(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 56 | Reduction ReduceJSLoadNamed(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | Reduction ReduceJSLoadProperty(Node* node); |
| 58 | Reduction ReduceJSStoreProperty(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 59 | Reduction ReduceJSInstanceOf(Node* node); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 60 | Reduction ReduceJSLoadContext(Node* node); |
| 61 | Reduction ReduceJSStoreContext(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 62 | Reduction ReduceJSEqual(Node* node, bool invert); |
| 63 | Reduction ReduceJSStrictEqual(Node* node, bool invert); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 64 | Reduction ReduceJSToBoolean(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 65 | Reduction ReduceJSToNumberInput(Node* input); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 66 | Reduction ReduceJSToNumber(Node* node); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | Reduction ReduceJSToStringInput(Node* input); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 68 | Reduction ReduceJSToString(Node* node); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 69 | 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 89 | Reduction ReduceNumberBinop(Node* node, const Operator* numberOp); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 90 | Reduction ReduceInt32Binop(Node* node, const Operator* intOp); |
| 91 | Reduction ReduceUI32Shift(Node* node, Signedness left_signedness, |
| 92 | const Operator* shift_op); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 93 | Reduction ReduceNewArray(Node* node, Node* length, int capacity, |
| 94 | Handle<AllocationSite> site); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 95 | |
| 96 | Node* Word32Shl(Node* const lhs, int32_t const rhs); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 97 | 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 Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 106 | |
| 107 | Factory* factory() const; |
| 108 | Graph* graph() const; |
| 109 | JSGraph* jsgraph() const { return jsgraph_; } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 110 | Isolate* isolate() const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 111 | JSOperatorBuilder* javascript() const; |
| 112 | CommonOperatorBuilder* common() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 113 | SimplifiedOperatorBuilder* simplified() const; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 114 | MachineOperatorBuilder* machine() const; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 115 | CompilationDependencies* dependencies() const; |
| 116 | Flags flags() const { return flags_; } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 117 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 118 | // 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 Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 124 | JSGraph* jsgraph_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 125 | Type* shifted_int32_ranges_[4]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 126 | Type* const true_type_; |
| 127 | Type* const false_type_; |
| 128 | Type* const the_hole_type_; |
| 129 | TypeCache const& type_cache_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 132 | DEFINE_OPERATORS_FOR_FLAGS(JSTypedLowering::Flags) |
| 133 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 134 | } // namespace compiler |
| 135 | } // namespace internal |
| 136 | } // namespace v8 |
| 137 | |
| 138 | #endif // V8_COMPILER_JS_TYPED_LOWERING_H_ |