Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 1 | //===-- GuardUtils.h - Utils for work with guards ---------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 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 | |
| 15 | namespace llvm { |
| 16 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 17 | class BasicBlock; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 18 | class Use; |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 19 | class User; |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 20 | class Value; |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 21 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 22 | /// Returns true iff \p U has semantics of a guard expressed in a form of call |
| 23 | /// of llvm.experimental.guard intrinsic. |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 24 | bool isGuard(const User *U); |
| 25 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 26 | /// Returns true iff \p U is a widenable branch (that is, parseWidenableBranch |
| 27 | /// returns true). |
| 28 | bool isWidenableBranch(const User *U); |
| 29 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 30 | /// Returns true iff \p U has semantics of a guard expressed in a form of a |
| 31 | /// widenable conditional branch to deopt block. |
| 32 | bool 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. |
| 43 | bool parseWidenableBranch(const User *U, Value *&Condition, |
| 44 | Value *&WidenableCondition, BasicBlock *&IfTrueBB, |
| 45 | BasicBlock *&IfFalseBB); |
| 46 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 47 | /// 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. |
| 49 | bool parseWidenableBranch(User *U, Use *&Cond, Use *&WC, BasicBlock *&IfTrueBB, |
| 50 | BasicBlock *&IfFalseBB); |
| 51 | |
Andrew Scull | 0372a57 | 2018-11-16 15:47:06 +0000 | [diff] [blame] | 52 | } // llvm |
| 53 | |
| 54 | #endif // LLVM_ANALYSIS_GUARDUTILS_H |