Skip to content

Commit ff21fd3

Browse files
bors[bot]ltratt
andauthored
21: Add a `YkMt*` first argument to control points. r=vext01 a=ltratt Co-authored-by: Laurence Tratt <[email protected]>
2 parents 81d683a + 36e52d9 commit ff21fd3

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

llvm/lib/Transforms/Yk/ControlPoint.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
// The pass converts an interpreter loop that looks like this:
88
//
99
// ```
10+
// YkMT *mt = ...;
11+
// YkLocation loc = ...;
1012
// pc = 0;
1113
// while (...) {
12-
// yk_control_point(); // <- dummy control point
14+
// yk_control_point(mt, loc); // <- dummy control point
1315
// bc = program[pc];
1416
// switch (bc) {
1517
// // bytecode handlers here.
@@ -32,7 +34,7 @@
3234
// while (...) {
3335
// // Now we call the patched control point.
3436
// cp_vars.pc = pc;
35-
// yk_new_control_point(&cp_vars);
37+
// __ykrt__control_point(mt, loc, &cp_vars);
3638
// pc = cp_vars.pc;
3739
// bc = program[pc];
3840
// switch (bc) {
@@ -59,6 +61,13 @@
5961
#define DEBUG_TYPE "yk-control-point"
6062
#define JIT_STATE_PREFIX "jit-state: "
6163

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+
6271
using namespace llvm;
6372

6473
/// Find the call to the dummy control point that we want to patch.
@@ -156,11 +165,16 @@ class YkControlPoint : public ModulePass {
156165
StructType *CtrlPointVarsTy =
157166
StructType::create(TypeParams, "YkCtrlPointVars");
158167

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+
159174
// Create the new control point.
160-
Type *YkLocTy = OldCtrlPointCall->getArgOperand(0)->getType();
161175
FunctionType *FType =
162176
FunctionType::get(Type::getVoidTy(Context),
163-
{YkLocTy, CtrlPointVarsTy->getPointerTo()}, false);
177+
{YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo()}, false);
164178
Function *NF = Function::Create(FType, GlobalVariable::ExternalLinkage,
165179
YK_NEW_CONTROL_POINT, M);
166180

@@ -183,7 +197,11 @@ class YkControlPoint : public ModulePass {
183197

184198
// Insert call to the new control point.
185199
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+
});
187205

188206
// Once the control point returns we need to extract the (potentially
189207
// mutated) values from the returned YkCtrlPointStruct and reassign them to

0 commit comments

Comments
 (0)