Skip to content

Commit eeb987f

Browse files
authored
[MC] Make generated MCInstPrinter::getMnemonic const (NFC) (#114682)
The value returned from the function depends only on the instruction opcode. As a drive-by, change the type of the argument to const-reference.
1 parent 89b948d commit eeb987f

File tree

34 files changed

+70
-39
lines changed

34 files changed

+70
-39
lines changed

bolt/lib/Core/HashUtilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ std::string hashBlockLoose(BinaryContext &BC, const BinaryBasicBlock &BB) {
145145
continue;
146146
}
147147

148-
std::string Mnemonic = BC.InstPrinter->getMnemonic(&Inst).first;
148+
std::string Mnemonic = BC.InstPrinter->getMnemonic(Inst).first;
149149
llvm::erase_if(Mnemonic, [](unsigned char ch) { return std::isspace(ch); });
150150
Opcodes.insert(Mnemonic);
151151
}

llvm/include/llvm/MC/MCInstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class MCInstPrinter {
131131

132132
/// Returns a pair containing the mnemonic for \p MI and the number of bits
133133
/// left for further processing by printInstruction (generated by tablegen).
134-
virtual std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) = 0;
134+
virtual std::pair<const char *, uint64_t>
135+
getMnemonic(const MCInst &MI) const = 0;
135136

136137
/// Print the specified MCInst to the specified raw_ostream.
137138
///

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class MCStreamer {
441441

442442
/// Returns the mnemonic for \p MI, if the streamer has access to a
443443
/// instruction printer and returns an empty string otherwise.
444-
virtual StringRef getMnemonic(MCInst &MI) { return ""; }
444+
virtual StringRef getMnemonic(const MCInst &MI) const { return ""; }
445445

446446
/// Emit a label for \p Symbol into the current section.
447447
///

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ class MCAsmStreamer final : public MCStreamer {
169169

170170
void emitGNUAttribute(unsigned Tag, unsigned Value) override;
171171

172-
StringRef getMnemonic(MCInst &MI) override {
173-
auto [Ptr, Bits] = InstPrinter->getMnemonic(&MI);
172+
StringRef getMnemonic(const MCInst &MI) const override {
173+
auto [Ptr, Bits] = InstPrinter->getMnemonic(MI);
174174
assert((Bits != 0 || Ptr == nullptr) &&
175175
"Invalid char pointer for instruction with no mnemonic");
176176
return Ptr;

llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class AArch64InstPrinter : public MCInstPrinter {
3333
void printRegName(raw_ostream &OS, MCRegister Reg, unsigned AltIdx);
3434

3535
// Autogenerated by tblgen.
36-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
36+
std::pair<const char *, uint64_t>
37+
getMnemonic(const MCInst &MI) const override;
3738
virtual void printInstruction(const MCInst *MI, uint64_t Address,
3839
const MCSubtargetInfo &STI, raw_ostream &O);
3940
virtual bool printAliasInstr(const MCInst *MI, uint64_t Address,
@@ -248,7 +249,8 @@ class AArch64AppleInstPrinter : public AArch64InstPrinter {
248249
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
249250
const MCSubtargetInfo &STI, raw_ostream &O) override;
250251

251-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
252+
std::pair<const char *, uint64_t>
253+
getMnemonic(const MCInst &MI) const override;
252254
void printInstruction(const MCInst *MI, uint64_t Address,
253255
const MCSubtargetInfo &STI, raw_ostream &O) override;
254256
bool printAliasInstr(const MCInst *MI, uint64_t Address,

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class AMDGPUInstPrinter : public MCInstPrinter {
2424
: MCInstPrinter(MAI, MII, MRI) {}
2525

2626
// Autogenerated by tblgen
27-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
27+
std::pair<const char *, uint64_t>
28+
getMnemonic(const MCInst &MI) const override;
2829
void printInstruction(const MCInst *MI, uint64_t Address,
2930
const MCSubtargetInfo &STI, raw_ostream &O);
3031
static const char *getRegisterName(MCRegister Reg);

llvm/lib/Target/AMDGPU/MCTargetDesc/R600InstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class R600InstPrinter : public MCInstPrinter {
2121

2222
void printInst(const MCInst *MI, uint64_t Address, StringRef Annot,
2323
const MCSubtargetInfo &STI, raw_ostream &O) override;
24-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
24+
std::pair<const char *, uint64_t>
25+
getMnemonic(const MCInst &MI) const override;
2526
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
2627
static const char *getRegisterName(MCRegister Reg);
2728

llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class ARCInstPrinter : public MCInstPrinter {
2626
: MCInstPrinter(MAI, MII, MRI) {}
2727

2828
// Autogenerated by tblgen.
29-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
29+
std::pair<const char *, uint64_t>
30+
getMnemonic(const MCInst &MI) const override;
3031
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
3132
static const char *getRegisterName(MCRegister Reg);
3233

llvm/lib/Target/ARM/MCTargetDesc/ARMInstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class ARMInstPrinter : public MCInstPrinter {
3030
void printRegName(raw_ostream &OS, MCRegister Reg) override;
3131

3232
// Autogenerated by tblgen.
33-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
33+
std::pair<const char *, uint64_t>
34+
getMnemonic(const MCInst &MI) const override;
3435
void printInstruction(const MCInst *MI, uint64_t Address,
3536
const MCSubtargetInfo &STI, raw_ostream &O);
3637
virtual bool printAliasInstr(const MCInst *MI, uint64_t Address,

llvm/lib/Target/AVR/MCTargetDesc/AVRInstPrinter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class AVRInstPrinter : public MCInstPrinter {
4848
}
4949

5050
// Autogenerated by TableGen.
51-
std::pair<const char *, uint64_t> getMnemonic(const MCInst *MI) override;
51+
std::pair<const char *, uint64_t>
52+
getMnemonic(const MCInst &MI) const override;
5253
void printInstruction(const MCInst *MI, uint64_t Address, raw_ostream &O);
5354
bool printAliasInstr(const MCInst *MI, uint64_t Address, raw_ostream &O);
5455
void printCustomAliasOperand(const MCInst *MI, uint64_t Address,

0 commit comments

Comments
 (0)