Skip to content

Commit f77eda8

Browse files
committed
[NFC][TableGen] Use StringRef in X86RecognizableInstr
- Use `StringRef` instead of `std::string` in several functions. - Fix some variable names to conform to LLVM coding standard.
1 parent 86c5112 commit f77eda8

File tree

2 files changed

+44
-52
lines changed

2 files changed

+44
-52
lines changed

llvm/utils/TableGen/X86RecognizableInstr.cpp

+30-36
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ void RecognizableInstr::adjustOperandEncoding(OperandEncoding &encoding) {
440440
void RecognizableInstr::handleOperand(
441441
bool optional, unsigned &operandIndex, unsigned &physicalOperandIndex,
442442
unsigned numPhysicalOperands, const unsigned *operandMapping,
443-
OperandEncoding (*encodingFromString)(const std::string &,
444-
uint8_t OpSize)) {
443+
OperandEncoding (*encodingFromString)(StringRef, uint8_t OpSize)) {
445444
if (optional) {
446445
if (physicalOperandIndex >= numPhysicalOperands)
447446
return;
@@ -458,12 +457,12 @@ void RecognizableInstr::handleOperand(
458457

459458
StringRef typeName = (*Operands)[operandIndex].Rec->getName();
460459

461-
OperandEncoding encoding = encodingFromString(typeName.str(), OpSize);
460+
OperandEncoding encoding = encodingFromString(typeName, OpSize);
462461
// Adjust the encoding type for an operand based on the instruction.
463462
adjustOperandEncoding(encoding);
464463
Spec->operands[operandIndex].encoding = encoding;
465464
Spec->operands[operandIndex].type =
466-
typeFromString(typeName.str(), HasREX_W, OpSize);
465+
typeFromString(typeName, HasREX_W, OpSize);
467466

468467
++operandIndex;
469468
++physicalOperandIndex;
@@ -1020,11 +1019,11 @@ void RecognizableInstr::emitDecodePath(DisassemblerTables &tables) const {
10201019
#undef MAP
10211020
}
10221021

1023-
#define TYPE(str, type) \
1024-
if (s == str) \
1025-
return type;
1026-
OperandType RecognizableInstr::typeFromString(const std::string &s,
1027-
bool hasREX_W, uint8_t OpSize) {
1022+
#define TYPE(Expected, Type) \
1023+
if (Str == Expected) \
1024+
return Type;
1025+
OperandType RecognizableInstr::typeFromString(StringRef Str, bool hasREX_W,
1026+
uint8_t OpSize) {
10281027
if (hasREX_W) {
10291028
// For instructions with a REX_W prefix, a declared 32-bit register encoding
10301029
// is special.
@@ -1163,17 +1162,16 @@ OperandType RecognizableInstr::typeFromString(const std::string &s,
11631162
TYPE("BNDR", TYPE_BNDR)
11641163
TYPE("TILE", TYPE_TMM)
11651164
TYPE("TILEPair", TYPE_TMM_PAIR)
1166-
errs() << "Unhandled type string " << s << "\n";
1165+
errs() << "Unhandled type string " << Str << "\n";
11671166
llvm_unreachable("Unhandled type string");
11681167
}
11691168
#undef TYPE
11701169

1171-
#define ENCODING(str, encoding) \
1172-
if (s == str) \
1173-
return encoding;
1174-
OperandEncoding
1175-
RecognizableInstr::immediateEncodingFromString(const std::string &s,
1176-
uint8_t OpSize) {
1170+
#define ENCODING(Expected, Encoding) \
1171+
if (Str == Expected) \
1172+
return Encoding;
1173+
OperandEncoding RecognizableInstr::immediateEncodingFromString(StringRef Str,
1174+
uint8_t OpSize) {
11771175
if (OpSize != X86Local::OpSize16) {
11781176
// For instructions without an OpSize prefix, a declared 16-bit register or
11791177
// immediate encoding is special.
@@ -1208,13 +1206,12 @@ RecognizableInstr::immediateEncodingFromString(const std::string &s,
12081206
ENCODING("VR256X", ENCODING_IB)
12091207
ENCODING("VR512", ENCODING_IB)
12101208
ENCODING("TILE", ENCODING_IB)
1211-
errs() << "Unhandled immediate encoding " << s << "\n";
1209+
errs() << "Unhandled immediate encoding " << Str << "\n";
12121210
llvm_unreachable("Unhandled immediate encoding");
12131211
}
12141212

12151213
OperandEncoding
1216-
RecognizableInstr::rmRegisterEncodingFromString(const std::string &s,
1217-
uint8_t OpSize) {
1214+
RecognizableInstr::rmRegisterEncodingFromString(StringRef Str, uint8_t OpSize) {
12181215
ENCODING("RST", ENCODING_FP)
12191216
ENCODING("RSTi", ENCODING_FP)
12201217
ENCODING("GR16", ENCODING_RM)
@@ -1245,13 +1242,12 @@ RecognizableInstr::rmRegisterEncodingFromString(const std::string &s,
12451242
ENCODING("BNDR", ENCODING_RM)
12461243
ENCODING("TILE", ENCODING_RM)
12471244
ENCODING("TILEPair", ENCODING_RM)
1248-
errs() << "Unhandled R/M register encoding " << s << "\n";
1245+
errs() << "Unhandled R/M register encoding " << Str << "\n";
12491246
llvm_unreachable("Unhandled R/M register encoding");
12501247
}
12511248

12521249
OperandEncoding
1253-
RecognizableInstr::roRegisterEncodingFromString(const std::string &s,
1254-
uint8_t OpSize) {
1250+
RecognizableInstr::roRegisterEncodingFromString(StringRef Str, uint8_t OpSize) {
12551251
ENCODING("GR16", ENCODING_REG)
12561252
ENCODING("GR16orGR32orGR64", ENCODING_REG)
12571253
ENCODING("GR32", ENCODING_REG)
@@ -1295,12 +1291,12 @@ RecognizableInstr::roRegisterEncodingFromString(const std::string &s,
12951291
ENCODING("BNDR", ENCODING_REG)
12961292
ENCODING("TILE", ENCODING_REG)
12971293
ENCODING("TILEPair", ENCODING_REG)
1298-
errs() << "Unhandled reg/opcode register encoding " << s << "\n";
1294+
errs() << "Unhandled reg/opcode register encoding " << Str << "\n";
12991295
llvm_unreachable("Unhandled reg/opcode register encoding");
13001296
}
13011297

13021298
OperandEncoding
1303-
RecognizableInstr::vvvvRegisterEncodingFromString(const std::string &s,
1299+
RecognizableInstr::vvvvRegisterEncodingFromString(StringRef Str,
13041300
uint8_t OpSize) {
13051301
ENCODING("GR8", ENCODING_VVVV)
13061302
ENCODING("GR16", ENCODING_VVVV)
@@ -1326,12 +1322,12 @@ RecognizableInstr::vvvvRegisterEncodingFromString(const std::string &s,
13261322
ENCODING("VK64", ENCODING_VVVV)
13271323
ENCODING("TILE", ENCODING_VVVV)
13281324
ENCODING("TILEPair", ENCODING_VVVV)
1329-
errs() << "Unhandled VEX.vvvv register encoding " << s << "\n";
1325+
errs() << "Unhandled VEX.vvvv register encoding " << Str << "\n";
13301326
llvm_unreachable("Unhandled VEX.vvvv register encoding");
13311327
}
13321328

13331329
OperandEncoding
1334-
RecognizableInstr::writemaskRegisterEncodingFromString(const std::string &s,
1330+
RecognizableInstr::writemaskRegisterEncodingFromString(StringRef Str,
13351331
uint8_t OpSize) {
13361332
ENCODING("VK1WM", ENCODING_WRITEMASK)
13371333
ENCODING("VK2WM", ENCODING_WRITEMASK)
@@ -1340,13 +1336,12 @@ RecognizableInstr::writemaskRegisterEncodingFromString(const std::string &s,
13401336
ENCODING("VK16WM", ENCODING_WRITEMASK)
13411337
ENCODING("VK32WM", ENCODING_WRITEMASK)
13421338
ENCODING("VK64WM", ENCODING_WRITEMASK)
1343-
errs() << "Unhandled mask register encoding " << s << "\n";
1339+
errs() << "Unhandled mask register encoding " << Str << "\n";
13441340
llvm_unreachable("Unhandled mask register encoding");
13451341
}
13461342

1347-
OperandEncoding
1348-
RecognizableInstr::memoryEncodingFromString(const std::string &s,
1349-
uint8_t OpSize) {
1343+
OperandEncoding RecognizableInstr::memoryEncodingFromString(StringRef Str,
1344+
uint8_t OpSize) {
13501345
ENCODING("i16mem", ENCODING_RM)
13511346
ENCODING("i32mem", ENCODING_RM)
13521347
ENCODING("i64mem", ENCODING_RM)
@@ -1384,13 +1379,12 @@ RecognizableInstr::memoryEncodingFromString(const std::string &s,
13841379
ENCODING("vy64xmem", ENCODING_VSIB)
13851380
ENCODING("vz32mem", ENCODING_VSIB)
13861381
ENCODING("vz64mem", ENCODING_VSIB)
1387-
errs() << "Unhandled memory encoding " << s << "\n";
1382+
errs() << "Unhandled memory encoding " << Str << "\n";
13881383
llvm_unreachable("Unhandled memory encoding");
13891384
}
13901385

13911386
OperandEncoding
1392-
RecognizableInstr::relocationEncodingFromString(const std::string &s,
1393-
uint8_t OpSize) {
1387+
RecognizableInstr::relocationEncodingFromString(StringRef Str, uint8_t OpSize) {
13941388
if (OpSize != X86Local::OpSize16) {
13951389
// For instructions without an OpSize prefix, a declared 16-bit register or
13961390
// immediate encoding is special.
@@ -1434,19 +1428,19 @@ RecognizableInstr::relocationEncodingFromString(const std::string &s,
14341428
ENCODING("dstidx16", ENCODING_DI)
14351429
ENCODING("dstidx32", ENCODING_DI)
14361430
ENCODING("dstidx64", ENCODING_DI)
1437-
errs() << "Unhandled relocation encoding " << s << "\n";
1431+
errs() << "Unhandled relocation encoding " << Str << "\n";
14381432
llvm_unreachable("Unhandled relocation encoding");
14391433
}
14401434

14411435
OperandEncoding
1442-
RecognizableInstr::opcodeModifierEncodingFromString(const std::string &s,
1436+
RecognizableInstr::opcodeModifierEncodingFromString(StringRef Str,
14431437
uint8_t OpSize) {
14441438
ENCODING("GR32", ENCODING_Rv)
14451439
ENCODING("GR64", ENCODING_RO)
14461440
ENCODING("GR16", ENCODING_Rv)
14471441
ENCODING("GR8", ENCODING_RB)
14481442
ENCODING("ccode", ENCODING_CC)
1449-
errs() << "Unhandled opcode modifier encoding " << s << "\n";
1443+
errs() << "Unhandled opcode modifier encoding " << Str << "\n";
14501444
llvm_unreachable("Unhandled opcode modifier encoding");
14511445
}
14521446
#undef ENCODING

llvm/utils/TableGen/X86RecognizableInstr.h

+14-16
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class RecognizableInstr : public RecognizableInstrBase {
281281
/// If register size does not match OpSize, then
282282
/// register sizes keep their size.
283283
/// @return - The operand's type.
284-
static OperandType typeFromString(const std::string &s, bool hasREX_W,
284+
static OperandType typeFromString(StringRef Str, bool hasREX_W,
285285
uint8_t OpSize);
286286

287287
/// immediateEncodingFromString - Translates an immediate encoding from the
@@ -292,28 +292,28 @@ class RecognizableInstr : public RecognizableInstrBase {
292292
/// @param OpSize - Indicates whether this is an OpSize16 instruction.
293293
/// If it is not, then 16-bit immediate operands stay 16-bit.
294294
/// @return - The operand's encoding.
295-
static OperandEncoding immediateEncodingFromString(const std::string &s,
295+
static OperandEncoding immediateEncodingFromString(StringRef Str,
296296
uint8_t OpSize);
297297

298298
/// rmRegisterEncodingFromString - Like immediateEncodingFromString, but
299299
/// handles operands that are in the REG field of the ModR/M byte.
300-
static OperandEncoding rmRegisterEncodingFromString(const std::string &s,
300+
static OperandEncoding rmRegisterEncodingFromString(StringRef Str,
301301
uint8_t OpSize);
302302

303303
/// rmRegisterEncodingFromString - Like immediateEncodingFromString, but
304304
/// handles operands that are in the REG field of the ModR/M byte.
305-
static OperandEncoding roRegisterEncodingFromString(const std::string &s,
305+
static OperandEncoding roRegisterEncodingFromString(StringRef Str,
306306
uint8_t OpSize);
307-
static OperandEncoding memoryEncodingFromString(const std::string &s,
307+
static OperandEncoding memoryEncodingFromString(StringRef Str,
308308
uint8_t OpSize);
309-
static OperandEncoding relocationEncodingFromString(const std::string &s,
309+
static OperandEncoding relocationEncodingFromString(StringRef Str,
310310
uint8_t OpSize);
311-
static OperandEncoding opcodeModifierEncodingFromString(const std::string &s,
311+
static OperandEncoding opcodeModifierEncodingFromString(StringRef Str,
312312
uint8_t OpSize);
313-
static OperandEncoding vvvvRegisterEncodingFromString(const std::string &s,
313+
static OperandEncoding vvvvRegisterEncodingFromString(StringRef Str,
314314
uint8_t OpSize);
315-
static OperandEncoding
316-
writemaskRegisterEncodingFromString(const std::string &s, uint8_t OpSize);
315+
static OperandEncoding writemaskRegisterEncodingFromString(StringRef Str,
316+
uint8_t OpSize);
317317

318318
/// Adjust the encoding type for an operand based on the instruction.
319319
void adjustOperandEncoding(OperandEncoding &encoding);
@@ -336,12 +336,10 @@ class RecognizableInstr : public RecognizableInstrBase {
336336
/// @param operandMapping - The operand mapping, which has an entry for
337337
/// each operand that indicates whether it is a
338338
/// duplicate, and of what.
339-
void handleOperand(bool optional, unsigned &operandIndex,
340-
unsigned &physicalOperandIndex,
341-
unsigned numPhysicalOperands,
342-
const unsigned *operandMapping,
343-
OperandEncoding (*encodingFromString)(const std::string &,
344-
uint8_t OpSize));
339+
void handleOperand(
340+
bool optional, unsigned &operandIndex, unsigned &physicalOperandIndex,
341+
unsigned numPhysicalOperands, const unsigned *operandMapping,
342+
OperandEncoding (*encodingFromString)(StringRef s, uint8_t OpSize));
345343

346344
/// emitInstructionSpecifier - Loads the instruction specifier for the current
347345
/// instruction into a DisassemblerTables.

0 commit comments

Comments
 (0)