Line data Source code
1 : // Copyright 2014 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_CRANKSHAFT_HYDROGEN_TYPES_H_
6 : #define V8_CRANKSHAFT_HYDROGEN_TYPES_H_
7 :
8 : #include <climits>
9 : #include <iosfwd>
10 :
11 : #include "src/ast/ast-types.h"
12 : #include "src/base/macros.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : // Forward declarations.
18 : template <typename T> class Handle;
19 : class FieldType;
20 : class Object;
21 :
22 : #define HTYPE_LIST(V) \
23 : V(Any, 0x0) /* 0000 0000 0000 0000 */ \
24 : V(Tagged, 0x1) /* 0000 0000 0000 0001 */ \
25 : V(TaggedPrimitive, 0x5) /* 0000 0000 0000 0101 */ \
26 : V(TaggedNumber, 0xd) /* 0000 0000 0000 1101 */ \
27 : V(Smi, 0x1d) /* 0000 0000 0001 1101 */ \
28 : V(HeapObject, 0x21) /* 0000 0000 0010 0001 */ \
29 : V(HeapPrimitive, 0x25) /* 0000 0000 0010 0101 */ \
30 : V(Null, 0x27) /* 0000 0000 0010 0111 */ \
31 : V(HeapNumber, 0x2d) /* 0000 0000 0010 1101 */ \
32 : V(String, 0x65) /* 0000 0000 0110 0101 */ \
33 : V(Boolean, 0xa5) /* 0000 0000 1010 0101 */ \
34 : V(Undefined, 0x125) /* 0000 0001 0010 0101 */ \
35 : V(JSReceiver, 0x221) /* 0000 0010 0010 0001 */ \
36 : V(JSObject, 0x621) /* 0000 0110 0010 0001 */ \
37 : V(JSArray, 0xe21) /* 0000 1110 0010 0001 */ \
38 : V(None, 0xfff) /* 0000 1111 1111 1111 */
39 :
40 : class HType final {
41 : public:
42 : #define DECLARE_CONSTRUCTOR(Name, mask) \
43 : static HType Name() WARN_UNUSED_RESULT { return HType(k##Name); }
44 : HTYPE_LIST(DECLARE_CONSTRUCTOR)
45 : #undef DECLARE_CONSTRUCTOR
46 :
47 : // Return the weakest (least precise) common type.
48 : HType Combine(HType other) const WARN_UNUSED_RESULT {
49 26091691 : return HType(static_cast<Kind>(kind_ & other.kind_));
50 : }
51 :
52 : bool Equals(HType other) const WARN_UNUSED_RESULT {
53 39893088 : return kind_ == other.kind_;
54 : }
55 :
56 : bool IsSubtypeOf(HType other) const WARN_UNUSED_RESULT {
57 : return Combine(other).Equals(other);
58 : }
59 :
60 : #define DECLARE_IS_TYPE(Name, mask) \
61 : bool Is##Name() const WARN_UNUSED_RESULT { \
62 : return IsSubtypeOf(HType::Name()); \
63 : }
64 : HTYPE_LIST(DECLARE_IS_TYPE)
65 : #undef DECLARE_IS_TYPE
66 :
67 : static HType FromType(AstType* type) WARN_UNUSED_RESULT;
68 : static HType FromFieldType(Handle<FieldType> type,
69 : Zone* temp_zone) WARN_UNUSED_RESULT;
70 : static HType FromValue(Handle<Object> value) WARN_UNUSED_RESULT;
71 :
72 : friend std::ostream& operator<<(std::ostream& os, const HType& t);
73 :
74 : private:
75 : enum Kind {
76 : #define DECLARE_TYPE(Name, mask) k##Name = mask,
77 : HTYPE_LIST(DECLARE_TYPE)
78 : #undef DECLARE_TYPE
79 : LAST_KIND = kNone
80 : };
81 :
82 : // Make sure type fits in int16.
83 : STATIC_ASSERT(LAST_KIND < (1 << (CHAR_BIT * sizeof(int16_t))));
84 :
85 : explicit HType(Kind kind) : kind_(kind) { }
86 :
87 : int16_t kind_;
88 : };
89 :
90 :
91 : std::ostream& operator<<(std::ostream& os, const HType& t);
92 : } // namespace internal
93 : } // namespace v8
94 :
95 : #endif // V8_CRANKSHAFT_HYDROGEN_TYPES_H_
|