diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-04 05:34:15 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-04 05:34:15 +0800 |
| commit | 183e2354e9fdd107be420cbb185c1d239434aa48 (patch) | |
| tree | ce5c42cb6e9790072d5dcf00d1d55cb7f6573ddc /backend/include/rcc/CodeGen | |
| parent | 67d6231fba98e776c0f442e5b6908e279c35e346 (diff) | |
| download | rcc-project-183e2354e9fdd107be420cbb185c1d239434aa48.tar.gz rcc-project-183e2354e9fdd107be420cbb185c1d239434aa48.tar.xz | |
[MIR] Add machine instruction parser and printer
Parse MachineFunction bodies in two passes and serialize the same MachineIR model in complete or readable form. Extend instruction attachments and memory operands required by the fixed LLVM MIR grammar, and cover deterministic parse-print round trips.
Diffstat (limited to 'backend/include/rcc/CodeGen')
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineInstr.h | 59 | ||||
| -rw-r--r-- | backend/include/rcc/CodeGen/MachineMemOperand.h | 23 |
2 files changed, 82 insertions, 0 deletions
diff --git a/backend/include/rcc/CodeGen/MachineInstr.h b/backend/include/rcc/CodeGen/MachineInstr.h index 69d7dd7..e7294b4 100644 --- a/backend/include/rcc/CodeGen/MachineInstr.h +++ b/backend/include/rcc/CodeGen/MachineInstr.h @@ -13,6 +13,8 @@ #include <functional> #include <optional> #include <span> +#include <string> +#include <string_view> #include <utility> #include <vector> @@ -154,6 +156,56 @@ public: DebugInstrNumber = 0; } + [[nodiscard]] std::optional<std::string_view> preInstrSymbol() const noexcept; + [[nodiscard]] Expected<void> setPreInstrSymbol(std::string Symbol); + void clearPreInstrSymbol() noexcept { + PreInstrSymbol.reset(); + } + + [[nodiscard]] std::optional<std::string_view> postInstrSymbol() const noexcept; + [[nodiscard]] Expected<void> setPostInstrSymbol(std::string Symbol); + void clearPostInstrSymbol() noexcept { + PostInstrSymbol.reset(); + } + + [[nodiscard]] const std::optional<MachineMetadataReference> &heapAllocMarker() const noexcept { + return HeapAllocMarker; + } + [[nodiscard]] Expected<void> setHeapAllocMarker(MachineMetadataReference Marker); + void clearHeapAllocMarker() noexcept { + HeapAllocMarker.reset(); + } + + [[nodiscard]] const std::optional<MachineMetadataReference> &pcSections() const noexcept { + return PCSections; + } + [[nodiscard]] Expected<void> setPCSections(MachineMetadataReference Sections); + void clearPCSections() noexcept { + PCSections.reset(); + } + + [[nodiscard]] const std::optional<MachineMetadataReference> &mmra() const noexcept { + return MMRA; + } + [[nodiscard]] Expected<void> setMMRA(MachineMetadataReference Metadata); + void clearMMRA() noexcept { + MMRA.reset(); + } + + [[nodiscard]] std::optional<std::uint32_t> cfiType() const noexcept { + return CFIType; + } + [[nodiscard]] Expected<void> setCFIType(std::uint64_t Type); + void clearCFIType() noexcept { + CFIType.reset(); + } + + [[nodiscard]] std::optional<std::string_view> deactivationSymbol() const noexcept; + [[nodiscard]] Expected<void> setDeactivationSymbol(std::string Symbol); + void clearDeactivationSymbol() noexcept { + DeactivationSymbol.reset(); + } + private: MachineInstr(MachineFunction &OwnerFunction, Opcode InstructionOpcode, MachineInstrStableID StableID); @@ -177,6 +229,13 @@ private: std::optional<MachineDebugLocation> DebugLocation; std::optional<OriginID> Origin; std::uint32_t DebugInstrNumber = 0; + std::optional<std::string> PreInstrSymbol; + std::optional<std::string> PostInstrSymbol; + std::optional<MachineMetadataReference> HeapAllocMarker; + std::optional<MachineMetadataReference> PCSections; + std::optional<MachineMetadataReference> MMRA; + std::optional<std::uint32_t> CFIType; + std::optional<std::string> DeactivationSymbol; friend class MachineArena; friend class MachineBasicBlock; diff --git a/backend/include/rcc/CodeGen/MachineMemOperand.h b/backend/include/rcc/CodeGen/MachineMemOperand.h index b6cb07f..a9e19a6 100644 --- a/backend/include/rcc/CodeGen/MachineMemOperand.h +++ b/backend/include/rcc/CodeGen/MachineMemOperand.h @@ -5,6 +5,7 @@ #include "rcc/CodeGen/LowLevelType.h" #include "rcc/CodeGen/MachineIRTypes.h" +#include "rcc/CodeGen/MachineMetadata.h" #include <cstdint> #include <initializer_list> @@ -138,6 +139,14 @@ public: JumpTable, GlobalSymbol, ExternalSymbol, + IRValue, + Stack, + GOT, + ConstantPoolPseudo, + JumpTablePseudo, + CallEntryGlobal, + CallEntryExternal, + Custom, }; MemoryBase() = default; @@ -147,6 +156,14 @@ public: [[nodiscard]] static MemoryBase jumpTable(JumpTableIndex Index); [[nodiscard]] static MemoryBase globalSymbol(std::string Name); [[nodiscard]] static MemoryBase externalSymbol(std::string Name); + [[nodiscard]] static MemoryBase irValue(std::string Name); + [[nodiscard]] static MemoryBase stack(); + [[nodiscard]] static MemoryBase got(); + [[nodiscard]] static MemoryBase constantPoolPseudo(); + [[nodiscard]] static MemoryBase jumpTablePseudo(); + [[nodiscard]] static MemoryBase callEntryGlobal(std::string Name); + [[nodiscard]] static MemoryBase callEntryExternal(std::string Name); + [[nodiscard]] static MemoryBase custom(std::string Name); [[nodiscard]] Kind kind() const noexcept { return BaseKind; @@ -177,11 +194,17 @@ struct MachineMemOperandDesc final { SyncScopeID SyncScope; MemorySize Size; Alignment Align; + std::optional<Alignment> BaseAlign; std::uint32_t AddressSpace = 0; MemoryBase Base; std::int64_t Offset = 0; std::optional<MemoryOffsetRange> OffsetRange; std::optional<MemoryAliasSourceID> AliasSource; + std::optional<MachineMetadataReference> TBAA; + std::optional<MachineMetadataReference> AliasScope; + std::optional<MachineMetadataReference> NoAlias; + std::optional<MachineMetadataReference> NoAliasAddressSpace; + std::optional<MachineMetadataReference> RangeMetadata; std::uint16_t TargetFlags = 0; friend bool operator==(const MachineMemOperandDesc &Left, |
