From c3932f55208e3fe2019d26a0e5af421c0b644872 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Tue, 25 Aug 2026 02:38:56 +0800 Subject: [RISCV] Implement make-compressible pass --- backend/lib/CodeGen/MIRParser/MIRParser.cpp | 2 ++ backend/lib/CodeGen/MachineFunctionAttributes.cpp | 2 ++ backend/lib/CodeGen/MachineOperand.cpp | 5 +++++ 3 files changed, 9 insertions(+) (limited to 'backend/lib/CodeGen') diff --git a/backend/lib/CodeGen/MIRParser/MIRParser.cpp b/backend/lib/CodeGen/MIRParser/MIRParser.cpp index c7e92a0..944d0c9 100644 --- a/backend/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/backend/lib/CodeGen/MIRParser/MIRParser.cpp @@ -276,6 +276,8 @@ bool MIRDocumentParser::parseFunction(const yaml::Node &Root, MIRDocument &Docum return importError(NameNode->range(), Created.error()); MachineFunction &Function = **Created; ActiveFunction = &Function; + if (IRFunction != nullptr && IRFunction->hasMinSize()) + Function.attributes().set(MachineFunctionAttribute::MinSize); MIRFunctionDocumentInfo DocumentInfo{ .Function = Function.stableID(), diff --git a/backend/lib/CodeGen/MachineFunctionAttributes.cpp b/backend/lib/CodeGen/MachineFunctionAttributes.cpp index 799e701..afe18a9 100644 --- a/backend/lib/CodeGen/MachineFunctionAttributes.cpp +++ b/backend/lib/CodeGen/MachineFunctionAttributes.cpp @@ -31,6 +31,8 @@ std::string_view getMachineFunctionAttributeName(MachineFunctionAttribute Attrib return "DebugInstrRef"; case MachineFunctionAttribute::TracksDebugUserValues: return "TracksDebugUserValues"; + case MachineFunctionAttribute::MinSize: + return "MinSize"; case MachineFunctionAttribute::Count: return "Invalid"; } diff --git a/backend/lib/CodeGen/MachineOperand.cpp b/backend/lib/CodeGen/MachineOperand.cpp index f265c3f..3994286 100644 --- a/backend/lib/CodeGen/MachineOperand.cpp +++ b/backend/lib/CodeGen/MachineOperand.cpp @@ -300,6 +300,11 @@ Expected MachineOperand::setRegister(Register Reg) { return makeUnexpected(ErrorCode::InvalidArgument, "setRegister requires a register operand"); } + if (std::get(Storage) == Reg) + return {}; + + RegFlags.clear(RegisterOperandFlag::Renamable); + MachineRegisterInfo *RegInfo = LinkedRegInfo; if (RegInfo == nullptr && Parent != nullptr) RegInfo = &Parent->function().registerInfo(); -- cgit v1.2.3