mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[NFC] Add function to parse widenable conditional branches
llvm-svn: 351803
This commit is contained in:
parent
ac45f0ce9d
commit
03355e4336
@ -14,7 +14,9 @@
|
||||
|
||||
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.
|
||||
@ -24,6 +26,19 @@ bool isGuard(const User *U);
|
||||
/// 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
|
||||
|
@ -20,24 +20,13 @@ bool llvm::isGuard(const User *U) {
|
||||
}
|
||||
|
||||
bool llvm::isGuardAsWidenableBranch(const User *U) {
|
||||
Value *Condition, *WidenableCondition;
|
||||
BasicBlock *GuardedBB, *DeoptBB;
|
||||
if (!parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
|
||||
DeoptBB))
|
||||
return false;
|
||||
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())
|
||||
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) {
|
||||
for (auto &Insn : *DeoptBB) {
|
||||
if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
|
||||
return true;
|
||||
if (Insn.mayHaveSideEffects())
|
||||
@ -45,3 +34,11 @@ bool llvm::isGuardAsWidenableBranch(const User *U) {
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user