Skip to content

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Sep 12, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Sep 12, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2025

@llvm/pr-subscribers-backend-sparc

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/158271.diff

2 Files Affected:

  • (modified) llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp (-8)
  • (modified) llvm/lib/Target/Sparc/SparcInstrInfo.td (+19-2)
diff --git a/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp b/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
index c3d60f3689e1f..e585e5af42d32 100644
--- a/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
+++ b/llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
@@ -159,14 +159,6 @@ static DecodeStatus DecodeI64RegsRegisterClass(MCInst &Inst, unsigned RegNo,
   return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
 }
 
-// This is used for the type "ptr_rc", which is either IntRegs or I64Regs
-// depending on SparcRegisterInfo::getPointerRegClass.
-static DecodeStatus DecodePointerLikeRegClass0(MCInst &Inst, unsigned RegNo,
-                                               uint64_t Address,
-                                               const MCDisassembler *Decoder) {
-  return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
-}
-
 static DecodeStatus DecodeFPRegsRegisterClass(MCInst &Inst, unsigned RegNo,
                                               uint64_t Address,
                                               const MCDisassembler *Decoder) {
diff --git a/llvm/lib/Target/Sparc/SparcInstrInfo.td b/llvm/lib/Target/Sparc/SparcInstrInfo.td
index 53972d6c105a4..97e7fd7769edb 100644
--- a/llvm/lib/Target/Sparc/SparcInstrInfo.td
+++ b/llvm/lib/Target/Sparc/SparcInstrInfo.td
@@ -95,10 +95,27 @@ def HasFSMULD : Predicate<"!Subtarget->hasNoFSMULD()">;
 // will pick deprecated instructions.
 def UseDeprecatedInsts : Predicate<"Subtarget->useV8DeprecatedInsts()">;
 
+//===----------------------------------------------------------------------===//
+// HwModes Pattern Stuff
+//===----------------------------------------------------------------------===//
+
+defvar SPARC32 = DefaultMode;
+def SPARC64 : HwMode<[Is64Bit]>;
+
 //===----------------------------------------------------------------------===//
 // Instruction Pattern Stuff
 //===----------------------------------------------------------------------===//
 
+def sparc_ptr_rc : RegClassByHwMode<
+  [SPARC32, SPARC64],
+  [IntRegs, I64Regs]>;
+
+// Both cases can use the same decoder method, so avoid the dispatch
+// by hwmode by setting an explicit DecoderMethod
+def ptr_op : RegisterOperand<sparc_ptr_rc> {
+  let DecoderMethod = "DecodeIntRegsRegisterClass";
+}
+
 // FIXME these should have AsmOperandClass.
 def uimm3 : PatLeaf<(imm), [{ return isUInt<3>(N->getZExtValue()); }]>;
 
@@ -178,12 +195,12 @@ def simm13Op : Operand<iPTR> {
 
 def MEMrr : Operand<iPTR> {
   let PrintMethod = "printMemOperand";
-  let MIOperandInfo = (ops ptr_rc, ptr_rc);
+  let MIOperandInfo = (ops ptr_op, ptr_op);
   let ParserMatchClass = SparcMEMrrAsmOperand;
 }
 def MEMri : Operand<iPTR> {
   let PrintMethod = "printMemOperand";
-  let MIOperandInfo = (ops ptr_rc, simm13Op);
+  let MIOperandInfo = (ops ptr_op, simm13Op);
   let ParserMatchClass = SparcMEMriAsmOperand;
 }
 

Comment on lines +102 to +103
defvar SPARC32 = DefaultMode;
def SPARC64 : HwMode<[Is64Bit]>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a default mode really, so maybe:

Suggested change
defvar SPARC32 = DefaultMode;
def SPARC64 : HwMode<[Is64Bit]>;
def Mode32Bit : HwMode<[Is32Bit]>;
def Mode64Bit : HwMode<[Is64Bit]>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean, there is a default mode. It's also weirdly baked into the tablegen APIs for it too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant default mode in hardware. This is more of a stylistic suggestion.

@brad0 brad0 requested a review from koachan September 14, 2025 23:04
@arsenm arsenm force-pushed the users/arsenm/codegen/targetinstrinfo-add-regclass-by-hwmode branch from ba508eb to b0954df Compare September 15, 2025 11:40
@arsenm arsenm force-pushed the users/arsenm/sparc/use-RegClassByHwMode branch 2 times, most recently from a349f1a to 7827021 Compare September 16, 2025 04:51
@arsenm arsenm force-pushed the users/arsenm/codegen/targetinstrinfo-add-regclass-by-hwmode branch from b0954df to 480926a Compare September 16, 2025 04:51
@arsenm arsenm force-pushed the users/arsenm/codegen/targetinstrinfo-add-regclass-by-hwmode branch from 480926a to bdfdc33 Compare September 17, 2025 15:22
@arsenm arsenm force-pushed the users/arsenm/sparc/use-RegClassByHwMode branch 2 times, most recently from 0836893 to 34d9fc2 Compare September 18, 2025 00:23
Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm force-pushed the users/arsenm/sparc/use-RegClassByHwMode branch from 34d9fc2 to e7ef891 Compare September 19, 2025 06:01
@arsenm arsenm force-pushed the users/arsenm/codegen/targetinstrinfo-add-regclass-by-hwmode branch from da6fc27 to 8bfcdcc Compare September 19, 2025 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants