[PATCH] D153303: [llvm-profdata] Fix llvm-profdata help and make sure it remains in sync
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 01:25:54 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf6be0814c3a5: [llvm-profdata] Fix llvm-profdata help and make sure it remains in sync (authored by serge-sans-paille).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153303/new/
https://reviews.llvm.org/D153303
Files:
llvm/include/llvm/ADT/STLExtras.h
llvm/tools/llvm-profdata/llvm-profdata.cpp
Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -3084,6 +3084,16 @@
return 0;
}
+typedef int (*llvm_profdata_subcommand)(int, const char *[]);
+
+static std::tuple<StringRef, llvm_profdata_subcommand>
+ 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<const char **>(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 << " <command> [args...]\n"
<< "USAGE: " << ProgName << " <command> -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;
}
@@ -3131,6 +3140,10 @@
else
errs() << ProgName << ": Unknown command!\n";
- errs() << "USAGE: " << ProgName << " <merge|show|overlap|order> [args...]\n";
+ errs() << "USAGE: " << ProgName << " <"
+ << join(map_range(llvm_profdata_subcommands,
+ [](auto const &KV) { return std::get<0>(KV); }),
+ "|")
+ << "> [args...]\n";
return 1;
}
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -459,7 +459,8 @@
template <class ContainerTy, class FuncTy>
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153303.532818.patch
Type: text/x-patch
Size: 2929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/a682db07/attachment.bin>
More information about the llvm-commits
mailing list