Skip to content

Commit 23597b1

Browse files
bors[bot]ptersilie
andauthored
73: Simplify the control point. r=ltratt a=ptersilie Co-authored-by: Lukas Diekmann <[email protected]>
2 parents 5f36f1f + 4c3be08 commit 23597b1

File tree

1 file changed

+3
-49
lines changed

1 file changed

+3
-49
lines changed

llvm/lib/Transforms/Yk/ControlPoint.cpp

+3-49
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ class YkControlPoint : public ModulePass {
162162
->getType();
163163

164164
// Create the new control point, which is of the form:
165-
// void* new_control_point(YkMT*, YkLocation*, CtrlPointVars*, void*)
165+
// void new_control_point(YkMT*, YkLocation*, CtrlPointVars*, void*)
166166
PointerType *VoidPtr = PointerType::get(Context, 0);
167167
FunctionType *FType = FunctionType::get(
168-
VoidPtr, {YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo(), VoidPtr},
169-
false);
168+
Type::getVoidTy(Context),
169+
{YkMTTy, YkLocTy, CtrlPointVarsTy->getPointerTo(), VoidPtr}, false);
170170
Function *NF = Function::Create(FType, GlobalVariable::ExternalLinkage,
171171
YK_NEW_CONTROL_POINT, M);
172172

@@ -199,55 +199,9 @@ class YkControlPoint : public ModulePass {
199199
OldCtrlPointCall->getArgOperand(YK_CONTROL_POINT_ARG_LOC_IDX),
200200
InputStruct, FAddr});
201201

202-
// Once the control point returns we need to extract the (potentially
203-
// mutated) values from the returned YkCtrlPointStruct and reassign them to
204-
// their corresponding live variables. In LLVM IR we can do this by simply
205-
// replacing all future references with the new values.
206-
LvIdx = 0;
207-
Instruction *New;
208-
for (Value *LV : LiveVals) {
209-
Value *FieldPtr =
210-
Builder.CreateGEP(CtrlPointVarsTy, InputStruct,
211-
{Builder.getInt32(0), Builder.getInt32(LvIdx)});
212-
New = Builder.CreateLoad(TypeParams[LvIdx], FieldPtr);
213-
LV->replaceUsesWithIf(
214-
New, [&](Use &U) { return DT.dominates(NewCtrlPointCallInst, U); });
215-
assert(LvIdx != UINT_MAX);
216-
LvIdx++;
217-
}
218-
219202
// Replace the call to the dummy control point.
220203
OldCtrlPointCall->eraseFromParent();
221204

222-
// Create the new exit block.
223-
BasicBlock *ExitBB = BasicBlock::Create(Context, "", Caller);
224-
Builder.SetInsertPoint(ExitBB);
225-
226-
// Create call to frame reconstructor.
227-
FunctionType *YKFRType =
228-
FunctionType::get(Type::getVoidTy(Context), {VoidPtr}, false);
229-
Function *YKFR = Function::Create(YKFRType, GlobalVariable::ExternalLinkage,
230-
YK_RECONSTRUCT_FRAMES, M);
231-
Builder.CreateCall(YKFR, {NewCtrlPointCallInst});
232-
Builder.CreateUnreachable();
233-
234-
// Split up the current block and then insert a conditional branch that
235-
// either continues after the control point or invokes frame reconstruction.
236-
BasicBlock *BB = NewCtrlPointCallInst->getParent();
237-
BasicBlock *ContBB = BB->splitBasicBlock(New->getNextNonDebugInstruction());
238-
Instruction &OldBr = BB->back();
239-
assert(OldBr.getPrevNonDebugInstruction() == New &&
240-
"Split block at the wrong spot.");
241-
OldBr.eraseFromParent();
242-
Builder.SetInsertPoint(BB);
243-
// The return value of the control point tells us whether a guard has failed
244-
// or not (i.e. anything other than a nullptr means a guard has failed). If
245-
// it has jump to `ExitBB` which calls the code that copies over the new
246-
// stack from the given pointer.
247-
Value *HasGuardFailed = Builder.CreateICmpEQ(
248-
NewCtrlPointCallInst, ConstantPointerNull::get(VoidPtr));
249-
Builder.CreateCondBr(HasGuardFailed, ContBB, ExitBB);
250-
251205
#ifndef NDEBUG
252206
// Our pass runs after LLVM normally does its verify pass. In debug builds
253207
// we run it again to check that our pass is generating valid IR.

0 commit comments

Comments
 (0)