aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-19 04:27:41 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-19 04:27:41 +0800
commit307fc0961972ac5264d6f3459978fbec95cad3a9 (patch)
tree80eff53db8f62a736a46221d258dcadf7543fa88 /backend/include/rcc/CodeGen
parent6a91664223881226e2b6186561c05ff378a19355 (diff)
downloadrcc-project-307fc0961972ac5264d6f3459978fbec95cad3a9.tar.gz
rcc-project-307fc0961972ac5264d6f3459978fbec95cad3a9.tar.xz
[RISCV][GlobalISel] Select and expand global addresses
Diffstat (limited to 'backend/include/rcc/CodeGen')
-rw-r--r--backend/include/rcc/CodeGen/GlobalObject.h9
-rw-r--r--backend/include/rcc/CodeGen/InstructionDescriptor.h1
-rw-r--r--backend/include/rcc/CodeGen/MIRParser/MIParser.h2
-rw-r--r--backend/include/rcc/CodeGen/MachineOperand.h5
-rw-r--r--backend/include/rcc/CodeGen/MachinePseudoExpansion.h14
-rw-r--r--backend/include/rcc/CodeGen/TargetPseudoExpansion.h1
6 files changed, 31 insertions, 1 deletions
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<MIMetadataSlot> Metadata;
std::vector<MISyncScopeSlot> SyncScopes;
std::function<bool(std::string_view)> HasIRBlock;
+ std::function<GlobalValueProperties(std::string_view)> GlobalValuePropertiesForName;
std::function<Expected<SyncScopeID>(std::string_view)> InternSyncScope;
std::function<Expected<std::uint32_t>(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<MachineOperand>
- 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<MachineOperand>
externalSymbol(std::string Name, std::int64_t Offset = 0, std::uint32_t TargetFlags = 0);
[[nodiscard]] static Expected<MachineOperand> 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<MachinePassResult> 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,