[llvm] r351803 - [NFC] Add function to parse widenable conditional branches

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 03:21:32 PST 2019


Author: mkazantsev
Date: Tue Jan 22 03:21:32 2019
New Revision: 351803

URL: http://llvm.org/viewvc/llvm-project?rev=351803&view=rev
Log:
[NFC] Add function to parse widenable conditional branches

Modified:
    llvm/trunk/include/llvm/Analysis/GuardUtils.h
    llvm/trunk/lib/Analysis/GuardUtils.cpp

Modified: llvm/trunk/include/llvm/Analysis/GuardUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/GuardUtils.h?rev=351803&r1=351802&r2=351803&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/GuardUtils.h (original)
+++ llvm/trunk/include/llvm/Analysis/GuardUtils.h Tue Jan 22 03:21:32 2019
@@ -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

Modified: llvm/trunk/lib/Analysis/GuardUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/GuardUtils.cpp?rev=351803&r1=351802&r2=351803&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/GuardUtils.cpp (original)
+++ llvm/trunk/lib/Analysis/GuardUtils.cpp Tue Jan 22 03:21:32 2019
@@ -20,24 +20,13 @@ bool llvm::isGuard(const User *U) {
 }
 
 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())
@@ -45,3 +34,11 @@ bool llvm::isGuardAsWidenableBranch(cons
   }
   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));
+}




More information about the llvm-commits mailing list