aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 18:17:33 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 18:17:33 +0800
commite0c77d80585428818c32886eb8c26755ea8ed159 (patch)
treef1d79404cb767c91b9aed3ad1a7709a628b3860f /backend/lib/CodeGen/MachineInstr.cpp
parent6e09614afd2a589690d107b41308f6fe6614c266 (diff)
downloadrcc-project-e0c77d80585428818c32886eb8c26755ea8ed159.tar.gz
rcc-project-e0c77d80585428818c32886eb8c26755ea8ed159.tar.xz
[CodeGen] Track debug instruction identities
Add monotonic MIR debug instruction numbers and structured value substitutions. Verify live number uniqueness, meta-instruction exclusion, substitution graph integrity, and target subregister references while preserving debug identities during cloning.
Diffstat (limited to 'backend/lib/CodeGen/MachineInstr.cpp')
-rw-r--r--backend/lib/CodeGen/MachineInstr.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/backend/lib/CodeGen/MachineInstr.cpp b/backend/lib/CodeGen/MachineInstr.cpp
index b201533..aaeeacd 100644
--- a/backend/lib/CodeGen/MachineInstr.cpp
+++ b/backend/lib/CodeGen/MachineInstr.cpp
@@ -8,7 +8,9 @@
#include "rcc/CodeGen/MachineRegisterInfo.h"
#include <cstddef>
+#include <cstdint>
#include <functional>
+#include <limits>
#include <optional>
#include <utility>
@@ -30,6 +32,30 @@ Expected<void> MachineInstr::setOpcode(Opcode NewOpcode) {
return {};
}
+Expected<void> MachineInstr::setDebugInstrNumber(std::uint64_t Number) {
+ if (Number == 0 || Number > std::numeric_limits<std::uint32_t>::max()) {
+ return makeUnexpected(ErrorCode::InvalidArgument,
+ "machine debug instruction number must fit in nonzero uint32");
+ }
+ if (DebugInstrNumber != 0 && DebugInstrNumber != Number) {
+ return makeUnexpected(ErrorCode::InvalidArgument,
+ "machine instruction already has a different debug number");
+ }
+ DebugInstrNumber = static_cast<std::uint32_t>(Number);
+ OwnerFunction->observeDebugInstrNumber(DebugInstrNumber);
+ return {};
+}
+
+Expected<std::uint32_t> MachineInstr::assignDebugInstrNumber() {
+ if (DebugInstrNumber != 0)
+ return DebugInstrNumber;
+ auto Number = OwnerFunction->allocateDebugInstrNumber();
+ if (!Number)
+ return std::unexpected(Number.error());
+ DebugInstrNumber = *Number;
+ return DebugInstrNumber;
+}
+
MachineOperand *MachineInstr::operandAt(std::size_t Index) noexcept {
if (Index >= Operands.size())
return nullptr;