From 84de01908b58f3aa25cc3dc700a8a1b01b5263f0 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 22 Mar 2023 10:24:57 -0700 Subject: [PATCH] [RISCV] Remove AnyReg RegisterClass used by .insn instructions. Use custom operand instead. The fake register class interferes too much with the autogenerated register class tables. Especially the fake spill size. I'm working on .insn support for compressed instructions and adding AnyRegC broke CodeGen. --- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 6 ++++++ llvm/lib/Target/RISCV/RISCVInstrInfo.td | 11 +++++++++++ llvm/lib/Target/RISCV/RISCVRegisterInfo.td | 12 ------------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 9c6d54e..d984f39 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -368,6 +368,12 @@ public: bool isV0Reg() const { return Kind == KindTy::Register && Reg.RegNum == RISCV::V0; } + bool isAnyReg() const { + return Kind == KindTy::Register && + (RISCVMCRegisterClasses[RISCV::GPRRegClassID].contains(Reg.RegNum) || + RISCVMCRegisterClasses[RISCV::FPR64RegClassID].contains(Reg.RegNum) || + RISCVMCRegisterClasses[RISCV::VRRegClassID].contains(Reg.RegNum)); + } bool isImm() const override { return Kind == KindTy::Immediate; } bool isMem() const override { return false; } bool isSystemRegister() const { return Kind == KindTy::SystemRegister; } diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td index ab8a8a4..85c3082 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -1090,6 +1090,17 @@ def : InstAlias<"zext.b $rd, $rs", (ANDI GPR:$rd, GPR:$rs, 0xFF), 0>; // .insn directive instructions //===----------------------------------------------------------------------===// +def AnyRegOperand : AsmOperandClass { + let Name = "AnyRegOperand"; + let RenderMethod = "addRegOperands"; + let PredicateMethod = "isAnyReg"; +} + +def AnyReg : Operand { + let OperandType = "OPERAND_REGISTER"; + let ParserMatchClass = AnyRegOperand; +} + // isCodeGenOnly = 1 to hide them from the tablegened assembly parser. let isCodeGenOnly = 1, hasSideEffects = 1, mayLoad = 1, mayStore = 1, hasNoSchedulingInfo = 1 in { diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td index 7e91441..d06453c 100644 --- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td +++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td @@ -578,15 +578,3 @@ foreach m = LMULList.m in { // Special registers def FFLAGS : RISCVReg<0, "fflags">; def FRM : RISCVReg<0, "frm">; - -// Any type register. Used for .insn directives when we don't know what the -// register types could be. -// NOTE: The alignment and size are bogus values. The Size needs to be non-zero -// or tablegen will use "untyped" to determine the size which will assert. -let isAllocatable = 0 in -def AnyReg : RegisterClass<"RISCV", [untyped], 32, - (add (sequence "X%u", 0, 31), - (sequence "F%u_D", 0, 31), - (sequence "V%u", 0, 31))> { - let Size = 32; -} -- 2.7.4