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