[PATCH] D56074: [NFC] Add detector function for explicitly expressed guards
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 25 02:40:20 PST 2018
mkazantsev created this revision.
mkazantsev added reviewers: anna, apilipenko, skatkov, reames.
This patch adds a function to detect guards expressed in explicit form:
%wc = call i1 @llvm.experimental.widenable.condition()
%guard_cond = and i1, %some_cond, %wc
br i1 %guard_cond, label %guarded, label %deopt
deopt:
<maybe some non-side-effecting instructions>
deoptimize()
This form can be used as alternative to implicit control flow guard
representation expressed by `experimental_guard` intrinsic.
https://reviews.llvm.org/D56074
Files:
include/llvm/Analysis/GuardUtils.h
lib/Analysis/GuardUtils.cpp
Index: lib/Analysis/GuardUtils.cpp
===================================================================
--- lib/Analysis/GuardUtils.cpp
+++ lib/Analysis/GuardUtils.cpp
@@ -19,3 +19,30 @@
using namespace llvm::PatternMatch;
return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
}
+
+bool llvm::isExplicitGuard(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())
+ 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) {
+ if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
+ return true;
+ if (Insn.mayHaveSideEffects())
+ return false;
+ }
+ return false;
+}
Index: include/llvm/Analysis/GuardUtils.h
===================================================================
--- include/llvm/Analysis/GuardUtils.h
+++ include/llvm/Analysis/GuardUtils.h
@@ -20,6 +20,9 @@
/// Returns true iff \p U has semantics of a guard.
bool isGuard(const User *U);
+/// Returns true iff \p U is a branch that has semantics of a guard.
+bool isExplicitGuard(const User *U);
+
} // llvm
#endif // LLVM_ANALYSIS_GUARDUTILS_H
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56074.179488.patch
Type: text/x-patch
Size: 1575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181225/dad29843/attachment.bin>
More information about the llvm-commits
mailing list