Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -146,6 +146,9 @@ /// If true, then CpSaveLocation is a register, otherwise it's an offset. bool CpSaveLocationIsRegister; + // Map of register aliases created via the .set directive. + StringMap RegisterSets; + // Print a warning along with its fix-it message at the given range. void printWarningWithFixIt(const Twine &Msg, const Twine &FixMsg, SMRange Range, bool ShowColors = true); @@ -184,6 +187,9 @@ matchAnyRegisterNameWithoutDollar(OperandVector &Operands, StringRef Identifier, SMLoc S); OperandMatchResultTy matchAnyRegisterWithoutDollar(OperandVector &Operands, + const AsmToken &Token, + SMLoc S); + OperandMatchResultTy matchAnyRegisterWithoutDollar(OperandVector &Operands, SMLoc S); OperandMatchResultTy parseAnyRegister(OperandVector &Operands); OperandMatchResultTy parseImm(OperandVector &Operands); @@ -5991,6 +5997,19 @@ llvm_unreachable("Should never ParseFail"); } } + } else if (Sym->isUnset()) { + // If symbol is unset, it might be created in the `parseSetAssignment` + // routine as an alias for a numeric register name. + // Lookup in the aliases list. + auto Entry = RegisterSets.find(Sym->getName()); + if (Entry != RegisterSets.end()) { + OperandMatchResultTy ResTy = + matchAnyRegisterWithoutDollar(Operands, Entry->getValue(), S); + if (ResTy == MatchOperand_Success) { + Parser.Lex(); + return true; + } + } } return false; @@ -6060,10 +6079,8 @@ } OperandMatchResultTy -MipsAsmParser::matchAnyRegisterWithoutDollar(OperandVector &Operands, SMLoc S) { - MCAsmParser &Parser = getParser(); - auto Token = Parser.getLexer().peekTok(false); - +MipsAsmParser::matchAnyRegisterWithoutDollar(OperandVector &Operands, + const AsmToken &Token, SMLoc S) { if (Token.is(AsmToken::Identifier)) { LLVM_DEBUG(dbgs() << ".. identifier\n"); StringRef Identifier = Token.getIdentifier(); @@ -6091,6 +6108,12 @@ } OperandMatchResultTy +MipsAsmParser::matchAnyRegisterWithoutDollar(OperandVector &Operands, SMLoc S) { + auto Token = getLexer().peekTok(false); + return matchAnyRegisterWithoutDollar(Operands, Token, S); +} + +OperandMatchResultTy MipsAsmParser::parseAnyRegister(OperandVector &Operands) { MCAsmParser &Parser = getParser(); LLVM_DEBUG(dbgs() << "parseAnyRegister\n"); @@ -6849,11 +6872,24 @@ return reportParseError("unexpected token, expected comma"); Lex(); // Eat comma - if (Parser.parseExpression(Value)) + if (getLexer().is(AsmToken::Dollar) && + getLexer().peekTok().is(AsmToken::Integer)) { + // Parse assignment of a numeric register: + // .set r1,$1 + Parser.Lex(); // Eat $. + RegisterSets[Name] = Parser.getTok(); + Parser.Lex(); // Eat identifier. + getContext().getOrCreateSymbol(Name); + } else if (!Parser.parseExpression(Value)) { + // Parse assignment of an expression including + // symbolic registers: + // .set $tmp, $BB0-$BB1 + // .set r2, $f2 + MCSymbol *Sym = getContext().getOrCreateSymbol(Name); + Sym->setVariableValue(Value); + } else { return reportParseError("expected valid expression after comma"); - - MCSymbol *Sym = getContext().getOrCreateSymbol(Name); - Sym->setVariableValue(Value); + } return false; } Index: test/MC/Mips/mips_directives.s =================================================================== --- test/MC/Mips/mips_directives.s +++ test/MC/Mips/mips_directives.s @@ -52,11 +52,12 @@ .set FPU_MASK,$f7 .set $tmp7, $BB0_4-$BB0_2 .set f6,$f6 + .set r1,$1 # CHECK: abs.s $f6, $f7 # encoding: [0x46,0x00,0x39,0x85] # CHECK: lui $1, %hi($tmp7) # encoding: [0x3c,0x01,A,A] # CHECK: # fixup A - offset: 0, value: %hi($tmp7), kind: fixup_Mips_HI16 abs.s f6,FPU_MASK - lui $1, %hi($tmp7) + lui r1, %hi($tmp7) # CHECK: .set mips32r2 # CHECK: ldxc1 $f0, $zero($5) # encoding: [0x4c,0xa0,0x00,0x01] @@ -89,4 +90,4 @@ # CHECK: balign $5, $6, 3 # encoding: [0x7c,0xc5,0x1c,0x31] .set dspr2 append $7, $10, 2 - balign $5, $6, 3 \ No newline at end of file + balign $5, $6, 3