Skip to content

Commit 3fe398d

Browse files
jayfoadmahesh-attarde
authored andcommitted
[TableGen] Use MapVector in InstrInfoEmitter::emitOperandNameMappings (llvm#150630)
This changes the order of names/numbers in the OpName enum, but that should not cause any change in behaviour.
1 parent e82537c commit 3fe398d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ void InstrInfoEmitter::emitOperandNameMappings(
248248
/// scan of the instructions below.
249249

250250
// Map of operand names to their ID.
251-
std::map<StringRef, unsigned> OperandNameToID;
252-
// Map from operand name enum value -> ID.
253-
std::vector<unsigned> OperandEnumToID;
251+
MapVector<StringRef, unsigned> OperandNameToID;
254252

255253
/// The keys of this map is a map which have OpName ID values as their keys
256254
/// and instruction operand indices as their values. The values of this map
@@ -278,16 +276,13 @@ void InstrInfoEmitter::emitOperandNameMappings(
278276
}
279277

280278
const size_t NumOperandNames = OperandNameToID.size();
281-
OperandEnumToID.reserve(NumOperandNames);
282-
for (const auto &Op : OperandNameToID)
283-
OperandEnumToID.push_back(Op.second);
284279

285280
OS << "#ifdef GET_INSTRINFO_OPERAND_ENUM\n";
286281
OS << "#undef GET_INSTRINFO_OPERAND_ENUM\n";
287282
OS << "namespace llvm::" << Namespace << " {\n";
288283
OS << "enum class OpName {\n";
289-
for (const auto &[I, Op] : enumerate(OperandNameToID))
290-
OS << " " << Op.first << " = " << I << ",\n";
284+
for (const auto &[Op, I] : OperandNameToID)
285+
OS << " " << Op << " = " << I << ",\n";
291286
OS << " NUM_OPERAND_NAMES = " << NumOperandNames << ",\n";
292287
OS << "}; // enum class OpName\n\n";
293288
OS << "LLVM_READONLY\n";
@@ -312,7 +307,7 @@ void InstrInfoEmitter::emitOperandNameMappings(
312307

313308
// Emit a row of the OperandMap table.
314309
OS << " {";
315-
for (unsigned ID : OperandEnumToID) {
310+
for (unsigned ID = 0; ID < NumOperandNames; ++ID) {
316311
auto Iter = OpList.find(ID);
317312
OS << (Iter != OpList.end() ? (int)Iter->second : -1) << ", ";
318313
}

0 commit comments

Comments
 (0)