aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/GlobalISel/Utils.h
blob: f2524545747507cec3b1cf48adf930a0aff4cd27 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_GLOBALISEL_UTILS_H
#define RCC_CODEGEN_GLOBALISEL_UTILS_H

#include "rcc/ADT/APInt.h"
#include "rcc/CodeGen/LowLevelType.h"
#include "rcc/CodeGen/Register.h"
#include "rcc/Support/Error.h"

#include <cstddef>
#include <optional>
#include <span>
#include <vector>

namespace rcc {

class MachineIRBuilder;
class MachineInstr;
class MachineRegisterInfo;
class TargetDescription;

struct ValueAndVReg final {
  APInt Value;
  Register VReg;
};

[[nodiscard]] std::optional<ValueAndVReg>
getIConstantVRegValWithLookThrough(Register VReg, const MachineRegisterInfo &MRI,
                                   bool LookThroughInstrs = true);

/// Check whether an instruction only defines dead virtual registers and has no
/// observable side effects.
[[nodiscard]] bool isTriviallyDead(const MachineInstr &Instruction, const MachineRegisterInfo &MRI,
                                   const TargetDescription &Target) noexcept;

[[nodiscard]] Expected<void> eraseInstrs(std::span<MachineInstr *const> Instructions,
                                         MachineRegisterInfo &MRI, const TargetDescription &Target);

[[nodiscard]] Expected<void> eraseInstr(MachineInstr &Instruction, MachineRegisterInfo &MRI,
                                        const TargetDescription &Target);

[[nodiscard]] Expected<void> extractParts(Register Reg, LowLevelType Type, int PartCount,
                                          std::vector<Register> &Parts,
                                          MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI);

[[nodiscard]] Expected<bool> extractParts(Register Reg, LowLevelType RegisterType,
                                          LowLevelType MainType, LowLevelType &LeftoverType,
                                          std::vector<Register> &Parts,
                                          std::vector<Register> &LeftoverParts,
                                          MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI);

[[nodiscard]] Expected<LowLevelType> getLCMType(LowLevelType OriginalType, LowLevelType TargetType);
[[nodiscard]] Expected<LowLevelType> getGCDType(LowLevelType OriginalType, LowLevelType TargetType);

} // namespace rcc

#endif // RCC_CODEGEN_GLOBALISEL_UTILS_H