From 307fc0961972ac5264d6f3459978fbec95cad3a9 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Wed, 19 Aug 2026 04:27:41 +0800 Subject: [RISCV][GlobalISel] Select and expand global addresses --- backend/include/rcc/CodeGen/GlobalObject.h | 9 +++++++++ backend/include/rcc/CodeGen/InstructionDescriptor.h | 1 + backend/include/rcc/CodeGen/MIRParser/MIParser.h | 2 ++ backend/include/rcc/CodeGen/MachineOperand.h | 5 ++++- backend/include/rcc/CodeGen/MachinePseudoExpansion.h | 14 ++++++++++++++ backend/include/rcc/CodeGen/TargetPseudoExpansion.h | 1 + 6 files changed, 31 insertions(+), 1 deletion(-) (limited to 'backend/include/rcc/CodeGen') diff --git a/backend/include/rcc/CodeGen/GlobalObject.h b/backend/include/rcc/CodeGen/GlobalObject.h index 1ddc34a..b67421f 100644 --- a/backend/include/rcc/CodeGen/GlobalObject.h +++ b/backend/include/rcc/CodeGen/GlobalObject.h @@ -156,6 +156,15 @@ enum class GlobalUnnamedAddress : std::uint8_t { Count, }; +struct GlobalValueProperties final { + bool DSOLocal = false; + bool ExternalWeak = false; + bool ThreadLocal = false; + + friend constexpr bool operator==(const GlobalValueProperties &Left, + const GlobalValueProperties &Right) noexcept = default; +}; + struct GlobalObjectDesc final { std::string Symbol; GenericConstantType ObjectType; diff --git a/backend/include/rcc/CodeGen/InstructionDescriptor.h b/backend/include/rcc/CodeGen/InstructionDescriptor.h index ccd1b63..91881e6 100644 --- a/backend/include/rcc/CodeGen/InstructionDescriptor.h +++ b/backend/include/rcc/CodeGen/InstructionDescriptor.h @@ -195,6 +195,7 @@ enum class PseudoOwner : std::uint8_t { InstructionSelect, PhiElimination, TwoAddressRewrite, + PreRAExpansion, RegisterAllocator, PrePEIExpansion, PrologueEpilogueInsertion, diff --git a/backend/include/rcc/CodeGen/MIRParser/MIParser.h b/backend/include/rcc/CodeGen/MIRParser/MIParser.h index 0b888e5..cd40882 100644 --- a/backend/include/rcc/CodeGen/MIRParser/MIParser.h +++ b/backend/include/rcc/CodeGen/MIRParser/MIParser.h @@ -5,6 +5,7 @@ #include "rcc/CodeGen/MachineIRTypes.h" #include "rcc/CodeGen/MachineMetadata.h" +#include "rcc/CodeGen/GlobalObject.h" #include "rcc/CodeGen/Register.h" #include "rcc/Support/Error.h" #include "rcc/Support/TextDiagnostic.h" @@ -66,6 +67,7 @@ struct MIParserContext final { std::vector Metadata; std::vector SyncScopes; std::function HasIRBlock; + std::function GlobalValuePropertiesForName; std::function(std::string_view)> InternSyncScope; std::function(std::uint32_t)> PointerSizeInBits; }; diff --git a/backend/include/rcc/CodeGen/MachineOperand.h b/backend/include/rcc/CodeGen/MachineOperand.h index 1f321b0..d82e41a 100644 --- a/backend/include/rcc/CodeGen/MachineOperand.h +++ b/backend/include/rcc/CodeGen/MachineOperand.h @@ -5,6 +5,7 @@ #include "rcc/ADT/APFloat.h" #include "rcc/ADT/APInt.h" +#include "rcc/CodeGen/GlobalObject.h" #include "rcc/CodeGen/LowLevelType.h" #include "rcc/CodeGen/MachineDebugInfo.h" #include "rcc/CodeGen/MachineIRTypes.h" @@ -127,6 +128,7 @@ struct JumpTableOperand final { struct GlobalSymbolOperand final { std::string Name; std::int64_t Offset = 0; + GlobalValueProperties Properties; friend bool operator==(const GlobalSymbolOperand &Left, const GlobalSymbolOperand &Right) = default; @@ -329,7 +331,8 @@ public: [[nodiscard]] static MachineOperand jumpTable(JumpTableIndex Index, std::uint32_t TargetFlags = 0); [[nodiscard]] static Expected - globalSymbol(std::string Name, std::int64_t Offset = 0, std::uint32_t TargetFlags = 0); + globalSymbol(std::string Name, std::int64_t Offset = 0, std::uint32_t TargetFlags = 0, + GlobalValueProperties Properties = {}); [[nodiscard]] static Expected externalSymbol(std::string Name, std::int64_t Offset = 0, std::uint32_t TargetFlags = 0); [[nodiscard]] static Expected blockAddress(std::string FunctionName, diff --git a/backend/include/rcc/CodeGen/MachinePseudoExpansion.h b/backend/include/rcc/CodeGen/MachinePseudoExpansion.h index 7d4b309..c30ba50 100644 --- a/backend/include/rcc/CodeGen/MachinePseudoExpansion.h +++ b/backend/include/rcc/CodeGen/MachinePseudoExpansion.h @@ -11,6 +11,20 @@ namespace rcc { class TargetInstrInfo; class TargetPseudoExpansionInfo; +class PreRATargetPseudoExpansionPass final : public MachineFunctionPass { +public: + explicit PreRATargetPseudoExpansionPass(const TargetPseudoExpansionInfo &Info) noexcept + : Info(&Info) {} + + [[nodiscard]] const MachinePassContract &contract() const noexcept override; + [[nodiscard]] Expected run(MachineFunction &Function, + const TargetDescription &Target, + MachineFunctionAnalysisManager &Analyses) override; + +private: + const TargetPseudoExpansionInfo *Info; +}; + class PreparePostRAPseudosPass final : public MachineFunctionPass { public: explicit PreparePostRAPseudosPass(const TargetPseudoExpansionInfo &Info) noexcept : Info(&Info) {} diff --git a/backend/include/rcc/CodeGen/TargetPseudoExpansion.h b/backend/include/rcc/CodeGen/TargetPseudoExpansion.h index 4d9f556..5135d78 100644 --- a/backend/include/rcc/CodeGen/TargetPseudoExpansion.h +++ b/backend/include/rcc/CodeGen/TargetPseudoExpansion.h @@ -14,6 +14,7 @@ class MachineInstr; class TargetDescription; enum class MachinePseudoExpansionPhase : std::uint8_t { + PreRA, PrePEI, PostRA, TargetLate, -- cgit v1.2.3