[llvm] [TRI][RISCV] Add methods to get common register class of two registers (PR #118435)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 07:56:39 PST 2024


================
@@ -222,6 +222,25 @@ TargetRegisterInfo::getMinimalPhysRegClass(MCRegister reg, MVT VT) const {
   return BestRC;
 }
 
+const TargetRegisterClass *TargetRegisterInfo::getCommonMinimalPhysRegClass(
----------------
ilovepi wrote:

I was thinking more that you'd just put all the logic in a new function that was templated, and let each of these just call that internally. Then you can keep your API as is (assuming it needs to be that way for a reason) and the two won't get out of sync. The only thing the original functions need to do is evaluate the boolean, and then return the call to the common impl. 

so Somthing like this, where the current functions are just think wrappers.

```
const TargetRegisterClass *TargetRegisterInfo::getCommonMinimalPhysRegClass(MCRegister Reg1, MCRegister Reg2, MVT VT) const {
  bool isValid = VT == MVT::Other;
  return commonImpl( Reg1, Reg2, VT, isValid);
}
``` 


https://github.com/llvm/llvm-project/pull/118435


More information about the llvm-commits mailing list