class CallInst;
class Function;
+class User;
+
+/// Returns true iff \p U has semantics of a guard.
+bool isGuard(const User *U);
/// Splits control flow at point of \p Guard, replacing it with explicit branch
/// by the condition of guard's first argument. The taken branch then goes to
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include <cassert>
#include <cstdint>
#include <vector>
// Guards are marked as modifying memory for control flow modelling purposes,
// but don't actually modify any specific memory location.
using namespace PatternMatch;
- bool MayWriteMemory = I->mayWriteToMemory() &&
- !match(I, m_Intrinsic<Intrinsic::experimental_guard>()) &&
+ bool MayWriteMemory = I->mayWriteToMemory() && !isGuard(I) &&
!(I->use_empty() && match(I, m_Intrinsic<Intrinsic::invariant_start>()));
if (!MayWriteMemory) {
Alias = SetMayAlias;
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include <algorithm>
#include <array>
#include <cassert>
BasicBlockEdge Edge(BI->getParent(), NonNullSuccessor);
if (Edge.isSingleEdge() && DT->dominates(Edge, CtxI->getParent()))
return true;
- } else if (Pred == ICmpInst::ICMP_NE &&
- match(Curr, m_Intrinsic<Intrinsic::experimental_guard>()) &&
+ } else if (Pred == ICmpInst::ICMP_NE && isGuard(Curr) &&
DT->dominates(cast<Instruction>(Curr), CtxI)) {
return true;
}
#include "llvm/Support/RecyclingAllocator.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include <cassert>
#include <deque>
#include <memory>
continue;
}
- if (match(Inst, m_Intrinsic<Intrinsic::experimental_guard>())) {
+ if (isGuard(Inst)) {
if (auto *CondI =
dyn_cast<Instruction>(cast<CallInst>(Inst)->getArgOperand(0))) {
if (SimpleValue::canHandle(CondI)) {
#include "llvm/Support/Debug.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
using namespace llvm;
cast<BranchInst>(I)->setCondition(NewCond);
}
-// Whether or not the particular instruction \p I is a guard.
-static bool isGuard(const Instruction *I) {
- using namespace llvm::PatternMatch;
- return match(I, m_Intrinsic<Intrinsic::experimental_guard>());
-}
-
// Eliminates the guard instruction properly.
static void eliminateGuard(Instruction *GuardInst) {
GuardInst->eraseFromParent();
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
if (auto *BI = dyn_cast<BranchInst>(Parent->getTerminator()))
for (auto &I : *BB)
- if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>()))
- if (ThreadGuard(BB, cast<IntrinsicInst>(&I), BI))
- return true;
+ if (isGuard(&I) && ThreadGuard(BB, cast<IntrinsicInst>(&I), BI))
+ return true;
return false;
}
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include <algorithm>
using namespace PatternMatch;
if (((I.use_empty() &&
match(&I, m_Intrinsic<Intrinsic::invariant_start>())) ||
- match(&I, m_Intrinsic<Intrinsic::experimental_guard>())) &&
+ isGuard(&I)) &&
IsMustExecute && IsMemoryNotModified &&
CurLoop->hasLoopInvariantOperands(&I)) {
hoist(I, DT, CurLoop, SafetyInfo, ORE);
SmallVector<CallInst *, 8> ToLower;
for (auto &I : instructions(F))
- if (auto *CI = dyn_cast<CallInst>(&I))
- if (auto *F = CI->getCalledFunction())
- if (F->getIntrinsicID() == Intrinsic::experimental_guard)
- ToLower.push_back(CI);
+ if (isGuard(&I))
+ ToLower.push_back(cast<CallInst>(&I));
if (ToLower.empty())
return false;
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/PatternMatch.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
using namespace llvm;
cl::desc("The probability of a guard failing is assumed to be the "
"reciprocal of this value (default = 1 << 20)"));
+bool llvm::isGuard(const User *U) {
+ using namespace llvm::PatternMatch;
+ return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
+}
+
void llvm::makeGuardControlFlowExplicit(Function *DeoptIntrinsic,
CallInst *Guard) {
OperandBundleDef DeoptOB(*Guard->getOperandBundle(LLVMContext::OB_deopt));