Skip to content

Commit 5ff77bb

Browse files
committed
Allow any return type in control point caller.
1 parent 7fa884a commit 5ff77bb

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

llvm/lib/Transforms/Yk/ControlPoint.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,25 @@ class YkControlPoint : public ModulePass {
304304
->getType();
305305

306306
// Create the new control point, which is of the form:
307-
// bool new_control_point(YkMT*, YkLocation*, CtrlPointVars*)
308-
FunctionType *FType = FunctionType::get(
309-
Type::getInt1Ty(Context),
310-
{YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo()}, false);
307+
// bool new_control_point(YkMT*, YkLocation*, CtrlPointVars*,
308+
// ReturnValue*)
309+
// If the return type of the control point's caller is void (i.e. if a
310+
// function f calls yk_control_point and f's return type is void), create
311+
// an Int1 pointer as a dummy. We have to pass something as the yk_stopgap
312+
// signature expects a pointer, even if its never used.
313+
Type *ReturnTy = Caller->getReturnType();
314+
Type *ReturnPtrTy;
315+
if (ReturnTy->isVoidTy()) {
316+
// Create dummy pointer which we pass in but which is never written to.
317+
ReturnPtrTy = Type::getInt1Ty(Context);
318+
} else {
319+
ReturnPtrTy = ReturnTy;
320+
}
321+
FunctionType *FType =
322+
FunctionType::get(Type::getInt1Ty(Context),
323+
{YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo(),
324+
ReturnPtrTy->getPointerTo()},
325+
false);
311326
Function *NF = Function::Create(FType, GlobalVariable::ExternalLinkage,
312327
YK_NEW_CONTROL_POINT, M);
313328

@@ -317,6 +332,10 @@ class YkControlPoint : public ModulePass {
317332
IRBuilder<> Builder(Caller->getEntryBlock().getFirstNonPHI());
318333
Value *InputStruct = Builder.CreateAlloca(CtrlPointVarsTy, 0, "");
319334

335+
// Also at the top, generate storage for the interpreted return of the
336+
// control points caller.
337+
Value *ReturnPtr = Builder.CreateAlloca(ReturnPtrTy, 0, "");
338+
320339
Builder.SetInsertPoint(OldCtrlPointCall);
321340
unsigned LvIdx = 0;
322341
for (Value *LV : LiveVals) {
@@ -332,7 +351,7 @@ class YkControlPoint : public ModulePass {
332351
Instruction *NewCtrlPointCallInst = Builder.CreateCall(
333352
NF, {OldCtrlPointCall->getArgOperand(YK_CONTROL_POINT_ARG_MT_IDX),
334353
OldCtrlPointCall->getArgOperand(YK_CONTROL_POINT_ARG_LOC_IDX),
335-
InputStruct});
354+
InputStruct, ReturnPtr});
336355

337356
// Once the control point returns we need to extract the (potentially
338357
// mutated) values from the returned YkCtrlPointStruct and reassign them to
@@ -363,11 +382,11 @@ class YkControlPoint : public ModulePass {
363382
Builder.SetInsertPoint(ExitBB);
364383
// YKFIXME: We need to return the value of interpreted return and the return
365384
// type must be that of the control point's caller.
366-
Type *RetTy = Caller->getReturnType();
367-
if (RetTy->isVoidTy()) {
385+
if (ReturnTy->isVoidTy()) {
368386
Builder.CreateRetVoid();
369387
} else {
370-
Builder.CreateRet(ConstantInt::get(Type::getInt32Ty(Context), 0));
388+
Value *ReturnValue = Builder.CreateLoad(ReturnTy, ReturnPtr);
389+
Builder.CreateRet(ReturnValue);
371390
}
372391

373392
// To do so we need to first split up the current block and then

0 commit comments

Comments
 (0)