46
46
// YKFIXME: The control point cannot yet be used in an interpreter using
47
47
// threaded dispatch.
48
48
//
49
- // YKFIXME: The tracing logic is currently over-simplified:
49
+ // YKFIXME: The tracing logic is currently over-simplified. The following items
50
+ // need to be fixed:
50
51
//
51
- // - A JIT location is assumed to be a simple integer program counter. It
52
- // should be a `ykrt::Location` .
52
+ // - The address of `YkLocation` instances are used for identity, but they are
53
+ // intended to be freely moved by the user .
53
54
//
54
55
// - Tracing starts when we encounter a location for which we have no machine
55
56
// code. A hot counter should be used instead.
@@ -123,7 +124,7 @@ void createJITStatePrint(IRBuilder<> &Builder, Module *Mod, std::string Str) {
123
124
// / Generates the new control point, which includes all logic to start/stop
124
125
// / tracing and to compile/execute traces.
125
126
void createControlPoint (Module &Mod, Function *F, std::vector<Value *> LiveVars,
126
- StructType *YkCtrlPointStruct) {
127
+ StructType *YkCtrlPointStruct, Type *YkLocTy ) {
127
128
auto &Context = Mod.getContext ();
128
129
129
130
// Create control point blocks and setup the IRBuilder.
@@ -166,9 +167,8 @@ void createControlPoint(Module &Mod, Function *F, std::vector<Value *> LiveVars,
166
167
PtNull, " compiled_trace" , (GlobalVariable *)nullptr );
167
168
168
169
GlobalVariable *GVStartLoc = new GlobalVariable (
169
- Mod, Type::getInt32Ty (Context), false , GlobalVariable::InternalLinkage,
170
- ConstantInt::get (Context, APInt (32 , -1 )), " start_loc" ,
171
- (GlobalVariable *)nullptr );
170
+ Mod, YkLocTy, false , GlobalVariable::InternalLinkage,
171
+ Constant::getNullValue (YkLocTy), " start_loc" , (GlobalVariable *)nullptr );
172
172
173
173
// Create control point entry block. Checks if we are currently tracing.
174
174
Value *GVTracingVal = Builder.CreateLoad (Type::getInt8Ty (Context), GVTracing);
@@ -196,8 +196,7 @@ void createControlPoint(Module &Mod, Function *F, std::vector<Value *> LiveVars,
196
196
// Create block that checks if we've reached the same location again so we
197
197
// can execute a compiled trace.
198
198
Builder.SetInsertPoint (BBHasTrace);
199
- Value *ValStartLoc =
200
- Builder.CreateLoad (Type::getInt32Ty (Context), GVStartLoc);
199
+ Value *ValStartLoc = Builder.CreateLoad (YkLocTy, GVStartLoc);
201
200
Value *ExecTraceCond = Builder.CreateICmp (CmpInst::Predicate::ICMP_EQ,
202
201
ValStartLoc, F->getArg (0 ));
203
202
Builder.CreateCondBr (ExecTraceCond, BBExecuteTrace, BBReturn);
@@ -220,8 +219,7 @@ void createControlPoint(Module &Mod, Function *F, std::vector<Value *> LiveVars,
220
219
221
220
// Create block that decides when to stop tracing.
222
221
Builder.SetInsertPoint (BBTracing);
223
- Value *ValStartLoc2 =
224
- Builder.CreateLoad (Type::getInt32Ty (Context), GVStartLoc);
222
+ Value *ValStartLoc2 = Builder.CreateLoad (YkLocTy, GVStartLoc);
225
223
Value *StopTracingCond = Builder.CreateICmp (CmpInst::Predicate::ICMP_EQ,
226
224
ValStartLoc2, F->getArg (0 ));
227
225
Builder.CreateCondBr (StopTracingCond, BBStopTracing, BBReturn);
@@ -312,8 +310,9 @@ PreservedAnalyses YkControlPointPass::run(Module &M,
312
310
StructType::create (TypeParams, " YkCtrlPointVars" );
313
311
314
312
// Create the new control point.
315
- FunctionType *FType = FunctionType::get (
316
- CtrlPointReturnTy, {Type::getInt32Ty (Context), CtrlPointReturnTy}, false );
313
+ Type *YkLocTy = OldCtrlPointCall->getArgOperand (0 )->getType ();
314
+ FunctionType *FType =
315
+ FunctionType::get (CtrlPointReturnTy, {YkLocTy, CtrlPointReturnTy}, false );
317
316
Function *NF = Function::Create (FType, GlobalVariable::ExternalLinkage,
318
317
YK_NEW_CONTROL_POINT, M);
319
318
@@ -347,7 +346,7 @@ PreservedAnalyses YkControlPointPass::run(Module &M,
347
346
OldCtrlPointCall->eraseFromParent ();
348
347
349
348
// Generate new control point logic.
350
- createControlPoint (M, NF, LiveVals, CtrlPointReturnTy);
349
+ createControlPoint (M, NF, LiveVals, CtrlPointReturnTy, YkLocTy );
351
350
352
351
return PreservedAnalyses::none ();
353
352
}
0 commit comments