From 2f27339050f369baef0fc9b85d7a74854d9ea02d Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Thu, 20 Jan 2022 14:28:14 +0000 Subject: [PATCH 1/2] 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. --- llvm/lib/Transforms/Yk/ControlPoint.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Yk/ControlPoint.cpp b/llvm/lib/Transforms/Yk/ControlPoint.cpp index 033bc495b81238..064c3d709c2b9e 100644 --- a/llvm/lib/Transforms/Yk/ControlPoint.cpp +++ b/llvm/lib/Transforms/Yk/ControlPoint.cpp @@ -45,6 +45,7 @@ // is shown as C code for easy comprehension. #include "llvm/Transforms/Yk/ControlPoint.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" @@ -121,8 +122,18 @@ class YkControlPoint : public ModulePass { // Get function containing the control point. Function *Caller = OldCtrlPointCall->getFunction(); - // Find all live variables just before the call to the control point. + // Check that the control point is inside a loop. DominatorTree DT(*Caller); + const LoopInfo Loops(DT); + if (!std::any_of(Loops.begin(), Loops.end(), [OldCtrlPointCall](Loop *L) { + return L->contains(OldCtrlPointCall); + })) { + ; + Context.emitError("yk_control_point() must be called inside a loop."); + return false; + } + + // Find all live variables just before the call to the control point. std::vector LiveVals = getLiveVars(DT, OldCtrlPointCall); if (LiveVals.size() == 0) { Context.emitError( From 1bf5b5f6d501e886304a36ba5db1f69b711eda7b Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Thu, 20 Jan 2022 14:40:42 +0000 Subject: [PATCH 2/2] Unify/sort headers in ControlPoint.cpp. --- llvm/lib/Transforms/Yk/ControlPoint.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Yk/ControlPoint.cpp b/llvm/lib/Transforms/Yk/ControlPoint.cpp index 064c3d709c2b9e..a3c8b66f18a76a 100644 --- a/llvm/lib/Transforms/Yk/ControlPoint.cpp +++ b/llvm/lib/Transforms/Yk/ControlPoint.cpp @@ -47,14 +47,14 @@ #include "llvm/Transforms/Yk/ControlPoint.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" -#include -#include -#include #define DEBUG_TYPE "yk-control-point" #define JIT_STATE_PREFIX "jit-state: "