[llvm] f6be081 - [llvm-profdata] Fix llvm-profdata help and make sure it remains in sync
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 20 01:25:49 PDT 2023
Author: serge-sans-paille
Date: 2023-06-20T10:25:29+02:00
New Revision: f6be0814c3a5d1b957164be0af16018dc2b9232d
URL: https://github.com/llvm/llvm-project/commit/f6be0814c3a5d1b957164be0af16018dc2b9232d
DIFF: https://github.com/llvm/llvm-project/commit/f6be0814c3a5d1b957164be0af16018dc2b9232d.diff
LOG: [llvm-profdata] Fix llvm-profdata help and make sure it remains in sync
This makes the new `order` subcommand part of the help.
As a side effect, also make llvm::map_range compatible with plain
arrays.
Differential Revision: https://reviews.llvm.org/D153303
Added:
Modified:
llvm/include/llvm/ADT/STLExtras.h
llvm/tools/llvm-profdata/llvm-profdata.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 6475ac7976072..6f4c06bf44330 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -459,7 +459,8 @@ inline mapped_iterator<ItTy, FuncTy> map_iterator(ItTy I, FuncTy F) {
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
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index 7c282e346747e..da10ddcc58c64 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -3084,6 +3084,16 @@ static int order_main(int argc, const char *argv[]) {
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 @@ int llvm_profdata_main(int argc, char **argvNonConst,
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 @@ int llvm_profdata_main(int argc, char **argvNonConst,
<< "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 @@ int llvm_profdata_main(int argc, char **argvNonConst,
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;
}
More information about the llvm-commits
mailing list