7
7
// The pass converts an interpreter loop that looks like this:
8
8
//
9
9
// ```
10
+ // YkMT *mt = ...;
11
+ // YkLocation loc = ...;
10
12
// pc = 0;
11
13
// while (...) {
12
- // yk_control_point(); // <- dummy control point
14
+ // yk_control_point(mt, loc ); // <- dummy control point
13
15
// bc = program[pc];
14
16
// switch (bc) {
15
17
// // bytecode handlers here.
32
34
// while (...) {
33
35
// // Now we call the patched control point.
34
36
// cp_vars.pc = pc;
35
- // yk_new_control_point( &cp_vars);
37
+ // __ykrt__control_point(mt, loc, &cp_vars);
36
38
// pc = cp_vars.pc;
37
39
// bc = program[pc];
38
40
// switch (bc) {
59
61
#define DEBUG_TYPE " yk-control-point"
60
62
#define JIT_STATE_PREFIX " jit-state: "
61
63
64
+ #define YK_OLD_CONTROL_POINT_NUM_ARGS 2
65
+
66
+ #define YK_CONTROL_POINT_ARG_MT_IDX 0
67
+ #define YK_CONTROL_POINT_ARG_LOC_IDX 1
68
+ #define YK_CONTROL_POINT_ARG_VARS_IDX 2
69
+ #define YK_CONTROL_POINT_NUM_ARGS 3
70
+
62
71
using namespace llvm ;
63
72
64
73
// / Find the call to the dummy control point that we want to patch.
@@ -156,11 +165,16 @@ class YkControlPoint : public ModulePass {
156
165
StructType *CtrlPointVarsTy =
157
166
StructType::create (TypeParams, " YkCtrlPointVars" );
158
167
168
+ // The old control point should be of the form:
169
+ // control_point(YkMT*, YkLocation*)
170
+ assert (OldCtrlPointCall->arg_size () == YK_OLD_CONTROL_POINT_NUM_ARGS);
171
+ Type *YkMTTy = OldCtrlPointCall->getArgOperand (YK_CONTROL_POINT_ARG_MT_IDX)->getType ();
172
+ Type *YkLocTy = OldCtrlPointCall->getArgOperand (YK_CONTROL_POINT_ARG_LOC_IDX)->getType ();
173
+
159
174
// Create the new control point.
160
- Type *YkLocTy = OldCtrlPointCall->getArgOperand (0 )->getType ();
161
175
FunctionType *FType =
162
176
FunctionType::get (Type::getVoidTy (Context),
163
- {YkLocTy, CtrlPointVarsTy->getPointerTo ()}, false );
177
+ {YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo ()}, false );
164
178
Function *NF = Function::Create (FType, GlobalVariable::ExternalLinkage,
165
179
YK_NEW_CONTROL_POINT, M);
166
180
@@ -183,7 +197,11 @@ class YkControlPoint : public ModulePass {
183
197
184
198
// Insert call to the new control point.
185
199
Instruction *NewCtrlPointCallInst = Builder.CreateCall (
186
- NF, {OldCtrlPointCall->getArgOperand (0 ), InputStruct});
200
+ NF, {
201
+ OldCtrlPointCall->getArgOperand (YK_CONTROL_POINT_ARG_MT_IDX),
202
+ OldCtrlPointCall->getArgOperand (YK_CONTROL_POINT_ARG_LOC_IDX),
203
+ InputStruct
204
+ });
187
205
188
206
// Once the control point returns we need to extract the (potentially
189
207
// mutated) values from the returned YkCtrlPointStruct and reassign them to
0 commit comments