@@ -434,7 +434,8 @@ class X86AsmParser : public MCTargetAsmParser {
434
434
435
435
class IntelExprStateMachine {
436
436
IntelExprState State = IES_INIT, PrevState = IES_ERROR;
437
- unsigned BaseReg = 0 , IndexReg = 0 , TmpReg = 0 , Scale = 0 ;
437
+ MCRegister BaseReg, IndexReg, TmpReg;
438
+ unsigned Scale = 0 ;
438
439
int64_t Imm = 0 ;
439
440
const MCExpr *Sym = nullptr ;
440
441
StringRef SymName;
@@ -468,8 +469,8 @@ class X86AsmParser : public MCTargetAsmParser {
468
469
bool isBracketUsed () const { return BracketUsed; }
469
470
bool isOffsetOperator () const { return OffsetOperator; }
470
471
SMLoc getOffsetLoc () const { return OffsetOperatorLoc; }
471
- unsigned getBaseReg () const { return BaseReg; }
472
- unsigned getIndexReg () const { return IndexReg; }
472
+ MCRegister getBaseReg () const { return BaseReg; }
473
+ MCRegister getIndexReg () const { return IndexReg; }
473
474
unsigned getScale () const { return Scale; }
474
475
const MCExpr *getSym () const { return Sym; }
475
476
StringRef getSymName () const { return SymName; }
@@ -791,7 +792,7 @@ class X86AsmParser : public MCTargetAsmParser {
791
792
}
792
793
PrevState = CurrState;
793
794
}
794
- bool onRegister (unsigned Reg, StringRef &ErrMsg) {
795
+ bool onRegister (MCRegister Reg, StringRef &ErrMsg) {
795
796
IntelExprState CurrState = State;
796
797
switch (State) {
797
798
default :
@@ -1111,8 +1112,8 @@ class X86AsmParser : public MCTargetAsmParser {
1111
1112
1112
1113
std::unique_ptr<X86Operand> DefaultMemSIOperand (SMLoc Loc);
1113
1114
std::unique_ptr<X86Operand> DefaultMemDIOperand (SMLoc Loc);
1114
- bool IsSIReg (unsigned Reg);
1115
- unsigned GetSIDIForRegClass (unsigned RegClassID, unsigned Reg , bool IsSIReg);
1115
+ bool IsSIReg (MCRegister Reg);
1116
+ MCRegister GetSIDIForRegClass (unsigned RegClassID, bool IsSIReg);
1116
1117
void
1117
1118
AddDefaultSrcDestOperands (OperandVector &Operands,
1118
1119
std::unique_ptr<llvm::MCParsedAsmOperand> &&Src,
@@ -1145,14 +1146,14 @@ class X86AsmParser : public MCTargetAsmParser {
1145
1146
void tryParseOperandIdx (AsmToken::TokenKind PrevTK,
1146
1147
IntelExprStateMachine &SM);
1147
1148
1148
- bool ParseMemOperand (unsigned SegReg, const MCExpr *Disp, SMLoc StartLoc,
1149
+ bool ParseMemOperand (MCRegister SegReg, const MCExpr *Disp, SMLoc StartLoc,
1149
1150
SMLoc EndLoc, OperandVector &Operands);
1150
1151
1151
1152
X86::CondCode ParseConditionCode (StringRef CCode);
1152
1153
1153
1154
bool ParseIntelMemoryOperandSize (unsigned &Size);
1154
- bool CreateMemForMSInlineAsm (unsigned SegReg, const MCExpr *Disp,
1155
- unsigned BaseReg, unsigned IndexReg,
1155
+ bool CreateMemForMSInlineAsm (MCRegister SegReg, const MCExpr *Disp,
1156
+ MCRegister BaseReg, MCRegister IndexReg,
1156
1157
unsigned Scale, bool NonAbsMem, SMLoc Start,
1157
1158
SMLoc End, unsigned Size, StringRef Identifier,
1158
1159
const InlineAsmIdentifierInfo &Info,
@@ -1300,14 +1301,15 @@ class X86AsmParser : public MCTargetAsmParser {
1300
1301
#define GET_SUBTARGET_FEATURE_NAME
1301
1302
#include " X86GenAsmMatcher.inc"
1302
1303
1303
- static bool CheckBaseRegAndIndexRegAndScale (unsigned BaseReg, unsigned IndexReg,
1304
- unsigned Scale, bool Is64BitMode,
1304
+ static bool CheckBaseRegAndIndexRegAndScale (MCRegister BaseReg,
1305
+ MCRegister IndexReg, unsigned Scale,
1306
+ bool Is64BitMode,
1305
1307
StringRef &ErrMsg) {
1306
1308
// If we have both a base register and an index register make sure they are
1307
1309
// both 64-bit or 32-bit registers.
1308
1310
// To support VSIB, IndexReg can be 128-bit or 256-bit registers.
1309
1311
1310
- if (BaseReg != 0 &&
1312
+ if (BaseReg &&
1311
1313
!(BaseReg == X86::RIP || BaseReg == X86::EIP ||
1312
1314
X86MCRegisterClasses[X86::GR16RegClassID].contains (BaseReg) ||
1313
1315
X86MCRegisterClasses[X86::GR32RegClassID].contains (BaseReg) ||
@@ -1316,7 +1318,7 @@ static bool CheckBaseRegAndIndexRegAndScale(unsigned BaseReg, unsigned IndexReg,
1316
1318
return true ;
1317
1319
}
1318
1320
1319
- if (IndexReg != 0 &&
1321
+ if (IndexReg &&
1320
1322
!(IndexReg == X86::EIZ || IndexReg == X86::RIZ ||
1321
1323
X86MCRegisterClasses[X86::GR16RegClassID].contains (IndexReg) ||
1322
1324
X86MCRegisterClasses[X86::GR32RegClassID].contains (IndexReg) ||
@@ -1328,9 +1330,9 @@ static bool CheckBaseRegAndIndexRegAndScale(unsigned BaseReg, unsigned IndexReg,
1328
1330
return true ;
1329
1331
}
1330
1332
1331
- if (((BaseReg == X86::RIP || BaseReg == X86::EIP) && IndexReg != 0 ) ||
1332
- IndexReg == X86::EIP || IndexReg == X86::RIP ||
1333
- IndexReg == X86::ESP || IndexReg == X86:: RSP) {
1333
+ if (((BaseReg == X86::RIP || BaseReg == X86::EIP) && IndexReg) ||
1334
+ IndexReg == X86::EIP || IndexReg == X86::RIP || IndexReg == X86::ESP ||
1335
+ IndexReg == X86::RSP) {
1334
1336
ErrMsg = " invalid base+index expression" ;
1335
1337
return true ;
1336
1338
}
@@ -1344,13 +1346,13 @@ static bool CheckBaseRegAndIndexRegAndScale(unsigned BaseReg, unsigned IndexReg,
1344
1346
return true ;
1345
1347
}
1346
1348
1347
- if (BaseReg == 0 &&
1349
+ if (! BaseReg &&
1348
1350
X86MCRegisterClasses[X86::GR16RegClassID].contains (IndexReg)) {
1349
1351
ErrMsg = " 16-bit memory operand may not include only index register" ;
1350
1352
return true ;
1351
1353
}
1352
1354
1353
- if (BaseReg != 0 && IndexReg != 0 ) {
1355
+ if (BaseReg && IndexReg) {
1354
1356
if (X86MCRegisterClasses[X86::GR64RegClassID].contains (BaseReg) &&
1355
1357
(X86MCRegisterClasses[X86::GR16RegClassID].contains (IndexReg) ||
1356
1358
X86MCRegisterClasses[X86::GR32RegClassID].contains (IndexReg) ||
@@ -1380,8 +1382,7 @@ static bool CheckBaseRegAndIndexRegAndScale(unsigned BaseReg, unsigned IndexReg,
1380
1382
}
1381
1383
1382
1384
// RIP/EIP-relative addressing is only supported in 64-bit mode.
1383
- if (!Is64BitMode && BaseReg != 0 &&
1384
- (BaseReg == X86::RIP || BaseReg == X86::EIP)) {
1385
+ if (!Is64BitMode && (BaseReg == X86::RIP || BaseReg == X86::EIP)) {
1385
1386
ErrMsg = " IP-relative addressing requires 64-bit mode" ;
1386
1387
return true ;
1387
1388
}
@@ -1608,7 +1609,8 @@ ParseStatus X86AsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
1608
1609
1609
1610
std::unique_ptr<X86Operand> X86AsmParser::DefaultMemSIOperand (SMLoc Loc) {
1610
1611
bool Parse32 = is32BitMode () || Code16GCC;
1611
- unsigned Basereg = is64BitMode () ? X86::RSI : (Parse32 ? X86::ESI : X86::SI);
1612
+ MCRegister Basereg =
1613
+ is64BitMode () ? X86::RSI : (Parse32 ? X86::ESI : X86::SI);
1612
1614
const MCExpr *Disp = MCConstantExpr::create (0 , getContext ());
1613
1615
return X86Operand::CreateMem (getPointerWidth (), /* SegReg=*/ 0 , Disp,
1614
1616
/* BaseReg=*/ Basereg, /* IndexReg=*/ 0 , /* Scale=*/ 1 ,
@@ -1617,15 +1619,16 @@ std::unique_ptr<X86Operand> X86AsmParser::DefaultMemSIOperand(SMLoc Loc) {
1617
1619
1618
1620
std::unique_ptr<X86Operand> X86AsmParser::DefaultMemDIOperand (SMLoc Loc) {
1619
1621
bool Parse32 = is32BitMode () || Code16GCC;
1620
- unsigned Basereg = is64BitMode () ? X86::RDI : (Parse32 ? X86::EDI : X86::DI);
1622
+ MCRegister Basereg =
1623
+ is64BitMode () ? X86::RDI : (Parse32 ? X86::EDI : X86::DI);
1621
1624
const MCExpr *Disp = MCConstantExpr::create (0 , getContext ());
1622
1625
return X86Operand::CreateMem (getPointerWidth (), /* SegReg=*/ 0 , Disp,
1623
1626
/* BaseReg=*/ Basereg, /* IndexReg=*/ 0 , /* Scale=*/ 1 ,
1624
1627
Loc, Loc, 0 );
1625
1628
}
1626
1629
1627
- bool X86AsmParser::IsSIReg (unsigned Reg) {
1628
- switch (Reg) {
1630
+ bool X86AsmParser::IsSIReg (MCRegister Reg) {
1631
+ switch (Reg. id () ) {
1629
1632
default : llvm_unreachable (" Only (R|E)SI and (R|E)DI are expected!" );
1630
1633
case X86::RSI:
1631
1634
case X86::ESI:
@@ -1638,8 +1641,7 @@ bool X86AsmParser::IsSIReg(unsigned Reg) {
1638
1641
}
1639
1642
}
1640
1643
1641
- unsigned X86AsmParser::GetSIDIForRegClass (unsigned RegClassID, unsigned Reg,
1642
- bool IsSIReg) {
1644
+ MCRegister X86AsmParser::GetSIDIForRegClass (unsigned RegClassID, bool IsSIReg) {
1643
1645
switch (RegClassID) {
1644
1646
default : llvm_unreachable (" Unexpected register class" );
1645
1647
case X86::GR64RegClassID:
@@ -1690,8 +1692,8 @@ bool X86AsmParser::VerifyAndAdjustOperands(OperandVector &OrigOperands,
1690
1692
// Return false and let a normal complaint about bogus operands happen
1691
1693
return false ;
1692
1694
1693
- unsigned OrigReg = OrigOp.Mem .BaseReg ;
1694
- unsigned FinalReg = FinalOp.Mem .BaseReg ;
1695
+ MCRegister OrigReg = OrigOp.Mem .BaseReg ;
1696
+ MCRegister FinalReg = FinalOp.Mem .BaseReg ;
1695
1697
1696
1698
// If we've already encounterd a register class, make sure all register
1697
1699
// bases are of the same register class
@@ -1713,7 +1715,7 @@ bool X86AsmParser::VerifyAndAdjustOperands(OperandVector &OrigOperands,
1713
1715
return false ;
1714
1716
1715
1717
bool IsSI = IsSIReg (FinalReg);
1716
- FinalReg = GetSIDIForRegClass (RegClassID, FinalReg, IsSI);
1718
+ FinalReg = GetSIDIForRegClass (RegClassID, IsSI);
1717
1719
1718
1720
if (FinalReg != OrigReg) {
1719
1721
std::string RegName = IsSI ? " ES:(R|E)SI" : " ES:(R|E)DI" ;
@@ -1753,13 +1755,11 @@ bool X86AsmParser::parseOperand(OperandVector &Operands, StringRef Name) {
1753
1755
return parseATTOperand (Operands);
1754
1756
}
1755
1757
1756
- bool X86AsmParser::CreateMemForMSInlineAsm (unsigned SegReg, const MCExpr *Disp,
1757
- unsigned BaseReg, unsigned IndexReg,
1758
- unsigned Scale, bool NonAbsMem,
1759
- SMLoc Start, SMLoc End,
1760
- unsigned Size, StringRef Identifier,
1761
- const InlineAsmIdentifierInfo &Info,
1762
- OperandVector &Operands) {
1758
+ bool X86AsmParser::CreateMemForMSInlineAsm (
1759
+ MCRegister SegReg, const MCExpr *Disp, MCRegister BaseReg,
1760
+ MCRegister IndexReg, unsigned Scale, bool NonAbsMem, SMLoc Start, SMLoc End,
1761
+ unsigned Size, StringRef Identifier, const InlineAsmIdentifierInfo &Info,
1762
+ OperandVector &Operands) {
1763
1763
// If we found a decl other than a VarDecl, then assume it is a FuncDecl or
1764
1764
// some other label reference.
1765
1765
if (Info.isKind (InlineAsmIdentifierInfo::IK_Label)) {
@@ -2651,10 +2651,10 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) {
2651
2651
}
2652
2652
2653
2653
StringRef ErrMsg;
2654
- unsigned BaseReg = SM.getBaseReg ();
2655
- unsigned IndexReg = SM.getIndexReg ();
2654
+ MCRegister BaseReg = SM.getBaseReg ();
2655
+ MCRegister IndexReg = SM.getIndexReg ();
2656
2656
if (IndexReg && BaseReg == X86::RIP)
2657
- BaseReg = 0 ;
2657
+ BaseReg = MCRegister () ;
2658
2658
unsigned Scale = SM.getScale ();
2659
2659
if (!PtrInOperand)
2660
2660
Size = SM.getElementSize () << 3 ;
@@ -2703,7 +2703,7 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) {
2703
2703
2704
2704
// When parsing x64 MS-style assembly, all non-absolute references to a named
2705
2705
// variable default to RIP-relative.
2706
- unsigned DefaultBaseReg = X86::NoRegister ;
2706
+ MCRegister DefaultBaseReg;
2707
2707
bool MaybeDirectBranchDest = true ;
2708
2708
2709
2709
if (Parser.isParsingMasm ()) {
@@ -2738,7 +2738,7 @@ bool X86AsmParser::parseIntelOperand(OperandVector &Operands, StringRef Name) {
2738
2738
MaybeDirectBranchDest = false ;
2739
2739
}
2740
2740
2741
- if ((BaseReg || IndexReg || RegNo || DefaultBaseReg != X86::NoRegister ))
2741
+ if ((BaseReg || IndexReg || RegNo || DefaultBaseReg))
2742
2742
Operands.push_back (X86Operand::CreateMem (
2743
2743
getPointerWidth (), RegNo, Disp, BaseReg, IndexReg, Scale, Start, End,
2744
2744
Size, DefaultBaseReg, /* SymName=*/ StringRef (), /* OpDecl=*/ nullptr ,
@@ -2782,7 +2782,7 @@ bool X86AsmParser::parseATTOperand(OperandVector &Operands) {
2782
2782
2783
2783
SMLoc Loc = Parser.getTok ().getLoc (), EndLoc;
2784
2784
const MCExpr *Expr = nullptr ;
2785
- unsigned Reg = 0 ;
2785
+ MCRegister Reg;
2786
2786
if (getLexer ().isNot (AsmToken::LParen)) {
2787
2787
// No '(' so this is either a displacement expression or a register.
2788
2788
if (Parser.parseExpression (Expr, EndLoc))
@@ -2954,7 +2954,7 @@ bool X86AsmParser::HandleAVX512Operand(OperandVector &Operands) {
2954
2954
2955
2955
// / ParseMemOperand: 'seg : disp(basereg, indexreg, scale)'. The '%ds:' prefix
2956
2956
// / has already been parsed if present. disp may be provided as well.
2957
- bool X86AsmParser::ParseMemOperand (unsigned SegReg, const MCExpr *Disp,
2957
+ bool X86AsmParser::ParseMemOperand (MCRegister SegReg, const MCExpr *Disp,
2958
2958
SMLoc StartLoc, SMLoc EndLoc,
2959
2959
OperandVector &Operands) {
2960
2960
MCAsmParser &Parser = getParser ();
@@ -3041,7 +3041,8 @@ bool X86AsmParser::ParseMemOperand(unsigned SegReg, const MCExpr *Disp,
3041
3041
3042
3042
// If we reached here, then eat the '(' and Process
3043
3043
// the rest of the memory operand.
3044
- unsigned BaseReg = 0 , IndexReg = 0 , Scale = 1 ;
3044
+ MCRegister BaseReg, IndexReg;
3045
+ unsigned Scale = 1 ;
3045
3046
SMLoc BaseLoc = getLexer ().getLoc ();
3046
3047
const MCExpr *E;
3047
3048
StringRef ErrMsg;
@@ -3888,14 +3889,14 @@ bool X86AsmParser::validateInstruction(MCInst &Inst, const OperandVector &Ops) {
3888
3889
uint64_t TSFlags = MII.get (Opcode).TSFlags ;
3889
3890
if (isVFCMADDCPH (Opcode) || isVFCMADDCSH (Opcode) || isVFMADDCPH (Opcode) ||
3890
3891
isVFMADDCSH (Opcode)) {
3891
- unsigned Dest = Inst.getOperand (0 ).getReg ();
3892
+ MCRegister Dest = Inst.getOperand (0 ).getReg ();
3892
3893
for (unsigned i = 2 ; i < Inst.getNumOperands (); i++)
3893
3894
if (Inst.getOperand (i).isReg () && Dest == Inst.getOperand (i).getReg ())
3894
3895
return Warning (Ops[0 ]->getStartLoc (), " Destination register should be "
3895
3896
" distinct from source registers" );
3896
3897
} else if (isVFCMULCPH (Opcode) || isVFCMULCSH (Opcode) || isVFMULCPH (Opcode) ||
3897
3898
isVFMULCSH (Opcode)) {
3898
- unsigned Dest = Inst.getOperand (0 ).getReg ();
3899
+ MCRegister Dest = Inst.getOperand (0 ).getReg ();
3899
3900
// The mask variants have different operand list. Scan from the third
3900
3901
// operand to avoid emitting incorrect warning.
3901
3902
// VFMULCPHZrr Dest, Src1, Src2
@@ -3909,8 +3910,9 @@ bool X86AsmParser::validateInstruction(MCInst &Inst, const OperandVector &Ops) {
3909
3910
} else if (isV4FMADDPS (Opcode) || isV4FMADDSS (Opcode) ||
3910
3911
isV4FNMADDPS (Opcode) || isV4FNMADDSS (Opcode) ||
3911
3912
isVP4DPWSSDS (Opcode) || isVP4DPWSSD (Opcode)) {
3912
- unsigned Src2 = Inst.getOperand (Inst.getNumOperands () -
3913
- X86::AddrNumOperands - 1 ).getReg ();
3913
+ MCRegister Src2 =
3914
+ Inst.getOperand (Inst.getNumOperands () - X86::AddrNumOperands - 1 )
3915
+ .getReg ();
3914
3916
unsigned Src2Enc = MRI->getEncodingValue (Src2);
3915
3917
if (Src2Enc % 4 != 0 ) {
3916
3918
StringRef RegName = X86IntelInstPrinter::getRegisterName (Src2);
@@ -3946,32 +3948,32 @@ bool X86AsmParser::validateInstruction(MCInst &Inst, const OperandVector &Ops) {
3946
3948
} else if (isTCMMIMFP16PS (Opcode) || isTCMMRLFP16PS (Opcode) ||
3947
3949
isTDPBF16PS (Opcode) || isTDPFP16PS (Opcode) || isTDPBSSD (Opcode) ||
3948
3950
isTDPBSUD (Opcode) || isTDPBUSD (Opcode) || isTDPBUUD (Opcode)) {
3949
- unsigned SrcDest = Inst.getOperand (0 ).getReg ();
3950
- unsigned Src1 = Inst.getOperand (2 ).getReg ();
3951
- unsigned Src2 = Inst.getOperand (3 ).getReg ();
3951
+ MCRegister SrcDest = Inst.getOperand (0 ).getReg ();
3952
+ MCRegister Src1 = Inst.getOperand (2 ).getReg ();
3953
+ MCRegister Src2 = Inst.getOperand (3 ).getReg ();
3952
3954
if (SrcDest == Src1 || SrcDest == Src2 || Src1 == Src2)
3953
3955
return Error (Ops[0 ]->getStartLoc (), " all tmm registers must be distinct" );
3954
3956
}
3955
3957
3956
3958
// Check that we aren't mixing AH/BH/CH/DH with REX prefix. We only need to
3957
3959
// check this with the legacy encoding, VEX/EVEX/XOP don't use REX.
3958
3960
if ((TSFlags & X86II::EncodingMask) == 0 ) {
3959
- MCPhysReg HReg = X86::NoRegister ;
3961
+ MCRegister HReg;
3960
3962
bool UsesRex = TSFlags & X86II::REX_W;
3961
3963
unsigned NumOps = Inst.getNumOperands ();
3962
3964
for (unsigned i = 0 ; i != NumOps; ++i) {
3963
3965
const MCOperand &MO = Inst.getOperand (i);
3964
3966
if (!MO.isReg ())
3965
3967
continue ;
3966
- unsigned Reg = MO.getReg ();
3968
+ MCRegister Reg = MO.getReg ();
3967
3969
if (Reg == X86::AH || Reg == X86::BH || Reg == X86::CH || Reg == X86::DH)
3968
3970
HReg = Reg;
3969
3971
if (X86II::isX86_64NonExtLowByteReg (Reg) ||
3970
3972
X86II::isX86_64ExtendedReg (Reg))
3971
3973
UsesRex = true ;
3972
3974
}
3973
3975
3974
- if (UsesRex && HReg != X86::NoRegister ) {
3976
+ if (UsesRex && HReg) {
3975
3977
StringRef RegName = X86IntelInstPrinter::getRegisterName (HReg);
3976
3978
return Error (Ops[0 ]->getStartLoc (),
3977
3979
" can't encode '" + RegName + " ' in an instruction requiring "
@@ -4022,7 +4024,7 @@ void X86AsmParser::applyLVICFIMitigation(MCInst &Inst, MCStreamer &Out) {
4022
4024
case X86::RETI64: {
4023
4025
MCInst ShlInst, FenceInst;
4024
4026
bool Parse32 = is32BitMode () || Code16GCC;
4025
- unsigned Basereg =
4027
+ MCRegister Basereg =
4026
4028
is64BitMode () ? X86::RSP : (Parse32 ? X86::ESP : X86::SP);
4027
4029
const MCExpr *Disp = MCConstantExpr::create (0 , getContext ());
4028
4030
auto ShlMemOp = X86Operand::CreateMem (getPointerWidth (), /* SegReg=*/ 0 , Disp,
0 commit comments