blob: 376273fb0eab28eef1aef28e0197921667165f15 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef RCC_CODEGEN_MACHINEINSTR_H
#define RCC_CODEGEN_MACHINEINSTR_H
#include "rcc/CodeGen/MachineIRTypes.h"
#include "rcc/CodeGen/MachineOperand.h"
#include "rcc/CodeGen/StableID.h"
#include "rcc/Support/Error.h"
#include <cstddef>
#include <functional>
#include <optional>
#include <span>
#include <utility>
#include <vector>
namespace rcc {
class MachineBasicBlock;
class MachineFunction;
class MachineMemOperand;
class MachineRegisterInfo;
class MachineInstr final {
public:
MachineInstr(const MachineInstr &) = delete;
MachineInstr &operator=(const MachineInstr &) = delete;
MachineInstr(MachineInstr &&) = delete;
MachineInstr &operator=(MachineInstr &&) = delete;
~MachineInstr();
[[nodiscard]] Opcode opcode() const noexcept {
return InstructionOpcode;
}
[[nodiscard]] Expected<void> setOpcode(Opcode NewOpcode);
[[nodiscard]] MachineInstrStableID stableID() const noexcept {
return StableID;
}
[[nodiscard]] MachineFunction &function() noexcept {
return *OwnerFunction;
}
[[nodiscard]] const MachineFunction &function() const noexcept {
return *OwnerFunction;
}
[[nodiscard]] MachineBasicBlock *parent() noexcept {
return ParentBlock;
}
[[nodiscard]] const MachineBasicBlock *parent() const noexcept {
return ParentBlock;
}
[[nodiscard]] MachineInstr *previous() noexcept {
return PreviousInstruction;
}
[[nodiscard]] const MachineInstr *previous() const noexcept {
return PreviousInstruction;
}
[[nodiscard]] MachineInstr *next() noexcept {
return NextInstruction;
}
[[nodiscard]] const MachineInstr *next() const noexcept {
return NextInstruction;
}
[[nodiscard]] bool isLinked() const noexcept {
return ParentBlock != nullptr;
}
[[nodiscard]] std::size_t operandCount() const noexcept {
return Operands.size();
}
[[nodiscard]] MachineOperand *operandAt(std::size_t Index) noexcept;
[[nodiscard]] const MachineOperand *operandAt(std::size_t Index) const noexcept;
[[nodiscard]] std::span<const MachineOperand> operands() const noexcept {
return Operands;
}
void reserveOperands(std::size_t Capacity);
[[nodiscard]] Expected<void> addOperand(MachineOperand Operand);
[[nodiscard]] Expected<void> insertOperand(std::size_t Index, MachineOperand Operand);
[[nodiscard]] Expected<void> eraseOperand(std::size_t Index);
[[nodiscard]] Expected<void> tieOperands(std::size_t DefIndex, std::size_t UseIndex);
[[nodiscard]] Expected<void> untieOperand(std::size_t Index);
[[nodiscard]] Expected<void> addMemOperand(const MachineMemOperand &MemOperand);
[[nodiscard]] Expected<void> eraseMemOperand(std::size_t Index);
[[nodiscard]] std::span<const MachineMemOperand *const> memOperands() const noexcept {
return MemOperands;
}
[[nodiscard]] MachineInstrFlags flags() const noexcept {
return Flags;
}
void setFlags(MachineInstrFlags NewFlags) noexcept {
Flags = NewFlags;
}
[[nodiscard]] const std::optional<SourceLocation> &sourceLocation() const noexcept {
return Location;
}
void setSourceLocation(SourceLocation NewLocation) {
Location = std::move(NewLocation);
}
void clearSourceLocation() noexcept {
Location.reset();
}
[[nodiscard]] std::optional<OriginID> origin() const noexcept {
return Origin;
}
void setOrigin(OriginID NewOrigin) noexcept {
Origin = NewOrigin;
}
void clearOrigin() noexcept {
Origin.reset();
}
private:
MachineInstr(MachineFunction &OwnerFunction, Opcode InstructionOpcode,
MachineInstrStableID StableID);
[[nodiscard]] MachineRegisterInfo *linkedRegisterInfo() noexcept;
[[nodiscard]] Expected<void> attachToBlock(MachineBasicBlock &Block);
void detachFromBlock() noexcept;
void adjustTiesForInsertion(std::size_t Index) noexcept;
void adjustTiesForErasure(std::size_t Index) noexcept;
MachineFunction *OwnerFunction;
Opcode InstructionOpcode;
MachineInstrStableID StableID;
MachineBasicBlock *ParentBlock = nullptr;
MachineInstr *PreviousInstruction = nullptr;
MachineInstr *NextInstruction = nullptr;
std::vector<MachineOperand> Operands;
std::vector<const MachineMemOperand *> MemOperands;
MachineInstrFlags Flags;
std::optional<SourceLocation> Location;
std::optional<OriginID> Origin;
friend class MachineArena;
friend class MachineBasicBlock;
friend class MachineFunction;
};
} // namespace rcc
#endif // RCC_CODEGEN_MACHINEINSTR_H
|