diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-15 03:11:22 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-15 03:11:22 +0800 |
| commit | 7d763c8b0ae6eee5f015fa82c744bff4c7ec8c8b (patch) | |
| tree | 5394846395d59f68a33a2f590ddd144940c61051 /backend/lib/CodeGen/MachineBasicBlock.cpp | |
| parent | 2c39d48321658c43d49ada4d2b06be5e0de5d158 (diff) | |
| download | rcc-project-7d763c8b0ae6eee5f015fa82c744bff4c7ec8c8b.tar.gz rcc-project-7d763c8b0ae6eee5f015fa82c744bff4c7ec8c8b.tar.xz | |
[GlobalISel] Preserve worklists when moving CSE instructions
Diffstat (limited to 'backend/lib/CodeGen/MachineBasicBlock.cpp')
| -rw-r--r-- | backend/lib/CodeGen/MachineBasicBlock.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/backend/lib/CodeGen/MachineBasicBlock.cpp b/backend/lib/CodeGen/MachineBasicBlock.cpp index 763a577..2de8f89 100644 --- a/backend/lib/CodeGen/MachineBasicBlock.cpp +++ b/backend/lib/CodeGen/MachineBasicBlock.cpp @@ -99,6 +99,34 @@ Expected<void> MachineBasicBlock::insertInstructionAfter(MachineInstr &Position, return {}; } +Expected<void> MachineBasicBlock::spliceInstructionBefore(MachineInstr &Position, + MachineInstr &Instruction) { + if (Position.parent() != this || Instruction.parent() != this) { + return makeUnexpected(ErrorCode::InvalidArgument, + "instruction splice requires two instructions in this block"); + } + if (&Position == &Instruction || Instruction.NextInstruction == &Position) + return {}; + + if (Instruction.PreviousInstruction != nullptr) + Instruction.PreviousInstruction->NextInstruction = Instruction.NextInstruction; + else + FirstInstruction = Instruction.NextInstruction; + if (Instruction.NextInstruction != nullptr) + Instruction.NextInstruction->PreviousInstruction = Instruction.PreviousInstruction; + else + LastInstruction = Instruction.PreviousInstruction; + + Instruction.PreviousInstruction = Position.PreviousInstruction; + Instruction.NextInstruction = &Position; + if (Position.PreviousInstruction != nullptr) + Position.PreviousInstruction->NextInstruction = &Instruction; + else + FirstInstruction = &Instruction; + Position.PreviousInstruction = &Instruction; + return {}; +} + Expected<void> MachineBasicBlock::removeInstruction(MachineInstr &Instruction) { if (Instruction.parent() != this) { return makeUnexpected(ErrorCode::InvalidArgument, "instruction does not belong to this block"); |
