blob: c099ee8e41c66efcfd9a4a380969d519a968adb4 [file] [log] [blame]
Max Kazantsev3c284bd2018-08-30 03:39:16 +00001//===-- GuardUtils.cpp - Utils for work with guards -------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Max Kazantsev3c284bd2018-08-30 03:39:16 +00006//
7//===----------------------------------------------------------------------===//
8// Utils that are used to perform analyzes related to guards and their
9// conditions.
10//===----------------------------------------------------------------------===//
11
12#include "llvm/Analysis/GuardUtils.h"
13#include "llvm/IR/PatternMatch.h"
14
15using namespace llvm;
16
17bool llvm::isGuard(const User *U) {
18 using namespace llvm::PatternMatch;
19 return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
20}
Max Kazantsevbd374b22019-01-22 09:36:22 +000021
22bool llvm::isGuardAsWidenableBranch(const User *U) {
Max Kazantsevca47f1f2019-01-22 11:21:32 +000023 Value *Condition, *WidenableCondition;
24 BasicBlock *GuardedBB, *DeoptBB;
25 if (!parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
26 DeoptBB))
27 return false;
Max Kazantsevbd374b22019-01-22 09:36:22 +000028 using namespace llvm::PatternMatch;
Max Kazantsevca47f1f2019-01-22 11:21:32 +000029 for (auto &Insn : *DeoptBB) {
Max Kazantsevbd374b22019-01-22 09:36:22 +000030 if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
31 return true;
32 if (Insn.mayHaveSideEffects())
33 return false;
34 }
35 return false;
36}
Max Kazantsevca47f1f2019-01-22 11:21:32 +000037
38bool 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}