aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineIRBuilder.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-02 03:37:46 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-02 03:37:46 +0800
commita8a9d7d926202450645deae872d4d9dc11d63215 (patch)
tree16a3640a93e3f567ff31045969c02a42e1f467e0 /backend/lib/CodeGen/MachineIRBuilder.cpp
parent49d70380a6a95e4039f6b5e5ccce09671d5b4796 (diff)
downloadrcc-project-a8a9d7d926202450645deae872d4d9dc11d63215.tar.gz
rcc-project-a8a9d7d926202450645deae872d4d9dc11d63215.tar.xz
[CodeGen] Model machine debug metadata
Replace marker-based metadata operands with scoped references and inline DIExpression values. Add structured DILocation chains, instruction debug attachments, stack variable records, and entry values with unified verification, builder support, and deterministic cloning.
Diffstat (limited to 'backend/lib/CodeGen/MachineIRBuilder.cpp')
-rw-r--r--backend/lib/CodeGen/MachineIRBuilder.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/backend/lib/CodeGen/MachineIRBuilder.cpp b/backend/lib/CodeGen/MachineIRBuilder.cpp
index 7f6421b..5afdd72 100644
--- a/backend/lib/CodeGen/MachineIRBuilder.cpp
+++ b/backend/lib/CodeGen/MachineIRBuilder.cpp
@@ -33,8 +33,8 @@ MachineInstrBuilder::MachineInstrBuilder(MachineInstrBuilder &&Other) noexcept
ExplicitOperands(std::move(Other.ExplicitOperands)),
ExtraImplicitOperands(std::move(Other.ExtraImplicitOperands)),
RequestedTies(std::move(Other.RequestedTies)), MemOperands(std::move(Other.MemOperands)),
- Flags(Other.Flags), Location(std::move(Other.Location)), Origin(Other.Origin),
- IsBuilt(Other.IsBuilt) {
+ Flags(Other.Flags), Location(std::move(Other.Location)),
+ DebugLocation(std::move(Other.DebugLocation)), Origin(Other.Origin), IsBuilt(Other.IsBuilt) {
Other.Function = nullptr;
Other.Target = nullptr;
Other.Descriptor = nullptr;
@@ -58,6 +58,7 @@ MachineInstrBuilder &MachineInstrBuilder::operator=(MachineInstrBuilder &&Other)
MemOperands = std::move(Other.MemOperands);
Flags = Other.Flags;
Location = std::move(Other.Location);
+ DebugLocation = std::move(Other.DebugLocation);
Origin = Other.Origin;
IsBuilt = Other.IsBuilt;
@@ -219,8 +220,9 @@ Expected<void> MachineInstrBuilder::addRegisterMask(std::shared_ptr<const Regist
return addOperand(std::move(*Operand));
}
-Expected<void> MachineInstrBuilder::addMetadata(std::string Marker, std::uint32_t TargetFlags) {
- auto Operand = MachineOperand::metadata(std::move(Marker), TargetFlags);
+Expected<void> MachineInstrBuilder::addMetadata(MachineMetadataValue Value,
+ std::uint32_t TargetFlags) {
+ auto Operand = MachineOperand::metadata(std::move(Value), TargetFlags);
if (!Operand)
return std::unexpected(Operand.error());
return addOperand(std::move(*Operand));
@@ -301,6 +303,25 @@ Expected<void> MachineInstrBuilder::clearSourceLocation() {
return {};
}
+Expected<void> MachineInstrBuilder::setDebugLocation(MachineDebugLocation NewLocation) {
+ auto Pending = ensurePending();
+ if (!Pending)
+ return std::unexpected(Pending.error());
+ if (!NewLocation.isValid()) {
+ return makeUnexpected(ErrorCode::InvalidArgument, "builder debug location is invalid");
+ }
+ DebugLocation = std::move(NewLocation);
+ return {};
+}
+
+Expected<void> MachineInstrBuilder::clearDebugLocation() {
+ auto Pending = ensurePending();
+ if (!Pending)
+ return std::unexpected(Pending.error());
+ DebugLocation.reset();
+ return {};
+}
+
Expected<void> MachineInstrBuilder::setOrigin(OriginID NewOrigin) {
auto Pending = ensurePending();
if (!Pending)
@@ -518,6 +539,11 @@ Expected<MachineInstr *> MachineInstrBuilder::build() {
Result->setFlags(Flags);
if (Location)
Result->setSourceLocation(std::move(*Location));
+ if (DebugLocation) {
+ auto DebugLocationResult = Result->setDebugLocation(std::move(*DebugLocation));
+ if (!DebugLocationResult)
+ return std::unexpected(DebugLocationResult.error());
+ }
if (Origin)
Result->setOrigin(*Origin);