v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
tnode.h
Go to the documentation of this file.
1// Copyright 2015 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_CODEGEN_TNODE_H_
6#define V8_CODEGEN_TNODE_H_
7
8#include <type_traits>
9
10#include "include/v8config.h"
12#include "src/objects/tagged.h"
13
14namespace v8 {
15namespace internal {
16
17class HeapNumber;
18class BigInt;
19
20namespace compiler {
21
22class Node;
23
24} // namespace compiler
25
26struct UntaggedT {};
27
28struct IntegralT : UntaggedT {};
29
34
35struct RawPtrT : WordT {
37};
38
39// A RawPtrT that is guaranteed to point into the sandbox.
43
44template <class To>
45struct RawPtr : RawPtrT {};
46
51struct Int32T : Word32T {
53};
54struct Uint32T : Word32T {
56};
57struct Int16T : Int32T {
59};
63struct Int8T : Int16T {
65};
68};
69
74
78
79struct Int64T : Word64T {
81};
82struct Uint64T : Word64T {
84};
85
86struct IntPtrT : WordT {
88};
89struct UintPtrT : WordT {
91};
92
96
100
104
108
109#ifdef V8_ENABLE_SANDBOX
110struct ExternalPointerT : Uint32T {
111 static constexpr MachineType kMachineType = MachineType::Uint32();
112};
113#else
117#endif
118
119#ifdef V8_COMPRESS_POINTERS
120struct CppHeapPointerT : Uint32T {
121 static constexpr MachineType kMachineType = MachineType::Uint32();
122};
123#else // !V8_COMPRESS_POINTERS
127#endif // !V8_COMPRESS_POINTERS
128
132
138
144
145#ifdef V8_COMPRESS_POINTERS
146using TaggedT = Int32T;
147#else
149#endif
150
151#ifdef V8_ENABLE_SANDBOX
153#else
155#endif
156
157// Result of a comparison operation.
158struct BoolT : Word32T {
160};
161
162// Value type of a Turbofan node with two results.
163template <class T1, class T2>
164struct PairT {};
165
171
172struct I8x16T : Simd128T {};
173struct I16x8T : Simd128T {};
174struct I32x2T : Simd128T {};
175
177 MachineType type2) {
178 return (type1 == type2) ? type1
179 : ((type1.IsTagged() && type2.IsTagged())
182}
183
184template <class Type, class Enable = void>
186 static constexpr MachineType value = Type::kMachineType;
187};
188
189template <class Type, class Enable>
191
192template <>
194 static constexpr MachineType value = MachineType::AnyTagged();
195};
196template <>
198 static constexpr MachineType value = MachineType::AnyTagged();
199};
200template <>
202 // TODO(leszeks): Can this be TaggedPointer?
203 static constexpr MachineType value = MachineType::AnyTagged();
204};
205template <>
207 static constexpr MachineType value = MachineType::TaggedPointer();
208};
209template <>
211 static constexpr MachineType value = MachineType::TaggedSigned();
212};
213template <>
215 static constexpr MachineType value = MachineType::Pointer();
216};
217template <class HeapObjectSubtype>
219 HeapObjectSubtype,
220 std::enable_if_t<std::is_base_of_v<HeapObject, HeapObjectSubtype> ||
221 std::is_base_of_v<HeapObjectLayout, HeapObjectSubtype>>> {
222 static constexpr MachineType value = MachineType::TaggedPointer();
223};
224
225template <class HeapObjectSubtype>
226constexpr MachineType MachineTypeOf<
227 HeapObjectSubtype,
228 std::enable_if_t<std::is_base_of_v<HeapObject, HeapObjectSubtype> ||
229 std::is_base_of_v<HeapObjectLayout, HeapObjectSubtype>>>::
230 value;
231
232template <>
234 static constexpr MachineType value = MachineType::Pointer();
235};
236
237template <class T>
239 static constexpr MachineType value = MachineTypeOf<T>::value;
240};
241
242template <class T, class... Ts>
243struct MachineTypeOf<Union<T, Ts...>> {
244 static constexpr MachineType value = CommonMachineType(
246
247 static_assert(value.representation() != MachineRepresentation::kNone,
248 "no common representation");
249};
250
251// Special case for Union<HeapObject,TaggedIndex>, which torque uses for
252// TaggedZeroPattern and can be treated as an AnyTagged
253template <>
257
258template <class Type, class Enable = void>
260 static const MachineRepresentation value = Type::kMachineRepresentation;
261};
262// If T defines kMachineType, then we take the machine representation from
263// there.
264template <class T>
265struct MachineRepresentationOf<T, std::void_t<decltype(T::kMachineType)>> {
266 static constexpr MachineRepresentation value =
267 T::kMachineType.representation();
268};
269template <class T>
270struct MachineRepresentationOf<T, std::enable_if_t<is_taggable_v<T>>> {
271 static constexpr MachineRepresentation value =
272 MachineTypeOf<T>::value.representation();
273};
274template <>
279
280template <typename T>
284
285template <class T>
287 std::is_base_of<Word32T, T>::value ? MachineRepresentation::kWord32
289
290template <class T>
292 static const bool value = is_taggable_v<T> ||
293 std::is_base_of<UntaggedT, T>::value ||
294 std::is_same<ExternalReference, T>::value;
295 static const bool is_tagged = is_taggable_v<T>;
296};
297
298template <class T1, class T2>
300 static const bool value =
302 static const bool is_tagged = false;
303};
304
305template <class... T>
307 static const bool is_tagged = (is_valid_type_tag<T>::is_tagged && ...);
308 static const bool value = is_tagged;
309
310 static_assert(is_tagged, "union types are only possible for tagged values");
311};
312
315
316// A pointer to a builtin function, used by Torque's function pointers.
318
319template <>
321 static const bool value = true;
322};
323template <>
325 static const bool value = true;
326};
327
328template <class T, class U>
332template <class U>
336template <class U>
340template <class U>
344template <class U>
348template <class U>
352template <class U>
356template <class U>
360template <class U>
364template <class... Ts, class U>
366 static const bool value =
367 std::disjunction_v<types_have_common_values<Ts, U>...>;
368};
369template <class T, class... Us>
371 static const bool value =
372 std::disjunction_v<types_have_common_values<T, Us>...>;
373};
374template <class... Ts, class... Us>
375struct types_have_common_values<Union<Ts...>, Union<Us...>> {
376 static const bool value =
377 std::disjunction_v<types_have_common_values<Ts, Union<Us...>>...>;
378};
379
380// TNode<T> is an SSA value with the static type tag T, which is one of the
381// following:
382// - MaybeObject> represents the type of all tagged values, including weak
383// pointers.
384// - a subclass of internal::Object represents a non-weak tagged type.
385// - a subclass of internal::UntaggedT represents an untagged type
386// - ExternalReference
387// - PairT<T1, T2> for an operation returning two values, with types T1
388// and T2
389// - UnionOf<T1, T2, ...> represents a value of one of types T1, T2, etc.
390template <class T>
391class TNode {
392 public:
393 template <class U>
396 : node_(other.node_) {
398 }
399
400 TNode(const TNode& other) V8_NOEXCEPT : node_(other.node_) {}
401 TNode() : node_(nullptr) {}
402
404 DCHECK_NOT_NULL(other.node_);
405 node_ = other.node_;
406 return *this;
407 }
408
409 operator compiler::Node*() const { return node_; }
410
411 explicit operator bool() const { return node_ != nullptr; }
412
413 static TNode UncheckedCast(compiler::Node* node) { return TNode(node); }
414
415 protected:
416 template <typename U>
417 friend class TNode;
418
419 explicit TNode(compiler::Node* node) : node_(node) { LazyTemplateChecks(); }
420 // These checks shouldn't be checked before TNode is actually used.
421 void LazyTemplateChecks() const {
422 static_assert(is_valid_type_tag<T>::value, "invalid type tag");
423 }
424
426};
427
428template <class T>
429class TNode<Tagged<T>> {
430 static_assert(!std::is_same_v<T, T>,
431 "Don't write TNode<Tagged<T>>, just write TNode<T> directly.");
432};
433
434// SloppyTNode<T> is a variant of TNode<T> and allows implicit casts from
435// Node*. It is intended for function arguments as long as some call sites
436// still use untyped Node* arguments.
437// TODO(turbofan): Delete this class once transition is finished.
438template <class T>
439class SloppyTNode : public TNode<T> {
440 public:
441 SloppyTNode(compiler::Node* node) // NOLINT(runtime/explicit)
442 : TNode<T>(node) {}
443 template <class U>
444 SloppyTNode(const TNode<U>& other) V8_NOEXCEPT // NOLINT(runtime/explicit)
446 : TNode<T>(other) {}
447};
448
449} // namespace internal
450} // namespace v8
451
452#endif // V8_CODEGEN_TNODE_H_
#define T
constexpr bool IsTagged() const
static constexpr MachineType Float64()
static constexpr MachineType Pointer()
static constexpr MachineType Uint8()
static constexpr MachineType Int32()
static constexpr MachineType Simd128()
static constexpr MachineType AnyTagged()
static constexpr MachineType Uint64()
static constexpr MachineType Uint32()
static constexpr MachineType SandboxedPointer()
static constexpr MachineType TaggedSigned()
static constexpr MachineType Uint16()
static constexpr MachineType Int16()
static constexpr MachineType Float32()
static constexpr MachineType Int64()
static constexpr MachineType None()
static constexpr MachineType TaggedPointer()
static constexpr MachineType UintPtr()
static constexpr MachineType Int8()
static constexpr MachineRepresentation PointerRepresentation()
static constexpr MachineType IntPtr()
SloppyTNode(const TNode< U > &other) V8_NOEXCEPT
Definition tnode.h:444
SloppyTNode(compiler::Node *node)
Definition tnode.h:441
void LazyTemplateChecks() const
Definition tnode.h:421
TNode(const TNode &other) V8_NOEXCEPT
Definition tnode.h:400
friend class TNode
Definition tnode.h:417
compiler::Node * node_
Definition tnode.h:425
TNode(const TNode< U > &other) V8_NOEXCEPT
Definition tnode.h:394
TNode(compiler::Node *node)
Definition tnode.h:419
static TNode UncheckedCast(compiler::Node *node)
Definition tnode.h:413
TNode operator=(TNode other)
Definition tnode.h:403
int r
Definition mul-fft.cc:298
STL namespace.
constexpr MachineType CommonMachineType(MachineType type1, MachineType type2)
Definition tnode.h:176
UnionOf< Object, MaybeObject > AnyTaggedT
Definition tnode.h:313
IntPtrT TaggedT
Definition tnode.h:148
static constexpr bool is_taggable_v
Definition tagged.h:316
constexpr int U
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
return value
Definition map-inl.h:893
constexpr bool IsMachineRepresentationOf(MachineRepresentation r)
Definition tnode.h:281
constexpr MachineRepresentation PhiMachineRepresentationOf
Definition tnode.h:286
UnionOf< Context, Smi > ContextOrEmptyContext
Definition tnode.h:314
#define V8_NOEXCEPT
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
static constexpr MachineType kMachineType
Definition tnode.h:76
static constexpr MachineType kMachineType
Definition tnode.h:159
static constexpr MachineType kMachineType
Definition tnode.h:98
static constexpr MachineType kMachineType
Definition tnode.h:125
static constexpr MachineType kMachineType
Definition tnode.h:94
static constexpr MachineType kMachineType
Definition tnode.h:115
static constexpr MachineType kMachineType
Definition tnode.h:130
static const MachineRepresentation kMachineRepresentation
Definition tnode.h:134
static constexpr MachineType kMachineType
Definition tnode.h:136
static const MachineRepresentation kMachineRepresentation
Definition tnode.h:140
static constexpr MachineType kMachineType
Definition tnode.h:142
static constexpr MachineType kMachineType
Definition tnode.h:102
static constexpr MachineType kMachineType
Definition tnode.h:58
static constexpr MachineType kMachineType
Definition tnode.h:52
static constexpr MachineType kMachineType
Definition tnode.h:80
static constexpr MachineType kMachineType
Definition tnode.h:64
static constexpr MachineType kMachineType
Definition tnode.h:87
static constexpr MachineType kMachineType
Definition tnode.h:106
static constexpr MachineType kMachineType
Definition tnode.h:36
static constexpr MachineType kMachineType
Definition tnode.h:41
static const MachineRepresentation kMachineRepresentation
Definition tnode.h:167
static constexpr MachineType kMachineType
Definition tnode.h:169
static constexpr MachineType kMachineType
Definition tnode.h:61
static constexpr MachineType kMachineType
Definition tnode.h:55
static constexpr MachineType kMachineType
Definition tnode.h:83
static constexpr MachineType kMachineType
Definition tnode.h:67
static constexpr MachineType kMachineType
Definition tnode.h:90
static const MachineRepresentation kMachineRepresentation
Definition tnode.h:48
static const MachineRepresentation kMachineRepresentation
Definition tnode.h:71
static const MachineRepresentation kMachineRepresentation
Definition tnode.h:31
static const bool is_tagged
Definition tnode.h:295
#define T1(name, string, precedence)
Definition token.cc:28
#define T2(name, string, precedence)
Definition token.cc:30