blob: b83211535ec234177dbfe017ed9dad1fe4de555b [file] [log] [blame]
Andrew Scull0372a572018-11-16 15:47:06 +00001//===-- GuardUtils.h - Utils for work with guards ---------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull0372a572018-11-16 15:47:06 +00006//
7//===----------------------------------------------------------------------===//
8// Utils that are used to perform analyzes related to guards and their
9// conditions.
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_ANALYSIS_GUARDUTILS_H
13#define LLVM_ANALYSIS_GUARDUTILS_H
14
15namespace llvm {
16
Andrew Walbran16937d02019-10-22 13:54:20 +010017class BasicBlock;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020018class Use;
Andrew Scull0372a572018-11-16 15:47:06 +000019class User;
Andrew Walbran16937d02019-10-22 13:54:20 +010020class Value;
Andrew Scull0372a572018-11-16 15:47:06 +000021
Andrew Walbran16937d02019-10-22 13:54:20 +010022/// Returns true iff \p U has semantics of a guard expressed in a form of call
23/// of llvm.experimental.guard intrinsic.
Andrew Scull0372a572018-11-16 15:47:06 +000024bool isGuard(const User *U);
25
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020026/// Returns true iff \p U is a widenable branch (that is, parseWidenableBranch
27/// returns true).
28bool isWidenableBranch(const User *U);
29
Andrew Walbran16937d02019-10-22 13:54:20 +010030/// Returns true iff \p U has semantics of a guard expressed in a form of a
31/// widenable conditional branch to deopt block.
32bool isGuardAsWidenableBranch(const User *U);
33
34/// If U is widenable branch looking like:
35/// %cond = ...
36/// %wc = call i1 @llvm.experimental.widenable.condition()
37/// %branch_cond = and i1 %cond, %wc
38/// br i1 %branch_cond, label %if_true_bb, label %if_false_bb ; <--- U
39/// The function returns true, and the values %cond and %wc and blocks
40/// %if_true_bb, if_false_bb are returned in
41/// the parameters (Condition, WidenableCondition, IfTrueBB and IfFalseFF)
42/// respectively. If \p U does not match this pattern, return false.
43bool parseWidenableBranch(const User *U, Value *&Condition,
44 Value *&WidenableCondition, BasicBlock *&IfTrueBB,
45 BasicBlock *&IfFalseBB);
46
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020047/// Analgous to the above, but return the Uses so that that they can be
48/// modified. Unlike previous version, Condition is optional and may be null.
49bool parseWidenableBranch(User *U, Use *&Cond, Use *&WC, BasicBlock *&IfTrueBB,
50 BasicBlock *&IfFalseBB);
51
Andrew Scull0372a572018-11-16 15:47:06 +000052} // llvm
53
54#endif // LLVM_ANALYSIS_GUARDUTILS_H