Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit b92e756

Browse files
author
Max Kazantsev
committed
[NFC] Add function to parse widenable conditional branches
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351803 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9ae4b86 commit b92e756

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

include/llvm/Analysis/GuardUtils.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
namespace llvm {
1616

17+
class BasicBlock;
1718
class User;
19+
class Value;
1820

1921
/// Returns true iff \p U has semantics of a guard expressed in a form of call
2022
/// of llvm.experimental.guard intrinsic.
@@ -24,6 +26,19 @@ bool isGuard(const User *U);
2426
/// widenable conditional branch to deopt block.
2527
bool isGuardAsWidenableBranch(const User *U);
2628

29+
/// If U is widenable branch looking like:
30+
/// %cond = ...
31+
/// %wc = call i1 @llvm.experimental.widenable.condition()
32+
/// %branch_cond = and i1 %cond, %wc
33+
/// br i1 %branch_cond, label %if_true_bb, label %if_false_bb ; <--- U
34+
/// The function returns true, and the values %cond and %wc and blocks
35+
/// %if_true_bb, if_false_bb are returned in
36+
/// the parameters (Condition, WidenableCondition, IfTrueBB and IfFalseFF)
37+
/// respectively. If \p U does not match this pattern, return false.
38+
bool parseWidenableBranch(const User *U, Value *&Condition,
39+
Value *&WidenableCondition, BasicBlock *&IfTrueBB,
40+
BasicBlock *&IfFalseBB);
41+
2742
} // llvm
2843

2944
#endif // LLVM_ANALYSIS_GUARDUTILS_H

lib/Analysis/GuardUtils.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,25 @@ bool llvm::isGuard(const User *U) {
2020
}
2121

2222
bool llvm::isGuardAsWidenableBranch(const User *U) {
23-
using namespace llvm::PatternMatch;
24-
const BranchInst *BI = dyn_cast<BranchInst>(U);
25-
26-
// We are looking for the following pattern:
27-
// br i1 %cond & widenable_condition(), label %guarded, label %deopt
28-
// deopt:
29-
// <non-side-effecting instructions>
30-
// deoptimize()
31-
if (!BI || !BI->isConditional())
23+
Value *Condition, *WidenableCondition;
24+
BasicBlock *GuardedBB, *DeoptBB;
25+
if (!parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
26+
DeoptBB))
3227
return false;
33-
34-
if (!match(BI->getCondition(),
35-
m_And(m_Value(),
36-
m_Intrinsic<Intrinsic::experimental_widenable_condition>())))
37-
return false;
38-
39-
const BasicBlock *DeoptBlock = BI->getSuccessor(1);
40-
for (auto &Insn : *DeoptBlock) {
28+
using namespace llvm::PatternMatch;
29+
for (auto &Insn : *DeoptBB) {
4130
if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
4231
return true;
4332
if (Insn.mayHaveSideEffects())
4433
return false;
4534
}
4635
return false;
4736
}
37+
38+
bool llvm::parseWidenableBranch(const User *U, Value *&Condition,
39+
Value *&WidenableCondition,
40+
BasicBlock *&IfTrueBB, BasicBlock *&IfFalseBB) {
41+
using namespace llvm::PatternMatch;
42+
return match(U, m_Br(m_And(m_Value(Condition), m_Value(WidenableCondition)),
43+
IfTrueBB, IfFalseBB));
44+
}

0 commit comments

Comments
 (0)