1 //===-- GuardUtils.cpp - Utils for work with guards -------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // Utils that are used to perform analyzes related to guards and their
10 //===----------------------------------------------------------------------===//
12 #include "llvm/Analysis/GuardUtils.h"
13 #include "llvm/IR/PatternMatch.h"
17 bool llvm::isGuard(const User
*U
) {
18 using namespace llvm::PatternMatch
;
19 return match(U
, m_Intrinsic
<Intrinsic::experimental_guard
>());
22 bool llvm::isGuardAsWidenableBranch(const User
*U
) {
23 Value
*Condition
, *WidenableCondition
;
24 BasicBlock
*GuardedBB
, *DeoptBB
;
25 if (!parseWidenableBranch(U
, Condition
, WidenableCondition
, GuardedBB
,
28 using namespace llvm::PatternMatch
;
29 for (auto &Insn
: *DeoptBB
) {
30 if (match(&Insn
, m_Intrinsic
<Intrinsic::experimental_deoptimize
>()))
32 if (Insn
.mayHaveSideEffects())
38 bool llvm::parseWidenableBranch(const User
*U
, Value
*&Condition
,
39 Value
*&WidenableCondition
,
40 BasicBlock
*&IfTrueBB
, BasicBlock
*&IfFalseBB
) {
41 using namespace llvm::PatternMatch
;
42 if (!match(U
, m_Br(m_And(m_Value(Condition
), m_Value(WidenableCondition
)),
43 IfTrueBB
, IfFalseBB
)))
45 // TODO: At the moment, we only recognize the branch if the WC call in this
46 // specific position. We should generalize!
47 return match(WidenableCondition
,
48 m_Intrinsic
<Intrinsic::experimental_widenable_condition
>());