LLVM 20.0.0git
GuardUtils.h
Go to the documentation of this file.
1//===-- GuardUtils.h - 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
12#ifndef LLVM_ANALYSIS_GUARDUTILS_H
13#define LLVM_ANALYSIS_GUARDUTILS_H
14
15namespace llvm {
16
17class BasicBlock;
18class Use;
19class User;
20class Value;
21template <typename T> class SmallVectorImpl;
22
23/// Returns true iff \p U has semantics of a guard expressed in a form of call
24/// of llvm.experimental.guard intrinsic.
25bool isGuard(const User *U);
26
27/// Returns true iff \p V has semantics of llvm.experimental.widenable.condition
28/// call
29bool isWidenableCondition(const Value *V);
30
31/// Returns true iff \p U is a widenable branch (that is,
32/// extractWidenableCondition returns widenable condition).
33bool isWidenableBranch(const User *U);
34
35/// Returns true iff \p U has semantics of a guard expressed in a form of a
36/// widenable conditional branch to deopt block.
37bool isGuardAsWidenableBranch(const User *U);
38
39/// If U is widenable branch looking like:
40/// %cond = ...
41/// %wc = call i1 @llvm.experimental.widenable.condition()
42/// %branch_cond = and i1 %cond, %wc
43/// br i1 %branch_cond, label %if_true_bb, label %if_false_bb ; <--- U
44/// The function returns true, and the values %cond and %wc and blocks
45/// %if_true_bb, if_false_bb are returned in
46/// the parameters (Condition, WidenableCondition, IfTrueBB and IfFalseFF)
47/// respectively. If \p U does not match this pattern, return false.
48bool parseWidenableBranch(const User *U, Value *&Condition,
49 Value *&WidenableCondition, BasicBlock *&IfTrueBB,
50 BasicBlock *&IfFalseBB);
51
52/// Analogous to the above, but return the Uses so that they can be
53/// modified. Unlike previous version, Condition is optional and may be null.
54bool parseWidenableBranch(User *U, Use *&Cond, Use *&WC, BasicBlock *&IfTrueBB,
55 BasicBlock *&IfFalseBB);
56
57// The guard condition is expected to be in form of:
58// cond1 && cond2 && cond3 ...
59// or in case of widenable branch:
60// cond1 && cond2 && cond3 && widenable_contidion ...
61// Method collects the list of checks, but skips widenable_condition.
62void parseWidenableGuard(const User *U, llvm::SmallVectorImpl<Value *> &Checks);
63
64// Returns widenable_condition if it exists in the expression tree rooting from
65// \p U and has only one use.
66Value *extractWidenableCondition(const User *U);
67} // llvm
68
69#endif // LLVM_ANALYSIS_GUARDUTILS_H
const SmallVectorImpl< MachineOperand > & Cond
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
Definition: RDFGraph.h:385
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Value * extractWidenableCondition(const User *U)
Definition: GuardUtils.cpp:151
void parseWidenableGuard(const User *U, llvm::SmallVectorImpl< Value * > &Checks)
Definition: GuardUtils.cpp:138
bool isGuard(const User *U)
Returns true iff U has semantics of a guard expressed in a form of call of llvm.experimental....
Definition: GuardUtils.cpp:18
bool isWidenableCondition(const Value *V)
Returns true iff V has semantics of llvm.experimental.widenable.condition call.
Definition: GuardUtils.cpp:22
bool parseWidenableBranch(const User *U, Value *&Condition, Value *&WidenableCondition, BasicBlock *&IfTrueBB, BasicBlock *&IfFalseBB)
If U is widenable branch looking like: cond = ... wc = call i1 @llvm.experimental....
Definition: GuardUtils.cpp:53
bool isWidenableBranch(const User *U)
Returns true iff U is a widenable branch (that is, extractWidenableCondition returns widenable condit...
Definition: GuardUtils.cpp:26
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:33