Switch-related cleanup
[hiphop-php.git] / hphp / runtime / vm / jit / types.h
blob3b967fad3cdc6d0e7ffb93ea668e8d96e40e235c
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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_
20 #include <vector>
22 #include "hphp/util/assertions.h"
23 #include "hphp/util/hash-map-typedefs.h"
25 #include "hphp/runtime/base/types.h"
27 namespace HPHP { namespace jit {
29 ///////////////////////////////////////////////////////////////////////////////
32 * Core types.
34 typedef unsigned char* TCA; // "Translation cache address."
35 typedef const unsigned char* CTCA;
37 struct ctca_identity_hash {
38 size_t operator()(CTCA val) const {
39 // Experiments show that this is a sufficient "hash function" on
40 // TCAs for now; using stronger functions didn't help given current
41 // data. Patterns of code emission in the translator could invalidate
42 // this finding going forward, though; e.g., if we frequently emit
43 // a call instruction N bytes into a cache-aligned region.
44 return uintptr_t(val);
48 ///////////////////////////////////////////////////////////////////////////////
50 typedef hphp_hash_set<TransID> TransIDSet;
51 typedef std::vector<TransID> TransIDVec;
53 ///////////////////////////////////////////////////////////////////////////////
55 /**
56 * The different kinds of translations that the JIT generates:
58 * - Anchor : a service request for retranslating
59 * - Prologue : function prologue
60 * - Interp : a service request to interpret at least one instruction
61 * - Live : translate one tracelet by inspecting live VM state
62 * - Profile : translate one block by inspecting live VM state and
63 * inserting profiling counters
64 * - Optimize : translate one region performing optimizations that may
65 * leverage data collected by Profile translations
66 * - Proflogue: a profiling function prologue
68 #define TRANS_KINDS \
69 DO(Anchor) \
70 DO(Prologue) \
71 DO(Interp) \
72 DO(Live) \
73 DO(Profile) \
74 DO(Optimize) \
75 DO(Proflogue) \
76 DO(Invalid) \
78 enum class TransKind {
79 #define DO(KIND) KIND,
80 TRANS_KINDS
81 #undef DO
84 constexpr size_t NumTransKinds =
85 #define DO(KIND) + 1
86 TRANS_KINDS
87 #undef DO
90 inline std::string show(TransKind k) {
91 #define DO(name) case TransKind::name: return "Trans" #name;
92 switch (k) { TRANS_KINDS }
93 #undef DO
94 not_reached();
98 * Compact flags which may be threaded through a service request to provide
99 * hints or demands for retranslations.
101 struct TransFlags {
102 /* implicit */ TransFlags(uint64_t flags = 0) : packed(flags) {}
104 union {
105 struct {
106 bool noinlineSingleton : 1;
108 uint64_t packed;
112 static_assert(sizeof(TransFlags) <= sizeof(uint64_t), "Too many TransFlags!");
114 ///////////////////////////////////////////////////////////////////////////////
117 * The "kind" of code being generated.
119 * Different contexts of code generation constrain codegen differently; e.g.,
120 * cross-trace code has fewer available registers.
122 enum class CodeKind {
123 Trace,
124 CrossTrace,
128 * Enumeration representing the various areas that we emit code.
130 * kNumAreas must be kept up to date.
132 enum class AreaIndex : unsigned { Main, Cold, Frozen };
133 constexpr size_t kNumAreas = 3;
135 inline std::string areaAsString(AreaIndex area) {
136 switch (area) {
137 case AreaIndex::Main:
138 return "Main";
139 case AreaIndex::Cold:
140 return "Cold";
141 case AreaIndex::Frozen:
142 return "Frozen";
144 always_assert(false);
147 ///////////////////////////////////////////////////////////////////////////////
151 #endif