• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/common/globals.h"
10 #include "src/compiler/graph-reducer.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 FrameState;
26 class JSGraph;
27 class JSOperatorBuilder;
28 class MachineOperatorBuilder;
29 class SimplifiedOperatorBuilder;
30 class SlackTrackingPrediction;
31 
32 // Lowers JSCreate-level operators to fast (inline) allocations.
33 class V8_EXPORT_PRIVATE JSCreateLowering final
NON_EXPORTED_BASE(AdvancedReducer)34     : public NON_EXPORTED_BASE(AdvancedReducer) {
35  public:
36   JSCreateLowering(Editor* editor, CompilationDependencies* dependencies,
37                    JSGraph* jsgraph, JSHeapBroker* broker, Zone* zone)
38       : AdvancedReducer(editor),
39         dependencies_(dependencies),
40         jsgraph_(jsgraph),
41         broker_(broker),
42         zone_(zone) {}
43   ~JSCreateLowering() final = default;
44 
45   const char* reducer_name() const override { return "JSCreateLowering"; }
46 
47   Reduction Reduce(Node* node) final;
48 
49  private:
50   Reduction ReduceJSCreate(Node* node);
51   Reduction ReduceJSCreateArguments(Node* node);
52   Reduction ReduceJSCreateArray(Node* node);
53   Reduction ReduceJSCreateArrayIterator(Node* node);
54   Reduction ReduceJSCreateAsyncFunctionObject(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 ReduceJSGetTemplateObject(Node* node);
72   Reduction ReduceNewArray(
73       Node* node, Node* length, MapRef initial_map, ElementsKind elements_kind,
74       AllocationType allocation,
75       const SlackTrackingPrediction& slack_tracking_prediction);
76   Reduction ReduceNewArray(
77       Node* node, Node* length, int capacity, MapRef initial_map,
78       ElementsKind elements_kind, AllocationType allocation,
79       const SlackTrackingPrediction& slack_tracking_prediction);
80   Reduction ReduceNewArray(
81       Node* node, std::vector<Node*> values, MapRef initial_map,
82       ElementsKind elements_kind, AllocationType allocation,
83       const SlackTrackingPrediction& slack_tracking_prediction);
84   Reduction ReduceJSCreateObject(Node* node);
85 
86   // The following functions all return nullptr iff there are too many arguments
87   // for inline allocation.
88   Node* TryAllocateArguments(Node* effect, Node* control,
89                              FrameState frame_state);
90   Node* TryAllocateRestArguments(Node* effect, Node* control,
91                                  FrameState frame_state, int start_index);
92   Node* TryAllocateAliasedArguments(Node* effect, Node* control,
93                                     FrameState frame_state, Node* context,
94                                     const SharedFunctionInfoRef& shared,
95                                     bool* has_aliased_arguments);
96   Node* TryAllocateAliasedArguments(Node* effect, Node* control, Node* context,
97                                     Node* arguments_length,
98                                     const SharedFunctionInfoRef& shared,
99                                     bool* has_aliased_arguments);
100   base::Optional<Node*> TryAllocateFastLiteral(Node* effect, Node* control,
101                                                JSObjectRef boilerplate,
102                                                AllocationType allocation,
103                                                int max_depth,
104                                                int* max_properties);
105   base::Optional<Node*> TryAllocateFastLiteralElements(
106       Node* effect, Node* control, JSObjectRef boilerplate,
107       AllocationType allocation, int max_depth, int* max_properties);
108 
109   Node* AllocateElements(Node* effect, Node* control,
110                          ElementsKind elements_kind, int capacity,
111                          AllocationType allocation);
112   Node* AllocateElements(Node* effect, Node* control,
113                          ElementsKind elements_kind, Node* capacity_and_length);
114   Node* AllocateElements(Node* effect, Node* control,
115                          ElementsKind elements_kind,
116                          std::vector<Node*> const& values,
117                          AllocationType allocation);
118   Node* AllocateLiteralRegExp(Node* effect, Node* control,
119                               RegExpBoilerplateDescriptionRef boilerplate);
120 
121   Factory* factory() const;
122   Graph* graph() const;
123   JSGraph* jsgraph() const { return jsgraph_; }
124   NativeContextRef native_context() const;
125   CommonOperatorBuilder* common() const;
126   SimplifiedOperatorBuilder* simplified() const;
127   CompilationDependencies* dependencies() const { return dependencies_; }
128   JSHeapBroker* broker() const { return broker_; }
129   Zone* zone() const { return zone_; }
130 
131   CompilationDependencies* const dependencies_;
132   JSGraph* const jsgraph_;
133   JSHeapBroker* const broker_;
134   Zone* const zone_;
135 };
136 
137 }  // namespace compiler
138 }  // namespace internal
139 }  // namespace v8
140 
141 #endif  // V8_COMPILER_JS_CREATE_LOWERING_H_
142