Clean up irgen.h a bit
[hiphop-php.git] / hphp / runtime / vm / jit / type-specialization.h
blobeaf3827cfdc7f88836a68813bbc9ddae453aad59
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_JIT_TYPE_SPECIALIZATION_H_
18 #define incl_HPHP_JIT_TYPE_SPECIALIZATION_H_
20 #include "hphp/runtime/base/array-data.h"
21 #include "hphp/runtime/base/repo-auth-type.h"
23 #include <folly/Optional.h>
25 #include <cstdint>
27 namespace HPHP {
28 ///////////////////////////////////////////////////////////////////////////////
30 struct Class;
31 struct Shape;
33 namespace jit {
34 ///////////////////////////////////////////////////////////////////////////////
37 * Array type specialization.
39 * May contain an ArrayKind and/or a pointer to a RAT or a Shape.
41 struct ArraySpec {
43 * Constructors.
45 constexpr ArraySpec();
46 explicit ArraySpec(ArrayData::ArrayKind kind);
47 explicit ArraySpec(const RepoAuthType::Array* arrTy);
48 ArraySpec(ArrayData::ArrayKind kind, const RepoAuthType::Array* arrTy);
49 explicit ArraySpec(const Shape* shape);
52 * Accessors.
54 * These return falsey values (folly::none or nullptr) if the respective bit
55 * in `m_sort' is not set.
57 * bits() returns the raw bits.
59 uintptr_t bits() const;
60 folly::Optional<ArrayData::ArrayKind> kind() const;
61 const RepoAuthType::Array* type() const;
62 const Shape* shape() const;
65 * Casts.
67 * Bottom and Top cast to false; everything else casts to true.
69 explicit operator bool() const;
72 * Comparisons.
74 bool operator==(const ArraySpec& rhs) const;
75 bool operator!=(const ArraySpec& rhs) const;
76 bool operator<=(const ArraySpec& rhs) const;
77 bool operator>=(const ArraySpec& rhs) const;
78 bool operator<(const ArraySpec& rhs) const;
79 bool operator>(const ArraySpec& rhs) const;
82 * Combinators.
84 ArraySpec operator|(const ArraySpec& rhs) const;
85 ArraySpec operator&(const ArraySpec& rhs) const;
86 ArraySpec operator-(const ArraySpec& rhs) const;
89 * Top and bottom types.
91 static const ArraySpec Top;
92 static const ArraySpec Bottom;
94 private:
96 * Bottom constructor.
98 enum class BottomTag {};
99 explicit ArraySpec(BottomTag);
102 * Mask of specializations that a given ArraySpec represents.
104 enum SortOf : uint8_t {
105 IsTop = 0,
106 IsBottom = 1 << 0,
107 HasKind = 1 << 1,
108 HasType = 1 << 2,
109 HasShape = 1 << 3,
111 friend SortOf operator|(SortOf, SortOf);
112 friend SortOf operator&(SortOf, SortOf);
115 * Data members.
117 union {
118 struct {
119 uintptr_t m_sort : 8;
120 uintptr_t m_kind : 8;
121 uintptr_t m_ptr : 48;
123 uintptr_t m_bits;
127 ArraySpec::SortOf operator|(ArraySpec::SortOf l, ArraySpec::SortOf r);
128 ArraySpec::SortOf operator&(ArraySpec::SortOf l, ArraySpec::SortOf r);
130 ///////////////////////////////////////////////////////////////////////////////
133 * Class type specialization.
135 struct ClassSpec {
137 * Constructor tags.
139 enum class SubTag {};
140 enum class ExactTag {};
143 * Constructors.
145 constexpr ClassSpec();
146 ClassSpec(const Class* cls, SubTag);
147 ClassSpec(const Class* cls, ExactTag);
150 * Accessors.
152 uintptr_t bits() const;
153 bool exact() const;
154 const Class* cls() const;
155 const Class* exactCls() const;
158 * Casts.
160 * Bottom and Top cast to false; everything else casts to true.
162 explicit operator bool() const;
165 * Comparisons.
167 bool operator==(const ClassSpec& rhs) const;
168 bool operator!=(const ClassSpec& rhs) const;
169 bool operator<=(const ClassSpec& rhs) const;
170 bool operator>=(const ClassSpec& rhs) const;
171 bool operator<(const ClassSpec& rhs) const;
172 bool operator>(const ClassSpec& rhs) const;
175 * Combinators.
177 ClassSpec operator|(const ClassSpec& rhs) const;
178 ClassSpec operator&(const ClassSpec& rhs) const;
179 ClassSpec operator-(const ClassSpec& rhs) const;
182 * Top and bottom types.
184 static const ClassSpec Top;
185 static const ClassSpec Bottom;
187 private:
189 * Bottom constructor.
191 enum class BottomTag {};
192 explicit ClassSpec(BottomTag);
195 * Sort tag.
197 enum SortOf : uint8_t {
198 IsTop,
199 IsBottom,
200 IsSub,
201 IsExact,
205 * Data members.
207 union {
208 struct {
209 uintptr_t m_sort : 8;
210 uintptr_t m_ptr : 56;
212 uintptr_t m_bits;
216 ///////////////////////////////////////////////////////////////////////////////
219 * Specialization kinds.
221 enum class SpecKind : uint8_t {
222 None = 0,
223 Array = 1 << 0,
224 Class = 1 << 1,
227 SpecKind operator|(SpecKind l, SpecKind r);
228 SpecKind operator&(SpecKind l, SpecKind r);
229 SpecKind& operator|=(SpecKind& l, SpecKind r);
232 * Discriminated specialization union.
234 * Used to encapsulate combinator logic.
236 struct TypeSpec {
238 * Constructors.
240 TypeSpec();
241 TypeSpec(ArraySpec, ClassSpec);
244 * Accessors.
246 SpecKind kind() const;
247 ArraySpec arrSpec() const;
248 ClassSpec clsSpec() const;
251 * Comparisons.
253 bool operator==(const TypeSpec& rhs) const;
254 bool operator!=(const TypeSpec& rhs) const;
255 bool operator<=(const TypeSpec& rhs) const;
256 bool operator>=(const TypeSpec& rhs) const;
259 * Combinators.
261 TypeSpec operator|(const TypeSpec& rhs) const;
262 TypeSpec operator&(const TypeSpec& rhs) const;
263 TypeSpec operator-(const TypeSpec& rhs) const;
265 private:
267 * Data members.
269 SpecKind m_kind;
270 ArraySpec m_arrSpec;
271 ClassSpec m_clsSpec;
274 ///////////////////////////////////////////////////////////////////////////////
277 #include "hphp/runtime/vm/jit/type-specialization-inl.h"
279 #endif