4646// YKFIXME: The control point cannot yet be used in an interpreter using
4747// threaded dispatch.
4848//
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:
5051//
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 .
5354//
5455// - Tracing starts when we encounter a location for which we have no machine
5556// code. A hot counter should be used instead.
@@ -123,7 +124,7 @@ void createJITStatePrint(IRBuilder<> &Builder, Module *Mod, std::string Str) {
123124// / Generates the new control point, which includes all logic to start/stop
124125// / tracing and to compile/execute traces.
125126void createControlPoint (Module &Mod, Function *F, std::vector<Value *> LiveVars,
126- StructType *YkCtrlPointStruct) {
127+ StructType *YkCtrlPointStruct, Type *YkLocTy ) {
127128 auto &Context = Mod.getContext ();
128129
129130 // Create control point blocks and setup the IRBuilder.
@@ -166,9 +167,8 @@ void createControlPoint(Module &Mod, Function *F, std::vector<Value *> LiveVars,
166167 PtNull, " compiled_trace" , (GlobalVariable *)nullptr );
167168
168169 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 );
172172
173173 // Create control point entry block. Checks if we are currently tracing.
174174 Value *GVTracingVal = Builder.CreateLoad (Type::getInt8Ty (Context), GVTracing);
@@ -196,8 +196,7 @@ void createControlPoint(Module &Mod, Function *F, std::vector<Value *> LiveVars,
196196 // Create block that checks if we've reached the same location again so we
197197 // can execute a compiled trace.
198198 Builder.SetInsertPoint (BBHasTrace);
199- Value *ValStartLoc =
200- Builder.CreateLoad (Type::getInt32Ty (Context), GVStartLoc);
199+ Value *ValStartLoc = Builder.CreateLoad (YkLocTy, GVStartLoc);
201200 Value *ExecTraceCond = Builder.CreateICmp (CmpInst::Predicate::ICMP_EQ,
202201 ValStartLoc, F->getArg (0 ));
203202 Builder.CreateCondBr (ExecTraceCond, BBExecuteTrace, BBReturn);
@@ -220,8 +219,7 @@ void createControlPoint(Module &Mod, Function *F, std::vector<Value *> LiveVars,
220219
221220 // Create block that decides when to stop tracing.
222221 Builder.SetInsertPoint (BBTracing);
223- Value *ValStartLoc2 =
224- Builder.CreateLoad (Type::getInt32Ty (Context), GVStartLoc);
222+ Value *ValStartLoc2 = Builder.CreateLoad (YkLocTy, GVStartLoc);
225223 Value *StopTracingCond = Builder.CreateICmp (CmpInst::Predicate::ICMP_EQ,
226224 ValStartLoc2, F->getArg (0 ));
227225 Builder.CreateCondBr (StopTracingCond, BBStopTracing, BBReturn);
@@ -312,8 +310,9 @@ PreservedAnalyses YkControlPointPass::run(Module &M,
312310 StructType::create (TypeParams, " YkCtrlPointVars" );
313311
314312 // 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 );
317316 Function *NF = Function::Create (FType, GlobalVariable::ExternalLinkage,
318317 YK_NEW_CONTROL_POINT, M);
319318
@@ -347,7 +346,7 @@ PreservedAnalyses YkControlPointPass::run(Module &M,
347346 OldCtrlPointCall->eraseFromParent ();
348347
349348 // Generate new control point logic.
350- createControlPoint (M, NF, LiveVals, CtrlPointReturnTy);
349+ createControlPoint (M, NF, LiveVals, CtrlPointReturnTy, YkLocTy );
351350
352351 return PreservedAnalyses::none ();
353352}
0 commit comments