[llvm] [Mips] Add named COP0 registers (PR #229391)

Jiaxun Yang via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 15:03:19 PDT 2026


================
@@ -6670,6 +6679,46 @@ MipsAsmParser::matchAnyRegisterWithoutDollar(OperandVector &Operands, SMLoc S) {
   return matchAnyRegisterWithoutDollar(Operands, Token, S);
 }
 
+ParseStatus MipsAsmParser::parseCOP0Register(OperandVector &Operands) {
+  SMLoc S = getLexer().getLoc();
+  SmallVector<std::unique_ptr<MCParsedAsmOperand>, 1> RegOperands;
+  ParseStatus Res = parseAnyRegister(RegOperands);
+  if (!Res.isSuccess())
+    return Res;
+  const auto &Op = static_cast<const MipsOperand &>(*RegOperands.back());
+  unsigned Encoding;
+  if (Op.isCOP0AsmReg())
+    Encoding = Op.getCOP0Encoding();
+  else if (Op.isNumericReg())
+    Encoding = MIPS_MC::encodeCOP0Register(Op.getNumericRegIndex(), 0);
+  else
+    return Error(S, "invalid operand for instruction");
+
+  const MCRegisterInfo &MRI = *getContext().getRegisterInfo();
+  if (getLexer().is(AsmToken::Comma)) {
+    Lex();
+    SMLoc SelLoc = getLexer().getLoc();
+    if (getLexer().is(AsmToken::Dollar))
+      return Error(SelLoc, "expected 3-bit unsigned immediate");
+    const MCExpr *Expr;
+    int64_t Sel;
+    if (getParser().parseExpression(Expr))
+      return ParseStatus::Failure;
+    if (!Expr->evaluateAsAbsolute(Sel) || !isUInt<3>(Sel))
+      return Error(SelLoc, "expected 3-bit unsigned immediate");
+    if (Op.isCOP0AsmReg() && Sel != MIPS_MC::getCOP0Sel(Encoding))
+      return Error(SelLoc, "selector does not match named COP0 register");
+    Encoding =
----------------
FlyGoat wrote:

That’s something GAS do support but I guess that’s bit of toxic… I’m 99% sure no one will rely on this behaviour.

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


More information about the llvm-commits mailing list