Skip to content

Commit

Permalink
Merge rust-lang#22
Browse files Browse the repository at this point in the history
22: Add conditional exit after control point. r=ltratt a=ptersilie



Co-authored-by: Lukas Diekmann <lukas.diekmann@gmail.com>
  • Loading branch information
bors[bot] and ptersilie committed Apr 7, 2022
2 parents f6ff7b1 + a10ba00 commit 69b24b9
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions llvm/lib/Transforms/Yk/ControlPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ class YkControlPoint : public ModulePass {
OldCtrlPointCall->getArgOperand(YK_CONTROL_POINT_ARG_LOC_IDX)
->getType();

// Create the new control point.
// Create the new control point, which is of the form:
// bool new_control_point(YkMT*, YkLocation*, CtrlPointVars*)
FunctionType *FType = FunctionType::get(
Type::getVoidTy(Context),
Type::getInt1Ty(Context),
{YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo()}, false);
Function *NF = Function::Create(FType, GlobalVariable::ExternalLinkage,
YK_NEW_CONTROL_POINT, M);
Expand Down Expand Up @@ -219,11 +220,12 @@ class YkControlPoint : public ModulePass {
// their corresponding live variables. In LLVM IR we can do this by simply
// replacing all future references with the new values.
LvIdx = 0;
Instruction *New;
for (Value *LV : LiveVals) {
Value *FieldPtr =
Builder.CreateGEP(CtrlPointVarsTy, InputStruct,
{Builder.getInt32(0), Builder.getInt32(LvIdx)});
Value *New = Builder.CreateLoad(TypeParams[LvIdx], FieldPtr);
New = Builder.CreateLoad(TypeParams[LvIdx], FieldPtr);
LV->replaceUsesWithIf(
New, [&](Use &U) { return DT.dominates(NewCtrlPointCallInst, U); });
assert(LvIdx != UINT_MAX);
Expand All @@ -233,6 +235,28 @@ class YkControlPoint : public ModulePass {
// Replace the call to the dummy control point.
OldCtrlPointCall->eraseFromParent();

// Get the result of the control point call. If it returns true, that means
// the stopgap interpreter has interpreted a return so we need to return as
// well.

// Create the new exit block.
BasicBlock *ExitBB = BasicBlock::Create(Context, "", Caller);
Builder.SetInsertPoint(ExitBB);
// YKFIXME: We need to return the value of interpreted return and the return
// type must be that of the control point's caller.
Builder.CreateRet(ConstantInt::get(Type::getInt32Ty(Context), 0));

// To do so we need to first split up the current block and then
// insert a conditional branch that either continues or returns.

BasicBlock *BB = NewCtrlPointCallInst->getParent();
BasicBlock *ContBB = BB->splitBasicBlock(New);

Instruction &OldBr = BB->back();
OldBr.eraseFromParent();
Builder.SetInsertPoint(BB);
Builder.CreateCondBr(NewCtrlPointCallInst, ExitBB, ContBB);

// Generate new control point logic.
return true;
}
Expand Down

0 comments on commit 69b24b9

Please sign in to comment.