1353940Sdim//=- MachineLoopUtils.h - Helper functions for manipulating loops -*- C++ -*-=//
2353940Sdim//
3353940Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353940Sdim// See https://llvm.org/LICENSE.txt for license information.
5353940Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6353940Sdim//
7353940Sdim//===----------------------------------------------------------------------===//
8353940Sdim
9353940Sdim#ifndef LLVM_LIB_CODEGEN_MACHINELOOPUTILS_H
10353940Sdim#define LLVM_LIB_CODEGEN_MACHINELOOPUTILS_H
11353940Sdim
12353940Sdimnamespace llvm {
13357095Sdimclass MachineLoop;
14353940Sdimclass MachineBasicBlock;
15353940Sdimclass MachineRegisterInfo;
16353940Sdimclass TargetInstrInfo;
17353940Sdim
18353940Sdimenum LoopPeelDirection {
19353940Sdim  LPD_Front, ///< Peel the first iteration of the loop.
20353940Sdim  LPD_Back   ///< Peel the last iteration of the loop.
21353940Sdim};
22353940Sdim
23353940Sdim/// Peels a single block loop. Loop must have two successors, one of which
24353940Sdim/// must be itself. Similarly it must have two predecessors, one of which must
25353940Sdim/// be itself.
26353940Sdim///
27353940Sdim/// The loop block is copied and inserted into the CFG such that two copies of
28353940Sdim/// the loop follow on from each other. The copy is inserted either before or
29353940Sdim/// after the loop based on Direction.
30353940Sdim///
31353940Sdim/// Phis are updated and an unconditional branch inserted at the end of the
32353940Sdim/// clone so as to execute a single iteration.
33353940Sdim///
34353940Sdim/// The trip count of Loop is not updated.
35353940SdimMachineBasicBlock *PeelSingleBlockLoop(LoopPeelDirection Direction,
36353940Sdim                                       MachineBasicBlock *Loop,
37353940Sdim                                       MachineRegisterInfo &MRI,
38353940Sdim                                       const TargetInstrInfo *TII);
39353940Sdim
40357095Sdim/// Return true if PhysReg is live outside the loop, i.e. determine if it
41357095Sdim/// is live in the loop exit blocks, and false otherwise.
42357095Sdimbool isRegLiveInExitBlocks(MachineLoop *Loop, int PhysReg);
43357095Sdim
44353940Sdim} // namespace llvm
45353940Sdim
46353940Sdim#endif // LLVM_LIB_CODEGEN_MACHINELOOPUTILS_H
47