Skip to content

Commit a2fee80

Browse files
z30050559superZWT123
authored andcommitted
[TableGen] Use set to collect HwModes for DecoderNamespace
Use std::set to collect HwModes for DecoderNamespace, simplifying code logic.
1 parent 5479f2d commit a2fee80

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ struct EncodingIDAndOpcode {
145145
};
146146

147147
using EncodingIDsVec = std::vector<EncodingIDAndOpcode>;
148-
using NamespacesHwModesMap =
149-
std::map<std::string, std::map<StringRef, unsigned>>;
148+
using NamespacesHwModesMap = std::map<std::string, std::set<StringRef>>;
150149

151150
raw_ostream &operator<<(raw_ostream &OS, const EncodingAndInst &Value) {
152151
if (Value.EncodingDef != Value.Inst->TheDef)
@@ -2446,10 +2445,10 @@ static void collectHwModesReferencedForEncodings(
24462445
std::string DecoderNamespace =
24472446
std::string(P.second->getValueAsString("DecoderNamespace"));
24482447
if (P.first == DefaultMode) {
2449-
NamespacesWithHwModes[DecoderNamespace][""] = 1;
2448+
NamespacesWithHwModes[DecoderNamespace].insert("");
24502449
} else {
2451-
NamespacesWithHwModes[DecoderNamespace][HWM.getMode(P.first).Name] =
2452-
1;
2450+
NamespacesWithHwModes[DecoderNamespace].insert(
2451+
HWM.getMode(P.first).Name);
24532452
}
24542453
BV.set(P.first);
24552454
}
@@ -2478,16 +2477,14 @@ handleHwModesUnrelatedEncodings(const CodeGenInstruction *Instr,
24782477
case SUPPRESSION_LEVEL1: {
24792478
std::string DecoderNamespace =
24802479
std::string(InstDef->getValueAsString("DecoderNamespace"));
2481-
for (StringRef HwModeName : HwModeNames) {
2482-
if (NamespacesWithHwModes.count(DecoderNamespace) > 0) {
2483-
if (NamespacesWithHwModes[DecoderNamespace].count(HwModeName) > 0)
2484-
GlobalEncodings.emplace_back(InstDef, Instr, HwModeName);
2485-
} else {
2486-
// Only emit the encoding once, as it's DecoderNamespace doesn't
2487-
// contain any HwModes.
2488-
GlobalEncodings.emplace_back(InstDef, Instr, "");
2489-
break;
2490-
}
2480+
auto It = NamespacesWithHwModes.find(DecoderNamespace);
2481+
if (It != NamespacesWithHwModes.end()) {
2482+
for (StringRef HwModeName : It->second)
2483+
GlobalEncodings.emplace_back(InstDef, Instr, HwModeName);
2484+
} else {
2485+
// Only emit the encoding once, as it's DecoderNamespace doesn't
2486+
// contain any HwModes.
2487+
GlobalEncodings.emplace_back(InstDef, Instr, "");
24912488
}
24922489
break;
24932490
}

0 commit comments

Comments
 (0)