namespace llvm {
+class BasicBlock;
class User;
+class Value;
/// Returns true iff \p U has semantics of a guard expressed in a form of call
/// of llvm.experimental.guard intrinsic.
/// widenable conditional branch to deopt block.
bool isGuardAsWidenableBranch(const User *U);
+/// If U is widenable branch looking like:
+/// %cond = ...
+/// %wc = call i1 @llvm.experimental.widenable.condition()
+/// %branch_cond = and i1 %cond, %wc
+/// br i1 %branch_cond, label %if_true_bb, label %if_false_bb ; <--- U
+/// The function returns true, and the values %cond and %wc and blocks
+/// %if_true_bb, if_false_bb are returned in
+/// the parameters (Condition, WidenableCondition, IfTrueBB and IfFalseFF)
+/// respectively. If \p U does not match this pattern, return false.
+bool parseWidenableBranch(const User *U, Value *&Condition,
+ Value *&WidenableCondition, BasicBlock *&IfTrueBB,
+ BasicBlock *&IfFalseBB);
+
} // llvm
#endif // LLVM_ANALYSIS_GUARDUTILS_H
}
bool llvm::isGuardAsWidenableBranch(const User *U) {
- using namespace llvm::PatternMatch;
- const BranchInst *BI = dyn_cast<BranchInst>(U);
-
- // We are looking for the following pattern:
- // br i1 %cond & widenable_condition(), label %guarded, label %deopt
- // deopt:
- // <non-side-effecting instructions>
- // deoptimize()
- if (!BI || !BI->isConditional())
+ Value *Condition, *WidenableCondition;
+ BasicBlock *GuardedBB, *DeoptBB;
+ if (!parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
+ DeoptBB))
return false;
-
- if (!match(BI->getCondition(),
- m_And(m_Value(),
- m_Intrinsic<Intrinsic::experimental_widenable_condition>())))
- return false;
-
- const BasicBlock *DeoptBlock = BI->getSuccessor(1);
- for (auto &Insn : *DeoptBlock) {
+ using namespace llvm::PatternMatch;
+ for (auto &Insn : *DeoptBB) {
if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
return true;
if (Insn.mayHaveSideEffects())
}
return false;
}
+
+bool llvm::parseWidenableBranch(const User *U, Value *&Condition,
+ Value *&WidenableCondition,
+ BasicBlock *&IfTrueBB, BasicBlock *&IfFalseBB) {
+ using namespace llvm::PatternMatch;
+ return match(U, m_Br(m_And(m_Value(Condition), m_Value(WidenableCondition)),
+ IfTrueBB, IfFalseBB));
+}