2 +----------------------------------------------------------------------+
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_TRANSL_TYPES_H_
18 #define incl_HPHP_TRANSL_TYPES_H_
22 #include "hphp/util/assertions.h"
23 #include "hphp/util/hash-map-typedefs.h"
24 #include "hphp/runtime/base/types.h"
26 namespace HPHP
{ namespace jit
{
28 ///////////////////////////////////////////////////////////////////////////////
33 typedef unsigned char* TCA
; // "Translation cache address."
34 typedef const unsigned char* CTCA
;
36 using LowTCA
= LowPtr
<uint8_t>;
37 using AtomicLowTCA
= AtomicLowPtr
<uint8_t,
38 std::memory_order_acquire
,
39 std::memory_order_release
>;
41 struct ctca_identity_hash
{
42 size_t operator()(CTCA val
) const {
43 // Experiments show that this is a sufficient "hash function" on
44 // TCAs for now; using stronger functions didn't help given current
45 // data. Patterns of code emission in the translator could invalidate
46 // this finding going forward, though; e.g., if we frequently emit
47 // a call instruction N bytes into a cache-aligned region.
48 return uintptr_t(val
);
52 ///////////////////////////////////////////////////////////////////////////////
54 using TransIDSet
= hphp_hash_set
<TransID
>;
55 using TransIDVec
= std::vector
<TransID
>;
57 using Annotation
= std::pair
<std::string
, std::string
>;
58 using Annotations
= std::vector
<Annotation
>;
60 using LiteralMap
= hphp_hash_map
<uint64_t,const uint64_t*>;
62 ///////////////////////////////////////////////////////////////////////////////
65 * The different kinds of translations that the JIT generates:
67 * - Anchor : a service request for retranslating
68 * - Prologue : function prologue
69 * - Interp : a service request to interpret at least one instruction
70 * - Live : translate one tracelet by inspecting live VM state
71 * - Profile : translate one block by inspecting live VM state and
72 * inserting profiling counters
73 * - Optimize : translate one region performing optimizations that may
74 * leverage data collected by Profile translations
75 * - Proflogue: a profiling function prologue
87 enum class TransKind {
88 #define DO(KIND) KIND,
93 constexpr size_t NumTransKinds
=
99 inline std::string
show(TransKind k
) {
100 #define DO(name) case TransKind::name: return "Trans" #name;
101 switch (k
) { TRANS_KINDS
}
107 * Compact flags which may be threaded through a service request to provide
108 * hints or demands for retranslations.
111 /* implicit */ TransFlags(uint64_t flags
= 0) : packed(flags
) {}
115 bool noinlineSingleton
: 1;
116 bool noProfiledFPush
: 1;
122 static_assert(sizeof(TransFlags
) <= sizeof(uint64_t), "Too many TransFlags!");
124 ///////////////////////////////////////////////////////////////////////////////
127 * The "kind" of code being generated.
129 * Different contexts of code generation constrain codegen differently; e.g.,
130 * cross-trace code has fewer available registers.
132 enum class CodeKind
: uint8_t {
134 * Normal PHP code in the TC.
139 * Code at the TC boundaries, e.g., service requests, unique stubs.
144 * Helper code that uses scratch registers only.
150 * Enumeration representing the various areas that we emit code.
152 * kNumAreas must be kept up to date.
154 enum class AreaIndex
: unsigned { Main
, Cold
, Frozen
};
155 constexpr size_t kNumAreas
= 3;
157 inline std::string
areaAsString(AreaIndex area
) {
159 case AreaIndex::Main
:
161 case AreaIndex::Cold
:
163 case AreaIndex::Frozen
:
166 always_assert(false);
169 ///////////////////////////////////////////////////////////////////////////////
172 * Some data structures are accessed often enough from translated code that we
173 * have shortcuts for getting offsets into them.
175 #define TVOFF(nm) int(offsetof(TypedValue, nm))
176 #define AROFF(nm) int(offsetof(ActRec, nm))
177 #define AFWHOFF(nm) int(offsetof(c_AsyncFunctionWaitHandle, nm))
178 #define GENDATAOFF(nm) int(offsetof(Generator, nm))
180 ///////////////////////////////////////////////////////////////////////////////