Skip to content

Commit 2f27339

Browse files
committed
Check that yk_control_point() is called inside an interpreter loop.
We check that `yk_control_point()` is called from inside what appears to be an interpreter loop, i.e. from within an outermost loop in a function.
1 parent 9d65766 commit 2f27339

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

llvm/lib/Transforms/Yk/ControlPoint.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
// is shown as C code for easy comprehension.
4646

4747
#include "llvm/Transforms/Yk/ControlPoint.h"
48+
#include "llvm/Analysis/LoopInfo.h"
4849
#include "llvm/IR/BasicBlock.h"
4950
#include "llvm/IR/Function.h"
5051
#include "llvm/IR/Instructions.h"
@@ -121,8 +122,18 @@ class YkControlPoint : public ModulePass {
121122
// Get function containing the control point.
122123
Function *Caller = OldCtrlPointCall->getFunction();
123124

124-
// Find all live variables just before the call to the control point.
125+
// Check that the control point is inside a loop.
125126
DominatorTree DT(*Caller);
127+
const LoopInfo Loops(DT);
128+
if (!std::any_of(Loops.begin(), Loops.end(), [OldCtrlPointCall](Loop *L) {
129+
return L->contains(OldCtrlPointCall);
130+
})) {
131+
;
132+
Context.emitError("yk_control_point() must be called inside a loop.");
133+
return false;
134+
}
135+
136+
// Find all live variables just before the call to the control point.
126137
std::vector<Value *> LiveVals = getLiveVars(DT, OldCtrlPointCall);
127138
if (LiveVals.size() == 0) {
128139
Context.emitError(

0 commit comments

Comments
 (0)