diff --git a/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp --- a/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp +++ b/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp @@ -59,6 +59,14 @@ "]->getOperand(" + to_string(OM.getOpIdx()) + ")"); } +template auto keys(Container &&C) { + return map_range(C, [](auto &Entry) -> auto & { return Entry.first; }); +} + +template auto values(Container &&C) { + return map_range(C, [](auto &Entry) -> auto & { return Entry.second; }); +} + //===- MatchData Handling -------------------------------------------------===// /// Represents MatchData defined by the match stage and required by the apply @@ -785,7 +793,7 @@ bool CombineRuleBuilder::buildOperandsTable() { // Walk each instruction pattern - for (auto &[_, P] : MatchPats) { + for (auto &P : values(MatchPats)) { auto *IP = dyn_cast(P.get()); if (!IP) continue; @@ -806,7 +814,7 @@ } } - for (auto &[_, P] : ApplyPats) { + for (auto &P : values(ApplyPats)) { auto *IP = dyn_cast(P.get()); if (!IP) continue; @@ -1019,7 +1027,7 @@ return false; // Emit remaining patterns - for (auto &[_, Pat] : MatchPats) { + for (auto &Pat : values(MatchPats)) { if (SeenPats.contains(Pat.get())) continue; @@ -1058,7 +1066,7 @@ IM.addPredicate(CGI); // Emit remaining patterns. - for (auto &[_, Pat] : MatchPats) { + for (auto &Pat : values(MatchPats)) { if (Pat.get() == &AOP) continue; @@ -1087,7 +1095,7 @@ } bool CombineRuleBuilder::emitApplyPatterns(CodeExpansions &CE, RuleMatcher &M) { - for (auto &[_, Pat] : ApplyPats) { + for (auto &Pat : values(ApplyPats)) { switch (Pat->getKind()) { case Pattern::K_AnyOpcode: case Pattern::K_Inst: @@ -1371,7 +1379,7 @@ // (GICXXPred_Invalid + 1). unsigned ExpectedID = 0; (void)ExpectedID; - for (const auto &[ID, _] : AllCombineRules) { + for (const auto &ID : keys(AllCombineRules)) { assert(ExpectedID++ == ID && "combine rules are not ordered!"); OS << " " << getIsEnabledPredicateEnumName(ID) << EnumeratorSeparator; EnumeratorSeparator = ",\n";