Skip to content

Commit 6810b60

Browse files
authored
Clarify in tools help message that -O == -Os. (#4516)
Introduce static consts with PassOptions Defaults. Add assertion to verify that the default options are the Os options. Also update the text in relevant tests.
1 parent a2552f1 commit 6810b60

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

src/pass.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,13 @@ struct PassOptions {
166166
// passes.
167167
std::map<std::string, std::string> arguments;
168168

169+
// -Os is our default
170+
static constexpr const int DEFAULT_OPTIMIZE_LEVEL = 2;
171+
static constexpr const int DEFAULT_SHRINK_LEVEL = 1;
172+
169173
void setDefaultOptimizationOptions() {
170-
// -Os is our default
171-
optimizeLevel = 2;
172-
shrinkLevel = 1;
174+
optimizeLevel = DEFAULT_OPTIMIZE_LEVEL;
175+
shrinkLevel = DEFAULT_SHRINK_LEVEL;
173176
}
174177

175178
static PassOptions getWithDefaultOptimizationOptions() {

src/tools/optimization-options.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace wasm {
2727

2828
struct OptimizationOptions : public ToolOptions {
2929
static constexpr const char* DEFAULT_OPT_PASSES = "O";
30+
static constexpr const int OS_OPTIMIZE_LEVEL = 2;
31+
static constexpr const int OS_SHRINK_LEVEL = 1;
3032

3133
std::vector<std::string> passes;
3234

@@ -37,15 +39,20 @@ struct OptimizationOptions : public ToolOptions {
3739
const std::string& description)
3840
: ToolOptions(command, description) {
3941
(*this)
40-
.add("",
41-
"-O",
42-
"execute default optimization passes",
43-
OptimizationOptionsCategory,
44-
Options::Arguments::Zero,
45-
[this](Options*, const std::string&) {
46-
passOptions.setDefaultOptimizationOptions();
47-
passes.push_back(DEFAULT_OPT_PASSES);
48-
})
42+
.add(
43+
"",
44+
"-O",
45+
"execute default optimization passes (equivalent to -Os)",
46+
OptimizationOptionsCategory,
47+
Options::Arguments::Zero,
48+
[this](Options*, const std::string&) {
49+
passOptions.setDefaultOptimizationOptions();
50+
static_assert(
51+
PassOptions::DEFAULT_OPTIMIZE_LEVEL == OS_OPTIMIZE_LEVEL &&
52+
PassOptions::DEFAULT_SHRINK_LEVEL == OS_SHRINK_LEVEL,
53+
"Help text states that -O is equivalent to -Os but now it isn't.");
54+
passes.push_back(DEFAULT_OPT_PASSES);
55+
})
4956
.add("",
5057
"-O0",
5158
"execute no optimization passes",
@@ -106,8 +113,8 @@ struct OptimizationOptions : public ToolOptions {
106113
OptimizationOptionsCategory,
107114
Options::Arguments::Zero,
108115
[this](Options*, const std::string&) {
109-
passOptions.optimizeLevel = 2;
110-
passOptions.shrinkLevel = 1;
116+
passOptions.optimizeLevel = OS_OPTIMIZE_LEVEL;
117+
passOptions.shrinkLevel = OS_SHRINK_LEVEL;
111118
passes.push_back(DEFAULT_OPT_PASSES);
112119
})
113120
.add("",

test/lit/help/wasm-opt.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@
422422
;; CHECK-NEXT: ---------------------
423423
;; CHECK-NEXT:
424424
;; CHECK-NEXT: -O execute default optimization
425-
;; CHECK-NEXT: passes
425+
;; CHECK-NEXT: passes (equivalent to -Os)
426426
;; CHECK-NEXT:
427427
;; CHECK-NEXT: -O0 execute no optimization passes
428428
;; CHECK-NEXT:

test/lit/help/wasm2js.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
;; CHECK-NEXT: ---------------------
385385
;; CHECK-NEXT:
386386
;; CHECK-NEXT: -O execute default optimization
387-
;; CHECK-NEXT: passes
387+
;; CHECK-NEXT: passes (equivalent to -Os)
388388
;; CHECK-NEXT:
389389
;; CHECK-NEXT: -O0 execute no optimization passes
390390
;; CHECK-NEXT:

0 commit comments

Comments
 (0)