11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_COMPILER_JS_CREATE_LOWERING_H_
61cb0ef41Sopenharmony_ci#define V8_COMPILER_JS_CREATE_LOWERING_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/base/compiler-specific.h"
91cb0ef41Sopenharmony_ci#include "src/common/globals.h"
101cb0ef41Sopenharmony_ci#include "src/compiler/graph-reducer.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// Forward declarations.
161cb0ef41Sopenharmony_ciclass AllocationSiteUsageContext;
171cb0ef41Sopenharmony_ciclass Factory;
181cb0ef41Sopenharmony_ciclass JSRegExp;
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cinamespace compiler {
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci// Forward declarations.
231cb0ef41Sopenharmony_ciclass CommonOperatorBuilder;
241cb0ef41Sopenharmony_ciclass CompilationDependencies;
251cb0ef41Sopenharmony_ciclass FrameState;
261cb0ef41Sopenharmony_ciclass JSGraph;
271cb0ef41Sopenharmony_ciclass JSOperatorBuilder;
281cb0ef41Sopenharmony_ciclass MachineOperatorBuilder;
291cb0ef41Sopenharmony_ciclass SimplifiedOperatorBuilder;
301cb0ef41Sopenharmony_ciclass SlackTrackingPrediction;
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci// Lowers JSCreate-level operators to fast (inline) allocations.
331cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE JSCreateLowering final
341cb0ef41Sopenharmony_ci    : public NON_EXPORTED_BASE(AdvancedReducer) {
351cb0ef41Sopenharmony_ci public:
361cb0ef41Sopenharmony_ci  JSCreateLowering(Editor* editor, CompilationDependencies* dependencies,
371cb0ef41Sopenharmony_ci                   JSGraph* jsgraph, JSHeapBroker* broker, Zone* zone)
381cb0ef41Sopenharmony_ci      : AdvancedReducer(editor),
391cb0ef41Sopenharmony_ci        dependencies_(dependencies),
401cb0ef41Sopenharmony_ci        jsgraph_(jsgraph),
411cb0ef41Sopenharmony_ci        broker_(broker),
421cb0ef41Sopenharmony_ci        zone_(zone) {}
431cb0ef41Sopenharmony_ci  ~JSCreateLowering() final = default;
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  const char* reducer_name() const override { return "JSCreateLowering"; }
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  Reduction Reduce(Node* node) final;
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci private:
501cb0ef41Sopenharmony_ci  Reduction ReduceJSCreate(Node* node);
511cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateArguments(Node* node);
521cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateArray(Node* node);
531cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateArrayIterator(Node* node);
541cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateAsyncFunctionObject(Node* node);
551cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateCollectionIterator(Node* node);
561cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateBoundFunction(Node* node);
571cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateClosure(Node* node);
581cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateIterResultObject(Node* node);
591cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateStringIterator(Node* node);
601cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateKeyValueArray(Node* node);
611cb0ef41Sopenharmony_ci  Reduction ReduceJSCreatePromise(Node* node);
621cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateLiteralArrayOrObject(Node* node);
631cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateEmptyLiteralObject(Node* node);
641cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateEmptyLiteralArray(Node* node);
651cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateLiteralRegExp(Node* node);
661cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateFunctionContext(Node* node);
671cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateWithContext(Node* node);
681cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateCatchContext(Node* node);
691cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateBlockContext(Node* node);
701cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateGeneratorObject(Node* node);
711cb0ef41Sopenharmony_ci  Reduction ReduceJSGetTemplateObject(Node* node);
721cb0ef41Sopenharmony_ci  Reduction ReduceNewArray(
731cb0ef41Sopenharmony_ci      Node* node, Node* length, MapRef initial_map, ElementsKind elements_kind,
741cb0ef41Sopenharmony_ci      AllocationType allocation,
751cb0ef41Sopenharmony_ci      const SlackTrackingPrediction& slack_tracking_prediction);
761cb0ef41Sopenharmony_ci  Reduction ReduceNewArray(
771cb0ef41Sopenharmony_ci      Node* node, Node* length, int capacity, MapRef initial_map,
781cb0ef41Sopenharmony_ci      ElementsKind elements_kind, AllocationType allocation,
791cb0ef41Sopenharmony_ci      const SlackTrackingPrediction& slack_tracking_prediction);
801cb0ef41Sopenharmony_ci  Reduction ReduceNewArray(
811cb0ef41Sopenharmony_ci      Node* node, std::vector<Node*> values, MapRef initial_map,
821cb0ef41Sopenharmony_ci      ElementsKind elements_kind, AllocationType allocation,
831cb0ef41Sopenharmony_ci      const SlackTrackingPrediction& slack_tracking_prediction);
841cb0ef41Sopenharmony_ci  Reduction ReduceJSCreateObject(Node* node);
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci  // The following functions all return nullptr iff there are too many arguments
871cb0ef41Sopenharmony_ci  // for inline allocation.
881cb0ef41Sopenharmony_ci  Node* TryAllocateArguments(Node* effect, Node* control,
891cb0ef41Sopenharmony_ci                             FrameState frame_state);
901cb0ef41Sopenharmony_ci  Node* TryAllocateRestArguments(Node* effect, Node* control,
911cb0ef41Sopenharmony_ci                                 FrameState frame_state, int start_index);
921cb0ef41Sopenharmony_ci  Node* TryAllocateAliasedArguments(Node* effect, Node* control,
931cb0ef41Sopenharmony_ci                                    FrameState frame_state, Node* context,
941cb0ef41Sopenharmony_ci                                    const SharedFunctionInfoRef& shared,
951cb0ef41Sopenharmony_ci                                    bool* has_aliased_arguments);
961cb0ef41Sopenharmony_ci  Node* TryAllocateAliasedArguments(Node* effect, Node* control, Node* context,
971cb0ef41Sopenharmony_ci                                    Node* arguments_length,
981cb0ef41Sopenharmony_ci                                    const SharedFunctionInfoRef& shared,
991cb0ef41Sopenharmony_ci                                    bool* has_aliased_arguments);
1001cb0ef41Sopenharmony_ci  base::Optional<Node*> TryAllocateFastLiteral(Node* effect, Node* control,
1011cb0ef41Sopenharmony_ci                                               JSObjectRef boilerplate,
1021cb0ef41Sopenharmony_ci                                               AllocationType allocation,
1031cb0ef41Sopenharmony_ci                                               int max_depth,
1041cb0ef41Sopenharmony_ci                                               int* max_properties);
1051cb0ef41Sopenharmony_ci  base::Optional<Node*> TryAllocateFastLiteralElements(
1061cb0ef41Sopenharmony_ci      Node* effect, Node* control, JSObjectRef boilerplate,
1071cb0ef41Sopenharmony_ci      AllocationType allocation, int max_depth, int* max_properties);
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci  Node* AllocateElements(Node* effect, Node* control,
1101cb0ef41Sopenharmony_ci                         ElementsKind elements_kind, int capacity,
1111cb0ef41Sopenharmony_ci                         AllocationType allocation);
1121cb0ef41Sopenharmony_ci  Node* AllocateElements(Node* effect, Node* control,
1131cb0ef41Sopenharmony_ci                         ElementsKind elements_kind, Node* capacity_and_length);
1141cb0ef41Sopenharmony_ci  Node* AllocateElements(Node* effect, Node* control,
1151cb0ef41Sopenharmony_ci                         ElementsKind elements_kind,
1161cb0ef41Sopenharmony_ci                         std::vector<Node*> const& values,
1171cb0ef41Sopenharmony_ci                         AllocationType allocation);
1181cb0ef41Sopenharmony_ci  Node* AllocateLiteralRegExp(Node* effect, Node* control,
1191cb0ef41Sopenharmony_ci                              RegExpBoilerplateDescriptionRef boilerplate);
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci  Factory* factory() const;
1221cb0ef41Sopenharmony_ci  Graph* graph() const;
1231cb0ef41Sopenharmony_ci  JSGraph* jsgraph() const { return jsgraph_; }
1241cb0ef41Sopenharmony_ci  NativeContextRef native_context() const;
1251cb0ef41Sopenharmony_ci  CommonOperatorBuilder* common() const;
1261cb0ef41Sopenharmony_ci  SimplifiedOperatorBuilder* simplified() const;
1271cb0ef41Sopenharmony_ci  CompilationDependencies* dependencies() const { return dependencies_; }
1281cb0ef41Sopenharmony_ci  JSHeapBroker* broker() const { return broker_; }
1291cb0ef41Sopenharmony_ci  Zone* zone() const { return zone_; }
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci  CompilationDependencies* const dependencies_;
1321cb0ef41Sopenharmony_ci  JSGraph* const jsgraph_;
1331cb0ef41Sopenharmony_ci  JSHeapBroker* const broker_;
1341cb0ef41Sopenharmony_ci  Zone* const zone_;
1351cb0ef41Sopenharmony_ci};
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci}  // namespace compiler
1381cb0ef41Sopenharmony_ci}  // namespace internal
1391cb0ef41Sopenharmony_ci}  // namespace v8
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci#endif  // V8_COMPILER_JS_CREATE_LOWERING_H_
142