diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -459,7 +459,8 @@ template auto map_range(ContainerTy &&C, FuncTy F) { - return make_range(map_iterator(C.begin(), F), map_iterator(C.end(), F)); + return make_range(map_iterator(std::begin(C), F), + map_iterator(std::end(C), F)); } /// A base type of mapped iterator, that is useful for building derived diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -3084,6 +3084,16 @@ return 0; } +typedef int (*llvm_profdata_subcommand)(int, const char *[]); + +static std::tuple + llvm_profdata_subcommands[] = { + {"merge", merge_main}, + {"show", show_main}, + {"order", order_main}, + {"overlap", overlap_main}, +}; + int llvm_profdata_main(int argc, char **argvNonConst, const llvm::ToolContext &) { const char **argv = const_cast(argvNonConst); @@ -3091,16 +3101,11 @@ StringRef ProgName(sys::path::filename(argv[0])); if (argc > 1) { - int (*func)(int, const char *[]) = nullptr; - if (strcmp(argv[1], "merge") == 0) - func = merge_main; - else if (strcmp(argv[1], "show") == 0) - func = show_main; - else if (strcmp(argv[1], "overlap") == 0) - func = overlap_main; - else if (strcmp(argv[1], "order") == 0) - func = order_main; + llvm_profdata_subcommand func = nullptr; + for (auto [subcmd_name, subcmd_action] : llvm_profdata_subcommands) + if (subcmd_name == argv[1]) + func = subcmd_action; if (func) { std::string Invocation(ProgName.str() + " " + argv[1]); @@ -3115,7 +3120,11 @@ << "USAGE: " << ProgName << " [args...]\n" << "USAGE: " << ProgName << " -help\n\n" << "See each individual command --help for more details.\n" - << "Available commands: merge, show, overlap\n"; + << "Available commands: " + << join(map_range(llvm_profdata_subcommands, + [](auto const &KV) { return std::get<0>(KV); }), + ", ") + << "\n"; return 0; }