Merged
Conversation
This was referenced Sep 12, 2025
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Member
|
@llvm/pr-subscribers-backend-mips @llvm/pr-subscribers-llvm-selectiondag Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/158273.diff 7 Files Affected:
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 8a5cb517c94c5..a8fd010c58ac8 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -3706,7 +3706,9 @@ void MipsAsmParser::expandMem16Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
MCRegister TmpReg = DstReg;
const MCInstrDesc &Desc = MII.get(OpCode);
- int16_t DstRegClass = Desc.operands()[StartOp].RegClass;
+ int16_t DstRegClass =
+ MII.getOpRegClassID(Desc.operands()[StartOp],
+ STI->getHwMode(MCSubtargetInfo::HwMode_RegClass));
unsigned DstRegClassID =
getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
@@ -3834,7 +3836,10 @@ void MipsAsmParser::expandMem9Inst(MCInst &Inst, SMLoc IDLoc, MCStreamer &Out,
MCRegister TmpReg = DstReg;
const MCInstrDesc &Desc = MII.get(OpCode);
- int16_t DstRegClass = Desc.operands()[StartOp].RegClass;
+ int16_t DstRegClass =
+ MII.getOpRegClassID(Desc.operands()[StartOp],
+ STI->getHwMode(MCSubtargetInfo::HwMode_RegClass));
+
unsigned DstRegClassID =
getContext().getRegisterInfo()->getRegClass(DstRegClass).getID();
bool IsGPR = (DstRegClassID == Mips::GPR32RegClassID) ||
diff --git a/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp b/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
index fa6cc0e3f0187..d569eda328ef0 100644
--- a/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
+++ b/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
@@ -916,6 +916,30 @@ DecodeGPRMM16MovePRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
return MCDisassembler::Success;
}
+static DecodeStatus DecodeGP32RegisterClass(MCInst &Inst, unsigned RegNo,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ llvm_unreachable("this is unused");
+}
+
+static DecodeStatus DecodeGP64RegisterClass(MCInst &Inst, unsigned RegNo,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ llvm_unreachable("this is unused");
+}
+
+static DecodeStatus DecodeSP32RegisterClass(MCInst &Inst, unsigned RegNo,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ llvm_unreachable("this is unused");
+}
+
+static DecodeStatus DecodeSP64RegisterClass(MCInst &Inst, unsigned RegNo,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ llvm_unreachable("this is unused");
+}
+
static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo,
uint64_t Address,
const MCDisassembler *Decoder) {
diff --git a/llvm/lib/Target/Mips/MicroMipsInstrInfo.td b/llvm/lib/Target/Mips/MicroMipsInstrInfo.td
index b3fd8f422f429..b44bf1391b73e 100644
--- a/llvm/lib/Target/Mips/MicroMipsInstrInfo.td
+++ b/llvm/lib/Target/Mips/MicroMipsInstrInfo.td
@@ -57,12 +57,6 @@ def MicroMipsMemGPRMM16AsmOperand : AsmOperandClass {
let PredicateMethod = "isMemWithGRPMM16Base";
}
-// Define the classes of pointers used by microMIPS.
-// The numbers must match those in MipsRegisterInfo::MipsPtrClass.
-def ptr_gpr16mm_rc : PointerLikeRegClass<1>;
-def ptr_sp_rc : PointerLikeRegClass<2>;
-def ptr_gp_rc : PointerLikeRegClass<3>;
-
class mem_mm_4_generic : Operand<i32> {
let PrintMethod = "printMemOperand";
let MIOperandInfo = (ops ptr_gpr16mm_rc, simm4);
@@ -114,7 +108,7 @@ def mem_mm_gp_simm7_lsl2 : Operand<i32> {
def mem_mm_9 : Operand<i32> {
let PrintMethod = "printMemOperand";
- let MIOperandInfo = (ops ptr_rc, simm9);
+ let MIOperandInfo = (ops mips_ptr_rc, simm9);
let EncoderMethod = "getMemEncodingMMImm9";
let ParserMatchClass = MipsMemSimmAsmOperand<9>;
let OperandType = "OPERAND_MEMORY";
@@ -130,7 +124,7 @@ def mem_mm_11 : Operand<i32> {
def mem_mm_12 : Operand<i32> {
let PrintMethod = "printMemOperand";
- let MIOperandInfo = (ops ptr_rc, simm12);
+ let MIOperandInfo = (ops mips_ptr_rc, simm12);
let EncoderMethod = "getMemEncodingMMImm12";
let ParserMatchClass = MipsMemAsmOperand;
let OperandType = "OPERAND_MEMORY";
@@ -138,7 +132,7 @@ def mem_mm_12 : Operand<i32> {
def mem_mm_16 : Operand<i32> {
let PrintMethod = "printMemOperand";
- let MIOperandInfo = (ops ptr_rc, simm16);
+ let MIOperandInfo = (ops mips_ptr_rc, simm16);
let EncoderMethod = "getMemEncodingMMImm16";
let DecoderMethod = "DecodeMemMMImm16";
let ParserMatchClass = MipsMemSimmAsmOperand<16>;
diff --git a/llvm/lib/Target/Mips/Mips.td b/llvm/lib/Target/Mips/Mips.td
index b346ba95f5984..bfde7740ba011 100644
--- a/llvm/lib/Target/Mips/Mips.td
+++ b/llvm/lib/Target/Mips/Mips.td
@@ -211,6 +211,21 @@ def FeatureUseIndirectJumpsHazard : SubtargetFeature<"use-indirect-jump-hazard",
def FeatureStrictAlign
: SubtargetFeature<"strict-align", "StrictAlign", "true",
"Disable unaligned load store for r6">;
+//===----------------------------------------------------------------------===//
+// Mips Instruction Predicate Definitions.
+//===----------------------------------------------------------------------===//
+
+def IsPTR64bit : Predicate<"Subtarget->isABI_N64()">,
+ AssemblerPredicate<(all_of FeaturePTR64Bit)>;
+def IsPTR32bit : Predicate<"!Subtarget->isABI_N64()">,
+ AssemblerPredicate<(all_of (not FeaturePTR64Bit))>;
+
+//===----------------------------------------------------------------------===//
+// HwModes
+//===----------------------------------------------------------------------===//
+
+defvar MIPS32 = DefaultMode;
+def MIPS64 : HwMode<[IsPTR64bit]>;
//===----------------------------------------------------------------------===//
// Register File, Calling Conv, Instruction Descriptions
diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.td b/llvm/lib/Target/Mips/MipsInstrInfo.td
index a124e84e9ca5f..eff80e59c64c9 100644
--- a/llvm/lib/Target/Mips/MipsInstrInfo.td
+++ b/llvm/lib/Target/Mips/MipsInstrInfo.td
@@ -156,6 +156,8 @@ def MipsSDR : SDNode<"MipsISD::SDR", SDTStore,
//===----------------------------------------------------------------------===//
// Mips Instruction Predicate Definitions.
//===----------------------------------------------------------------------===//
+// FIXME: Move to Mips.td
+
def HasMips2 : Predicate<"Subtarget->hasMips2()">,
AssemblerPredicate<(all_of FeatureMips2)>;
def HasMips3_32 : Predicate<"Subtarget->hasMips3_32()">,
@@ -188,10 +190,6 @@ def IsGP64bit : Predicate<"Subtarget->isGP64bit()">,
AssemblerPredicate<(all_of FeatureGP64Bit)>;
def IsGP32bit : Predicate<"!Subtarget->isGP64bit()">,
AssemblerPredicate<(all_of (not FeatureGP64Bit))>;
-def IsPTR64bit : Predicate<"Subtarget->isABI_N64()">,
- AssemblerPredicate<(all_of FeaturePTR64Bit)>;
-def IsPTR32bit : Predicate<"!Subtarget->isABI_N64()">,
- AssemblerPredicate<(all_of (not FeaturePTR64Bit))>;
def HasMips64 : Predicate<"Subtarget->hasMips64()">,
AssemblerPredicate<(all_of FeatureMips64)>;
def NotMips64 : Predicate<"!Subtarget->hasMips64()">,
@@ -1125,7 +1123,7 @@ def InvertedImOperand64 : Operand<i64> {
class mem_generic : Operand<iPTR> {
let PrintMethod = "printMemOperand";
- let MIOperandInfo = (ops ptr_rc, simm16);
+ let MIOperandInfo = (ops mips_ptr_rc, simm16);
let EncoderMethod = "getMemEncoding";
let ParserMatchClass = MipsMemAsmOperand;
let OperandType = "OPERAND_MEMORY";
@@ -1136,7 +1134,7 @@ def mem : mem_generic;
// MSA specific address operand
def mem_msa : mem_generic {
- let MIOperandInfo = (ops ptr_rc, simm10);
+ let MIOperandInfo = (ops mips_ptr_rc, simm10);
let EncoderMethod = "getMSAMemEncoding";
}
@@ -1145,7 +1143,7 @@ def simm12 : Operand<i32> {
}
def mem_simm9_exp : mem_generic {
- let MIOperandInfo = (ops ptr_rc, simm9);
+ let MIOperandInfo = (ops mips_ptr_rc, simm9);
let ParserMatchClass = MipsMemSimmPtrAsmOperand;
let OperandNamespace = "MipsII";
let OperandType = "OPERAND_MEM_SIMM9";
@@ -1153,13 +1151,13 @@ def mem_simm9_exp : mem_generic {
foreach I = {9, 10, 11, 12, 16} in
def mem_simm # I : mem_generic {
- let MIOperandInfo = (ops ptr_rc, !cast<Operand>("simm" # I));
+ let MIOperandInfo = (ops mips_ptr_rc, !cast<Operand>("simm" # I));
let ParserMatchClass = MipsMemSimmAsmOperand<I>;
}
foreach I = {1, 2, 3} in
def mem_simm10_lsl # I : mem_generic {
- let MIOperandInfo = (ops ptr_rc, !cast<Operand>("simm10_lsl" # I));
+ let MIOperandInfo = (ops mips_ptr_rc, !cast<Operand>("simm10_lsl" # I));
let EncoderMethod = "getMemEncoding<" # I # ">";
let ParserMatchClass = MipsMemSimmAsmOperand<10, I>;
}
@@ -1170,13 +1168,13 @@ def mem_simmptr : mem_generic {
def mem_ea : Operand<iPTR> {
let PrintMethod = "printMemOperandEA";
- let MIOperandInfo = (ops ptr_rc, simm16);
+ let MIOperandInfo = (ops mips_ptr_rc, simm16);
let EncoderMethod = "getMemEncoding";
let OperandType = "OPERAND_MEMORY";
}
def PtrRC : Operand<iPTR> {
- let MIOperandInfo = (ops ptr_rc);
+ let MIOperandInfo = (ops mips_ptr_rc);
let DecoderMethod = "DecodePtrRegisterClass";
let ParserMatchClass = GPR32AsmOperand;
}
diff --git a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp
index 4d105bddd4d9c..6f8d6764e77b8 100644
--- a/llvm/lib/Target/Mips/MipsRegisterInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsRegisterInfo.cpp
@@ -46,20 +46,8 @@ unsigned MipsRegisterInfo::getPICCallReg() { return Mips::T9; }
const TargetRegisterClass *
MipsRegisterInfo::getPointerRegClass(unsigned Kind) const {
- MipsPtrClass PtrClassKind = static_cast<MipsPtrClass>(Kind);
-
- switch (PtrClassKind) {
- case MipsPtrClass::Default:
- return ArePtrs64bit ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
- case MipsPtrClass::GPR16MM:
- return &Mips::GPRMM16RegClass;
- case MipsPtrClass::StackPointer:
- return ArePtrs64bit ? &Mips::SP64RegClass : &Mips::SP32RegClass;
- case MipsPtrClass::GlobalPointer:
- return ArePtrs64bit ? &Mips::GP64RegClass : &Mips::GP32RegClass;
- }
-
- llvm_unreachable("Unknown pointer kind");
+ assert(Kind == 0 && "this should only be used for default case");
+ return ArePtrs64bit ? &Mips::GPR64RegClass : &Mips::GPR32RegClass;
}
unsigned
diff --git a/llvm/lib/Target/Mips/MipsRegisterInfo.td b/llvm/lib/Target/Mips/MipsRegisterInfo.td
index 237ccdc5cc967..80ff119be37d5 100644
--- a/llvm/lib/Target/Mips/MipsRegisterInfo.td
+++ b/llvm/lib/Target/Mips/MipsRegisterInfo.td
@@ -758,3 +758,19 @@ def MSA128DOpnd : RegisterOperand<MSA128D> {
def MSA128CROpnd : RegisterOperand<MSACtrl> {
let ParserMatchClass = MSACtrlAsmOperand;
}
+
+def mips_ptr_rc : RegClassByHwMode<
+ [MIPS32, MIPS64],
+ [GPR32, GPR64]>;
+
+def ptr_gpr16mm_rc : RegClassByHwMode<
+ [MIPS32, MIPS64],
+ [GPRMM16, GPRMM16]>; // FIXME: Why even use this if it's just a constant
+
+def ptr_sp_rc : RegClassByHwMode<
+ [MIPS32, MIPS64],
+ [SP32, SP64]>;
+
+def ptr_gp_rc : RegClassByHwMode<
+ [MIPS32, MIPS64],
+ [GP32, GP64]>;
|
This was referenced Sep 12, 2025
ba508eb to
b0954df
Compare
cf6589f to
cc9b01e
Compare
480926a to
bdfdc33
Compare
6d6e9fd to
6fbe887
Compare
da6fc27 to
8bfcdcc
Compare
6fbe887 to
f0d6719
Compare
Base automatically changed from
users/arsenm/codegen/targetinstrinfo-add-regclass-by-hwmode
to
main
September 19, 2025 11:08
c14bc7a to
a29b2f7
Compare
This was referenced Sep 19, 2025
pedroclobo
pushed a commit
to pedroclobo/llvm-project
that referenced
this pull request
Jan 13, 2026
pedroclobo
pushed a commit
to pedroclobo/llvm-project
that referenced
this pull request
Jan 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

No description provided.