1//===----------------------------------------------------------------------===//
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// This file contains the base class used by the several RISC-V Pseudo
10// Instruction Expansion passes. This avoids having to re-implement some of the
11// boilerplate needed in these passes.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_RISCV_RISCVEXPANDPSEUDOBASE_H
16#define LLVM_LIB_TARGET_RISCV_RISCVEXPANDPSEUDOBASE_H
17
18#include "RISCV.h"
19#include "llvm/CodeGen/MachineFunction.h"
20
21namespace llvm {
22
23class RISCVSubtarget;
24class RISCVInstrInfo;
25
26class RISCVExpandPseudoImplBase {
27public:
28 /// Expand a subset of pseudos in the current function. Returns whether the
29 /// function was modified.
30 ///
31 /// This will assert if expansion increased the estimated size of the
32 /// function.
33 bool run(MachineFunction &MF);
34
35 virtual ~RISCVExpandPseudoImplBase() = default;
36
37protected:
38 /// The Subtarget for the current function.
39 const RISCVSubtarget *STI;
40
41 /// The derived TargetInstrInfo for the current function.
42 const RISCVInstrInfo *TII;
43
44 /// This method should be implemented to expand the instruction at `*MBBI`.
45 /// The iteration over the current basic block will continue at `NextMBBI`.
46 /// This method should return `true` if it replaced the instruction at
47 /// `*MBBI`.
48 virtual bool expandMI(MachineBasicBlock &MBB,
49 MachineBasicBlock::iterator MBBI,
50 MachineBasicBlock::iterator &NextMBBI) const {
51 reportFatalInternalError(reason: "Expand Pseudos not yet implemented.");
52 return false;
53 }
54
55private:
56 bool expandMBB(MachineBasicBlock &MBB) const;
57};
58
59} // namespace llvm
60
61#endif // LLVM_LIB_TARGET_RISCV_RISCVEXPANDPSEUDOBASE_H
62