@@ -184,9 +184,10 @@ class YkControlPoint : public ModulePass {
184
184
OldCtrlPointCall->getArgOperand (YK_CONTROL_POINT_ARG_LOC_IDX)
185
185
->getType ();
186
186
187
- // Create the new control point.
187
+ // Create the new control point, which is of the form:
188
+ // bool new_control_point(YkMT*, YkLocation*, CtrlPointVars*)
188
189
FunctionType *FType = FunctionType::get (
189
- Type::getVoidTy (Context),
190
+ Type::getInt1Ty (Context),
190
191
{YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo ()}, false );
191
192
Function *NF = Function::Create (FType, GlobalVariable::ExternalLinkage,
192
193
YK_NEW_CONTROL_POINT, M);
@@ -219,11 +220,12 @@ class YkControlPoint : public ModulePass {
219
220
// their corresponding live variables. In LLVM IR we can do this by simply
220
221
// replacing all future references with the new values.
221
222
LvIdx = 0 ;
223
+ Instruction *New;
222
224
for (Value *LV : LiveVals) {
223
225
Value *FieldPtr =
224
226
Builder.CreateGEP (CtrlPointVarsTy, InputStruct,
225
227
{Builder.getInt32 (0 ), Builder.getInt32 (LvIdx)});
226
- Value * New = Builder.CreateLoad (TypeParams[LvIdx], FieldPtr);
228
+ New = Builder.CreateLoad (TypeParams[LvIdx], FieldPtr);
227
229
LV->replaceUsesWithIf (
228
230
New, [&](Use &U) { return DT.dominates (NewCtrlPointCallInst, U); });
229
231
assert (LvIdx != UINT_MAX);
@@ -233,6 +235,28 @@ class YkControlPoint : public ModulePass {
233
235
// Replace the call to the dummy control point.
234
236
OldCtrlPointCall->eraseFromParent ();
235
237
238
+ // Get the result of the control point call. If it returns true, that means
239
+ // the stopgap interpreter has interpreted a return so we need to return as
240
+ // well.
241
+
242
+ // Create the new exit block.
243
+ BasicBlock *ExitBB = BasicBlock::Create (Context, " " , Caller);
244
+ Builder.SetInsertPoint (ExitBB);
245
+ // YKFIXME: We need to return the value of interpreted return and the return
246
+ // type must be that of the control point's caller.
247
+ Builder.CreateRet (ConstantInt::get (Type::getInt32Ty (Context), 0 ));
248
+
249
+ // To do so we need to first split up the current block and then
250
+ // insert a conditional branch that either continues or returns.
251
+
252
+ BasicBlock *BB = NewCtrlPointCallInst->getParent ();
253
+ BasicBlock *ContBB = BB->splitBasicBlock (New);
254
+
255
+ Instruction &OldBr = BB->back ();
256
+ OldBr.eraseFromParent ();
257
+ Builder.SetInsertPoint (BB);
258
+ Builder.CreateCondBr (NewCtrlPointCallInst, ExitBB, ContBB);
259
+
236
260
// Generate new control point logic.
237
261
return true ;
238
262
}
0 commit comments