aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen/MachineStripDebug.cpp
blob: 46d92d1a1c84a1931599f70e0076204a8d21e882 (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
// 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 = Instruction->eraseFromParent();
        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