11cb0ef41Sopenharmony_ci// Copyright 2014 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_SIMPLIFIED_LOWERING_H_
61cb0ef41Sopenharmony_ci#define V8_COMPILER_SIMPLIFIED_LOWERING_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/compiler/js-graph.h"
91cb0ef41Sopenharmony_ci#include "src/compiler/machine-operator.h"
101cb0ef41Sopenharmony_ci#include "src/compiler/node-properties.h"
111cb0ef41Sopenharmony_ci#include "src/compiler/node.h"
121cb0ef41Sopenharmony_ci#include "src/compiler/simplified-operator.h"
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cinamespace v8 {
151cb0ef41Sopenharmony_cinamespace internal {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciclass TickCounter;
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cinamespace compiler {
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// Forward declarations.
221cb0ef41Sopenharmony_ciclass NodeOriginTable;
231cb0ef41Sopenharmony_ciclass ObserveNodeManager;
241cb0ef41Sopenharmony_ciclass RepresentationChanger;
251cb0ef41Sopenharmony_ciclass RepresentationSelector;
261cb0ef41Sopenharmony_ciclass SourcePositionTable;
271cb0ef41Sopenharmony_ciclass TypeCache;
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE SimplifiedLowering final {
301cb0ef41Sopenharmony_ci public:
311cb0ef41Sopenharmony_ci  SimplifiedLowering(JSGraph* jsgraph, JSHeapBroker* broker, Zone* zone,
321cb0ef41Sopenharmony_ci                     SourcePositionTable* source_position,
331cb0ef41Sopenharmony_ci                     NodeOriginTable* node_origins, TickCounter* tick_counter,
341cb0ef41Sopenharmony_ci                     Linkage* linkage, OptimizedCompilationInfo* info,
351cb0ef41Sopenharmony_ci                     ObserveNodeManager* observe_node_manager = nullptr);
361cb0ef41Sopenharmony_ci  ~SimplifiedLowering() = default;
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  void LowerAllNodes();
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  void DoMax(Node* node, Operator const* op, MachineRepresentation rep);
411cb0ef41Sopenharmony_ci  void DoMin(Node* node, Operator const* op, MachineRepresentation rep);
421cb0ef41Sopenharmony_ci  void DoJSToNumberOrNumericTruncatesToFloat64(
431cb0ef41Sopenharmony_ci      Node* node, RepresentationSelector* selector);
441cb0ef41Sopenharmony_ci  void DoJSToNumberOrNumericTruncatesToWord32(Node* node,
451cb0ef41Sopenharmony_ci                                              RepresentationSelector* selector);
461cb0ef41Sopenharmony_ci  void DoIntegral32ToBit(Node* node);
471cb0ef41Sopenharmony_ci  void DoOrderedNumberToBit(Node* node);
481cb0ef41Sopenharmony_ci  void DoNumberToBit(Node* node);
491cb0ef41Sopenharmony_ci  void DoIntegerToUint8Clamped(Node* node);
501cb0ef41Sopenharmony_ci  void DoNumberToUint8Clamped(Node* node);
511cb0ef41Sopenharmony_ci  void DoSigned32ToUint8Clamped(Node* node);
521cb0ef41Sopenharmony_ci  void DoUnsigned32ToUint8Clamped(Node* node);
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci private:
551cb0ef41Sopenharmony_ci  // The purpose of this nested class is to hide method
561cb0ef41Sopenharmony_ci  // v8::internal::compiler::NodeProperties::ChangeOp which should not be
571cb0ef41Sopenharmony_ci  // directly used by code in SimplifiedLowering.
581cb0ef41Sopenharmony_ci  // SimplifiedLowering code should call SimplifiedLowering::ChangeOp instead,
591cb0ef41Sopenharmony_ci  // in order to notify the changes to ObserveNodeManager and support the
601cb0ef41Sopenharmony_ci  // %ObserveNode intrinsic.
611cb0ef41Sopenharmony_ci  class NodeProperties : public compiler::NodeProperties {
621cb0ef41Sopenharmony_ci    static void ChangeOp(Node* node, const Operator* new_op) { UNREACHABLE(); }
631cb0ef41Sopenharmony_ci  };
641cb0ef41Sopenharmony_ci  void ChangeOp(Node* node, const Operator* new_op);
651cb0ef41Sopenharmony_ci
661cb0ef41Sopenharmony_ci  JSGraph* const jsgraph_;
671cb0ef41Sopenharmony_ci  JSHeapBroker* broker_;
681cb0ef41Sopenharmony_ci  Zone* const zone_;
691cb0ef41Sopenharmony_ci  TypeCache const* type_cache_;
701cb0ef41Sopenharmony_ci  SetOncePointer<Node> to_number_code_;
711cb0ef41Sopenharmony_ci  SetOncePointer<Node> to_number_convert_big_int_code_;
721cb0ef41Sopenharmony_ci  SetOncePointer<Node> to_numeric_code_;
731cb0ef41Sopenharmony_ci  SetOncePointer<Operator const> to_number_operator_;
741cb0ef41Sopenharmony_ci  SetOncePointer<Operator const> to_number_convert_big_int_operator_;
751cb0ef41Sopenharmony_ci  SetOncePointer<Operator const> to_numeric_operator_;
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  // TODO(danno): SimplifiedLowering shouldn't know anything about the source
781cb0ef41Sopenharmony_ci  // positions table, but must for now since there currently is no other way to
791cb0ef41Sopenharmony_ci  // pass down source position information to nodes created during
801cb0ef41Sopenharmony_ci  // lowering. Once this phase becomes a vanilla reducer, it should get source
811cb0ef41Sopenharmony_ci  // position information via the SourcePositionWrapper like all other reducers.
821cb0ef41Sopenharmony_ci  SourcePositionTable* source_positions_;
831cb0ef41Sopenharmony_ci  NodeOriginTable* node_origins_;
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci  TickCounter* const tick_counter_;
861cb0ef41Sopenharmony_ci  Linkage* const linkage_;
871cb0ef41Sopenharmony_ci  OptimizedCompilationInfo* info_;
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci  ObserveNodeManager* const observe_node_manager_;
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  Node* Float64Round(Node* const node);
921cb0ef41Sopenharmony_ci  Node* Float64Sign(Node* const node);
931cb0ef41Sopenharmony_ci  Node* Int32Abs(Node* const node);
941cb0ef41Sopenharmony_ci  Node* Int32Div(Node* const node);
951cb0ef41Sopenharmony_ci  Node* Int32Mod(Node* const node);
961cb0ef41Sopenharmony_ci  Node* Int32Sign(Node* const node);
971cb0ef41Sopenharmony_ci  Node* Uint32Div(Node* const node);
981cb0ef41Sopenharmony_ci  Node* Uint32Mod(Node* const node);
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci  Node* ToNumberCode();
1011cb0ef41Sopenharmony_ci  Node* ToNumberConvertBigIntCode();
1021cb0ef41Sopenharmony_ci  Node* ToNumericCode();
1031cb0ef41Sopenharmony_ci  Operator const* ToNumberOperator();
1041cb0ef41Sopenharmony_ci  Operator const* ToNumberConvertBigIntOperator();
1051cb0ef41Sopenharmony_ci  Operator const* ToNumericOperator();
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci  friend class RepresentationSelector;
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci  Isolate* isolate() { return jsgraph_->isolate(); }
1101cb0ef41Sopenharmony_ci  Zone* zone() { return jsgraph_->zone(); }
1111cb0ef41Sopenharmony_ci  JSGraph* jsgraph() { return jsgraph_; }
1121cb0ef41Sopenharmony_ci  Graph* graph() { return jsgraph()->graph(); }
1131cb0ef41Sopenharmony_ci  CommonOperatorBuilder* common() { return jsgraph()->common(); }
1141cb0ef41Sopenharmony_ci  MachineOperatorBuilder* machine() { return jsgraph()->machine(); }
1151cb0ef41Sopenharmony_ci  SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); }
1161cb0ef41Sopenharmony_ci  Linkage* linkage() { return linkage_; }
1171cb0ef41Sopenharmony_ci};
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_ci}  // namespace compiler
1201cb0ef41Sopenharmony_ci}  // namespace internal
1211cb0ef41Sopenharmony_ci}  // namespace v8
1221cb0ef41Sopenharmony_ci
1231cb0ef41Sopenharmony_ci#endif  // V8_COMPILER_SIMPLIFIED_LOWERING_H_
124