11cb0ef41Sopenharmony_ci// Copyright 2015 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#include "src/compiler/js-intrinsic-lowering.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include <stack>
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#include "src/codegen/code-factory.h"
101cb0ef41Sopenharmony_ci#include "src/compiler/access-builder.h"
111cb0ef41Sopenharmony_ci#include "src/compiler/js-graph.h"
121cb0ef41Sopenharmony_ci#include "src/compiler/js-heap-broker.h"
131cb0ef41Sopenharmony_ci#include "src/compiler/linkage.h"
141cb0ef41Sopenharmony_ci#include "src/compiler/node-matchers.h"
151cb0ef41Sopenharmony_ci#include "src/compiler/node-properties.h"
161cb0ef41Sopenharmony_ci#include "src/compiler/operator-properties.h"
171cb0ef41Sopenharmony_ci#include "src/logging/counters.h"
181cb0ef41Sopenharmony_ci#include "src/objects/js-generator.h"
191cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cinamespace v8 {
221cb0ef41Sopenharmony_cinamespace internal {
231cb0ef41Sopenharmony_cinamespace compiler {
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciJSIntrinsicLowering::JSIntrinsicLowering(Editor* editor, JSGraph* jsgraph,
261cb0ef41Sopenharmony_ci                                         JSHeapBroker* broker)
271cb0ef41Sopenharmony_ci    : AdvancedReducer(editor), jsgraph_(jsgraph), broker_(broker) {}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::Reduce(Node* node) {
301cb0ef41Sopenharmony_ci  if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange();
311cb0ef41Sopenharmony_ci  const Runtime::Function* const f =
321cb0ef41Sopenharmony_ci      Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id());
331cb0ef41Sopenharmony_ci  switch (f->function_id) {
341cb0ef41Sopenharmony_ci    case Runtime::kIsBeingInterpreted:
351cb0ef41Sopenharmony_ci      return ReduceIsBeingInterpreted(node);
361cb0ef41Sopenharmony_ci    case Runtime::kTurbofanStaticAssert:
371cb0ef41Sopenharmony_ci      return ReduceTurbofanStaticAssert(node);
381cb0ef41Sopenharmony_ci    case Runtime::kVerifyType:
391cb0ef41Sopenharmony_ci      return ReduceVerifyType(node);
401cb0ef41Sopenharmony_ci    default:
411cb0ef41Sopenharmony_ci      break;
421cb0ef41Sopenharmony_ci  }
431cb0ef41Sopenharmony_ci  if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange();
441cb0ef41Sopenharmony_ci  switch (f->function_id) {
451cb0ef41Sopenharmony_ci    case Runtime::kInlineCopyDataProperties:
461cb0ef41Sopenharmony_ci      return ReduceCopyDataProperties(node);
471cb0ef41Sopenharmony_ci    case Runtime::kInlineCopyDataPropertiesWithExcludedPropertiesOnStack:
481cb0ef41Sopenharmony_ci      return ReduceCopyDataPropertiesWithExcludedPropertiesOnStack(node);
491cb0ef41Sopenharmony_ci    case Runtime::kInlineCreateIterResultObject:
501cb0ef41Sopenharmony_ci      return ReduceCreateIterResultObject(node);
511cb0ef41Sopenharmony_ci    case Runtime::kInlineDeoptimizeNow:
521cb0ef41Sopenharmony_ci      return ReduceDeoptimizeNow(node);
531cb0ef41Sopenharmony_ci    case Runtime::kInlineGeneratorClose:
541cb0ef41Sopenharmony_ci      return ReduceGeneratorClose(node);
551cb0ef41Sopenharmony_ci    case Runtime::kInlineCreateJSGeneratorObject:
561cb0ef41Sopenharmony_ci      return ReduceCreateJSGeneratorObject(node);
571cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncFunctionAwaitCaught:
581cb0ef41Sopenharmony_ci      return ReduceAsyncFunctionAwaitCaught(node);
591cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncFunctionAwaitUncaught:
601cb0ef41Sopenharmony_ci      return ReduceAsyncFunctionAwaitUncaught(node);
611cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncFunctionEnter:
621cb0ef41Sopenharmony_ci      return ReduceAsyncFunctionEnter(node);
631cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncFunctionReject:
641cb0ef41Sopenharmony_ci      return ReduceAsyncFunctionReject(node);
651cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncFunctionResolve:
661cb0ef41Sopenharmony_ci      return ReduceAsyncFunctionResolve(node);
671cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncGeneratorAwaitCaught:
681cb0ef41Sopenharmony_ci      return ReduceAsyncGeneratorAwaitCaught(node);
691cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncGeneratorAwaitUncaught:
701cb0ef41Sopenharmony_ci      return ReduceAsyncGeneratorAwaitUncaught(node);
711cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncGeneratorReject:
721cb0ef41Sopenharmony_ci      return ReduceAsyncGeneratorReject(node);
731cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncGeneratorResolve:
741cb0ef41Sopenharmony_ci      return ReduceAsyncGeneratorResolve(node);
751cb0ef41Sopenharmony_ci    case Runtime::kInlineAsyncGeneratorYield:
761cb0ef41Sopenharmony_ci      return ReduceAsyncGeneratorYield(node);
771cb0ef41Sopenharmony_ci    case Runtime::kInlineGeneratorGetResumeMode:
781cb0ef41Sopenharmony_ci      return ReduceGeneratorGetResumeMode(node);
791cb0ef41Sopenharmony_ci    case Runtime::kInlineIncBlockCounter:
801cb0ef41Sopenharmony_ci      return ReduceIncBlockCounter(node);
811cb0ef41Sopenharmony_ci    case Runtime::kInlineGetImportMetaObject:
821cb0ef41Sopenharmony_ci      return ReduceGetImportMetaObject(node);
831cb0ef41Sopenharmony_ci    default:
841cb0ef41Sopenharmony_ci      break;
851cb0ef41Sopenharmony_ci  }
861cb0ef41Sopenharmony_ci  return NoChange();
871cb0ef41Sopenharmony_ci}
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceCopyDataProperties(Node* node) {
901cb0ef41Sopenharmony_ci  return Change(
911cb0ef41Sopenharmony_ci      node, Builtins::CallableFor(isolate(), Builtin::kCopyDataProperties), 0);
921cb0ef41Sopenharmony_ci}
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ciReduction
951cb0ef41Sopenharmony_ciJSIntrinsicLowering::ReduceCopyDataPropertiesWithExcludedPropertiesOnStack(
961cb0ef41Sopenharmony_ci    Node* node) {
971cb0ef41Sopenharmony_ci  int input_count =
981cb0ef41Sopenharmony_ci      static_cast<int>(CallRuntimeParametersOf(node->op()).arity());
991cb0ef41Sopenharmony_ci  CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState;
1001cb0ef41Sopenharmony_ci  auto callable = Builtins::CallableFor(
1011cb0ef41Sopenharmony_ci      isolate(), Builtin::kCopyDataPropertiesWithExcludedProperties);
1021cb0ef41Sopenharmony_ci  auto call_descriptor = Linkage::GetStubCallDescriptor(
1031cb0ef41Sopenharmony_ci      graph()->zone(), callable.descriptor(), input_count - 1, flags,
1041cb0ef41Sopenharmony_ci      node->op()->properties());
1051cb0ef41Sopenharmony_ci  node->InsertInput(graph()->zone(), 0,
1061cb0ef41Sopenharmony_ci                    jsgraph()->HeapConstant(callable.code()));
1071cb0ef41Sopenharmony_ci  node->InsertInput(graph()->zone(), 2,
1081cb0ef41Sopenharmony_ci                    jsgraph()->SmiConstant(input_count - 1));
1091cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, common()->Call(call_descriptor));
1101cb0ef41Sopenharmony_ci  return Changed(node);
1111cb0ef41Sopenharmony_ci}
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceCreateIterResultObject(Node* node) {
1141cb0ef41Sopenharmony_ci  Node* const value = NodeProperties::GetValueInput(node, 0);
1151cb0ef41Sopenharmony_ci  Node* const done = NodeProperties::GetValueInput(node, 1);
1161cb0ef41Sopenharmony_ci  Node* const context = NodeProperties::GetContextInput(node);
1171cb0ef41Sopenharmony_ci  Node* const effect = NodeProperties::GetEffectInput(node);
1181cb0ef41Sopenharmony_ci  return Change(node, javascript()->CreateIterResultObject(), value, done,
1191cb0ef41Sopenharmony_ci                context, effect);
1201cb0ef41Sopenharmony_ci}
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) {
1231cb0ef41Sopenharmony_ci  Node* const frame_state = NodeProperties::GetFrameStateInput(node);
1241cb0ef41Sopenharmony_ci  Node* const effect = NodeProperties::GetEffectInput(node);
1251cb0ef41Sopenharmony_ci  Node* const control = NodeProperties::GetControlInput(node);
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_ci  // TODO(bmeurer): Move MergeControlToEnd() to the AdvancedReducer.
1281cb0ef41Sopenharmony_ci  Node* deoptimize = graph()->NewNode(
1291cb0ef41Sopenharmony_ci      common()->Deoptimize(DeoptimizeReason::kDeoptimizeNow, FeedbackSource()),
1301cb0ef41Sopenharmony_ci      frame_state, effect, control);
1311cb0ef41Sopenharmony_ci  NodeProperties::MergeControlToEnd(graph(), common(), deoptimize);
1321cb0ef41Sopenharmony_ci  Revisit(graph()->end());
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ci  node->TrimInputCount(0);
1351cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, common()->Dead());
1361cb0ef41Sopenharmony_ci  return Changed(node);
1371cb0ef41Sopenharmony_ci}
1381cb0ef41Sopenharmony_ci
1391cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceCreateJSGeneratorObject(Node* node) {
1401cb0ef41Sopenharmony_ci  Node* const closure = NodeProperties::GetValueInput(node, 0);
1411cb0ef41Sopenharmony_ci  Node* const receiver = NodeProperties::GetValueInput(node, 1);
1421cb0ef41Sopenharmony_ci  Node* const context = NodeProperties::GetContextInput(node);
1431cb0ef41Sopenharmony_ci  Node* const effect = NodeProperties::GetEffectInput(node);
1441cb0ef41Sopenharmony_ci  Node* const control = NodeProperties::GetControlInput(node);
1451cb0ef41Sopenharmony_ci  Operator const* const op = javascript()->CreateGeneratorObject();
1461cb0ef41Sopenharmony_ci  Node* create_generator =
1471cb0ef41Sopenharmony_ci      graph()->NewNode(op, closure, receiver, context, effect, control);
1481cb0ef41Sopenharmony_ci  ReplaceWithValue(node, create_generator, create_generator);
1491cb0ef41Sopenharmony_ci  return Changed(create_generator);
1501cb0ef41Sopenharmony_ci}
1511cb0ef41Sopenharmony_ci
1521cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceGeneratorClose(Node* node) {
1531cb0ef41Sopenharmony_ci  Node* const generator = NodeProperties::GetValueInput(node, 0);
1541cb0ef41Sopenharmony_ci  Node* const effect = NodeProperties::GetEffectInput(node);
1551cb0ef41Sopenharmony_ci  Node* const control = NodeProperties::GetControlInput(node);
1561cb0ef41Sopenharmony_ci  Node* const closed = jsgraph()->Constant(JSGeneratorObject::kGeneratorClosed);
1571cb0ef41Sopenharmony_ci  Node* const undefined = jsgraph()->UndefinedConstant();
1581cb0ef41Sopenharmony_ci  Operator const* const op = simplified()->StoreField(
1591cb0ef41Sopenharmony_ci      AccessBuilder::ForJSGeneratorObjectContinuation());
1601cb0ef41Sopenharmony_ci
1611cb0ef41Sopenharmony_ci  ReplaceWithValue(node, undefined, node);
1621cb0ef41Sopenharmony_ci  NodeProperties::RemoveType(node);
1631cb0ef41Sopenharmony_ci  return Change(node, op, generator, closed, effect, control);
1641cb0ef41Sopenharmony_ci}
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncFunctionAwaitCaught(Node* node) {
1671cb0ef41Sopenharmony_ci  return Change(
1681cb0ef41Sopenharmony_ci      node,
1691cb0ef41Sopenharmony_ci      Builtins::CallableFor(isolate(), Builtin::kAsyncFunctionAwaitCaught), 0);
1701cb0ef41Sopenharmony_ci}
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncFunctionAwaitUncaught(Node* node) {
1731cb0ef41Sopenharmony_ci  return Change(
1741cb0ef41Sopenharmony_ci      node,
1751cb0ef41Sopenharmony_ci      Builtins::CallableFor(isolate(), Builtin::kAsyncFunctionAwaitUncaught),
1761cb0ef41Sopenharmony_ci      0);
1771cb0ef41Sopenharmony_ci}
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncFunctionEnter(Node* node) {
1801cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->AsyncFunctionEnter());
1811cb0ef41Sopenharmony_ci  return Changed(node);
1821cb0ef41Sopenharmony_ci}
1831cb0ef41Sopenharmony_ci
1841cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncFunctionReject(Node* node) {
1851cb0ef41Sopenharmony_ci  RelaxControls(node);
1861cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->AsyncFunctionReject());
1871cb0ef41Sopenharmony_ci  return Changed(node);
1881cb0ef41Sopenharmony_ci}
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncFunctionResolve(Node* node) {
1911cb0ef41Sopenharmony_ci  RelaxControls(node);
1921cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->AsyncFunctionResolve());
1931cb0ef41Sopenharmony_ci  return Changed(node);
1941cb0ef41Sopenharmony_ci}
1951cb0ef41Sopenharmony_ci
1961cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncGeneratorAwaitCaught(Node* node) {
1971cb0ef41Sopenharmony_ci  return Change(
1981cb0ef41Sopenharmony_ci      node,
1991cb0ef41Sopenharmony_ci      Builtins::CallableFor(isolate(), Builtin::kAsyncGeneratorAwaitCaught), 0);
2001cb0ef41Sopenharmony_ci}
2011cb0ef41Sopenharmony_ci
2021cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncGeneratorAwaitUncaught(Node* node) {
2031cb0ef41Sopenharmony_ci  return Change(
2041cb0ef41Sopenharmony_ci      node,
2051cb0ef41Sopenharmony_ci      Builtins::CallableFor(isolate(), Builtin::kAsyncGeneratorAwaitUncaught),
2061cb0ef41Sopenharmony_ci      0);
2071cb0ef41Sopenharmony_ci}
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncGeneratorReject(Node* node) {
2101cb0ef41Sopenharmony_ci  return Change(
2111cb0ef41Sopenharmony_ci      node, Builtins::CallableFor(isolate(), Builtin::kAsyncGeneratorReject),
2121cb0ef41Sopenharmony_ci      0);
2131cb0ef41Sopenharmony_ci}
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncGeneratorResolve(Node* node) {
2161cb0ef41Sopenharmony_ci  return Change(
2171cb0ef41Sopenharmony_ci      node, Builtins::CallableFor(isolate(), Builtin::kAsyncGeneratorResolve),
2181cb0ef41Sopenharmony_ci      0);
2191cb0ef41Sopenharmony_ci}
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceAsyncGeneratorYield(Node* node) {
2221cb0ef41Sopenharmony_ci  return Change(
2231cb0ef41Sopenharmony_ci      node, Builtins::CallableFor(isolate(), Builtin::kAsyncGeneratorYield), 0);
2241cb0ef41Sopenharmony_ci}
2251cb0ef41Sopenharmony_ci
2261cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceGeneratorGetResumeMode(Node* node) {
2271cb0ef41Sopenharmony_ci  Node* const generator = NodeProperties::GetValueInput(node, 0);
2281cb0ef41Sopenharmony_ci  Node* const effect = NodeProperties::GetEffectInput(node);
2291cb0ef41Sopenharmony_ci  Node* const control = NodeProperties::GetControlInput(node);
2301cb0ef41Sopenharmony_ci  Operator const* const op =
2311cb0ef41Sopenharmony_ci      simplified()->LoadField(AccessBuilder::ForJSGeneratorObjectResumeMode());
2321cb0ef41Sopenharmony_ci
2331cb0ef41Sopenharmony_ci  return Change(node, op, generator, effect, control);
2341cb0ef41Sopenharmony_ci}
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceIsInstanceType(
2371cb0ef41Sopenharmony_ci    Node* node, InstanceType instance_type) {
2381cb0ef41Sopenharmony_ci  // if (%_IsSmi(value)) {
2391cb0ef41Sopenharmony_ci  //   return false;
2401cb0ef41Sopenharmony_ci  // } else {
2411cb0ef41Sopenharmony_ci  //   return %_GetInstanceType(%_GetMap(value)) == instance_type;
2421cb0ef41Sopenharmony_ci  // }
2431cb0ef41Sopenharmony_ci  Node* value = NodeProperties::GetValueInput(node, 0);
2441cb0ef41Sopenharmony_ci  Node* effect = NodeProperties::GetEffectInput(node);
2451cb0ef41Sopenharmony_ci  Node* control = NodeProperties::GetControlInput(node);
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ci  Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), value);
2481cb0ef41Sopenharmony_ci  Node* branch = graph()->NewNode(common()->Branch(), check, control);
2491cb0ef41Sopenharmony_ci
2501cb0ef41Sopenharmony_ci  Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
2511cb0ef41Sopenharmony_ci  Node* etrue = effect;
2521cb0ef41Sopenharmony_ci  Node* vtrue = jsgraph()->FalseConstant();
2531cb0ef41Sopenharmony_ci
2541cb0ef41Sopenharmony_ci  Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
2551cb0ef41Sopenharmony_ci  Node* efalse = effect;
2561cb0ef41Sopenharmony_ci  Node* map = efalse =
2571cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()), value,
2581cb0ef41Sopenharmony_ci                       efalse, if_false);
2591cb0ef41Sopenharmony_ci  Node* map_instance_type = efalse = graph()->NewNode(
2601cb0ef41Sopenharmony_ci      simplified()->LoadField(AccessBuilder::ForMapInstanceType()), map, efalse,
2611cb0ef41Sopenharmony_ci      if_false);
2621cb0ef41Sopenharmony_ci  Node* vfalse =
2631cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->NumberEqual(), map_instance_type,
2641cb0ef41Sopenharmony_ci                       jsgraph()->Constant(instance_type));
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci  Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_ci  // Replace all effect uses of {node} with the {ephi}.
2691cb0ef41Sopenharmony_ci  Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge);
2701cb0ef41Sopenharmony_ci  ReplaceWithValue(node, node, ephi, merge);
2711cb0ef41Sopenharmony_ci
2721cb0ef41Sopenharmony_ci  // Turn the {node} into a Phi.
2731cb0ef41Sopenharmony_ci  return Change(node, common()->Phi(MachineRepresentation::kTagged, 2), vtrue,
2741cb0ef41Sopenharmony_ci                vfalse, merge);
2751cb0ef41Sopenharmony_ci}
2761cb0ef41Sopenharmony_ci
2771cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceIsJSReceiver(Node* node) {
2781cb0ef41Sopenharmony_ci  return Change(node, simplified()->ObjectIsReceiver());
2791cb0ef41Sopenharmony_ci}
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceTurbofanStaticAssert(Node* node) {
2821cb0ef41Sopenharmony_ci  if (FLAG_always_opt) {
2831cb0ef41Sopenharmony_ci    // Ignore static asserts, as we most likely won't have enough information
2841cb0ef41Sopenharmony_ci    RelaxEffectsAndControls(node);
2851cb0ef41Sopenharmony_ci  } else {
2861cb0ef41Sopenharmony_ci    Node* value = NodeProperties::GetValueInput(node, 0);
2871cb0ef41Sopenharmony_ci    Node* effect = NodeProperties::GetEffectInput(node);
2881cb0ef41Sopenharmony_ci    Node* assert = graph()->NewNode(
2891cb0ef41Sopenharmony_ci        common()->StaticAssert("%TurbofanStaticAssert"), value, effect);
2901cb0ef41Sopenharmony_ci    ReplaceWithValue(node, node, assert, nullptr);
2911cb0ef41Sopenharmony_ci  }
2921cb0ef41Sopenharmony_ci  return Changed(jsgraph_->UndefinedConstant());
2931cb0ef41Sopenharmony_ci}
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceVerifyType(Node* node) {
2961cb0ef41Sopenharmony_ci  return Change(node, simplified()->VerifyType());
2971cb0ef41Sopenharmony_ci}
2981cb0ef41Sopenharmony_ci
2991cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceIsBeingInterpreted(Node* node) {
3001cb0ef41Sopenharmony_ci  RelaxEffectsAndControls(node);
3011cb0ef41Sopenharmony_ci  return Changed(jsgraph_->FalseConstant());
3021cb0ef41Sopenharmony_ci}
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::Change(Node* node, const Operator* op) {
3051cb0ef41Sopenharmony_ci  // Replace all effect uses of {node} with the effect dependency.
3061cb0ef41Sopenharmony_ci  RelaxEffectsAndControls(node);
3071cb0ef41Sopenharmony_ci  // Remove the inputs corresponding to context, effect and control.
3081cb0ef41Sopenharmony_ci  NodeProperties::RemoveNonValueInputs(node);
3091cb0ef41Sopenharmony_ci  // Finally update the operator to the new one.
3101cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, op);
3111cb0ef41Sopenharmony_ci  return Changed(node);
3121cb0ef41Sopenharmony_ci}
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceToLength(Node* node) {
3151cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->ToLength());
3161cb0ef41Sopenharmony_ci  return Changed(node);
3171cb0ef41Sopenharmony_ci}
3181cb0ef41Sopenharmony_ci
3191cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceToObject(Node* node) {
3201cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->ToObject());
3211cb0ef41Sopenharmony_ci  return Changed(node);
3221cb0ef41Sopenharmony_ci}
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceToString(Node* node) {
3251cb0ef41Sopenharmony_ci  // ToString is unnecessary if the input is a string.
3261cb0ef41Sopenharmony_ci  HeapObjectMatcher m(NodeProperties::GetValueInput(node, 0));
3271cb0ef41Sopenharmony_ci  if (m.HasResolvedValue() && m.Ref(broker()).IsString()) {
3281cb0ef41Sopenharmony_ci    ReplaceWithValue(node, m.node());
3291cb0ef41Sopenharmony_ci    return Replace(m.node());
3301cb0ef41Sopenharmony_ci  }
3311cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->ToString());
3321cb0ef41Sopenharmony_ci  return Changed(node);
3331cb0ef41Sopenharmony_ci}
3341cb0ef41Sopenharmony_ci
3351cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceCall(Node* node) {
3361cb0ef41Sopenharmony_ci  int const arity =
3371cb0ef41Sopenharmony_ci      static_cast<int>(CallRuntimeParametersOf(node->op()).arity());
3381cb0ef41Sopenharmony_ci  static constexpr int kTargetAndReceiver = 2;
3391cb0ef41Sopenharmony_ci  STATIC_ASSERT(JSCallNode::kFeedbackVectorIsLastInput);
3401cb0ef41Sopenharmony_ci  Node* feedback = jsgraph()->UndefinedConstant();
3411cb0ef41Sopenharmony_ci  node->InsertInput(graph()->zone(), arity, feedback);
3421cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(
3431cb0ef41Sopenharmony_ci      node,
3441cb0ef41Sopenharmony_ci      javascript()->Call(JSCallNode::ArityForArgc(arity - kTargetAndReceiver)));
3451cb0ef41Sopenharmony_ci  return Changed(node);
3461cb0ef41Sopenharmony_ci}
3471cb0ef41Sopenharmony_ci
3481cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceIncBlockCounter(Node* node) {
3491cb0ef41Sopenharmony_ci  DCHECK(!Linkage::NeedsFrameStateInput(Runtime::kIncBlockCounter));
3501cb0ef41Sopenharmony_ci  DCHECK(!Linkage::NeedsFrameStateInput(Runtime::kInlineIncBlockCounter));
3511cb0ef41Sopenharmony_ci  return Change(node,
3521cb0ef41Sopenharmony_ci                Builtins::CallableFor(isolate(), Builtin::kIncBlockCounter), 0,
3531cb0ef41Sopenharmony_ci                kDoesNotNeedFrameState);
3541cb0ef41Sopenharmony_ci}
3551cb0ef41Sopenharmony_ci
3561cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::ReduceGetImportMetaObject(Node* node) {
3571cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, javascript()->GetImportMeta());
3581cb0ef41Sopenharmony_ci  return Changed(node);
3591cb0ef41Sopenharmony_ci}
3601cb0ef41Sopenharmony_ci
3611cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
3621cb0ef41Sopenharmony_ci                                      Node* b) {
3631cb0ef41Sopenharmony_ci  RelaxControls(node);
3641cb0ef41Sopenharmony_ci  node->ReplaceInput(0, a);
3651cb0ef41Sopenharmony_ci  node->ReplaceInput(1, b);
3661cb0ef41Sopenharmony_ci  node->TrimInputCount(2);
3671cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, op);
3681cb0ef41Sopenharmony_ci  return Changed(node);
3691cb0ef41Sopenharmony_ci}
3701cb0ef41Sopenharmony_ci
3711cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
3721cb0ef41Sopenharmony_ci                                      Node* b, Node* c) {
3731cb0ef41Sopenharmony_ci  RelaxControls(node);
3741cb0ef41Sopenharmony_ci  node->ReplaceInput(0, a);
3751cb0ef41Sopenharmony_ci  node->ReplaceInput(1, b);
3761cb0ef41Sopenharmony_ci  node->ReplaceInput(2, c);
3771cb0ef41Sopenharmony_ci  node->TrimInputCount(3);
3781cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, op);
3791cb0ef41Sopenharmony_ci  return Changed(node);
3801cb0ef41Sopenharmony_ci}
3811cb0ef41Sopenharmony_ci
3821cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::Change(Node* node, const Operator* op, Node* a,
3831cb0ef41Sopenharmony_ci                                      Node* b, Node* c, Node* d) {
3841cb0ef41Sopenharmony_ci  RelaxControls(node);
3851cb0ef41Sopenharmony_ci  node->ReplaceInput(0, a);
3861cb0ef41Sopenharmony_ci  node->ReplaceInput(1, b);
3871cb0ef41Sopenharmony_ci  node->ReplaceInput(2, c);
3881cb0ef41Sopenharmony_ci  node->ReplaceInput(3, d);
3891cb0ef41Sopenharmony_ci  node->TrimInputCount(4);
3901cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, op);
3911cb0ef41Sopenharmony_ci  return Changed(node);
3921cb0ef41Sopenharmony_ci}
3931cb0ef41Sopenharmony_ci
3941cb0ef41Sopenharmony_ciReduction JSIntrinsicLowering::Change(Node* node, Callable const& callable,
3951cb0ef41Sopenharmony_ci                                      int stack_parameter_count,
3961cb0ef41Sopenharmony_ci                                      enum FrameStateFlag frame_state_flag) {
3971cb0ef41Sopenharmony_ci  CallDescriptor::Flags flags = frame_state_flag == kNeedsFrameState
3981cb0ef41Sopenharmony_ci                                    ? CallDescriptor::kNeedsFrameState
3991cb0ef41Sopenharmony_ci                                    : CallDescriptor::kNoFlags;
4001cb0ef41Sopenharmony_ci  auto call_descriptor = Linkage::GetStubCallDescriptor(
4011cb0ef41Sopenharmony_ci      graph()->zone(), callable.descriptor(), stack_parameter_count, flags,
4021cb0ef41Sopenharmony_ci      node->op()->properties());
4031cb0ef41Sopenharmony_ci  node->InsertInput(graph()->zone(), 0,
4041cb0ef41Sopenharmony_ci                    jsgraph()->HeapConstant(callable.code()));
4051cb0ef41Sopenharmony_ci  NodeProperties::ChangeOp(node, common()->Call(call_descriptor));
4061cb0ef41Sopenharmony_ci  return Changed(node);
4071cb0ef41Sopenharmony_ci}
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ciGraph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); }
4101cb0ef41Sopenharmony_ci
4111cb0ef41Sopenharmony_ciIsolate* JSIntrinsicLowering::isolate() const { return jsgraph()->isolate(); }
4121cb0ef41Sopenharmony_ci
4131cb0ef41Sopenharmony_ciCommonOperatorBuilder* JSIntrinsicLowering::common() const {
4141cb0ef41Sopenharmony_ci  return jsgraph()->common();
4151cb0ef41Sopenharmony_ci}
4161cb0ef41Sopenharmony_ci
4171cb0ef41Sopenharmony_ciJSOperatorBuilder* JSIntrinsicLowering::javascript() const {
4181cb0ef41Sopenharmony_ci  return jsgraph_->javascript();
4191cb0ef41Sopenharmony_ci}
4201cb0ef41Sopenharmony_ci
4211cb0ef41Sopenharmony_ciSimplifiedOperatorBuilder* JSIntrinsicLowering::simplified() const {
4221cb0ef41Sopenharmony_ci  return jsgraph()->simplified();
4231cb0ef41Sopenharmony_ci}
4241cb0ef41Sopenharmony_ci
4251cb0ef41Sopenharmony_ci}  // namespace compiler
4261cb0ef41Sopenharmony_ci}  // namespace internal
4271cb0ef41Sopenharmony_ci}  // namespace v8
428