Skip to content

Commit 605420e

Browse files
committed
[MC] Use MCRegister and remove implicit casts from MCRegister to unsigned. NFC
1 parent 330ecf0 commit 605420e

File tree

9 files changed

+30
-30
lines changed

9 files changed

+30
-30
lines changed

llvm/include/llvm/MC/MCInstrAnalysis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class MCInstrAnalysis {
8585
if (isBranch(Inst) || isCall(Inst) || isReturn(Inst) ||
8686
isIndirectBranch(Inst))
8787
return true;
88-
unsigned PC = MCRI.getProgramCounter();
89-
if (PC == 0)
88+
MCRegister PC = MCRI.getProgramCounter();
89+
if (!PC)
9090
return false;
9191
return Info->get(Inst.getOpcode()).hasDefOfPhysReg(Inst, PC, MCRI);
9292
}

llvm/include/llvm/MC/MCInstrDesc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,13 @@ class MCInstrDesc {
584584

585585
/// Return true if this instruction implicitly
586586
/// uses the specified physical register.
587-
bool hasImplicitUseOfPhysReg(unsigned Reg) const {
587+
bool hasImplicitUseOfPhysReg(MCRegister Reg) const {
588588
return is_contained(implicit_uses(), Reg);
589589
}
590590

591591
/// Return true if this instruction implicitly
592592
/// defines the specified physical register.
593-
bool hasImplicitDefOfPhysReg(unsigned Reg,
593+
bool hasImplicitDefOfPhysReg(MCRegister Reg,
594594
const MCRegisterInfo *MRI = nullptr) const;
595595

596596
/// Return the scheduling class for this instruction. The
@@ -617,7 +617,7 @@ class MCInstrDesc {
617617

618618
/// Return true if this instruction defines the specified physical
619619
/// register, either explicitly or implicitly.
620-
bool hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
620+
bool hasDefOfPhysReg(const MCInst &MI, MCRegister Reg,
621621
const MCRegisterInfo &RI) const;
622622
};
623623

llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/MC/MCExpr.h"
1414
#include "llvm/MC/MCParser/MCAsmParserExtension.h"
1515
#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
16+
#include "llvm/MC/MCRegister.h"
1617
#include "llvm/MC/MCTargetOptions.h"
1718
#include "llvm/Support/SMLoc.h"
1819
#include "llvm/TargetParser/SubtargetFeature.h"
@@ -24,7 +25,6 @@ namespace llvm {
2425
class MCContext;
2526
class MCInst;
2627
class MCInstrInfo;
27-
class MCRegister;
2828
class MCStreamer;
2929
class MCSubtargetInfo;
3030
class MCSymbol;
@@ -483,7 +483,7 @@ class MCTargetAsmParser : public MCAsmParserExtension {
483483
bool MatchingInlineAsm) = 0;
484484

485485
/// Allows targets to let registers opt out of clobber lists.
486-
virtual bool omitRegisterFromClobberLists(unsigned RegNo) { return false; }
486+
virtual bool omitRegisterFromClobberLists(MCRegister Reg) { return false; }
487487

488488
/// Allow a target to add special case operand matching for things that
489489
/// tblgen doesn't/can't handle effectively. For example, literal

llvm/include/llvm/MC/MCRegisterInfo.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MCRegisterClass {
7171
/// contains - Return true if the specified register is included in this
7272
/// register class. This does not include virtual registers.
7373
bool contains(MCRegister Reg) const {
74-
unsigned RegNo = unsigned(Reg);
74+
unsigned RegNo = Reg.id();
7575
unsigned InByte = RegNo % 8;
7676
unsigned Byte = RegNo / 8;
7777
if (Byte >= RegSetSize)
@@ -188,7 +188,7 @@ class MCRegisterInfo {
188188
DenseMap<MCRegister, int> L2CVRegs; // LLVM to CV regs mapping
189189

190190
mutable std::vector<std::vector<MCPhysReg>> RegAliasesCache;
191-
ArrayRef<MCPhysReg> getCachedAliasesOf(MCPhysReg R) const;
191+
ArrayRef<MCPhysReg> getCachedAliasesOf(MCRegister R) const;
192192

193193
/// Iterator class that can traverse the differentially encoded values in
194194
/// DiffLists. Don't use this class directly, use one of the adaptors below.
@@ -358,16 +358,16 @@ class MCRegisterInfo {
358358
return PCReg;
359359
}
360360

361-
const MCRegisterDesc &operator[](MCRegister RegNo) const {
362-
assert(RegNo < NumRegs &&
361+
const MCRegisterDesc &operator[](MCRegister Reg) const {
362+
assert(Reg.id() < NumRegs &&
363363
"Attempting to access record for invalid register number!");
364-
return Desc[RegNo];
364+
return Desc[Reg.id()];
365365
}
366366

367367
/// Provide a get method, equivalent to [], but more useful with a
368368
/// pointer to this object.
369-
const MCRegisterDesc &get(MCRegister RegNo) const {
370-
return operator[](RegNo);
369+
const MCRegisterDesc &get(MCRegister Reg) const {
370+
return operator[](Reg);
371371
}
372372

373373
/// Returns the physical register number of sub-register "Index"
@@ -457,11 +457,11 @@ class MCRegisterInfo {
457457
return RegClassStrings + Class->NameIdx;
458458
}
459459

460-
/// Returns the encoding for RegNo
461-
uint16_t getEncodingValue(MCRegister RegNo) const {
462-
assert(RegNo < NumRegs &&
460+
/// Returns the encoding for Reg
461+
uint16_t getEncodingValue(MCRegister Reg) const {
462+
assert(Reg.id() < NumRegs &&
463463
"Attempting to get encoding for invalid register number!");
464-
return RegEncodingTable[RegNo];
464+
return RegEncodingTable[Reg.id()];
465465
}
466466

467467
/// Returns true if RegB is a sub-register of RegA.

llvm/lib/MC/MCInstrDesc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI,
2121
const MCRegisterInfo &RI) const {
2222
if (isBranch() || isCall() || isReturn() || isIndirectBranch())
2323
return true;
24-
unsigned PC = RI.getProgramCounter();
25-
if (PC == 0)
24+
MCRegister PC = RI.getProgramCounter();
25+
if (!PC)
2626
return false;
2727
if (hasDefOfPhysReg(MI, PC, RI))
2828
return true;
2929
return false;
3030
}
3131

32-
bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
32+
bool MCInstrDesc::hasImplicitDefOfPhysReg(MCRegister Reg,
3333
const MCRegisterInfo *MRI) const {
3434
for (MCPhysReg ImpDef : implicit_defs())
3535
if (ImpDef == Reg || (MRI && MRI->isSubRegister(Reg, ImpDef)))
3636
return true;
3737
return false;
3838
}
3939

40-
bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
40+
bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, MCRegister Reg,
4141
const MCRegisterInfo &RI) const {
4242
for (int i = 0, e = NumDefs; i != e; ++i)
4343
if (MI.getOperand(i).isReg() && MI.getOperand(i).getReg() &&

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6009,7 +6009,7 @@ bool AsmParser::parseMSInlineAsm(
60096009
SmallVector<bool, 4> OutputDeclsAddressOf;
60106010
SmallVector<std::string, 4> InputConstraints;
60116011
SmallVector<std::string, 4> OutputConstraints;
6012-
SmallVector<unsigned, 4> ClobberRegs;
6012+
SmallVector<MCRegister, 4> ClobberRegs;
60136013

60146014
SmallVector<AsmRewrite, 4> AsmStrRewrites;
60156015

llvm/lib/MC/MCParser/MasmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7349,7 +7349,7 @@ bool MasmParser::parseMSInlineAsm(
73497349
SmallVector<bool, 4> OutputDeclsAddressOf;
73507350
SmallVector<std::string, 4> InputConstraints;
73517351
SmallVector<std::string, 4> OutputConstraints;
7352-
SmallVector<unsigned, 4> ClobberRegs;
7352+
SmallVector<MCRegister, 4> ClobberRegs;
73537353

73547354
SmallVector<AsmRewrite, 4> AsmStrRewrites;
73557355

llvm/lib/MC/MCRegisterInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class MCRegAliasIteratorImpl {
8383
};
8484
} // namespace
8585

86-
ArrayRef<MCPhysReg> MCRegisterInfo::getCachedAliasesOf(MCPhysReg R) const {
87-
auto &Aliases = RegAliasesCache[R];
86+
ArrayRef<MCPhysReg> MCRegisterInfo::getCachedAliasesOf(MCRegister R) const {
87+
auto &Aliases = RegAliasesCache[R.id()];
8888
if (!Aliases.empty())
8989
return Aliases;
9090

@@ -99,7 +99,7 @@ ArrayRef<MCPhysReg> MCRegisterInfo::getCachedAliasesOf(MCPhysReg R) const {
9999
// Always put "self" at the end, so the iterator can choose to ignore it.
100100
// For registers without aliases, it also serves as a sentinel value that
101101
// tells us to not recompute the alias set.
102-
Aliases.push_back(R);
102+
Aliases.push_back(R.id());
103103
Aliases.shrink_to_fit();
104104
return Aliases;
105105
}

llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ class X86AsmParser : public MCTargetAsmParser {
12151215
uint64_t &ErrorInfo,
12161216
bool MatchingInlineAsm);
12171217

1218-
bool omitRegisterFromClobberLists(unsigned RegNo) override;
1218+
bool omitRegisterFromClobberLists(MCRegister Reg) override;
12191219

12201220
/// Parses AVX512 specific operand primitives: masked registers ({%k<NUM>}, {z})
12211221
/// and memory broadcasting ({1to<NUM>}) primitives, updating Operands vector if required.
@@ -4659,8 +4659,8 @@ bool X86AsmParser::matchAndEmitIntelInstruction(
46594659
MatchingInlineAsm);
46604660
}
46614661

4662-
bool X86AsmParser::omitRegisterFromClobberLists(unsigned RegNo) {
4663-
return X86MCRegisterClasses[X86::SEGMENT_REGRegClassID].contains(RegNo);
4662+
bool X86AsmParser::omitRegisterFromClobberLists(MCRegister Reg) {
4663+
return X86MCRegisterClasses[X86::SEGMENT_REGRegClassID].contains(Reg);
46644664
}
46654665

46664666
bool X86AsmParser::ParseDirective(AsmToken DirectiveID) {

0 commit comments

Comments
 (0)