blob: ec0b3529c0d60313d637d3e1cd2f8daca573ddfc [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//=- MachineLoopUtils.h - Helper functions for manipulating loops -*- 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
9#ifndef LLVM_LIB_CODEGEN_MACHINELOOPUTILS_H
10#define LLVM_LIB_CODEGEN_MACHINELOOPUTILS_H
11
12namespace llvm {
13class MachineLoop;
14class MachineBasicBlock;
15class MachineRegisterInfo;
16class TargetInstrInfo;
17
18enum LoopPeelDirection {
19 LPD_Front, ///< Peel the first iteration of the loop.
20 LPD_Back ///< Peel the last iteration of the loop.
21};
22
23/// Peels a single block loop. Loop must have two successors, one of which
24/// must be itself. Similarly it must have two predecessors, one of which must
25/// be itself.
26///
27/// The loop block is copied and inserted into the CFG such that two copies of
28/// the loop follow on from each other. The copy is inserted either before or
29/// after the loop based on Direction.
30///
31/// Phis are updated and an unconditional branch inserted at the end of the
32/// clone so as to execute a single iteration.
33///
34/// The trip count of Loop is not updated.
35MachineBasicBlock *PeelSingleBlockLoop(LoopPeelDirection Direction,
36 MachineBasicBlock *Loop,
37 MachineRegisterInfo &MRI,
38 const TargetInstrInfo *TII);
39
40} // namespace llvm
41
42#endif // LLVM_LIB_CODEGEN_MACHINELOOPUTILS_H