diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-11 19:54:56 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-11 19:54:56 +0800 |
| commit | 8b797159e6c8fe1294fd2d26de3bd0992c61ea24 (patch) | |
| tree | 7cc00e81b3ea30ac90528cbeca6787b321549618 /backend | |
| parent | dee2d0ab83c60c3e86214656e2e7bcd7a1cdca0d (diff) | |
| download | rcc-project-8b797159e6c8fe1294fd2d26de3bd0992c61ea24.tar.gz rcc-project-8b797159e6c8fe1294fd2d26de3bd0992c61ea24.tar.xz | |
[RISCV] Use canonical copies for full ABI values
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/lib/Target/RISCV/RISCVCallLowering.cpp | 14 | ||||
| -rw-r--r-- | backend/unittests/Target/RISCVCallLoweringTest.cpp | 8 |
2 files changed, 15 insertions, 7 deletions
diff --git a/backend/lib/Target/RISCV/RISCVCallLowering.cpp b/backend/lib/Target/RISCV/RISCVCallLowering.cpp index ec794bc..fd01d52 100644 --- a/backend/lib/Target/RISCV/RISCVCallLowering.cpp +++ b/backend/lib/Target/RISCV/RISCVCallLowering.cpp @@ -2,6 +2,7 @@ #include "rcc/Target/RISCV/RISCVCallLowering.h" +#include "rcc/CodeGen/GenericOpcodes.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFrameInfo.h" #include "rcc/CodeGen/MachineFunction.h" @@ -777,7 +778,10 @@ createMemoryOperand(MachineFunction &Function, MemoryAccessFlags Accesses, std:: [[nodiscard]] Expected<void> emitCCCopy(MachineIRBuilder &Builder, Register Destination, Register Source, CallValueTransform Transform) { - auto Instruction = Builder.buildInstr(targetOpcode(InstructionOpcode::PseudoCC_COPY)); + const Opcode CopyOpcode = Transform == CallValueTransform::Full + ? opcode(GenericOpcode::COPY) + : targetOpcode(InstructionOpcode::PseudoCC_COPY); + auto Instruction = Builder.buildInstr(CopyOpcode); if (!Instruction) return std::unexpected(Instruction.error()); auto Def = Instruction->addDef(Destination); @@ -786,9 +790,11 @@ createMemoryOperand(MachineFunction &Function, MemoryAccessFlags Accesses, std:: auto Use = Instruction->addUse(Source); if (!Use) return std::unexpected(Use.error()); - auto Action = Instruction->addImmediate(static_cast<std::int64_t>(Transform)); - if (!Action) - return std::unexpected(Action.error()); + if (Transform != CallValueTransform::Full) { + auto Action = Instruction->addImmediate(static_cast<std::int64_t>(Transform)); + if (!Action) + return std::unexpected(Action.error()); + } auto Built = Instruction->build(); if (!Built) return std::unexpected(Built.error()); diff --git a/backend/unittests/Target/RISCVCallLoweringTest.cpp b/backend/unittests/Target/RISCVCallLoweringTest.cpp index 514c277..d3685ae 100644 --- a/backend/unittests/Target/RISCVCallLoweringTest.cpp +++ b/backend/unittests/Target/RISCVCallLoweringTest.cpp @@ -2,6 +2,7 @@ #include "rcc/Target/RISCV/RISCVCallLowering.h" +#include "rcc/CodeGen/GenericOpcodes.h" #include "rcc/CodeGen/MachineBasicBlock.h" #include "rcc/CodeGen/MachineFrameInfo.h" #include "rcc/CodeGen/MachineFunction.h" @@ -486,15 +487,16 @@ void testOrdinaryAndIndirectEmission(TestContext &Context) { Context.expect(Instructions.size() == 5 && Instructions.front()->opcode() == opcode(rcc::riscv::InstructionOpcode::ADJCALLSTACKDOWN) && - Instructions.back()->opcode() == - opcode(rcc::riscv::InstructionOpcode::PseudoCC_COPY) && + Instructions[1]->opcode() == rcc::opcode(rcc::GenericOpcode::COPY) && + Instructions.back()->opcode() == rcc::opcode(rcc::GenericOpcode::COPY) && Call != nullptr && Call->operandCount() >= 6 && Call->operandAt(0)->kind() == rcc::MachineOperand::Kind::ExternalSymbol && Call->operandAt(0)->targetFlags() == static_cast<std::uint32_t>(rcc::riscv::CallTargetFlag::DirectCall) && Call->operandAt(1)->kind() == rcc::MachineOperand::Kind::IntegerImmediate && Call->operandAt(2)->kind() == rcc::MachineOperand::Kind::RegisterMask, - "ordinary emission must materialize call-frame, copies, target, ID, and RegMask"); + "ordinary emission must materialize canonical full-value copies, call-frame, " + "target, ID, and RegMask"); bool HasArgumentUse = false; bool HasResultDef = false; for (const rcc::MachineOperand &Operand : Call->operands()) { |
