Skip to content

Commit ae94994

Browse files
authored
[EH] Rename option/pass names for new EH (exnref) (#6592)
We settled on the name `WASM_EXNREF` for the new setting in Emscripten for the name for the new EH option. https://github.com/emscripten-core/emscripten/blob/2bc5e3156f07e603bc4f3580cf84c038ea99b2df/src/settings.js#L782-L786 "New EH" sounds vague and I'm not sure if "experimental" is really necessary anyway, given that the potential users of this option is aware that this is a new spec that has been adopted recently. To make the option names consistent, this renames `--translate-to-eh` (the option that only runs the translator) to `--translate-to-exnref`, and `--experimental-new-eh` to `--emit-exnref` (the option that runs the translator at the end of the whole pipeline), and renames the pass and variable names in the code accordingly as well. In case anyone is using the old option names (and also to make the Chromium CI pass), this does not delete the old options.
1 parent b70d8df commit ae94994

File tree

9 files changed

+68
-53
lines changed

9 files changed

+68
-53
lines changed

src/passes/TranslateEH.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
//
18-
// TranslateToNewEH translates the old Phase 3 EH instructions, which include
18+
// TranslateToExnref translates the old Phase 3 EH instructions, which include
1919
// try, catch, catch_all, delegate, and rethrow, into the new EH instructions,
2020
// which include try_table (with catch / catch_ref / catch_all / catch_all_ref)
2121
// and throw_ref, passed at the Oct 2023 CG meeting. This translator can be used
@@ -39,7 +39,7 @@ namespace {
3939
// Translates the old EH instructions (try / catch / catch_all / delegate /
4040
// rethrow) into the new ones (try_table (+ catch / catch_ref / catch_all /
4141
// catch_all_ref) / throw_ref).
42-
struct TranslateToNewEH : public WalkerPass<PostWalker<TranslateToNewEH>> {
42+
struct TranslateToExnref : public WalkerPass<PostWalker<TranslateToExnref>> {
4343
bool isFunctionParallel() override { return true; }
4444

4545
// Scans and records which try labels are targeted by delegates and rethrows.
@@ -195,7 +195,7 @@ struct TranslateToNewEH : public WalkerPass<PostWalker<TranslateToNewEH>> {
195195
std::unordered_map<Type, Index> typeToScratchLocal;
196196

197197
std::unique_ptr<Pass> create() override {
198-
return std::make_unique<TranslateToNewEH>();
198+
return std::make_unique<TranslateToExnref>();
199199
}
200200

201201
// Get a scratch local for a given type. These locals are used to contain
@@ -814,6 +814,6 @@ struct TranslateToNewEH : public WalkerPass<PostWalker<TranslateToNewEH>> {
814814

815815
} // namespace
816816

817-
Pass* createTranslateToNewEHPass() { return new TranslateToNewEH(); }
817+
Pass* createTranslateToExnrefPass() { return new TranslateToExnref(); }
818818

819819
} // namespace wasm

src/passes/pass.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,11 @@ void PassRegistry::registerPasses() {
501501
"strip the wasm target features section",
502502
createStripTargetFeaturesPass);
503503
registerPass("translate-to-new-eh",
504-
"translate old EH instructions to new ones",
505-
createTranslateToNewEHPass);
504+
"deprecated; same as translate-to-exnref",
505+
createTranslateToExnrefPass);
506+
registerPass("translate-to-exnref",
507+
"translate old Phase 3 EH instructions to new ones with exnref",
508+
createTranslateToExnrefPass);
506509
registerPass("trap-mode-clamp",
507510
"replace trapping operations with clamping semantics",
508511
createTrapModeClamp);

src/passes/passes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Pass* createStripEHPass();
166166
Pass* createStubUnsupportedJSOpsPass();
167167
Pass* createSSAifyPass();
168168
Pass* createSSAifyNoMergePass();
169-
Pass* createTranslateToNewEHPass();
169+
Pass* createTranslateToExnrefPass();
170170
Pass* createTrapModeClamp();
171171
Pass* createTrapModeJS();
172172
Pass* createTupleOptimizationPass();

src/tools/wasm-opt.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int main(int argc, const char* argv[]) {
9191
std::string inputSourceMapFilename;
9292
std::string outputSourceMapFilename;
9393
std::string outputSourceMapUrl;
94-
bool experimentalNewEH = false;
94+
bool emitExnref = false;
9595

9696
const std::string WasmOptOption = "wasm-opt options";
9797

@@ -240,16 +240,20 @@ int main(int argc, const char* argv[]) {
240240
o->extra["infile"] = argument;
241241
})
242242
.add("--experimental-new-eh",
243+
"",
244+
"Deprecated; same as --emit-exnref",
245+
WasmOptOption,
246+
Options::Arguments::Zero,
247+
[&emitExnref](Options*, const std::string&) { emitExnref = true; })
248+
.add("--emit-exnref",
243249
"",
244250
"After running all requested transformations / optimizations, "
245251
"translate the instruction to use the new EH instructions at the end. "
246252
"Depending on the optimization level specified, this may do some more "
247253
"post-translation optimizations.",
248254
WasmOptOption,
249255
Options::Arguments::Zero,
250-
[&experimentalNewEH](Options*, const std::string&) {
251-
experimentalNewEH = true;
252-
});
256+
[&emitExnref](Options*, const std::string&) { emitExnref = true; });
253257
options.parse(argc, argv);
254258

255259
Module wasm;
@@ -356,11 +360,10 @@ int main(int argc, const char* argv[]) {
356360
std::cout << "[extra-fuzz-command first output:]\n" << firstOutput << '\n';
357361
}
358362

359-
bool translateToNewEH =
360-
wasm.features.hasExceptionHandling() && experimentalNewEH;
363+
bool translateToExnref = wasm.features.hasExceptionHandling() && emitExnref;
361364

362365
if (!options.runningPasses()) {
363-
if (!options.quiet && !translateToNewEH) {
366+
if (!options.quiet && !translateToExnref) {
364367
std::cerr << "warning: no passes specified, not doing any work\n";
365368
}
366369
} else {
@@ -397,12 +400,10 @@ int main(int argc, const char* argv[]) {
397400
}
398401
}
399402

400-
if (translateToNewEH) {
403+
if (translateToExnref) {
401404
BYN_TRACE("translating to new EH instructions...\n");
402405
PassRunner runner(&wasm, options.passOptions);
403-
runner.add("translate-to-new-eh");
404-
// Perform Stack IR optimizations here, at the very end of the
405-
// optimization pipeline.
406+
runner.add("translate-to-exnref");
406407
runner.run();
407408
if (options.passOptions.validate) {
408409
bool valid = WasmValidator().validate(wasm, options.passOptions);

test/lit/help/wasm-opt.test

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
;; CHECK-NEXT: --new-wat-parser Use the experimental new WAT
8080
;; CHECK-NEXT: parser
8181
;; CHECK-NEXT:
82-
;; CHECK-NEXT: --experimental-new-eh After running all requested
82+
;; CHECK-NEXT: --experimental-new-eh Deprecated; same as
83+
;; CHECK-NEXT: --emit-exnref
84+
;; CHECK-NEXT:
85+
;; CHECK-NEXT: --emit-exnref After running all requested
8386
;; CHECK-NEXT: transformations / optimizations,
8487
;; CHECK-NEXT: translate the instruction to use
8588
;; CHECK-NEXT: the new EH instructions at the
@@ -502,8 +505,12 @@
502505
;; CHECK-NEXT:
503506
;; CHECK-NEXT: --symbolmap (alias for print-function-map)
504507
;; CHECK-NEXT:
505-
;; CHECK-NEXT: --translate-to-new-eh translate old EH instructions to
506-
;; CHECK-NEXT: new ones
508+
;; CHECK-NEXT: --translate-to-exnref translate old Phase 3 EH
509+
;; CHECK-NEXT: instructions to new ones with
510+
;; CHECK-NEXT: exnref
511+
;; CHECK-NEXT:
512+
;; CHECK-NEXT: --translate-to-new-eh deprecated; same as
513+
;; CHECK-NEXT: translate-to-exnref
507514
;; CHECK-NEXT:
508515
;; CHECK-NEXT: --trap-mode-clamp replace trapping operations with
509516
;; CHECK-NEXT: clamping semantics

test/lit/help/wasm2js.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,12 @@
452452
;; CHECK-NEXT:
453453
;; CHECK-NEXT: --symbolmap (alias for print-function-map)
454454
;; CHECK-NEXT:
455-
;; CHECK-NEXT: --translate-to-new-eh translate old EH instructions to
456-
;; CHECK-NEXT: new ones
455+
;; CHECK-NEXT: --translate-to-exnref translate old Phase 3 EH
456+
;; CHECK-NEXT: instructions to new ones with
457+
;; CHECK-NEXT: exnref
458+
;; CHECK-NEXT:
459+
;; CHECK-NEXT: --translate-to-new-eh deprecated; same as
460+
;; CHECK-NEXT: translate-to-exnref
457461
;; CHECK-NEXT:
458462
;; CHECK-NEXT: --trap-mode-clamp replace trapping operations with
459463
;; CHECK-NEXT: clamping semantics

test/lit/passes/emit-exnref.wast

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
;; When given alone, --emit-exnref just runs --translate-to-exnref
2+
;; RUN: wasm-opt %s -all --translate-to-exnref -S -o %t1.wasm
3+
;; RUN: wasm-opt %s -all --emit-exnref -S -o %t2.wasm
4+
;; RUN: diff %t1.wasm %t2.wasm
5+
6+
;; When given with other flags, --emit-exnref runs the translator after running
7+
;; other passes. If --optimize-level >=3, --experimenal-new-eh also runs StackIR
8+
;; (+ local2stack) optimization. So running '-O --emit-exnref' should be the
9+
;; same as running all these passes separately.
10+
;; RUN: wasm-opt %s -all -O --translate-to-exnref --optimize-level=3 --generate-stack-ir --optimize-stack-ir -o %t1.wasm
11+
;; RUN: wasm-opt %s -all -O --emit-exnref -o %t2.wasm
12+
;; RUN: diff %t1.wasm %t2.wasm
13+
14+
(module
15+
(import "env" "foo" (func $foo))
16+
(start $test)
17+
(func $test
18+
(try $l
19+
(do
20+
(call $foo)
21+
)
22+
(catch_all
23+
(call $foo)
24+
(rethrow $l)
25+
)
26+
)
27+
)
28+
)

test/lit/passes/experimental-new_eh.wast

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/lit/passes/translate-to-new-eh.wast renamed to test/lit/passes/translate-to-exnref.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2-
;; RUN: wasm-opt %s -all --translate-to-new-eh -S -o - | filecheck %s
3-
;; RUN: wasm-opt %s -all --translate-to-new-eh -S -o %t
2+
;; RUN: wasm-opt %s -all --translate-to-exnref -S -o - | filecheck %s
3+
;; RUN: wasm-opt %s -all --translate-to-exnref -S -o %t
44
;; RUN: wasm-opt %t -all --optimize-level=3 --generate-stack-ir --optimize-stack-ir --print-stack-ir | filecheck %s --check-prefix STACKIR-OPT
55

66
(module

0 commit comments

Comments
 (0)