1 // Copyright 2016 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_CREATE_LOWERING_H_ 6 #define V8_COMPILER_JS_CREATE_LOWERING_H_ 7 8 #include "src/base/compiler-specific.h" 9 #include "src/compiler/graph-reducer.h" 10 #include "src/globals.h" 11 12 namespace v8 { 13 namespace internal { 14 15 // Forward declarations. 16 class AllocationSiteUsageContext; 17 class Factory; 18 class JSRegExp; 19 20 namespace compiler { 21 22 // Forward declarations. 23 class CommonOperatorBuilder; 24 class CompilationDependencies; 25 class JSGraph; 26 class JSOperatorBuilder; 27 class MachineOperatorBuilder; 28 class SimplifiedOperatorBuilder; 29 class SlackTrackingPrediction; 30 31 // Lowers JSCreate-level operators to fast (inline) allocations. 32 class V8_EXPORT_PRIVATE JSCreateLowering final NON_EXPORTED_BASE(AdvancedReducer)33 : public NON_EXPORTED_BASE(AdvancedReducer) { 34 public: 35 JSCreateLowering(Editor* editor, CompilationDependencies* dependencies, 36 JSGraph* jsgraph, JSHeapBroker* js_heap_broker, 37 Handle<Context> native_context, Zone* zone) 38 : AdvancedReducer(editor), 39 dependencies_(dependencies), 40 jsgraph_(jsgraph), 41 js_heap_broker_(js_heap_broker), 42 native_context_(native_context), 43 zone_(zone) {} 44 ~JSCreateLowering() final {} 45 46 const char* reducer_name() const override { return "JSCreateLowering"; } 47 48 Reduction Reduce(Node* node) final; 49 50 private: 51 Reduction ReduceJSCreate(Node* node); 52 Reduction ReduceJSCreateArguments(Node* node); 53 Reduction ReduceJSCreateArray(Node* node); 54 Reduction ReduceJSCreateArrayIterator(Node* node); 55 Reduction ReduceJSCreateCollectionIterator(Node* node); 56 Reduction ReduceJSCreateBoundFunction(Node* node); 57 Reduction ReduceJSCreateClosure(Node* node); 58 Reduction ReduceJSCreateIterResultObject(Node* node); 59 Reduction ReduceJSCreateStringIterator(Node* node); 60 Reduction ReduceJSCreateKeyValueArray(Node* node); 61 Reduction ReduceJSCreatePromise(Node* node); 62 Reduction ReduceJSCreateLiteralArrayOrObject(Node* node); 63 Reduction ReduceJSCreateEmptyLiteralObject(Node* node); 64 Reduction ReduceJSCreateEmptyLiteralArray(Node* node); 65 Reduction ReduceJSCreateLiteralRegExp(Node* node); 66 Reduction ReduceJSCreateFunctionContext(Node* node); 67 Reduction ReduceJSCreateWithContext(Node* node); 68 Reduction ReduceJSCreateCatchContext(Node* node); 69 Reduction ReduceJSCreateBlockContext(Node* node); 70 Reduction ReduceJSCreateGeneratorObject(Node* node); 71 Reduction ReduceNewArray( 72 Node* node, Node* length, MapRef initial_map, PretenureFlag pretenure, 73 const SlackTrackingPrediction& slack_tracking_prediction); 74 Reduction ReduceNewArray( 75 Node* node, Node* length, int capacity, MapRef initial_map, 76 PretenureFlag pretenure, 77 const SlackTrackingPrediction& slack_tracking_prediction); 78 Reduction ReduceNewArray( 79 Node* node, std::vector<Node*> values, MapRef initial_map, 80 PretenureFlag pretenure, 81 const SlackTrackingPrediction& slack_tracking_prediction); 82 Reduction ReduceJSCreateObject(Node* node); 83 84 Node* AllocateArguments(Node* effect, Node* control, Node* frame_state); 85 Node* AllocateRestArguments(Node* effect, Node* control, Node* frame_state, 86 int start_index); 87 Node* AllocateAliasedArguments(Node* effect, Node* control, Node* frame_state, 88 Node* context, 89 const SharedFunctionInfoRef& shared, 90 bool* has_aliased_arguments); 91 Node* AllocateAliasedArguments(Node* effect, Node* control, Node* context, 92 Node* arguments_frame, Node* arguments_length, 93 const SharedFunctionInfoRef& shared, 94 bool* has_aliased_arguments); 95 Node* AllocateElements(Node* effect, Node* control, 96 ElementsKind elements_kind, int capacity, 97 PretenureFlag pretenure); 98 Node* AllocateElements(Node* effect, Node* control, 99 ElementsKind elements_kind, Node* capacity_and_length); 100 Node* AllocateElements(Node* effect, Node* control, 101 ElementsKind elements_kind, 102 std::vector<Node*> const& values, 103 PretenureFlag pretenure); 104 Node* AllocateFastLiteral(Node* effect, Node* control, 105 JSObjectRef boilerplate, PretenureFlag pretenure); 106 Node* AllocateFastLiteralElements(Node* effect, Node* control, 107 JSObjectRef boilerplate, 108 PretenureFlag pretenure); 109 Node* AllocateLiteralRegExp(Node* effect, Node* control, 110 JSRegExpRef boilerplate); 111 112 Reduction ReduceNewArrayToStubCall(Node* node, 113 base::Optional<AllocationSiteRef> site); 114 115 Factory* factory() const; 116 Graph* graph() const; 117 JSGraph* jsgraph() const { return jsgraph_; } 118 Isolate* isolate() const; 119 Handle<Context> native_context() const { return native_context_; } 120 NativeContextRef native_context_ref() const; 121 CommonOperatorBuilder* common() const; 122 SimplifiedOperatorBuilder* simplified() const; 123 CompilationDependencies* dependencies() const { return dependencies_; } 124 JSHeapBroker* js_heap_broker() const { return js_heap_broker_; } 125 Zone* zone() const { return zone_; } 126 127 CompilationDependencies* const dependencies_; 128 JSGraph* const jsgraph_; 129 JSHeapBroker* const js_heap_broker_; 130 Handle<Context> const native_context_; 131 Zone* const zone_; 132 }; 133 134 } // namespace compiler 135 } // namespace internal 136 } // namespace v8 137 138 #endif // V8_COMPILER_JS_CREATE_LOWERING_H_ 139