v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
use-info.h
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_USE_INFO_H_
6#define V8_COMPILER_USE_INFO_H_
7
8#include "src/base/hashing.h"
12
13namespace v8::internal::compiler {
14
15// Enum to specify if `+0` and `-0` should be treated as the same value.
16enum IdentifyZeros : uint8_t {
17 // `+0` and `-0` should be treated as the same value.
19 // `+0` and `-0` should be treated as different values.
21};
22
23class Truncation;
24size_t hash_value(const Truncation&);
25
26class Truncation final {
27 public:
28 // Constructors.
49
55
56 // Queries.
57 bool IsUnused() const { return kind_ == TruncationKind::kNone; }
58 bool IsUsedAsBool() const {
60 }
61 bool IsUsedAsWord32() const {
63 }
64 bool IsUsedAsWord64() const {
65 DCHECK(Is64());
67 }
77 }
78
79 // Operators.
80 bool operator==(Truncation other) const {
81 return kind() == other.kind() && identify_zeros() == other.identify_zeros();
82 }
83 bool operator!=(Truncation other) const { return !(*this == other); }
84
85 // Debug utilities.
86 const char* description() const;
87 bool IsLessGeneralThan(Truncation other) const {
88 return LessGeneral(kind(), other.kind()) &&
89 LessGeneralIdentifyZeros(identify_zeros(), other.identify_zeros());
90 }
91
93
94 private:
95 enum class TruncationKind : uint8_t {
96 kNone,
97 kBool,
98 kWord32,
99 kWord64,
101 kAny
102 };
103
106
107 TruncationKind kind() const { return kind_; }
108
110 friend size_t hash_value(const Truncation&);
113
116 IdentifyZeros i2);
117 static bool LessGeneral(TruncationKind rep1, TruncationKind rep2);
119};
120
121inline size_t hash_value(const Truncation& truncation) {
122 return base::hash_combine(truncation.kind(), truncation.identify_zeros());
123}
124
125inline std::ostream& operator<<(std::ostream& os,
126 const Truncation& truncation) {
127 return os << truncation.description();
128}
129
130enum class TypeCheckKind : uint8_t {
131 kNone,
133 kSigned32,
134 kSigned64,
136 kNumber,
140 kBigInt,
141 kBigInt64,
143};
144
145inline std::ostream& operator<<(std::ostream& os, TypeCheckKind type_check) {
146 switch (type_check) {
148 return os << "None";
150 return os << "SignedSmall";
152 return os << "Signed32";
154 return os << "Signed64";
156 return os << "AdditiveSafeInteger";
158 return os << "Number";
160 return os << "NumberOrBoolean";
162 return os << "NumberOrOddball";
164 return os << "HeapObject";
166 return os << "BigInt";
168 return os << "BigInt64";
170 return os << "ArrayIndex";
171 }
172 UNREACHABLE();
173}
174
175// The {UseInfo} class is used to describe a use of an input of a node.
176//
177// This information is used in two different ways, based on the phase:
178//
179// 1. During propagation, the use info is used to inform the input node
180// about what part of the input is used (we call this truncation) and what
181// is the preferred representation. For conversions that will require
182// checks, we also keep track of whether a minus zero check is needed.
183//
184// 2. During lowering, the use info is used to properly convert the input
185// to the preferred representation. The preferred representation might be
186// insufficient to do the conversion (e.g. word32->float64 conv), so we also
187// need the signedness information to produce the correct value.
188// Additionally, use info may contain {CheckParameters} which contains
189// information for the deoptimizer such as a CallIC on which speculation
190// should be disallowed if the check fails.
191class UseInfo {
192 public:
203
208 DCHECK(Is64());
209 // Note that Trunction::Word64() can safely use kIdentifyZero, because
210 // TypeCheckKind::kBigInt will make sure we deopt for anything other than
211 // type BigInt anyway.
213 TypeCheckKind::kBigInt, feedback);
214 }
222 Truncation::Any(identify_zeros));
223 }
269
270 // Possibly deoptimizing conversions.
281
286
288 const FeedbackSource& feedback,
289 IdentifyZeros identify_zeros = kDistinguishZeros) {
292 feedback);
293 }
295 const FeedbackSource& feedback) {
298 feedback);
299 }
301 const FeedbackSource& feedback) {
304 feedback);
305 }
307 const FeedbackSource& feedback) {
310 feedback);
311 }
313 const FeedbackSource& feedback) {
316 feedback);
317 }
323 IdentifyZeros identify_zeros, const FeedbackSource& feedback) {
325 Truncation::Any(identify_zeros),
327 }
329 IdentifyZeros identify_zeros, const FeedbackSource& feedback) {
331 Truncation::Any(identify_zeros),
333 }
339
340 // Undetermined representation.
347
348 // Value not used.
352
361 const FeedbackSource& feedback() const { return feedback_; }
362
363 private:
368};
369
370inline bool operator==(const UseInfo& lhs, const UseInfo& rhs) {
371 return lhs.representation() == rhs.representation() &&
372 lhs.truncation() == rhs.truncation() &&
373 lhs.type_check() == rhs.type_check() &&
374 lhs.feedback() == rhs.feedback();
375}
376
377inline size_t hash_value(const UseInfo& use_info) {
378 return base::hash_combine(use_info.representation(), use_info.truncation(),
379 use_info.type_check(), use_info.feedback());
380}
381
382inline std::ostream& operator<<(std::ostream& os, const UseInfo& use_info) {
383 return os << use_info.representation() << ", " << use_info.truncation()
384 << ", " << use_info.type_check() << ", " << use_info.feedback();
385}
386
387} // namespace v8::internal::compiler
388
389#endif // V8_COMPILER_USE_INFO_H_
static constexpr MachineRepresentation PointerRepresentation()
static Truncation Any(IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:46
bool TruncatesOddballAndBigIntToNumber() const
Definition use-info.h:68
TruncationKind kind() const
Definition use-info.h:107
bool operator!=(Truncation other) const
Definition use-info.h:83
static bool LessGeneral(TruncationKind rep1, TruncationKind rep2)
static bool LessGeneralIdentifyZeros(IdentifyZeros u1, IdentifyZeros u2)
bool IsLessGeneralThan(Truncation other) const
Definition use-info.h:87
IdentifyZeros identify_zeros() const
Definition use-info.h:92
bool operator==(Truncation other) const
Definition use-info.h:80
friend size_t hash_value(const Truncation &)
Definition use-info.h:121
static Truncation Word32()
Definition use-info.h:35
bool IdentifiesZeroAndMinusZero() const
Definition use-info.h:75
static Truncation Generalize(Truncation t1, Truncation t2)
Definition use-info.h:50
static Truncation OddballAndBigIntToNumber(IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:41
Truncation(TruncationKind kind, IdentifyZeros identify_zeros)
Definition use-info.h:104
static Truncation Word64()
Definition use-info.h:38
static IdentifyZeros GeneralizeIdentifyZeros(IdentifyZeros i1, IdentifyZeros i2)
static UseInfo CheckedSignedSmallAsTaggedSigned(const FeedbackSource &feedback, IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:287
static UseInfo CheckedSignedSmallAsWord32(IdentifyZeros identify_zeros, const FeedbackSource &feedback)
Definition use-info.h:294
Truncation truncation() const
Definition use-info.h:354
static UseInfo TruncatingFloat64(IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:239
static UseInfo TaggedPointer()
Definition use-info.h:266
const FeedbackSource & feedback() const
Definition use-info.h:361
static UseInfo CheckedBigIntAsTaggedPointer(const FeedbackSource &feedback)
Definition use-info.h:282
static UseInfo CheckedNumberOrOddballAsFloat64(IdentifyZeros identify_zeros, const FeedbackSource &feedback)
Definition use-info.h:328
static UseInfo CheckedNumberAsFloat64(IdentifyZeros identify_zeros, const FeedbackSource &feedback)
Definition use-info.h:312
static UseInfo Float16RawBits()
Definition use-info.h:233
static UseInfo TruncatingFloat16RawBits(IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:244
TypeCheckKind type_check() const
Definition use-info.h:355
static UseInfo AnyTruncatingToBool()
Definition use-info.h:344
static UseInfo CheckedSafeIntAsWord64(const FeedbackSource &feedback)
Definition use-info.h:255
static UseInfo CheckedSigned32AsWord32(IdentifyZeros identify_zeros, const FeedbackSource &feedback)
Definition use-info.h:300
MachineRepresentation representation_
Definition use-info.h:364
static UseInfo TruncatingWord64()
Definition use-info.h:204
static UseInfo TaggedSigned()
Definition use-info.h:263
static UseInfo Word64(IdentifyZeros identify_zeros=kDistinguishZeros)
Definition use-info.h:220
static UseInfo CheckedNumberAsWord32(const FeedbackSource &feedback)
Definition use-info.h:318
UseInfo(MachineRepresentation representation, Truncation truncation, TypeCheckKind type_check=TypeCheckKind::kNone, const FeedbackSource &feedback=FeedbackSource())
Definition use-info.h:193
static UseInfo TruncatingWord32()
Definition use-info.h:200
static UseInfo CheckedBigIntTruncatingWord64(const FeedbackSource &feedback)
Definition use-info.h:207
static UseInfo CheckedBigInt64AsWord64(const FeedbackSource &feedback)
Definition use-info.h:215
static UseInfo CheckedSigned64AsWord64(IdentifyZeros identify_zeros, const FeedbackSource &feedback)
Definition use-info.h:306
static UseInfo CheckedNumberOrBooleanAsFloat64(IdentifyZeros identify_zeros, const FeedbackSource &feedback)
Definition use-info.h:322
static UseInfo CheckedHeapObjectAsTaggedPointer(const FeedbackSource &feedback)
Definition use-info.h:276
CheckForMinusZeroMode minus_zero_check() const
Definition use-info.h:356
MachineRepresentation representation() const
Definition use-info.h:353
static UseInfo CheckedNumberOrOddballAsWord32(const FeedbackSource &feedback)
Definition use-info.h:334
static UseInfo CheckedSafeIntTruncatingWord32(const FeedbackSource &feedback)
Definition use-info.h:249
static UseInfo CheckedTaggedAsArrayIndex(const FeedbackSource &feedback)
Definition use-info.h:271
V8_INLINE size_t hash_combine(size_t seed, size_t hash)
Definition hashing.h:77
size_t hash_value(const BranchParameters &p)
bool operator==(const BranchParameters &lhs, const BranchParameters &rhs)
std::ostream & operator<<(std::ostream &os, AccessMode access_mode)
constexpr bool Is64()
#define DCHECK(condition)
Definition logging.h:482