diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-16 17:28:49 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-16 17:28:49 +0800 |
| commit | 864a29abbdce86353ec91c3587757711d3a42f10 (patch) | |
| tree | 772390cad70fe8e47044f5c921174b254bd8297a /backend/include/rcc | |
| parent | ca25d25d4c5131491a50b1a94e63e9b2d3c34ed4 (diff) | |
| download | rcc-project-864a29abbdce86353ec91c3587757711d3a42f10.tar.gz rcc-project-864a29abbdce86353ec91c3587757711d3a42f10.tar.xz | |
[RISCV][GlobalISel] Generate integer comparisons
Diffstat (limited to 'backend/include/rcc')
| -rw-r--r-- | backend/include/rcc/CodeGen/GlobalISel/GIMatchTableExecutor.h | 28 | ||||
| -rw-r--r-- | backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h | 6 | ||||
| -rw-r--r-- | backend/include/rcc/TableGen/Record.h | 30 |
3 files changed, 58 insertions, 6 deletions
diff --git a/backend/include/rcc/CodeGen/GlobalISel/GIMatchTableExecutor.h b/backend/include/rcc/CodeGen/GlobalISel/GIMatchTableExecutor.h index 7cceca3..afd0d70 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/GIMatchTableExecutor.h +++ b/backend/include/rcc/CodeGen/GlobalISel/GIMatchTableExecutor.h @@ -22,17 +22,27 @@ enum class GIMatchTypeKind : std::uint8_t { Pointer, }; +enum class GIMatchImmediateTransform : std::uint8_t { + Identity, + Negate, + PlusOne, +}; + enum class GIMatchTableOpcode : std::uint8_t { CheckOpcode, CheckOperandType, CheckOperandBank, CheckOperandClass, CheckIntegerPredicate, - CheckOperandDefConstant, + CheckOperandDefConstantRanges, + CreateTemporary, MutateOpcode, + BuildInstruction, RenderOperand, RenderPhysicalRegister, - AppendImmediate, + RenderTemporary, + RenderCapturedImmediate, + RenderImmediate, EraseOperandDefinition, Complete, }; @@ -45,6 +55,11 @@ struct GIMatchTableInstruction final { std::int64_t Immediate = 0; }; +struct GIMatchTableConstantRange final { + std::int64_t Minimum = 0; + std::int64_t Maximum = 0; +}; + struct GIMatchTableRule final { std::string_view Name; std::uint32_t Priority = 0; @@ -55,10 +70,13 @@ struct GIMatchTableRule final { struct GIMatchTable final { std::span<const GIMatchTableInstruction> Instructions; std::span<const GIMatchTableRule> Rules; + std::span<const GIMatchTableConstantRange> ConstantRanges; }; class GIMatchTableExecutor { public: + virtual ~GIMatchTableExecutor() = default; + [[nodiscard]] Expected<bool> match(const GIMatchTable &Table, const MachineInstr &Instruction, const MachineFunction &Function, const TargetDescription &Target) const; @@ -68,6 +86,12 @@ public: [[nodiscard]] Expected<bool> select(const GIMatchTable &Table, MachineInstr &Instruction, MachineFunction &Function, const TargetDescription &Target) const; + +protected: + [[nodiscard]] virtual Expected<void> + finalizeGeneratedInstruction(MachineInstr &Output, MachineFunction &Function, + const TargetDescription &Target, MachineInstrFlags InputFlags, + bool InputMayRaiseFPException) const; }; } // namespace rcc diff --git a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h index 36fca8d..f45b24d 100644 --- a/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h +++ b/backend/include/rcc/CodeGen/GlobalISel/InstructionSelector.h @@ -38,6 +38,12 @@ public: [[nodiscard]] Expected<void> propagateSelectionFlags(MachineInstr &Output, const MachineInstr &Input, const TargetDescription &Target) const; + +protected: + [[nodiscard]] Expected<void> + finalizeGeneratedInstruction(MachineInstr &Output, MachineFunction &Function, + const TargetDescription &Target, MachineInstrFlags InputFlags, + bool InputMayRaiseFPException) const override; }; } // namespace rcc diff --git a/backend/include/rcc/TableGen/Record.h b/backend/include/rcc/TableGen/Record.h index 4378af8..57e5832 100644 --- a/backend/include/rcc/TableGen/Record.h +++ b/backend/include/rcc/TableGen/Record.h @@ -237,17 +237,40 @@ struct SourceSelectionIntegerPredicate final { struct SourceSelectionOperandDefConstantPredicate final { std::uint32_t OperandIndex = 0; - std::int64_t Value = 0; + struct ConstantRange final { + std::int64_t Minimum = 0; + std::int64_t Maximum = 0; + TextRange SourceRange; + }; + + std::vector<ConstantRange> Ranges; + TextRange Range; +}; + +struct SourceSelectionTemporary final { + std::string Symbol; + std::uint32_t TypeFromOperand = 0; TextRange Range; }; struct SourceSelectionOperandRenderer final { std::optional<std::uint32_t> OperandIndex; std::string PhysicalRegisterSymbol; + std::string TemporarySymbol; + std::optional<std::uint32_t> CapturedImmediateOperand; + std::optional<std::int64_t> Immediate; + std::string ImmediateTransform; std::vector<std::string> Flags; TextRange Range; }; +struct SourceSelectionAction final { + std::string ResultOpcodeSymbol; + bool ReplacesRoot = false; + std::vector<SourceSelectionOperandRenderer> OperandRenderers; + TextRange Range; +}; + struct SourceSelectionRule final { std::string Symbol; std::uint32_t Priority = 0; @@ -258,9 +281,8 @@ struct SourceSelectionRule final { std::vector<SourceSelectionOperandBankPredicate> OperandBanks; std::vector<SourceSelectionOperandClassPredicate> OperandClasses; std::vector<SourceSelectionOperandDefConstantPredicate> OperandDefConstants; - std::string ResultOpcodeSymbol; - std::optional<std::vector<SourceSelectionOperandRenderer>> OperandRenderers; - std::vector<std::int64_t> AppendedImmediates; + std::vector<SourceSelectionTemporary> Temporaries; + std::vector<SourceSelectionAction> Actions; std::vector<std::uint32_t> EraseOperandDefinitions; TextRange Range; }; |
