18b4ffe66SMax Kazantsev //===-- GuardUtils.h - Utils for work with guards ---------------*- C++ -*-===//
28b4ffe66SMax Kazantsev //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
68b4ffe66SMax Kazantsev //
78b4ffe66SMax Kazantsev //===----------------------------------------------------------------------===//
88b4ffe66SMax Kazantsev // Utils that are used to perform transformations related to guards and their
98b4ffe66SMax Kazantsev // conditions.
108b4ffe66SMax Kazantsev //===----------------------------------------------------------------------===//
118b4ffe66SMax Kazantsev 
128b4ffe66SMax Kazantsev #ifndef LLVM_TRANSFORMS_UTILS_GUARDUTILS_H
138b4ffe66SMax Kazantsev #define LLVM_TRANSFORMS_UTILS_GUARDUTILS_H
148b4ffe66SMax Kazantsev 
158b4ffe66SMax Kazantsev namespace llvm {
168b4ffe66SMax Kazantsev 
1770c68a6bSPhilip Reames class BranchInst;
188b4ffe66SMax Kazantsev class CallInst;
198b4ffe66SMax Kazantsev class Function;
2070c68a6bSPhilip Reames class Value;
218b4ffe66SMax Kazantsev 
228b4ffe66SMax Kazantsev /// Splits control flow at point of \p Guard, replacing it with explicit branch
238b4ffe66SMax Kazantsev /// by the condition of guard's first argument. The taken branch then goes to
248b4ffe66SMax Kazantsev /// the block that contains  \p Guard's successors, and the non-taken branch
258b4ffe66SMax Kazantsev /// goes to a newly-created deopt block that contains a sole call of the
26*8ba56f32SPhilip Reames /// deoptimize function \p DeoptIntrinsic.  If 'UseWC' is set, preserve the
27*8ba56f32SPhilip Reames /// widenable nature of the guard by lowering to equivelent form.  If not set,
28*8ba56f32SPhilip Reames /// lower to a form without widenable semantics.
29*8ba56f32SPhilip Reames void makeGuardControlFlowExplicit(Function *DeoptIntrinsic, CallInst *Guard,
30*8ba56f32SPhilip Reames                                   bool UseWC);
318b4ffe66SMax Kazantsev 
3270c68a6bSPhilip Reames /// Given a branch we know is widenable (defined per Analysis/GuardUtils.h),
3370c68a6bSPhilip Reames /// widen it such that condition 'NewCond' is also known to hold on the taken
3470c68a6bSPhilip Reames /// path.  Branch remains widenable after transform.
3570c68a6bSPhilip Reames void widenWidenableBranch(BranchInst *WidenableBR, Value *NewCond);
3670c68a6bSPhilip Reames 
3770c68a6bSPhilip Reames /// Given a branch we know is widenable (defined per Analysis/GuardUtils.h),
3870c68a6bSPhilip Reames /// *set* it's condition such that (only) 'Cond' is known to hold on the taken
3970c68a6bSPhilip Reames /// path and that the branch remains widenable after transform.
4070c68a6bSPhilip Reames void setWidenableBranchCond(BranchInst *WidenableBR, Value *Cond);
4170c68a6bSPhilip Reames 
428b4ffe66SMax Kazantsev } // llvm
438b4ffe66SMax Kazantsev 
448b4ffe66SMax Kazantsev #endif // LLVM_TRANSFORMS_UTILS_GUARDUTILS_H
45