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/graph-assembler.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/codegen/code-factory.h"
81cb0ef41Sopenharmony_ci#include "src/compiler/access-builder.h"
91cb0ef41Sopenharmony_ci#include "src/compiler/graph-reducer.h"
101cb0ef41Sopenharmony_ci#include "src/compiler/linkage.h"
111cb0ef41Sopenharmony_ci#include "src/compiler/schedule.h"
121cb0ef41Sopenharmony_ci// For TNode types.
131cb0ef41Sopenharmony_ci#include "src/objects/heap-number.h"
141cb0ef41Sopenharmony_ci#include "src/objects/oddball.h"
151cb0ef41Sopenharmony_ci#include "src/objects/smi.h"
161cb0ef41Sopenharmony_ci#include "src/objects/string.h"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_cinamespace v8 {
191cb0ef41Sopenharmony_cinamespace internal {
201cb0ef41Sopenharmony_cinamespace compiler {
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciclass V8_NODISCARD GraphAssembler::BlockInlineReduction {
231cb0ef41Sopenharmony_ci public:
241cb0ef41Sopenharmony_ci  explicit BlockInlineReduction(GraphAssembler* gasm) : gasm_(gasm) {
251cb0ef41Sopenharmony_ci    DCHECK(!gasm_->inline_reductions_blocked_);
261cb0ef41Sopenharmony_ci    gasm_->inline_reductions_blocked_ = true;
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci  ~BlockInlineReduction() {
291cb0ef41Sopenharmony_ci    DCHECK(gasm_->inline_reductions_blocked_);
301cb0ef41Sopenharmony_ci    gasm_->inline_reductions_blocked_ = false;
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci private:
341cb0ef41Sopenharmony_ci  GraphAssembler* gasm_;
351cb0ef41Sopenharmony_ci};
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ciGraphAssembler::GraphAssembler(
381cb0ef41Sopenharmony_ci    MachineGraph* mcgraph, Zone* zone,
391cb0ef41Sopenharmony_ci    base::Optional<NodeChangedCallback> node_changed_callback,
401cb0ef41Sopenharmony_ci    bool mark_loop_exits)
411cb0ef41Sopenharmony_ci    : temp_zone_(zone),
421cb0ef41Sopenharmony_ci      mcgraph_(mcgraph),
431cb0ef41Sopenharmony_ci      effect_(nullptr),
441cb0ef41Sopenharmony_ci      control_(nullptr),
451cb0ef41Sopenharmony_ci      node_changed_callback_(node_changed_callback),
461cb0ef41Sopenharmony_ci      inline_reducers_(zone),
471cb0ef41Sopenharmony_ci      inline_reductions_blocked_(false),
481cb0ef41Sopenharmony_ci      loop_headers_(zone),
491cb0ef41Sopenharmony_ci      mark_loop_exits_(mark_loop_exits) {}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ciGraphAssembler::~GraphAssembler() { DCHECK_EQ(loop_nesting_level_, 0); }
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciNode* GraphAssembler::IntPtrConstant(intptr_t value) {
541cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->IntPtrConstant(value));
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ciNode* GraphAssembler::UintPtrConstant(uintptr_t value) {
581cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->UintPtrConstant(value));
591cb0ef41Sopenharmony_ci}
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ciNode* GraphAssembler::Int32Constant(int32_t value) {
621cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->Int32Constant(value));
631cb0ef41Sopenharmony_ci}
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ciNode* GraphAssembler::Uint32Constant(uint32_t value) {
661cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->Uint32Constant(value));
671cb0ef41Sopenharmony_ci}
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ciNode* GraphAssembler::Int64Constant(int64_t value) {
701cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->Int64Constant(value));
711cb0ef41Sopenharmony_ci}
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ciNode* GraphAssembler::Uint64Constant(uint64_t value) {
741cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->Uint64Constant(value));
751cb0ef41Sopenharmony_ci}
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciNode* GraphAssembler::UniqueIntPtrConstant(intptr_t value) {
781cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(
791cb0ef41Sopenharmony_ci      machine()->Is64()
801cb0ef41Sopenharmony_ci          ? common()->Int64Constant(value)
811cb0ef41Sopenharmony_ci          : common()->Int32Constant(static_cast<int32_t>(value))));
821cb0ef41Sopenharmony_ci}
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ciNode* JSGraphAssembler::SmiConstant(int32_t value) {
851cb0ef41Sopenharmony_ci  return AddClonedNode(jsgraph()->SmiConstant(value));
861cb0ef41Sopenharmony_ci}
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ciNode* GraphAssembler::Float64Constant(double value) {
891cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->Float64Constant(value));
901cb0ef41Sopenharmony_ci}
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ciTNode<HeapObject> JSGraphAssembler::HeapConstant(Handle<HeapObject> object) {
931cb0ef41Sopenharmony_ci  return TNode<HeapObject>::UncheckedCast(
941cb0ef41Sopenharmony_ci      AddClonedNode(jsgraph()->HeapConstant(object)));
951cb0ef41Sopenharmony_ci}
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciTNode<Object> JSGraphAssembler::Constant(const ObjectRef& ref) {
981cb0ef41Sopenharmony_ci  return TNode<Object>::UncheckedCast(AddClonedNode(jsgraph()->Constant(ref)));
991cb0ef41Sopenharmony_ci}
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::NumberConstant(double value) {
1021cb0ef41Sopenharmony_ci  return TNode<Number>::UncheckedCast(
1031cb0ef41Sopenharmony_ci      AddClonedNode(jsgraph()->Constant(value)));
1041cb0ef41Sopenharmony_ci}
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ciNode* GraphAssembler::ExternalConstant(ExternalReference ref) {
1071cb0ef41Sopenharmony_ci  return AddClonedNode(mcgraph()->ExternalConstant(ref));
1081cb0ef41Sopenharmony_ci}
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ciNode* GraphAssembler::Parameter(int index) {
1111cb0ef41Sopenharmony_ci  return AddNode(
1121cb0ef41Sopenharmony_ci      graph()->NewNode(common()->Parameter(index), graph()->start()));
1131cb0ef41Sopenharmony_ci}
1141cb0ef41Sopenharmony_ci
1151cb0ef41Sopenharmony_ciNode* JSGraphAssembler::CEntryStubConstant(int result_size) {
1161cb0ef41Sopenharmony_ci  return AddClonedNode(jsgraph()->CEntryStubConstant(result_size));
1171cb0ef41Sopenharmony_ci}
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ciNode* GraphAssembler::LoadFramePointer() {
1201cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->LoadFramePointer()));
1211cb0ef41Sopenharmony_ci}
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ciNode* GraphAssembler::LoadHeapNumberValue(Node* heap_number) {
1241cb0ef41Sopenharmony_ci  return Load(MachineType::Float64(), heap_number,
1251cb0ef41Sopenharmony_ci              IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag));
1261cb0ef41Sopenharmony_ci}
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ci#define SINGLETON_CONST_DEF(Name, Type)              \
1291cb0ef41Sopenharmony_ci  TNode<Type> JSGraphAssembler::Name##Constant() {   \
1301cb0ef41Sopenharmony_ci    return TNode<Type>::UncheckedCast(               \
1311cb0ef41Sopenharmony_ci        AddClonedNode(jsgraph()->Name##Constant())); \
1321cb0ef41Sopenharmony_ci  }
1331cb0ef41Sopenharmony_ciJSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_DEF)
1341cb0ef41Sopenharmony_ci#undef SINGLETON_CONST_DEF
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci#define SINGLETON_CONST_TEST_DEF(Name, ...)                        \
1371cb0ef41Sopenharmony_ci  TNode<Boolean> JSGraphAssembler::Is##Name(TNode<Object> value) { \
1381cb0ef41Sopenharmony_ci    return TNode<Boolean>::UncheckedCast(                          \
1391cb0ef41Sopenharmony_ci        ReferenceEqual(value, Name##Constant()));                  \
1401cb0ef41Sopenharmony_ci  }
1411cb0ef41Sopenharmony_ciJSGRAPH_SINGLETON_CONSTANT_LIST(SINGLETON_CONST_TEST_DEF)
1421cb0ef41Sopenharmony_ci#undef SINGLETON_CONST_TEST_DEF
1431cb0ef41Sopenharmony_ci
1441cb0ef41Sopenharmony_ci#define PURE_UNOP_DEF(Name)                                     \
1451cb0ef41Sopenharmony_ci  Node* GraphAssembler::Name(Node* input) {                     \
1461cb0ef41Sopenharmony_ci    return AddNode(graph()->NewNode(machine()->Name(), input)); \
1471cb0ef41Sopenharmony_ci  }
1481cb0ef41Sopenharmony_ciPURE_ASSEMBLER_MACH_UNOP_LIST(PURE_UNOP_DEF)
1491cb0ef41Sopenharmony_ci#undef PURE_UNOP_DEF
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci#define PURE_BINOP_DEF(Name)                                          \
1521cb0ef41Sopenharmony_ci  Node* GraphAssembler::Name(Node* left, Node* right) {               \
1531cb0ef41Sopenharmony_ci    return AddNode(graph()->NewNode(machine()->Name(), left, right)); \
1541cb0ef41Sopenharmony_ci  }
1551cb0ef41Sopenharmony_ciPURE_ASSEMBLER_MACH_BINOP_LIST(PURE_BINOP_DEF)
1561cb0ef41Sopenharmony_ci#undef PURE_BINOP_DEF
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci#define CHECKED_BINOP_DEF(Name)                                       \
1591cb0ef41Sopenharmony_ci  Node* GraphAssembler::Name(Node* left, Node* right) {               \
1601cb0ef41Sopenharmony_ci    return AddNode(                                                   \
1611cb0ef41Sopenharmony_ci        graph()->NewNode(machine()->Name(), left, right, control())); \
1621cb0ef41Sopenharmony_ci  }
1631cb0ef41Sopenharmony_ciCHECKED_ASSEMBLER_MACH_BINOP_LIST(CHECKED_BINOP_DEF)
1641cb0ef41Sopenharmony_ci#undef CHECKED_BINOP_DEF
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ciNode* GraphAssembler::IntPtrEqual(Node* left, Node* right) {
1671cb0ef41Sopenharmony_ci  return WordEqual(left, right);
1681cb0ef41Sopenharmony_ci}
1691cb0ef41Sopenharmony_ci
1701cb0ef41Sopenharmony_ciNode* GraphAssembler::TaggedEqual(Node* left, Node* right) {
1711cb0ef41Sopenharmony_ci  if (COMPRESS_POINTERS_BOOL) {
1721cb0ef41Sopenharmony_ci    return Word32Equal(left, right);
1731cb0ef41Sopenharmony_ci  } else {
1741cb0ef41Sopenharmony_ci    return WordEqual(left, right);
1751cb0ef41Sopenharmony_ci  }
1761cb0ef41Sopenharmony_ci}
1771cb0ef41Sopenharmony_ci
1781cb0ef41Sopenharmony_ciNode* GraphAssembler::SmiSub(Node* left, Node* right) {
1791cb0ef41Sopenharmony_ci  if (COMPRESS_POINTERS_BOOL) {
1801cb0ef41Sopenharmony_ci    return Int32Sub(left, right);
1811cb0ef41Sopenharmony_ci  } else {
1821cb0ef41Sopenharmony_ci    return IntSub(left, right);
1831cb0ef41Sopenharmony_ci  }
1841cb0ef41Sopenharmony_ci}
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ciNode* GraphAssembler::SmiLessThan(Node* left, Node* right) {
1871cb0ef41Sopenharmony_ci  if (COMPRESS_POINTERS_BOOL) {
1881cb0ef41Sopenharmony_ci    return Int32LessThan(left, right);
1891cb0ef41Sopenharmony_ci  } else {
1901cb0ef41Sopenharmony_ci    return IntLessThan(left, right);
1911cb0ef41Sopenharmony_ci  }
1921cb0ef41Sopenharmony_ci}
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ciNode* GraphAssembler::Float64RoundDown(Node* value) {
1951cb0ef41Sopenharmony_ci  CHECK(machine()->Float64RoundDown().IsSupported());
1961cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->Float64RoundDown().op(), value));
1971cb0ef41Sopenharmony_ci}
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ciNode* GraphAssembler::Float64RoundTruncate(Node* value) {
2001cb0ef41Sopenharmony_ci  CHECK(machine()->Float64RoundTruncate().IsSupported());
2011cb0ef41Sopenharmony_ci  return AddNode(
2021cb0ef41Sopenharmony_ci      graph()->NewNode(machine()->Float64RoundTruncate().op(), value));
2031cb0ef41Sopenharmony_ci}
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ciNode* GraphAssembler::TruncateFloat64ToInt64(Node* value, TruncateKind kind) {
2061cb0ef41Sopenharmony_ci  return AddNode(
2071cb0ef41Sopenharmony_ci      graph()->NewNode(machine()->TruncateFloat64ToInt64(kind), value));
2081cb0ef41Sopenharmony_ci}
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ciNode* GraphAssembler::Projection(int index, Node* value) {
2111cb0ef41Sopenharmony_ci  return AddNode(
2121cb0ef41Sopenharmony_ci      graph()->NewNode(common()->Projection(index), value, control()));
2131cb0ef41Sopenharmony_ci}
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ciNode* JSGraphAssembler::Allocate(AllocationType allocation, Node* size) {
2161cb0ef41Sopenharmony_ci  return AddNode(
2171cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->AllocateRaw(Type::Any(), allocation), size,
2181cb0ef41Sopenharmony_ci                       effect(), control()));
2191cb0ef41Sopenharmony_ci}
2201cb0ef41Sopenharmony_ci
2211cb0ef41Sopenharmony_ciNode* JSGraphAssembler::LoadField(FieldAccess const& access, Node* object) {
2221cb0ef41Sopenharmony_ci  Node* value = AddNode(graph()->NewNode(simplified()->LoadField(access),
2231cb0ef41Sopenharmony_ci                                         object, effect(), control()));
2241cb0ef41Sopenharmony_ci  return value;
2251cb0ef41Sopenharmony_ci}
2261cb0ef41Sopenharmony_ci
2271cb0ef41Sopenharmony_ciNode* JSGraphAssembler::LoadElement(ElementAccess const& access, Node* object,
2281cb0ef41Sopenharmony_ci                                    Node* index) {
2291cb0ef41Sopenharmony_ci  Node* value = AddNode(graph()->NewNode(simplified()->LoadElement(access),
2301cb0ef41Sopenharmony_ci                                         object, index, effect(), control()));
2311cb0ef41Sopenharmony_ci  return value;
2321cb0ef41Sopenharmony_ci}
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ciNode* JSGraphAssembler::StoreField(FieldAccess const& access, Node* object,
2351cb0ef41Sopenharmony_ci                                   Node* value) {
2361cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(simplified()->StoreField(access), object,
2371cb0ef41Sopenharmony_ci                                  value, effect(), control()));
2381cb0ef41Sopenharmony_ci}
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci#ifdef V8_MAP_PACKING
2411cb0ef41Sopenharmony_ciTNode<Map> GraphAssembler::UnpackMapWord(Node* map_word) {
2421cb0ef41Sopenharmony_ci  map_word = BitcastTaggedToWordForTagAndSmiBits(map_word);
2431cb0ef41Sopenharmony_ci  // TODO(wenyuzhao): Clear header metadata.
2441cb0ef41Sopenharmony_ci  Node* map = WordXor(map_word, IntPtrConstant(Internals::kMapWordXorMask));
2451cb0ef41Sopenharmony_ci  return TNode<Map>::UncheckedCast(BitcastWordToTagged(map));
2461cb0ef41Sopenharmony_ci}
2471cb0ef41Sopenharmony_ci
2481cb0ef41Sopenharmony_ciNode* GraphAssembler::PackMapWord(TNode<Map> map) {
2491cb0ef41Sopenharmony_ci  Node* map_word = BitcastTaggedToWordForTagAndSmiBits(map);
2501cb0ef41Sopenharmony_ci  Node* packed = WordXor(map_word, IntPtrConstant(Internals::kMapWordXorMask));
2511cb0ef41Sopenharmony_ci  return BitcastWordToTaggedSigned(packed);
2521cb0ef41Sopenharmony_ci}
2531cb0ef41Sopenharmony_ci#endif
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ciTNode<Map> GraphAssembler::LoadMap(Node* object) {
2561cb0ef41Sopenharmony_ci  Node* map_word = Load(MachineType::TaggedPointer(), object,
2571cb0ef41Sopenharmony_ci                        HeapObject::kMapOffset - kHeapObjectTag);
2581cb0ef41Sopenharmony_ci#ifdef V8_MAP_PACKING
2591cb0ef41Sopenharmony_ci  return UnpackMapWord(map_word);
2601cb0ef41Sopenharmony_ci#else
2611cb0ef41Sopenharmony_ci  return TNode<Map>::UncheckedCast(map_word);
2621cb0ef41Sopenharmony_ci#endif
2631cb0ef41Sopenharmony_ci}
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_ciNode* JSGraphAssembler::StoreElement(ElementAccess const& access, Node* object,
2661cb0ef41Sopenharmony_ci                                     Node* index, Node* value) {
2671cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(simplified()->StoreElement(access), object,
2681cb0ef41Sopenharmony_ci                                  index, value, effect(), control()));
2691cb0ef41Sopenharmony_ci}
2701cb0ef41Sopenharmony_ci
2711cb0ef41Sopenharmony_civoid JSGraphAssembler::TransitionAndStoreElement(MapRef double_map,
2721cb0ef41Sopenharmony_ci                                                 MapRef fast_map,
2731cb0ef41Sopenharmony_ci                                                 TNode<HeapObject> object,
2741cb0ef41Sopenharmony_ci                                                 TNode<Number> index,
2751cb0ef41Sopenharmony_ci                                                 TNode<Object> value) {
2761cb0ef41Sopenharmony_ci  AddNode(graph()->NewNode(simplified()->TransitionAndStoreElement(
2771cb0ef41Sopenharmony_ci                               double_map.object(), fast_map.object()),
2781cb0ef41Sopenharmony_ci                           object, index, value, effect(), control()));
2791cb0ef41Sopenharmony_ci}
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::StringLength(TNode<String> string) {
2821cb0ef41Sopenharmony_ci  return AddNode<Number>(
2831cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->StringLength(), string));
2841cb0ef41Sopenharmony_ci}
2851cb0ef41Sopenharmony_ci
2861cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::ReferenceEqual(TNode<Object> lhs,
2871cb0ef41Sopenharmony_ci                                                TNode<Object> rhs) {
2881cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
2891cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->ReferenceEqual(), lhs, rhs));
2901cb0ef41Sopenharmony_ci}
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::NumberEqual(TNode<Number> lhs,
2931cb0ef41Sopenharmony_ci                                             TNode<Number> rhs) {
2941cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
2951cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->NumberEqual(), lhs, rhs));
2961cb0ef41Sopenharmony_ci}
2971cb0ef41Sopenharmony_ci
2981cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::NumberMin(TNode<Number> lhs,
2991cb0ef41Sopenharmony_ci                                          TNode<Number> rhs) {
3001cb0ef41Sopenharmony_ci  return AddNode<Number>(graph()->NewNode(simplified()->NumberMin(), lhs, rhs));
3011cb0ef41Sopenharmony_ci}
3021cb0ef41Sopenharmony_ci
3031cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::NumberMax(TNode<Number> lhs,
3041cb0ef41Sopenharmony_ci                                          TNode<Number> rhs) {
3051cb0ef41Sopenharmony_ci  return AddNode<Number>(graph()->NewNode(simplified()->NumberMax(), lhs, rhs));
3061cb0ef41Sopenharmony_ci}
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::NumberAdd(TNode<Number> lhs,
3091cb0ef41Sopenharmony_ci                                          TNode<Number> rhs) {
3101cb0ef41Sopenharmony_ci  return AddNode<Number>(graph()->NewNode(simplified()->NumberAdd(), lhs, rhs));
3111cb0ef41Sopenharmony_ci}
3121cb0ef41Sopenharmony_ci
3131cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::NumberSubtract(TNode<Number> lhs,
3141cb0ef41Sopenharmony_ci                                               TNode<Number> rhs) {
3151cb0ef41Sopenharmony_ci  return AddNode<Number>(
3161cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->NumberSubtract(), lhs, rhs));
3171cb0ef41Sopenharmony_ci}
3181cb0ef41Sopenharmony_ci
3191cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::NumberLessThan(TNode<Number> lhs,
3201cb0ef41Sopenharmony_ci                                                TNode<Number> rhs) {
3211cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
3221cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->NumberLessThan(), lhs, rhs));
3231cb0ef41Sopenharmony_ci}
3241cb0ef41Sopenharmony_ci
3251cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::NumberLessThanOrEqual(TNode<Number> lhs,
3261cb0ef41Sopenharmony_ci                                                       TNode<Number> rhs) {
3271cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
3281cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->NumberLessThanOrEqual(), lhs, rhs));
3291cb0ef41Sopenharmony_ci}
3301cb0ef41Sopenharmony_ci
3311cb0ef41Sopenharmony_ciTNode<String> JSGraphAssembler::StringSubstring(TNode<String> string,
3321cb0ef41Sopenharmony_ci                                                TNode<Number> from,
3331cb0ef41Sopenharmony_ci                                                TNode<Number> to) {
3341cb0ef41Sopenharmony_ci  return AddNode<String>(graph()->NewNode(
3351cb0ef41Sopenharmony_ci      simplified()->StringSubstring(), string, from, to, effect(), control()));
3361cb0ef41Sopenharmony_ci}
3371cb0ef41Sopenharmony_ci
3381cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::ObjectIsCallable(TNode<Object> value) {
3391cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
3401cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->ObjectIsCallable(), value));
3411cb0ef41Sopenharmony_ci}
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::ObjectIsUndetectable(TNode<Object> value) {
3441cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
3451cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->ObjectIsUndetectable(), value));
3461cb0ef41Sopenharmony_ci}
3471cb0ef41Sopenharmony_ci
3481cb0ef41Sopenharmony_ciNode* JSGraphAssembler::CheckIf(Node* cond, DeoptimizeReason reason) {
3491cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(simplified()->CheckIf(reason), cond, effect(),
3501cb0ef41Sopenharmony_ci                                  control()));
3511cb0ef41Sopenharmony_ci}
3521cb0ef41Sopenharmony_ci
3531cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::NumberIsFloat64Hole(TNode<Number> value) {
3541cb0ef41Sopenharmony_ci  return AddNode<Boolean>(
3551cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->NumberIsFloat64Hole(), value));
3561cb0ef41Sopenharmony_ci}
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ciTNode<Boolean> JSGraphAssembler::ToBoolean(TNode<Object> value) {
3591cb0ef41Sopenharmony_ci  return AddNode<Boolean>(graph()->NewNode(simplified()->ToBoolean(), value));
3601cb0ef41Sopenharmony_ci}
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ciTNode<Object> JSGraphAssembler::ConvertTaggedHoleToUndefined(
3631cb0ef41Sopenharmony_ci    TNode<Object> value) {
3641cb0ef41Sopenharmony_ci  return AddNode<Object>(
3651cb0ef41Sopenharmony_ci      graph()->NewNode(simplified()->ConvertTaggedHoleToUndefined(), value));
3661cb0ef41Sopenharmony_ci}
3671cb0ef41Sopenharmony_ci
3681cb0ef41Sopenharmony_ciTNode<FixedArrayBase> JSGraphAssembler::MaybeGrowFastElements(
3691cb0ef41Sopenharmony_ci    ElementsKind kind, const FeedbackSource& feedback, TNode<JSArray> array,
3701cb0ef41Sopenharmony_ci    TNode<FixedArrayBase> elements, TNode<Number> new_length,
3711cb0ef41Sopenharmony_ci    TNode<Number> old_length) {
3721cb0ef41Sopenharmony_ci  GrowFastElementsMode mode = IsDoubleElementsKind(kind)
3731cb0ef41Sopenharmony_ci                                  ? GrowFastElementsMode::kDoubleElements
3741cb0ef41Sopenharmony_ci                                  : GrowFastElementsMode::kSmiOrObjectElements;
3751cb0ef41Sopenharmony_ci  return AddNode<FixedArrayBase>(graph()->NewNode(
3761cb0ef41Sopenharmony_ci      simplified()->MaybeGrowFastElements(mode, feedback), array, elements,
3771cb0ef41Sopenharmony_ci      new_length, old_length, effect(), control()));
3781cb0ef41Sopenharmony_ci}
3791cb0ef41Sopenharmony_ci
3801cb0ef41Sopenharmony_ciNode* JSGraphAssembler::StringCharCodeAt(TNode<String> string,
3811cb0ef41Sopenharmony_ci                                         TNode<Number> position) {
3821cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(simplified()->StringCharCodeAt(), string,
3831cb0ef41Sopenharmony_ci                                  position, effect(), control()));
3841cb0ef41Sopenharmony_ci}
3851cb0ef41Sopenharmony_ci
3861cb0ef41Sopenharmony_ciNode* GraphAssembler::TypeGuard(Type type, Node* value) {
3871cb0ef41Sopenharmony_ci  return AddNode(
3881cb0ef41Sopenharmony_ci      graph()->NewNode(common()->TypeGuard(type), value, effect(), control()));
3891cb0ef41Sopenharmony_ci}
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_ciNode* GraphAssembler::Checkpoint(FrameState frame_state) {
3921cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(common()->Checkpoint(), frame_state, effect(),
3931cb0ef41Sopenharmony_ci                                  control()));
3941cb0ef41Sopenharmony_ci}
3951cb0ef41Sopenharmony_ci
3961cb0ef41Sopenharmony_ciNode* GraphAssembler::DebugBreak() {
3971cb0ef41Sopenharmony_ci  return AddNode(
3981cb0ef41Sopenharmony_ci      graph()->NewNode(machine()->DebugBreak(), effect(), control()));
3991cb0ef41Sopenharmony_ci}
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ciNode* GraphAssembler::Unreachable(
4021cb0ef41Sopenharmony_ci    GraphAssemblerLabel<0u>* block_updater_successor) {
4031cb0ef41Sopenharmony_ci  Node* result = UnreachableWithoutConnectToEnd();
4041cb0ef41Sopenharmony_ci  ConnectUnreachableToEnd();
4051cb0ef41Sopenharmony_ci  InitializeEffectControl(nullptr, nullptr);
4061cb0ef41Sopenharmony_ci  return result;
4071cb0ef41Sopenharmony_ci}
4081cb0ef41Sopenharmony_ci
4091cb0ef41Sopenharmony_ciNode* GraphAssembler::UnreachableWithoutConnectToEnd() {
4101cb0ef41Sopenharmony_ci  return AddNode(
4111cb0ef41Sopenharmony_ci      graph()->NewNode(common()->Unreachable(), effect(), control()));
4121cb0ef41Sopenharmony_ci}
4131cb0ef41Sopenharmony_ci
4141cb0ef41Sopenharmony_ciTNode<RawPtrT> GraphAssembler::StackSlot(int size, int alignment) {
4151cb0ef41Sopenharmony_ci  return AddNode<RawPtrT>(
4161cb0ef41Sopenharmony_ci      graph()->NewNode(machine()->StackSlot(size, alignment)));
4171cb0ef41Sopenharmony_ci}
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ciNode* GraphAssembler::Store(StoreRepresentation rep, Node* object, Node* offset,
4201cb0ef41Sopenharmony_ci                            Node* value) {
4211cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->Store(rep), object, offset, value,
4221cb0ef41Sopenharmony_ci                                  effect(), control()));
4231cb0ef41Sopenharmony_ci}
4241cb0ef41Sopenharmony_ci
4251cb0ef41Sopenharmony_ciNode* GraphAssembler::Store(StoreRepresentation rep, Node* object, int offset,
4261cb0ef41Sopenharmony_ci                            Node* value) {
4271cb0ef41Sopenharmony_ci  return Store(rep, object, Int32Constant(offset), value);
4281cb0ef41Sopenharmony_ci}
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ciNode* GraphAssembler::Load(MachineType type, Node* object, Node* offset) {
4311cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->Load(type), object, offset,
4321cb0ef41Sopenharmony_ci                                  effect(), control()));
4331cb0ef41Sopenharmony_ci}
4341cb0ef41Sopenharmony_ci
4351cb0ef41Sopenharmony_ciNode* GraphAssembler::Load(MachineType type, Node* object, int offset) {
4361cb0ef41Sopenharmony_ci  return Load(type, object, Int32Constant(offset));
4371cb0ef41Sopenharmony_ci}
4381cb0ef41Sopenharmony_ci
4391cb0ef41Sopenharmony_ciNode* GraphAssembler::StoreUnaligned(MachineRepresentation rep, Node* object,
4401cb0ef41Sopenharmony_ci                                     Node* offset, Node* value) {
4411cb0ef41Sopenharmony_ci  Operator const* const op =
4421cb0ef41Sopenharmony_ci      (rep == MachineRepresentation::kWord8 ||
4431cb0ef41Sopenharmony_ci       machine()->UnalignedStoreSupported(rep))
4441cb0ef41Sopenharmony_ci          ? machine()->Store(StoreRepresentation(rep, kNoWriteBarrier))
4451cb0ef41Sopenharmony_ci          : machine()->UnalignedStore(rep);
4461cb0ef41Sopenharmony_ci  return AddNode(
4471cb0ef41Sopenharmony_ci      graph()->NewNode(op, object, offset, value, effect(), control()));
4481cb0ef41Sopenharmony_ci}
4491cb0ef41Sopenharmony_ci
4501cb0ef41Sopenharmony_ciNode* GraphAssembler::LoadUnaligned(MachineType type, Node* object,
4511cb0ef41Sopenharmony_ci                                    Node* offset) {
4521cb0ef41Sopenharmony_ci  Operator const* const op =
4531cb0ef41Sopenharmony_ci      (type.representation() == MachineRepresentation::kWord8 ||
4541cb0ef41Sopenharmony_ci       machine()->UnalignedLoadSupported(type.representation()))
4551cb0ef41Sopenharmony_ci          ? machine()->Load(type)
4561cb0ef41Sopenharmony_ci          : machine()->UnalignedLoad(type);
4571cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(op, object, offset, effect(), control()));
4581cb0ef41Sopenharmony_ci}
4591cb0ef41Sopenharmony_ci
4601cb0ef41Sopenharmony_ciNode* GraphAssembler::ProtectedStore(MachineRepresentation rep, Node* object,
4611cb0ef41Sopenharmony_ci                                     Node* offset, Node* value) {
4621cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->ProtectedStore(rep), object,
4631cb0ef41Sopenharmony_ci                                  offset, value, effect(), control()));
4641cb0ef41Sopenharmony_ci}
4651cb0ef41Sopenharmony_ci
4661cb0ef41Sopenharmony_ciNode* GraphAssembler::ProtectedLoad(MachineType type, Node* object,
4671cb0ef41Sopenharmony_ci                                    Node* offset) {
4681cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->ProtectedLoad(type), object,
4691cb0ef41Sopenharmony_ci                                  offset, effect(), control()));
4701cb0ef41Sopenharmony_ci}
4711cb0ef41Sopenharmony_ci
4721cb0ef41Sopenharmony_ciNode* GraphAssembler::Retain(Node* buffer) {
4731cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(common()->Retain(), buffer, effect()));
4741cb0ef41Sopenharmony_ci}
4751cb0ef41Sopenharmony_ci
4761cb0ef41Sopenharmony_ciNode* GraphAssembler::UnsafePointerAdd(Node* base, Node* external) {
4771cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->UnsafePointerAdd(), base, external,
4781cb0ef41Sopenharmony_ci                                  effect(), control()));
4791cb0ef41Sopenharmony_ci}
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ciTNode<Number> JSGraphAssembler::PlainPrimitiveToNumber(TNode<Object> value) {
4821cb0ef41Sopenharmony_ci  return AddNode<Number>(graph()->NewNode(
4831cb0ef41Sopenharmony_ci      PlainPrimitiveToNumberOperator(), PlainPrimitiveToNumberBuiltinConstant(),
4841cb0ef41Sopenharmony_ci      value, effect()));
4851cb0ef41Sopenharmony_ci}
4861cb0ef41Sopenharmony_ci
4871cb0ef41Sopenharmony_ciNode* GraphAssembler::BitcastWordToTaggedSigned(Node* value) {
4881cb0ef41Sopenharmony_ci  return AddNode(
4891cb0ef41Sopenharmony_ci      graph()->NewNode(machine()->BitcastWordToTaggedSigned(), value));
4901cb0ef41Sopenharmony_ci}
4911cb0ef41Sopenharmony_ci
4921cb0ef41Sopenharmony_ciNode* GraphAssembler::BitcastWordToTagged(Node* value) {
4931cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->BitcastWordToTagged(), value,
4941cb0ef41Sopenharmony_ci                                  effect(), control()));
4951cb0ef41Sopenharmony_ci}
4961cb0ef41Sopenharmony_ci
4971cb0ef41Sopenharmony_ciNode* GraphAssembler::BitcastTaggedToWord(Node* value) {
4981cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->BitcastTaggedToWord(), value,
4991cb0ef41Sopenharmony_ci                                  effect(), control()));
5001cb0ef41Sopenharmony_ci}
5011cb0ef41Sopenharmony_ci
5021cb0ef41Sopenharmony_ciNode* GraphAssembler::BitcastTaggedToWordForTagAndSmiBits(Node* value) {
5031cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(
5041cb0ef41Sopenharmony_ci      machine()->BitcastTaggedToWordForTagAndSmiBits(), value));
5051cb0ef41Sopenharmony_ci}
5061cb0ef41Sopenharmony_ci
5071cb0ef41Sopenharmony_ciNode* GraphAssembler::BitcastMaybeObjectToWord(Node* value) {
5081cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(machine()->BitcastMaybeObjectToWord(), value,
5091cb0ef41Sopenharmony_ci                                  effect(), control()));
5101cb0ef41Sopenharmony_ci}
5111cb0ef41Sopenharmony_ci
5121cb0ef41Sopenharmony_ciNode* GraphAssembler::DeoptimizeIf(DeoptimizeReason reason,
5131cb0ef41Sopenharmony_ci                                   FeedbackSource const& feedback,
5141cb0ef41Sopenharmony_ci                                   Node* condition, Node* frame_state) {
5151cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(common()->DeoptimizeIf(reason, feedback),
5161cb0ef41Sopenharmony_ci                                  condition, frame_state, effect(), control()));
5171cb0ef41Sopenharmony_ci}
5181cb0ef41Sopenharmony_ci
5191cb0ef41Sopenharmony_ciNode* GraphAssembler::DeoptimizeIfNot(DeoptimizeReason reason,
5201cb0ef41Sopenharmony_ci                                      FeedbackSource const& feedback,
5211cb0ef41Sopenharmony_ci                                      Node* condition, Node* frame_state) {
5221cb0ef41Sopenharmony_ci  return AddNode(graph()->NewNode(common()->DeoptimizeUnless(reason, feedback),
5231cb0ef41Sopenharmony_ci                                  condition, frame_state, effect(), control()));
5241cb0ef41Sopenharmony_ci}
5251cb0ef41Sopenharmony_ci
5261cb0ef41Sopenharmony_ciTNode<Object> GraphAssembler::Call(const CallDescriptor* call_descriptor,
5271cb0ef41Sopenharmony_ci                                   int inputs_size, Node** inputs) {
5281cb0ef41Sopenharmony_ci  return Call(common()->Call(call_descriptor), inputs_size, inputs);
5291cb0ef41Sopenharmony_ci}
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_ciTNode<Object> GraphAssembler::Call(const Operator* op, int inputs_size,
5321cb0ef41Sopenharmony_ci                                   Node** inputs) {
5331cb0ef41Sopenharmony_ci  DCHECK_EQ(IrOpcode::kCall, op->opcode());
5341cb0ef41Sopenharmony_ci  return AddNode<Object>(graph()->NewNode(op, inputs_size, inputs));
5351cb0ef41Sopenharmony_ci}
5361cb0ef41Sopenharmony_ci
5371cb0ef41Sopenharmony_civoid GraphAssembler::TailCall(const CallDescriptor* call_descriptor,
5381cb0ef41Sopenharmony_ci                              int inputs_size, Node** inputs) {
5391cb0ef41Sopenharmony_ci#ifdef DEBUG
5401cb0ef41Sopenharmony_ci  static constexpr int kTargetEffectControl = 3;
5411cb0ef41Sopenharmony_ci  DCHECK_EQ(inputs_size,
5421cb0ef41Sopenharmony_ci            call_descriptor->ParameterCount() + kTargetEffectControl);
5431cb0ef41Sopenharmony_ci#endif  // DEBUG
5441cb0ef41Sopenharmony_ci
5451cb0ef41Sopenharmony_ci  Node* node = AddNode(graph()->NewNode(common()->TailCall(call_descriptor),
5461cb0ef41Sopenharmony_ci                                        inputs_size, inputs));
5471cb0ef41Sopenharmony_ci
5481cb0ef41Sopenharmony_ci  // Unlike ConnectUnreachableToEnd, the TailCall node terminates a block; to
5491cb0ef41Sopenharmony_ci  // keep it live, it *must* be connected to End (also in Turboprop schedules).
5501cb0ef41Sopenharmony_ci  NodeProperties::MergeControlToEnd(graph(), common(), node);
5511cb0ef41Sopenharmony_ci
5521cb0ef41Sopenharmony_ci  // Setting effect, control to nullptr effectively terminates the current block
5531cb0ef41Sopenharmony_ci  // by disallowing the addition of new nodes until a new label has been bound.
5541cb0ef41Sopenharmony_ci  InitializeEffectControl(nullptr, nullptr);
5551cb0ef41Sopenharmony_ci}
5561cb0ef41Sopenharmony_ci
5571cb0ef41Sopenharmony_civoid GraphAssembler::BranchWithCriticalSafetyCheck(
5581cb0ef41Sopenharmony_ci    Node* condition, GraphAssemblerLabel<0u>* if_true,
5591cb0ef41Sopenharmony_ci    GraphAssemblerLabel<0u>* if_false) {
5601cb0ef41Sopenharmony_ci  BranchHint hint = BranchHint::kNone;
5611cb0ef41Sopenharmony_ci  if (if_true->IsDeferred() != if_false->IsDeferred()) {
5621cb0ef41Sopenharmony_ci    hint = if_false->IsDeferred() ? BranchHint::kTrue : BranchHint::kFalse;
5631cb0ef41Sopenharmony_ci  }
5641cb0ef41Sopenharmony_ci
5651cb0ef41Sopenharmony_ci  BranchImpl(condition, if_true, if_false, hint);
5661cb0ef41Sopenharmony_ci}
5671cb0ef41Sopenharmony_ci
5681cb0ef41Sopenharmony_civoid GraphAssembler::ConnectUnreachableToEnd() {
5691cb0ef41Sopenharmony_ci  DCHECK_EQ(effect()->opcode(), IrOpcode::kUnreachable);
5701cb0ef41Sopenharmony_ci  Node* throw_node = graph()->NewNode(common()->Throw(), effect(), control());
5711cb0ef41Sopenharmony_ci  NodeProperties::MergeControlToEnd(graph(), common(), throw_node);
5721cb0ef41Sopenharmony_ci  if (node_changed_callback_.has_value()) {
5731cb0ef41Sopenharmony_ci    (*node_changed_callback_)(graph()->end());
5741cb0ef41Sopenharmony_ci  }
5751cb0ef41Sopenharmony_ci  effect_ = control_ = mcgraph()->Dead();
5761cb0ef41Sopenharmony_ci}
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ciNode* GraphAssembler::AddClonedNode(Node* node) {
5791cb0ef41Sopenharmony_ci  DCHECK(node->op()->HasProperty(Operator::kPure));
5801cb0ef41Sopenharmony_ci  UpdateEffectControlWith(node);
5811cb0ef41Sopenharmony_ci  return node;
5821cb0ef41Sopenharmony_ci}
5831cb0ef41Sopenharmony_ci
5841cb0ef41Sopenharmony_ciNode* GraphAssembler::AddNode(Node* node) {
5851cb0ef41Sopenharmony_ci  if (!inline_reducers_.empty() && !inline_reductions_blocked_) {
5861cb0ef41Sopenharmony_ci    // Reducers may add new nodes to the graph using this graph assembler,
5871cb0ef41Sopenharmony_ci    // however they should never introduce nodes that need further reduction,
5881cb0ef41Sopenharmony_ci    // so block reduction
5891cb0ef41Sopenharmony_ci    BlockInlineReduction scope(this);
5901cb0ef41Sopenharmony_ci    Reduction reduction;
5911cb0ef41Sopenharmony_ci    for (auto reducer : inline_reducers_) {
5921cb0ef41Sopenharmony_ci      reduction = reducer->Reduce(node, nullptr);
5931cb0ef41Sopenharmony_ci      if (reduction.Changed()) break;
5941cb0ef41Sopenharmony_ci    }
5951cb0ef41Sopenharmony_ci    if (reduction.Changed()) {
5961cb0ef41Sopenharmony_ci      Node* replacement = reduction.replacement();
5971cb0ef41Sopenharmony_ci      if (replacement != node) {
5981cb0ef41Sopenharmony_ci        // Replace all uses of node and kill the node to make sure we don't
5991cb0ef41Sopenharmony_ci        // leave dangling dead uses.
6001cb0ef41Sopenharmony_ci        NodeProperties::ReplaceUses(node, replacement, effect(), control());
6011cb0ef41Sopenharmony_ci        node->Kill();
6021cb0ef41Sopenharmony_ci        return replacement;
6031cb0ef41Sopenharmony_ci      }
6041cb0ef41Sopenharmony_ci    }
6051cb0ef41Sopenharmony_ci  }
6061cb0ef41Sopenharmony_ci
6071cb0ef41Sopenharmony_ci  if (node->opcode() == IrOpcode::kTerminate) {
6081cb0ef41Sopenharmony_ci    return node;
6091cb0ef41Sopenharmony_ci  }
6101cb0ef41Sopenharmony_ci
6111cb0ef41Sopenharmony_ci  UpdateEffectControlWith(node);
6121cb0ef41Sopenharmony_ci  return node;
6131cb0ef41Sopenharmony_ci}
6141cb0ef41Sopenharmony_ci
6151cb0ef41Sopenharmony_civoid GraphAssembler::Reset() {
6161cb0ef41Sopenharmony_ci  effect_ = nullptr;
6171cb0ef41Sopenharmony_ci  control_ = nullptr;
6181cb0ef41Sopenharmony_ci}
6191cb0ef41Sopenharmony_ci
6201cb0ef41Sopenharmony_civoid GraphAssembler::InitializeEffectControl(Node* effect, Node* control) {
6211cb0ef41Sopenharmony_ci  effect_ = effect;
6221cb0ef41Sopenharmony_ci  control_ = control;
6231cb0ef41Sopenharmony_ci}
6241cb0ef41Sopenharmony_ci
6251cb0ef41Sopenharmony_ciOperator const* JSGraphAssembler::PlainPrimitiveToNumberOperator() {
6261cb0ef41Sopenharmony_ci  if (!to_number_operator_.is_set()) {
6271cb0ef41Sopenharmony_ci    Callable callable =
6281cb0ef41Sopenharmony_ci        Builtins::CallableFor(isolate(), Builtin::kPlainPrimitiveToNumber);
6291cb0ef41Sopenharmony_ci    CallDescriptor::Flags flags = CallDescriptor::kNoFlags;
6301cb0ef41Sopenharmony_ci    auto call_descriptor = Linkage::GetStubCallDescriptor(
6311cb0ef41Sopenharmony_ci        graph()->zone(), callable.descriptor(),
6321cb0ef41Sopenharmony_ci        callable.descriptor().GetStackParameterCount(), flags,
6331cb0ef41Sopenharmony_ci        Operator::kEliminatable);
6341cb0ef41Sopenharmony_ci    to_number_operator_.set(common()->Call(call_descriptor));
6351cb0ef41Sopenharmony_ci  }
6361cb0ef41Sopenharmony_ci  return to_number_operator_.get();
6371cb0ef41Sopenharmony_ci}
6381cb0ef41Sopenharmony_ci
6391cb0ef41Sopenharmony_ci}  // namespace compiler
6401cb0ef41Sopenharmony_ci}  // namespace internal
6411cb0ef41Sopenharmony_ci}  // namespace v8
642