forked from facebook/hhvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcg-meta.h
More file actions
246 lines (207 loc) · 7.24 KB
/
Copy pathcg-meta.h
File metadata and controls
246 lines (207 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_JIT_CODE_GEN_FIXUPS_H_
#define incl_HPHP_JIT_CODE_GEN_FIXUPS_H_
#include "hphp/runtime/base/backtrace.h"
#include "hphp/runtime/vm/jit/alignment.h"
#include "hphp/runtime/vm/jit/containers.h"
#include "hphp/runtime/vm/jit/fixup.h"
#include "hphp/runtime/vm/jit/srcdb.h"
#include "hphp/runtime/vm/jit/trans-rec.h"
#include "hphp/runtime/vm/jit/types.h"
#include "hphp/util/growable-vector.h"
#include <map>
#include <vector>
namespace HPHP { namespace jit {
/*
* CGMeta contains a variety of different metadata information that is
* collected during code generation.
*
* A major use case of this class is to expose metadata to the code relocator
* for adjustment before it is written to global data structures (e.g., in
* MCGenerator).
*/
struct CGMeta {
void process(GrowableVector<IncomingBranch>* inProgressTailBranches);
void process_only(GrowableVector<IncomingBranch>* inProgressTailBranches);
void process_literals();
bool empty() const;
void clear();
void setJmpTransID(TCA jmp, TransID transID, TransKind kind);
void setCallFuncId(TCA callRetAddr, FuncId funcId, TransKind kind);
/*
* Code addresses of interest to the code generator.
*
* At emit-time, these should be set to point to TCAs of interest, and will
* be updated if those addresses change. A watchpoint set immediately
* following an instruction is guaranteed to still follow it immediately,
* even if updated.
*/
std::vector<TCA*> watchpoints;
/*
* Pending MCGenerator table entries.
*/
std::vector<std::pair<TCA,Fixup>> fixups;
std::vector<std::pair<TCA,TCA>> catches;
std::vector<std::pair<TCA,TransID>> jmpTransIDs;
std::vector<std::pair<TCA,FuncId>> callFuncIds;
std::vector<std::pair<TCA,Reason>> trapReasons;
std::vector<IFrame> inlineFrames;
std::vector<std::pair<TCA,IStack>> inlineStacks;
/*
* On some architectures (like ARM) we want to pool up literals and emit them
* at once. This allows us to accumulate literals until the end of a
* Vunit, where we can emit them together.
*/
struct PoolLiteralMeta {
uint64_t value;
CodeAddress patchAddress;
bool smashable;
uint8_t width;
};
std::vector<PoolLiteralMeta> literalsToPool;
/*
* We want to collapse emitting literals multiple times. This map allows us
* to find the addresses of already emitted literals.
*/
jit::fast_map<uint64_t, const uint64_t*> literalAddrs;
struct VeneerData {
TCA source; // address of instruction that jumps/calls the veneer
TCA target; // address that the veneer jumps to
};
std::vector<VeneerData> veneers;
/*
* Addresses of veneers.
*/
std::set<TCA> veneerAddrs;
/*
* All the alignment constraints on each code address.
*/
std::multimap<TCA,std::pair<Alignment,AlignContext>> alignments;
/*
* Addresses of any allocated service request stubs.
*/
std::vector<TCA> reusedStubs;
/*
* Address immediates in the generated code.
*
* Also contains the addresses of any mcprep{} instructions that were emitted.
*/
std::set<TCA> addressImmediates;
/*
* Certain addresses are fallthrough to the next vunit.
* We tag such an address so we can patch a jump over any inserted literal
* pools/veneers. This metadata is kept around so the relocator can properly
* adjust or remove the jump to keep it pointing directly after the Vunit.
*/
folly::Optional<TCA> fallthru;
/*
* Code addresses of interest to other code.
*
* These are like `watchpoints', except that the pointers point into the TC
* data segment rather than, e.g., code generator data structures. Used for
* REQ_BIND_ADDR service requests.
*
* These also omit the "stickiness" guarantee w.r.t. previous instructions.
*/
std::set<TCA*> codePointers;
/*
* Smash targets of fallback{} and fallbackcc{} instructions (e.g.,
* REQ_RETRANSLATE service requests).
*
* These always correspond to the initial SrcKey of the current IR unit---
* see cgReqRetranslate().
*/
GrowableVector<IncomingBranch> inProgressTailJumps;
/*
* Smashable locations. Used on relocation to be sure a smashable instruction
* is not optimized.
*/
std::set<TCA> smashableLocations;
/*
* Extra data kept for smashable calls. Used to pre-smash calls before the
* code is published.
*/
jit::fast_map<TCA,PrologueID> smashableCallData;
/*
* Extra data kept for smashable jumps/jccs. Used to pre-smash jumps/jccs
* before code is published.
*/
enum class JumpKind { Bindjmp, Bindjcc, Fallback, Fallbackcc };
struct JumpData {
SrcKey sk;
JumpKind kind;
};
jit::fast_map<TCA,JumpData> smashableJumpData;
/*
* Debug-only map from bytecode to machine code address.
*/
std::vector<TransBCMapping> bcMap;
};
/*
* If the literal val has already been written into the TCA return its address,
* otherwise return nullptr
*/
const uint64_t* addrForLiteral(uint64_t val);
/*
* Look up a TCA-to-landingpad mapping.
*/
folly::Optional<TCA> getCatchTrace(CTCA ip);
/*
* Return the number of registered catch traces
*/
size_t numCatchTraces();
/*
* Erase catch trace at addr. If no trace is registered at addr no action is
* performed.
*/
void eraseCatchTrace(CTCA addr);
/*
* Get the reason for the jit::trap instruction (UD2 on x64) at given address.
* The returned pointer refers to memory subject to the treadmill, so should
* only be used in the current request.
*/
Reason* getTrapReason(CTCA addr);
/*
* Pool up literal to be emitted at patch time.
*/
void poolLiteral(CodeBlock& cb, CGMeta& meta, uint64_t val, uint8_t width,
bool smashable);
void addVeneer(CGMeta& meta, TCA source, TCA target);
folly::Optional<IStack> inlineStackAt(CTCA addr);
IFrame getInlineFrame(IFrameID id);
void eraseInlineStack(CTCA addr);
void eraseInlineStacksInRange(CTCA start, CTCA end);
}}
namespace folly {
template<> class FormatValue<HPHP::IFrame> {
public:
explicit FormatValue(HPHP::IFrame ifr) : m_ifr(ifr) {}
template<typename Callback>
void format(FormatArg& arg, Callback& cb) const {
auto str = folly::sformat(
"IFrame{{func = {}, callOff = {}, parent = {}}}",
m_ifr.func->fullName()->data(),
m_ifr.callOff,
m_ifr.parent
);
format_value::formatString(str, arg, cb);
}
private:
HPHP::IFrame m_ifr;
};
}
#endif