aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineStripDebug.cpp
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-22 18:59:22 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-22 18:59:22 +0800
commit36b0be1ec1558f88d4f031a1817c3a4c2cba07a6 (patch)
tree3cf29b19ec7e450bd04dca8d416d68350aa20de2 /backend/lib/CodeGen/MachineStripDebug.cpp
parent8a4bb6e3b0bffa0ed79b51347b12ee4293b622a7 (diff)
downloadrcc-project-36b0be1ec1558f88d4f031a1817c3a4c2cba07a6.tar.gz
rcc-project-36b0be1ec1558f88d4f031a1817c3a4c2cba07a6.tar.xz
[CodeGen] Match LLVM machine debug stripping
Diffstat (limited to 'backend/lib/CodeGen/MachineStripDebug.cpp')
-rw-r--r--backend/lib/CodeGen/MachineStripDebug.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/backend/lib/CodeGen/MachineStripDebug.cpp b/backend/lib/CodeGen/MachineStripDebug.cpp
new file mode 100644
index 0000000..4699ef0
--- /dev/null
+++ b/backend/lib/CodeGen/MachineStripDebug.cpp
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "rcc/CodeGen/MachineStripDebug.h"
+
+#include "rcc/CodeGen/MachineBasicBlock.h"
+#include "rcc/CodeGen/MachineFunction.h"
+#include "rcc/CodeGen/MachineInstr.h"
+
+namespace rcc {
+
+Expected<bool> stripDebugMachineFunction(MachineFunction &Function) {
+ bool Changed = false;
+ for (MachineBasicBlock *Block = Function.firstBlock(); Block != nullptr; Block = Block->next()) {
+ for (MachineInstr *Instruction = Block->firstInstruction(); Instruction != nullptr;) {
+ MachineInstr *Next = Instruction->next();
+ if (Instruction->isDebugInstr() && Instruction->operandCount() > 1) {
+ auto Removed = Block->removeInstruction(*Instruction);
+ if (!Removed)
+ return std::unexpected(Removed.error());
+ Changed = true;
+ Instruction = Next;
+ continue;
+ }
+ if (Instruction->debugLocation()) {
+ Instruction->clearDebugLocation();
+ Changed = true;
+ }
+ Instruction = Next;
+ }
+ }
+ return Changed;
+}
+
+} // namespace rcc