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_REPRESENTATION_CHANGE_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_REPRESENTATION_CHANGE_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/compiler/feedback-source.h" 91cb0ef41Sopenharmony_ci#include "src/compiler/js-graph.h" 101cb0ef41Sopenharmony_ci#include "src/compiler/simplified-operator.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cinamespace v8 { 131cb0ef41Sopenharmony_cinamespace internal { 141cb0ef41Sopenharmony_cinamespace compiler { 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci// Foward declarations. 171cb0ef41Sopenharmony_ciclass SimplifiedLoweringVerifier; 181cb0ef41Sopenharmony_ciclass TypeCache; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cienum IdentifyZeros : uint8_t { kIdentifyZeros, kDistinguishZeros }; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciclass Truncation final { 231cb0ef41Sopenharmony_ci public: 241cb0ef41Sopenharmony_ci // Constructors. 251cb0ef41Sopenharmony_ci static Truncation None() { 261cb0ef41Sopenharmony_ci return Truncation(TruncationKind::kNone, kIdentifyZeros); 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci static Truncation Bool() { 291cb0ef41Sopenharmony_ci return Truncation(TruncationKind::kBool, kIdentifyZeros); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci static Truncation Word32() { 321cb0ef41Sopenharmony_ci return Truncation(TruncationKind::kWord32, kIdentifyZeros); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci static Truncation Word64() { 351cb0ef41Sopenharmony_ci return Truncation(TruncationKind::kWord64, kIdentifyZeros); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci static Truncation OddballAndBigIntToNumber( 381cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros = kDistinguishZeros) { 391cb0ef41Sopenharmony_ci return Truncation(TruncationKind::kOddballAndBigIntToNumber, 401cb0ef41Sopenharmony_ci identify_zeros); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci static Truncation Any(IdentifyZeros identify_zeros = kDistinguishZeros) { 431cb0ef41Sopenharmony_ci return Truncation(TruncationKind::kAny, identify_zeros); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci static Truncation Generalize(Truncation t1, Truncation t2) { 471cb0ef41Sopenharmony_ci return Truncation( 481cb0ef41Sopenharmony_ci Generalize(t1.kind(), t2.kind()), 491cb0ef41Sopenharmony_ci GeneralizeIdentifyZeros(t1.identify_zeros(), t2.identify_zeros())); 501cb0ef41Sopenharmony_ci } 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci // Queries. 531cb0ef41Sopenharmony_ci bool IsUnused() const { return kind_ == TruncationKind::kNone; } 541cb0ef41Sopenharmony_ci bool IsUsedAsBool() const { 551cb0ef41Sopenharmony_ci return LessGeneral(kind_, TruncationKind::kBool); 561cb0ef41Sopenharmony_ci } 571cb0ef41Sopenharmony_ci bool IsUsedAsWord32() const { 581cb0ef41Sopenharmony_ci return LessGeneral(kind_, TruncationKind::kWord32); 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci bool IsUsedAsWord64() const { 611cb0ef41Sopenharmony_ci return LessGeneral(kind_, TruncationKind::kWord64); 621cb0ef41Sopenharmony_ci } 631cb0ef41Sopenharmony_ci bool TruncatesOddballAndBigIntToNumber() const { 641cb0ef41Sopenharmony_ci return LessGeneral(kind_, TruncationKind::kOddballAndBigIntToNumber); 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci bool IdentifiesUndefinedAndZero() { 671cb0ef41Sopenharmony_ci return LessGeneral(kind_, TruncationKind::kWord32) || 681cb0ef41Sopenharmony_ci LessGeneral(kind_, TruncationKind::kBool); 691cb0ef41Sopenharmony_ci } 701cb0ef41Sopenharmony_ci bool IdentifiesZeroAndMinusZero() const { 711cb0ef41Sopenharmony_ci return identify_zeros() == kIdentifyZeros; 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci // Operators. 751cb0ef41Sopenharmony_ci bool operator==(Truncation other) const { 761cb0ef41Sopenharmony_ci return kind() == other.kind() && identify_zeros() == other.identify_zeros(); 771cb0ef41Sopenharmony_ci } 781cb0ef41Sopenharmony_ci bool operator!=(Truncation other) const { return !(*this == other); } 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci // Debug utilities. 811cb0ef41Sopenharmony_ci const char* description() const; 821cb0ef41Sopenharmony_ci bool IsLessGeneralThan(Truncation other) const { 831cb0ef41Sopenharmony_ci return LessGeneral(kind(), other.kind()) && 841cb0ef41Sopenharmony_ci LessGeneralIdentifyZeros(identify_zeros(), other.identify_zeros()); 851cb0ef41Sopenharmony_ci } 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros() const { return identify_zeros_; } 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ci private: 901cb0ef41Sopenharmony_ci enum class TruncationKind : uint8_t { 911cb0ef41Sopenharmony_ci kNone, 921cb0ef41Sopenharmony_ci kBool, 931cb0ef41Sopenharmony_ci kWord32, 941cb0ef41Sopenharmony_ci kWord64, 951cb0ef41Sopenharmony_ci kOddballAndBigIntToNumber, 961cb0ef41Sopenharmony_ci kAny 971cb0ef41Sopenharmony_ci }; 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ci explicit Truncation(TruncationKind kind, IdentifyZeros identify_zeros) 1001cb0ef41Sopenharmony_ci : kind_(kind), identify_zeros_(identify_zeros) {} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ci TruncationKind kind() const { return kind_; } 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci friend class SimplifiedLoweringVerifier; 1051cb0ef41Sopenharmony_ci TruncationKind kind_; 1061cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros_; 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci static TruncationKind Generalize(TruncationKind rep1, TruncationKind rep2); 1091cb0ef41Sopenharmony_ci static IdentifyZeros GeneralizeIdentifyZeros(IdentifyZeros i1, 1101cb0ef41Sopenharmony_ci IdentifyZeros i2); 1111cb0ef41Sopenharmony_ci static bool LessGeneral(TruncationKind rep1, TruncationKind rep2); 1121cb0ef41Sopenharmony_ci static bool LessGeneralIdentifyZeros(IdentifyZeros u1, IdentifyZeros u2); 1131cb0ef41Sopenharmony_ci}; 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_cienum class TypeCheckKind : uint8_t { 1161cb0ef41Sopenharmony_ci kNone, 1171cb0ef41Sopenharmony_ci kSignedSmall, 1181cb0ef41Sopenharmony_ci kSigned32, 1191cb0ef41Sopenharmony_ci kSigned64, 1201cb0ef41Sopenharmony_ci kNumber, 1211cb0ef41Sopenharmony_ci kNumberOrBoolean, 1221cb0ef41Sopenharmony_ci kNumberOrOddball, 1231cb0ef41Sopenharmony_ci kHeapObject, 1241cb0ef41Sopenharmony_ci kBigInt, 1251cb0ef41Sopenharmony_ci kArrayIndex 1261cb0ef41Sopenharmony_ci}; 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ciinline std::ostream& operator<<(std::ostream& os, TypeCheckKind type_check) { 1291cb0ef41Sopenharmony_ci switch (type_check) { 1301cb0ef41Sopenharmony_ci case TypeCheckKind::kNone: 1311cb0ef41Sopenharmony_ci return os << "None"; 1321cb0ef41Sopenharmony_ci case TypeCheckKind::kSignedSmall: 1331cb0ef41Sopenharmony_ci return os << "SignedSmall"; 1341cb0ef41Sopenharmony_ci case TypeCheckKind::kSigned32: 1351cb0ef41Sopenharmony_ci return os << "Signed32"; 1361cb0ef41Sopenharmony_ci case TypeCheckKind::kSigned64: 1371cb0ef41Sopenharmony_ci return os << "Signed64"; 1381cb0ef41Sopenharmony_ci case TypeCheckKind::kNumber: 1391cb0ef41Sopenharmony_ci return os << "Number"; 1401cb0ef41Sopenharmony_ci case TypeCheckKind::kNumberOrBoolean: 1411cb0ef41Sopenharmony_ci return os << "NumberOrBoolean"; 1421cb0ef41Sopenharmony_ci case TypeCheckKind::kNumberOrOddball: 1431cb0ef41Sopenharmony_ci return os << "NumberOrOddball"; 1441cb0ef41Sopenharmony_ci case TypeCheckKind::kHeapObject: 1451cb0ef41Sopenharmony_ci return os << "HeapObject"; 1461cb0ef41Sopenharmony_ci case TypeCheckKind::kBigInt: 1471cb0ef41Sopenharmony_ci return os << "BigInt"; 1481cb0ef41Sopenharmony_ci case TypeCheckKind::kArrayIndex: 1491cb0ef41Sopenharmony_ci return os << "ArrayIndex"; 1501cb0ef41Sopenharmony_ci } 1511cb0ef41Sopenharmony_ci UNREACHABLE(); 1521cb0ef41Sopenharmony_ci} 1531cb0ef41Sopenharmony_ci 1541cb0ef41Sopenharmony_ci// The {UseInfo} class is used to describe a use of an input of a node. 1551cb0ef41Sopenharmony_ci// 1561cb0ef41Sopenharmony_ci// This information is used in two different ways, based on the phase: 1571cb0ef41Sopenharmony_ci// 1581cb0ef41Sopenharmony_ci// 1. During propagation, the use info is used to inform the input node 1591cb0ef41Sopenharmony_ci// about what part of the input is used (we call this truncation) and what 1601cb0ef41Sopenharmony_ci// is the preferred representation. For conversions that will require 1611cb0ef41Sopenharmony_ci// checks, we also keep track of whether a minus zero check is needed. 1621cb0ef41Sopenharmony_ci// 1631cb0ef41Sopenharmony_ci// 2. During lowering, the use info is used to properly convert the input 1641cb0ef41Sopenharmony_ci// to the preferred representation. The preferred representation might be 1651cb0ef41Sopenharmony_ci// insufficient to do the conversion (e.g. word32->float64 conv), so we also 1661cb0ef41Sopenharmony_ci// need the signedness information to produce the correct value. 1671cb0ef41Sopenharmony_ci// Additionally, use info may contain {CheckParameters} which contains 1681cb0ef41Sopenharmony_ci// information for the deoptimizer such as a CallIC on which speculation 1691cb0ef41Sopenharmony_ci// should be disallowed if the check fails. 1701cb0ef41Sopenharmony_ciclass UseInfo { 1711cb0ef41Sopenharmony_ci public: 1721cb0ef41Sopenharmony_ci UseInfo(MachineRepresentation representation, Truncation truncation, 1731cb0ef41Sopenharmony_ci TypeCheckKind type_check = TypeCheckKind::kNone, 1741cb0ef41Sopenharmony_ci const FeedbackSource& feedback = FeedbackSource()) 1751cb0ef41Sopenharmony_ci : representation_(representation), 1761cb0ef41Sopenharmony_ci truncation_(truncation), 1771cb0ef41Sopenharmony_ci type_check_(type_check), 1781cb0ef41Sopenharmony_ci feedback_(feedback) {} 1791cb0ef41Sopenharmony_ci static UseInfo TruncatingWord32() { 1801cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord32, Truncation::Word32()); 1811cb0ef41Sopenharmony_ci } 1821cb0ef41Sopenharmony_ci static UseInfo CheckedBigIntTruncatingWord64(const FeedbackSource& feedback) { 1831cb0ef41Sopenharmony_ci // Note that Trunction::Word64() can safely use kIdentifyZero, because 1841cb0ef41Sopenharmony_ci // TypeCheckKind::kBigInt will make sure we deopt for anything other than 1851cb0ef41Sopenharmony_ci // type BigInt anyway. 1861cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord64, Truncation::Word64(), 1871cb0ef41Sopenharmony_ci TypeCheckKind::kBigInt, feedback); 1881cb0ef41Sopenharmony_ci } 1891cb0ef41Sopenharmony_ci static UseInfo Word64() { 1901cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord64, Truncation::Any()); 1911cb0ef41Sopenharmony_ci } 1921cb0ef41Sopenharmony_ci static UseInfo Word() { 1931cb0ef41Sopenharmony_ci return UseInfo(MachineType::PointerRepresentation(), Truncation::Any()); 1941cb0ef41Sopenharmony_ci } 1951cb0ef41Sopenharmony_ci static UseInfo Bool() { 1961cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kBit, Truncation::Bool()); 1971cb0ef41Sopenharmony_ci } 1981cb0ef41Sopenharmony_ci static UseInfo Float32() { 1991cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kFloat32, Truncation::Any()); 2001cb0ef41Sopenharmony_ci } 2011cb0ef41Sopenharmony_ci static UseInfo Float64() { 2021cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kFloat64, Truncation::Any()); 2031cb0ef41Sopenharmony_ci } 2041cb0ef41Sopenharmony_ci static UseInfo TruncatingFloat64( 2051cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros = kDistinguishZeros) { 2061cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kFloat64, 2071cb0ef41Sopenharmony_ci Truncation::OddballAndBigIntToNumber(identify_zeros)); 2081cb0ef41Sopenharmony_ci } 2091cb0ef41Sopenharmony_ci static UseInfo AnyTagged() { 2101cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kTagged, Truncation::Any()); 2111cb0ef41Sopenharmony_ci } 2121cb0ef41Sopenharmony_ci static UseInfo TaggedSigned() { 2131cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kTaggedSigned, Truncation::Any()); 2141cb0ef41Sopenharmony_ci } 2151cb0ef41Sopenharmony_ci static UseInfo TaggedPointer() { 2161cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kTaggedPointer, Truncation::Any()); 2171cb0ef41Sopenharmony_ci } 2181cb0ef41Sopenharmony_ci 2191cb0ef41Sopenharmony_ci // Possibly deoptimizing conversions. 2201cb0ef41Sopenharmony_ci static UseInfo CheckedTaggedAsArrayIndex(const FeedbackSource& feedback) { 2211cb0ef41Sopenharmony_ci return UseInfo(MachineType::PointerRepresentation(), 2221cb0ef41Sopenharmony_ci Truncation::Any(kIdentifyZeros), TypeCheckKind::kArrayIndex, 2231cb0ef41Sopenharmony_ci feedback); 2241cb0ef41Sopenharmony_ci } 2251cb0ef41Sopenharmony_ci static UseInfo CheckedHeapObjectAsTaggedPointer( 2261cb0ef41Sopenharmony_ci const FeedbackSource& feedback) { 2271cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kTaggedPointer, Truncation::Any(), 2281cb0ef41Sopenharmony_ci TypeCheckKind::kHeapObject, feedback); 2291cb0ef41Sopenharmony_ci } 2301cb0ef41Sopenharmony_ci 2311cb0ef41Sopenharmony_ci static UseInfo CheckedBigIntAsTaggedPointer(const FeedbackSource& feedback) { 2321cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kTaggedPointer, Truncation::Any(), 2331cb0ef41Sopenharmony_ci TypeCheckKind::kBigInt, feedback); 2341cb0ef41Sopenharmony_ci } 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_ci static UseInfo CheckedSignedSmallAsTaggedSigned( 2371cb0ef41Sopenharmony_ci const FeedbackSource& feedback, 2381cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros = kDistinguishZeros) { 2391cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kTaggedSigned, 2401cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), TypeCheckKind::kSignedSmall, 2411cb0ef41Sopenharmony_ci feedback); 2421cb0ef41Sopenharmony_ci } 2431cb0ef41Sopenharmony_ci static UseInfo CheckedSignedSmallAsWord32(IdentifyZeros identify_zeros, 2441cb0ef41Sopenharmony_ci const FeedbackSource& feedback) { 2451cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord32, 2461cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), TypeCheckKind::kSignedSmall, 2471cb0ef41Sopenharmony_ci feedback); 2481cb0ef41Sopenharmony_ci } 2491cb0ef41Sopenharmony_ci static UseInfo CheckedSigned32AsWord32(IdentifyZeros identify_zeros, 2501cb0ef41Sopenharmony_ci const FeedbackSource& feedback) { 2511cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord32, 2521cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), TypeCheckKind::kSigned32, 2531cb0ef41Sopenharmony_ci feedback); 2541cb0ef41Sopenharmony_ci } 2551cb0ef41Sopenharmony_ci static UseInfo CheckedSigned64AsWord64(IdentifyZeros identify_zeros, 2561cb0ef41Sopenharmony_ci const FeedbackSource& feedback) { 2571cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord64, 2581cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), TypeCheckKind::kSigned64, 2591cb0ef41Sopenharmony_ci feedback); 2601cb0ef41Sopenharmony_ci } 2611cb0ef41Sopenharmony_ci static UseInfo CheckedNumberAsFloat64(IdentifyZeros identify_zeros, 2621cb0ef41Sopenharmony_ci const FeedbackSource& feedback) { 2631cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kFloat64, 2641cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), TypeCheckKind::kNumber, 2651cb0ef41Sopenharmony_ci feedback); 2661cb0ef41Sopenharmony_ci } 2671cb0ef41Sopenharmony_ci static UseInfo CheckedNumberAsWord32(const FeedbackSource& feedback) { 2681cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord32, Truncation::Word32(), 2691cb0ef41Sopenharmony_ci TypeCheckKind::kNumber, feedback); 2701cb0ef41Sopenharmony_ci } 2711cb0ef41Sopenharmony_ci static UseInfo CheckedNumberOrBooleanAsFloat64( 2721cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros, const FeedbackSource& feedback) { 2731cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kFloat64, 2741cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), 2751cb0ef41Sopenharmony_ci TypeCheckKind::kNumberOrBoolean, feedback); 2761cb0ef41Sopenharmony_ci } 2771cb0ef41Sopenharmony_ci static UseInfo CheckedNumberOrOddballAsFloat64( 2781cb0ef41Sopenharmony_ci IdentifyZeros identify_zeros, const FeedbackSource& feedback) { 2791cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kFloat64, 2801cb0ef41Sopenharmony_ci Truncation::Any(identify_zeros), 2811cb0ef41Sopenharmony_ci TypeCheckKind::kNumberOrOddball, feedback); 2821cb0ef41Sopenharmony_ci } 2831cb0ef41Sopenharmony_ci static UseInfo CheckedNumberOrOddballAsWord32( 2841cb0ef41Sopenharmony_ci const FeedbackSource& feedback) { 2851cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kWord32, Truncation::Word32(), 2861cb0ef41Sopenharmony_ci TypeCheckKind::kNumberOrOddball, feedback); 2871cb0ef41Sopenharmony_ci } 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci // Undetermined representation. 2901cb0ef41Sopenharmony_ci static UseInfo Any() { 2911cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kNone, Truncation::Any()); 2921cb0ef41Sopenharmony_ci } 2931cb0ef41Sopenharmony_ci static UseInfo AnyTruncatingToBool() { 2941cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kNone, Truncation::Bool()); 2951cb0ef41Sopenharmony_ci } 2961cb0ef41Sopenharmony_ci 2971cb0ef41Sopenharmony_ci // Value not used. 2981cb0ef41Sopenharmony_ci static UseInfo None() { 2991cb0ef41Sopenharmony_ci return UseInfo(MachineRepresentation::kNone, Truncation::None()); 3001cb0ef41Sopenharmony_ci } 3011cb0ef41Sopenharmony_ci 3021cb0ef41Sopenharmony_ci MachineRepresentation representation() const { return representation_; } 3031cb0ef41Sopenharmony_ci Truncation truncation() const { return truncation_; } 3041cb0ef41Sopenharmony_ci TypeCheckKind type_check() const { return type_check_; } 3051cb0ef41Sopenharmony_ci CheckForMinusZeroMode minus_zero_check() const { 3061cb0ef41Sopenharmony_ci return truncation().IdentifiesZeroAndMinusZero() 3071cb0ef41Sopenharmony_ci ? CheckForMinusZeroMode::kDontCheckForMinusZero 3081cb0ef41Sopenharmony_ci : CheckForMinusZeroMode::kCheckForMinusZero; 3091cb0ef41Sopenharmony_ci } 3101cb0ef41Sopenharmony_ci const FeedbackSource& feedback() const { return feedback_; } 3111cb0ef41Sopenharmony_ci 3121cb0ef41Sopenharmony_ci private: 3131cb0ef41Sopenharmony_ci MachineRepresentation representation_; 3141cb0ef41Sopenharmony_ci Truncation truncation_; 3151cb0ef41Sopenharmony_ci TypeCheckKind type_check_; 3161cb0ef41Sopenharmony_ci FeedbackSource feedback_; 3171cb0ef41Sopenharmony_ci}; 3181cb0ef41Sopenharmony_ci 3191cb0ef41Sopenharmony_ci// Contains logic related to changing the representation of values for constants 3201cb0ef41Sopenharmony_ci// and other nodes, as well as lowering Simplified->Machine operators. 3211cb0ef41Sopenharmony_ci// Eagerly folds any representation changes for constants. 3221cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE RepresentationChanger final { 3231cb0ef41Sopenharmony_ci public: 3241cb0ef41Sopenharmony_ci RepresentationChanger(JSGraph* jsgraph, JSHeapBroker* broker, 3251cb0ef41Sopenharmony_ci SimplifiedLoweringVerifier* verifier); 3261cb0ef41Sopenharmony_ci 3271cb0ef41Sopenharmony_ci // Changes representation from {output_type} to {use_rep}. The {truncation} 3281cb0ef41Sopenharmony_ci // parameter is only used for checking - if the changer cannot figure 3291cb0ef41Sopenharmony_ci // out signedness for the word32->float64 conversion, then we check that the 3301cb0ef41Sopenharmony_ci // uses truncate to word32 (so they do not care about signedness). 3311cb0ef41Sopenharmony_ci Node* GetRepresentationFor(Node* node, MachineRepresentation output_rep, 3321cb0ef41Sopenharmony_ci Type output_type, Node* use_node, 3331cb0ef41Sopenharmony_ci UseInfo use_info); 3341cb0ef41Sopenharmony_ci const Operator* Int32OperatorFor(IrOpcode::Value opcode); 3351cb0ef41Sopenharmony_ci const Operator* Int32OverflowOperatorFor(IrOpcode::Value opcode); 3361cb0ef41Sopenharmony_ci const Operator* Int64OperatorFor(IrOpcode::Value opcode); 3371cb0ef41Sopenharmony_ci const Operator* TaggedSignedOperatorFor(IrOpcode::Value opcode); 3381cb0ef41Sopenharmony_ci const Operator* Uint32OperatorFor(IrOpcode::Value opcode); 3391cb0ef41Sopenharmony_ci const Operator* Uint32OverflowOperatorFor(IrOpcode::Value opcode); 3401cb0ef41Sopenharmony_ci const Operator* Float64OperatorFor(IrOpcode::Value opcode); 3411cb0ef41Sopenharmony_ci 3421cb0ef41Sopenharmony_ci MachineType TypeForBasePointer(const FieldAccess& access) { 3431cb0ef41Sopenharmony_ci return access.tag() != 0 ? MachineType::AnyTagged() 3441cb0ef41Sopenharmony_ci : MachineType::Pointer(); 3451cb0ef41Sopenharmony_ci } 3461cb0ef41Sopenharmony_ci 3471cb0ef41Sopenharmony_ci MachineType TypeForBasePointer(const ElementAccess& access) { 3481cb0ef41Sopenharmony_ci return access.tag() != 0 ? MachineType::AnyTagged() 3491cb0ef41Sopenharmony_ci : MachineType::Pointer(); 3501cb0ef41Sopenharmony_ci } 3511cb0ef41Sopenharmony_ci 3521cb0ef41Sopenharmony_ci bool verification_enabled() const { return verifier_ != nullptr; } 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_ci private: 3551cb0ef41Sopenharmony_ci TypeCache const* cache_; 3561cb0ef41Sopenharmony_ci JSGraph* jsgraph_; 3571cb0ef41Sopenharmony_ci JSHeapBroker* broker_; 3581cb0ef41Sopenharmony_ci SimplifiedLoweringVerifier* verifier_; 3591cb0ef41Sopenharmony_ci 3601cb0ef41Sopenharmony_ci friend class RepresentationChangerTester; // accesses the below fields. 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_ci bool testing_type_errors_; // If {true}, don't abort on a type error. 3631cb0ef41Sopenharmony_ci bool type_error_; // Set when a type error is detected. 3641cb0ef41Sopenharmony_ci 3651cb0ef41Sopenharmony_ci Node* GetTaggedSignedRepresentationFor(Node* node, 3661cb0ef41Sopenharmony_ci MachineRepresentation output_rep, 3671cb0ef41Sopenharmony_ci Type output_type, Node* use_node, 3681cb0ef41Sopenharmony_ci UseInfo use_info); 3691cb0ef41Sopenharmony_ci Node* GetTaggedPointerRepresentationFor(Node* node, 3701cb0ef41Sopenharmony_ci MachineRepresentation output_rep, 3711cb0ef41Sopenharmony_ci Type output_type, Node* use_node, 3721cb0ef41Sopenharmony_ci UseInfo use_info); 3731cb0ef41Sopenharmony_ci Node* GetTaggedRepresentationFor(Node* node, MachineRepresentation output_rep, 3741cb0ef41Sopenharmony_ci Type output_type, Truncation truncation); 3751cb0ef41Sopenharmony_ci Node* GetFloat32RepresentationFor(Node* node, 3761cb0ef41Sopenharmony_ci MachineRepresentation output_rep, 3771cb0ef41Sopenharmony_ci Type output_type, Truncation truncation); 3781cb0ef41Sopenharmony_ci Node* GetFloat64RepresentationFor(Node* node, 3791cb0ef41Sopenharmony_ci MachineRepresentation output_rep, 3801cb0ef41Sopenharmony_ci Type output_type, Node* use_node, 3811cb0ef41Sopenharmony_ci UseInfo use_info); 3821cb0ef41Sopenharmony_ci Node* GetWord32RepresentationFor(Node* node, MachineRepresentation output_rep, 3831cb0ef41Sopenharmony_ci Type output_type, Node* use_node, 3841cb0ef41Sopenharmony_ci UseInfo use_info); 3851cb0ef41Sopenharmony_ci Node* GetBitRepresentationFor(Node* node, MachineRepresentation output_rep, 3861cb0ef41Sopenharmony_ci Type output_type); 3871cb0ef41Sopenharmony_ci Node* GetWord64RepresentationFor(Node* node, MachineRepresentation output_rep, 3881cb0ef41Sopenharmony_ci Type output_type, Node* use_node, 3891cb0ef41Sopenharmony_ci UseInfo use_info); 3901cb0ef41Sopenharmony_ci Node* TypeError(Node* node, MachineRepresentation output_rep, 3911cb0ef41Sopenharmony_ci Type output_type, MachineRepresentation use); 3921cb0ef41Sopenharmony_ci Node* MakeTruncatedInt32Constant(double value); 3931cb0ef41Sopenharmony_ci Node* InsertChangeBitToTagged(Node* node); 3941cb0ef41Sopenharmony_ci Node* InsertChangeFloat32ToFloat64(Node* node); 3951cb0ef41Sopenharmony_ci Node* InsertChangeFloat64ToInt32(Node* node); 3961cb0ef41Sopenharmony_ci Node* InsertChangeFloat64ToUint32(Node* node); 3971cb0ef41Sopenharmony_ci Node* InsertChangeInt32ToFloat64(Node* node); 3981cb0ef41Sopenharmony_ci Node* InsertChangeTaggedSignedToInt32(Node* node); 3991cb0ef41Sopenharmony_ci Node* InsertChangeTaggedToFloat64(Node* node); 4001cb0ef41Sopenharmony_ci Node* InsertChangeUint32ToFloat64(Node* node); 4011cb0ef41Sopenharmony_ci Node* InsertCheckedFloat64ToInt32(Node* node, CheckForMinusZeroMode check, 4021cb0ef41Sopenharmony_ci const FeedbackSource& feedback, 4031cb0ef41Sopenharmony_ci Node* use_node); 4041cb0ef41Sopenharmony_ci Node* InsertConversion(Node* node, const Operator* op, Node* use_node); 4051cb0ef41Sopenharmony_ci Node* InsertTruncateInt64ToInt32(Node* node); 4061cb0ef41Sopenharmony_ci Node* InsertUnconditionalDeopt(Node* node, DeoptimizeReason reason, 4071cb0ef41Sopenharmony_ci const FeedbackSource& feedback = {}); 4081cb0ef41Sopenharmony_ci Node* InsertTypeOverrideForVerifier(const Type& type, Node* node); 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_ci JSGraph* jsgraph() const { return jsgraph_; } 4111cb0ef41Sopenharmony_ci Isolate* isolate() const; 4121cb0ef41Sopenharmony_ci Factory* factory() const { return isolate()->factory(); } 4131cb0ef41Sopenharmony_ci SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); } 4141cb0ef41Sopenharmony_ci MachineOperatorBuilder* machine() { return jsgraph()->machine(); } 4151cb0ef41Sopenharmony_ci}; 4161cb0ef41Sopenharmony_ci 4171cb0ef41Sopenharmony_ci} // namespace compiler 4181cb0ef41Sopenharmony_ci} // namespace internal 4191cb0ef41Sopenharmony_ci} // namespace v8 4201cb0ef41Sopenharmony_ci 4211cb0ef41Sopenharmony_ci#endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ 422