Skip to content

Commit

Permalink
[TableGen] Optimize SizeToOperandName iteration. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Sep 27, 2023
1 parent 126f037 commit 0bc68ca
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Types.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -474,15 +475,15 @@ void InstrInfoEmitter::emitOperandTypeMappings(
OS << "LLVM_READONLY\n";
OS << "static int getMemOperandSize(int OpType) {\n";
OS << " switch (OpType) {\n";
std::map<int, std::vector<StringRef>> SizeToOperandName;
std::map<int, SmallVector<StringRef, 0>> SizeToOperandName;
for (const Record *Op : Operands) {
if (!Op->isSubClassOf("X86MemOperand"))
continue;
if (int Size = Op->getValueAsInt("Size"))
SizeToOperandName[Size].push_back(Op->getName());
}
OS << " default: return 0;\n";
for (auto KV : SizeToOperandName) {
for (const auto &KV : SizeToOperandName) {
for (const StringRef &OperandName : KV.second)
OS << " case OpTypes::" << OperandName << ":\n";
OS << " return " << KV.first << ";\n\n";
Expand Down

0 comments on commit 0bc68ca

Please sign in to comment.