Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:13

0001 //===-- GuardUtils.h - Utils for work with guards ---------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 // Utils that are used to perform analyzes related to guards and their
0009 // conditions.
0010 //===----------------------------------------------------------------------===//
0011 
0012 #ifndef LLVM_ANALYSIS_GUARDUTILS_H
0013 #define LLVM_ANALYSIS_GUARDUTILS_H
0014 
0015 namespace llvm {
0016 
0017 class BasicBlock;
0018 class Use;
0019 class User;
0020 class Value;
0021 template <typename T> class SmallVectorImpl;
0022 
0023 /// Returns true iff \p U has semantics of a guard expressed in a form of call
0024 /// of llvm.experimental.guard intrinsic.
0025 bool isGuard(const User *U);
0026 
0027 /// Returns true iff \p V has semantics of llvm.experimental.widenable.condition
0028 /// call
0029 bool isWidenableCondition(const Value *V);
0030 
0031 /// Returns true iff \p U is a widenable branch (that is,
0032 /// extractWidenableCondition returns widenable condition).
0033 bool isWidenableBranch(const User *U);
0034 
0035 /// Returns true iff \p U has semantics of a guard expressed in a form of a
0036 /// widenable conditional branch to deopt block.
0037 bool isGuardAsWidenableBranch(const User *U);
0038 
0039 /// If U is widenable branch looking like:
0040 ///   %cond = ...
0041 ///   %wc = call i1 @llvm.experimental.widenable.condition()
0042 ///   %branch_cond = and i1 %cond, %wc
0043 ///   br i1 %branch_cond, label %if_true_bb, label %if_false_bb ; <--- U
0044 /// The function returns true, and the values %cond and %wc and blocks
0045 /// %if_true_bb, if_false_bb are returned in
0046 /// the parameters (Condition, WidenableCondition, IfTrueBB and IfFalseFF)
0047 /// respectively. If \p U does not match this pattern, return false.
0048 bool parseWidenableBranch(const User *U, Value *&Condition,
0049                           Value *&WidenableCondition, BasicBlock *&IfTrueBB,
0050                           BasicBlock *&IfFalseBB);
0051 
0052 /// Analogous to the above, but return the Uses so that they can be
0053 /// modified. Unlike previous version, Condition is optional and may be null.
0054 bool parseWidenableBranch(User *U, Use *&Cond, Use *&WC, BasicBlock *&IfTrueBB,
0055                           BasicBlock *&IfFalseBB);
0056 
0057 // The guard condition is expected to be in form of:
0058 //   cond1 && cond2 && cond3 ...
0059 // or in case of widenable branch:
0060 //   cond1 && cond2 && cond3 && widenable_contidion ...
0061 // Method collects the list of checks, but skips widenable_condition.
0062 void parseWidenableGuard(const User *U, llvm::SmallVectorImpl<Value *> &Checks);
0063 
0064 // Returns widenable_condition if it exists in the expression tree rooting from
0065 // \p U and has only one use.
0066 Value *extractWidenableCondition(const User *U);
0067 } // llvm
0068 
0069 #endif // LLVM_ANALYSIS_GUARDUTILS_H