aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/TargetMemoryFolding.h
blob: e40fbc0f69deaa4bc6968d0696cb78ca9f0e36f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_TARGETMEMORYFOLDING_H
#define RCC_CODEGEN_TARGETMEMORYFOLDING_H

#include "rcc/CodeGen/MachineMemOperand.h"
#include "rcc/Support/Error.h"

#include <cstddef>
#include <optional>

namespace rcc {

class MachineFunction;
class MachineInstr;
class TargetDescription;

class TargetMemoryFoldingInfo {
public:
  virtual ~TargetMemoryFoldingInfo() = default;

  [[nodiscard]] virtual Expected<bool>
  canFoldMemoryOperand(const MachineInstr &Consumer, std::size_t OperandIndex,
                       const MachineInstr &MemoryInstruction, const MachineFunction &Function,
                       const TargetDescription &Target) const = 0;

  [[nodiscard]] virtual Expected<MachineInstr *>
  foldMemoryOperand(MachineInstr &Consumer, std::size_t OperandIndex,
                    MachineInstr &MemoryInstruction, MachineFunction &Function,
                    const TargetDescription &Target) const = 0;

  [[nodiscard]] virtual Expected<bool>
  unfoldMemoryOperand(MachineInstr &Instruction, MachineFunction &Function,
                      const TargetDescription &Target) const = 0;

  [[nodiscard]] virtual Expected<std::optional<MemorySize>>
  getFoldedMemorySize(const MachineInstr &Instruction, const MachineFunction &Function,
                      const TargetDescription &Target) const = 0;
};

} // namespace rcc

#endif // RCC_CODEGEN_TARGETMEMORYFOLDING_H