LLVM  9.0.0svn
GuardUtils.cpp
Go to the documentation of this file.
1 //===-- GuardUtils.cpp - Utils for work with guards -------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 // Utils that are used to perform analyzes related to guards and their
9 // conditions.
10 //===----------------------------------------------------------------------===//
11 
13 #include "llvm/IR/PatternMatch.h"
14 
15 using namespace llvm;
16 
17 bool llvm::isGuard(const User *U) {
18  using namespace llvm::PatternMatch;
19  return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
20 }
21 
23  Value *Condition, *WidenableCondition;
24  BasicBlock *GuardedBB, *DeoptBB;
25  if (!parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
26  DeoptBB))
27  return false;
28  using namespace llvm::PatternMatch;
29  for (auto &Insn : *DeoptBB) {
30  if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
31  return true;
32  if (Insn.mayHaveSideEffects())
33  return false;
34  }
35  return false;
36 }
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 }
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Definition: PatternMatch.h:748
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:70
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool match(Val *V, const Pattern &P)
Definition: PatternMatch.h:47
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
brc_match< Cond_t > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
bool parseWidenableBranch(const User *U, Value *&Condition, Value *&WidenableCondition, BasicBlock *&IfTrueBB, BasicBlock *&IfFalseBB)
If U is widenable branch looking like: cond = ...
Definition: GuardUtils.cpp:38
bool isGuard(const User *U)
Returns true iff U has semantics of a guard expressed in a form of call of llvm.experimental.guard intrinsic.
Definition: GuardUtils.cpp:17
LLVM Value Representation.
Definition: Value.h:72
bool isGuardAsWidenableBranch(const User *U)
Returns true iff U has semantics of a guard expressed in a form of a widenable conditional branch to ...
Definition: GuardUtils.cpp:22