Skip to content

Commit 81d683a

Browse files
bors[bot]vext01
andauthored
20: Check ctrlp inside loop r=ltratt a=vext01 Co-authored-by: Edd Barrett <[email protected]>
2 parents 9d65766 + 1bf5b5f commit 81d683a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

llvm/lib/Transforms/Yk/ControlPoint.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@
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"
50+
#include "llvm/IR/Dominators.h"
4951
#include "llvm/IR/Function.h"
52+
#include "llvm/IR/IRBuilder.h"
5053
#include "llvm/IR/Instructions.h"
5154
#include "llvm/IR/Module.h"
55+
#include "llvm/IR/Verifier.h"
5256
#include "llvm/InitializePasses.h"
5357
#include "llvm/Pass.h"
54-
#include <llvm/IR/Dominators.h>
55-
#include <llvm/IR/IRBuilder.h>
56-
#include <llvm/IR/Verifier.h>
5758

5859
#define DEBUG_TYPE "yk-control-point"
5960
#define JIT_STATE_PREFIX "jit-state: "
@@ -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)