From 32a365a2dc0096b4421fb3947b32d971b7f34c40 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sat, 15 Aug 2026 04:48:16 +0800 Subject: [GlobalISel] Lower stack operations --- backend/include/rcc/CodeGen/TargetDescription.h | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'backend/include/rcc/CodeGen/TargetDescription.h') diff --git a/backend/include/rcc/CodeGen/TargetDescription.h b/backend/include/rcc/CodeGen/TargetDescription.h index 56d328e..6504ba8 100644 --- a/backend/include/rcc/CodeGen/TargetDescription.h +++ b/backend/include/rcc/CodeGen/TargetDescription.h @@ -36,6 +36,16 @@ struct TargetBooleanContentInfo final { BooleanContent Vector = BooleanContent::Undefined; }; +enum class StackGrowthDirection : std::uint8_t { + Down, + Up, +}; + +struct TargetStackInfo final { + PhysicalRegister StackPointerRegisterToSaveRestore; + StackGrowthDirection GrowthDirection = StackGrowthDirection::Down; +}; + class TargetDescription final { public: TargetDescription(const TargetDescription &) = delete; @@ -44,9 +54,11 @@ public: TargetDescription &operator=(TargetDescription &&) noexcept = default; ~TargetDescription() = default; - [[nodiscard]] static Expected - create(InstructionSet Instructions, TargetRegisterInfo Registers, - TargetMIRTextInfoDesc MIRText = {}, TargetBooleanContentInfo BooleanInfo = {}); + [[nodiscard]] static Expected create(InstructionSet Instructions, + TargetRegisterInfo Registers, + TargetMIRTextInfoDesc MIRText = {}, + TargetBooleanContentInfo BooleanInfo = {}, + TargetStackInfo StackInfo = {}); [[nodiscard]] const InstructionSet &instructions() const noexcept { return Instructions; @@ -67,6 +79,14 @@ public: return IsFloatingPoint ? BooleanInfo.ScalarFloatingPoint : BooleanInfo.ScalarInteger; } + [[nodiscard]] PhysicalRegister stackPointerRegisterToSaveRestore() const noexcept { + return StackInfo.StackPointerRegisterToSaveRestore; + } + + [[nodiscard]] StackGrowthDirection stackGrowthDirection() const noexcept { + return StackInfo.GrowthDirection; + } + [[nodiscard]] const InstructionDescriptor * instructionDescriptor(Opcode InstructionOpcode) const noexcept { return Instructions.descriptor(InstructionOpcode); @@ -107,9 +127,10 @@ public: private: TargetDescription(InstructionSet Instructions, TargetRegisterInfo Registers, - TargetMIRTextInfo MIRText, TargetBooleanContentInfo BooleanInfo) + TargetMIRTextInfo MIRText, TargetBooleanContentInfo BooleanInfo, + TargetStackInfo StackInfo) : Instructions(std::move(Instructions)), Registers(std::move(Registers)), - MIRText(std::move(MIRText)), BooleanInfo(BooleanInfo) {} + MIRText(std::move(MIRText)), BooleanInfo(BooleanInfo), StackInfo(StackInfo) {} [[nodiscard]] Expected validateTargetOperand(const OperandDescriptor *Descriptor, const MachineOperand &Operand, @@ -122,6 +143,7 @@ private: TargetRegisterInfo Registers; TargetMIRTextInfo MIRText; TargetBooleanContentInfo BooleanInfo; + TargetStackInfo StackInfo; }; } // namespace rcc -- cgit v1.2.3