aboutsummaryrefslogtreecommitdiff
path: root/backend/lib/CodeGen
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-16 01:09:11 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-16 01:09:11 +0800
commit72a559302280a3837efea331829b70d9bb218f7a (patch)
tree01345284e79d76b071fed85406e5c983aa413720 /backend/lib/CodeGen
parent94124b0d5604d6d6a6e1b923411e97287fa51e8b (diff)
downloadrcc-project-72a559302280a3837efea331829b70d9bb218f7a.tar.gz
rcc-project-72a559302280a3837efea331829b70d9bb218f7a.tar.xz
[RISCV][GlobalISel] Select constant operands as immediates
Diffstat (limited to 'backend/lib/CodeGen')
-rw-r--r--backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp13
-rw-r--r--backend/lib/CodeGen/MachineVerifier.cpp18
2 files changed, 24 insertions, 7 deletions
diff --git a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
index 642e26f..31d880e 100644
--- a/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
+++ b/backend/lib/CodeGen/GlobalISel/InstructionSelect.cpp
@@ -2,6 +2,7 @@
#include "rcc/CodeGen/GlobalISel/InstructionSelect.h"
+#include "rcc/CodeGen/GlobalISel/Utils.h"
#include "rcc/CodeGen/MachineBasicBlock.h"
#include "rcc/CodeGen/MachineFunction.h"
#include "rcc/CodeGen/MachineFunctionCloner.h"
@@ -240,8 +241,16 @@ Expected<MachinePassResult> InstructionSelect::runImplementation(MachineFunction
for (std::size_t Index = 0; Index < Worklist.size(); ++Index) {
MachineInstr *Instruction = Worklist[Index];
- if (Instruction->parent() == nullptr)
- return std::unexpected(passFailure("instruction selector lost its input instruction"));
+ if (Instruction == nullptr || Instruction->parent() == nullptr)
+ continue;
+ if (isTriviallyDead(*Instruction, Function.registerInfo(), Target)) {
+ auto Removed = eraseInstr(*Instruction, Function.registerInfo(), Target);
+ if (!Removed)
+ return std::unexpected(Removed.error());
+ Result.Changed = true;
+ Result.Changes.add(MachinePassChange::Instructions);
+ continue;
+ }
const InstructionDescriptor *CurrentDescriptor =
Target.instructionDescriptor(Instruction->opcode());
if (CurrentDescriptor == nullptr)
diff --git a/backend/lib/CodeGen/MachineVerifier.cpp b/backend/lib/CodeGen/MachineVerifier.cpp
index 5a040b9..abccc56 100644
--- a/backend/lib/CodeGen/MachineVerifier.cpp
+++ b/backend/lib/CodeGen/MachineVerifier.cpp
@@ -838,7 +838,9 @@ private:
return fail("reserved-register list contains invalid or duplicate entries");
}
- for (const VirtualRegisterInfo &Info : RegInfo.virtualRegisters()) {
+ const auto VirtualRegisters = RegInfo.virtualRegisters();
+ for (std::size_t Index = 0; Index < VirtualRegisters.size(); ++Index) {
+ const VirtualRegisterInfo &Info = VirtualRegisters[Index];
if (Info.IsTombstone) {
if (Info.Type || Info.Bank || Info.RegClass || !Info.AllocationHints.empty() ||
Info.TargetFlags != 0) {
@@ -846,10 +848,16 @@ private:
}
continue;
}
- HasLiveVirtualRegister = true;
- MissingVirtualType |= !Info.Type;
- MissingVirtualBank |= !Info.Bank;
- MissingVirtualClass |= !Info.RegClass;
+ auto Reg = Register::makeVirtual(Index);
+ if (!Reg)
+ return failWith("virtual register", Reg.error());
+ const auto Operands = RegInfo.regOperands(*Reg);
+ if (Operands.begin() != Operands.end()) {
+ HasLiveVirtualRegister = true;
+ MissingVirtualType |= !Info.Type;
+ MissingVirtualBank |= !Info.Bank;
+ MissingVirtualClass |= !Info.RegClass;
+ }
if (Info.Type && !Info.Type->isValid())
return fail("virtual register has an invalid LowLevelType");