aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'backend/lib/CodeGen')
-rw-r--r--backend/lib/CodeGen/CMakeLists.txt2
-rw-r--r--backend/lib/CodeGen/MIRPrinter.cpp3
-rw-r--r--backend/lib/CodeGen/MachineInstr.cpp16
-rw-r--r--backend/lib/CodeGen/MachineStripDebug.cpp34
4 files changed, 54 insertions, 1 deletions
diff --git a/backend/lib/CodeGen/CMakeLists.txt b/backend/lib/CodeGen/CMakeLists.txt
index 2fc7254..b95fe42 100644
--- a/backend/lib/CodeGen/CMakeLists.txt
+++ b/backend/lib/CodeGen/CMakeLists.txt
@@ -23,6 +23,7 @@ set(
MachineCopyPropagation.cpp
MachineCSE.cpp
MachineDebugInfo.cpp
+ MachineStripDebug.cpp
MachineDCE.cpp
MachineFrameInfo.cpp
MachineFinalization.cpp
@@ -111,6 +112,7 @@ set(
"${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineCopyPropagation.h"
"${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineCSE.h"
"${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineDebugInfo.h"
+ "${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineStripDebug.h"
"${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineDCE.h"
"${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineFrameInfo.h"
"${RCC_BACKEND_SOURCE_DIR}/include/rcc/CodeGen/MachineFinalization.h"
diff --git a/backend/lib/CodeGen/MIRPrinter.cpp b/backend/lib/CodeGen/MIRPrinter.cpp
index 5eb244a..c684368 100644
--- a/backend/lib/CodeGen/MIRPrinter.cpp
+++ b/backend/lib/CodeGen/MIRPrinter.cpp
@@ -1935,7 +1935,8 @@ Expected<void> BodyPrinter::printRegisterOperand(const MachineOperand &Operand,
Output.append("internal ");
if (Flags.has(RegisterOperandFlag::EarlyClobber))
Output.append("early-clobber ");
- if (Flags.has(RegisterOperandFlag::Debug))
+ if (Flags.has(RegisterOperandFlag::Debug) &&
+ (Operand.parent() == nullptr || !Operand.parent()->isDebugInstr()))
Output.append("debug-use ");
if (Flags.has(RegisterOperandFlag::Renamable))
Output.append("renamable ");
diff --git a/backend/lib/CodeGen/MachineInstr.cpp b/backend/lib/CodeGen/MachineInstr.cpp
index f4602e0..55b4ce9 100644
--- a/backend/lib/CodeGen/MachineInstr.cpp
+++ b/backend/lib/CodeGen/MachineInstr.cpp
@@ -2,6 +2,7 @@
#include "rcc/CodeGen/MachineInstr.h"
+#include "rcc/CodeGen/GenericOpcodes.h"
#include "rcc/CodeGen/MachineBasicBlock.h"
#include "rcc/CodeGen/MachineFunction.h"
#include "rcc/CodeGen/MachineMemOperand.h"
@@ -18,6 +19,14 @@
namespace rcc {
+bool MachineInstr::isDebugInstr() const noexcept {
+ return InstructionOpcode == rcc::opcode(GenericOpcode::DBG_VALUE) ||
+ InstructionOpcode == rcc::opcode(GenericOpcode::DBG_VALUE_LIST) ||
+ InstructionOpcode == rcc::opcode(GenericOpcode::DBG_LABEL) ||
+ InstructionOpcode == rcc::opcode(GenericOpcode::DBG_INSTR_REF) ||
+ InstructionOpcode == rcc::opcode(GenericOpcode::DBG_PHI);
+}
+
MachineInstr::MachineInstr(MachineFunction &OwnerFunction, Opcode InstructionOpcode,
MachineInstrStableID StableID)
: OwnerFunction(&OwnerFunction), InstructionOpcode(InstructionOpcode), StableID(StableID) {}
@@ -97,6 +106,13 @@ Expected<void> MachineInstr::insertOperand(std::size_t Index, MachineOperand &&O
return makeUnexpected(ErrorCode::InvalidArgument,
"register operand references an unknown virtual register");
}
+ if (Operand.isUse() && isDebugInstr()) {
+ RegisterOperandFlags RegisterFlags = Operand.registerFlags();
+ RegisterFlags.set(RegisterOperandFlag::Debug);
+ auto Updated = Operand.setRegisterFlags(RegisterFlags);
+ if (!Updated)
+ return std::unexpected(Updated.error());
+ }
Operands.insert(Operands.begin() + static_cast<std::ptrdiff_t>(Index), std::move(Operand));
adjustTiesForInsertion(Index);
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