Skip to content

Commit d1bab36

Browse files
committed
Make the control point accept a pointer to a YkLocation.
Currently the JIT identifies a user-program location using a simple integer, but it should use the `YkLocation` struct, which would allow for more realistic control point behaviour (hot counts etc.). This change modifies the type of the patched-in control point (and its call-site) to use `YkLocation`. Note that the control point is still very simple and uses the addresses of YkLocations as an identifier. This is not how we intend this to work in the long run: YkLocations should be freely moveable (see `location.rs` for our preliminary intent from the old yk design). Needless to say, for now we also bypass all of YkLocation's multi-threaded synchronisation too.
1 parent 39f8f8a commit d1bab36

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

llvm/lib/Transforms/Yk/ControlPoint.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@
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.
125126
void 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

Comments
 (0)