Skip to content

Commit

Permalink
[WASM] Reorder some passes for Wasm in preparation for non-native JsE…
Browse files Browse the repository at this point in the history
…num optimization.

In particular:
 - NormalizeJsEnums needs to run after NormalizeEnumClasses and before NormalizeOverlayMembers. Moved NormalizeEnumClasses above.
 - InsertJsEnumBoxingAndUnboxingConversions needs to run after NormalizeSwitchStatements and ImplementStringConcatenation and before RewriteReferenceEqualityOperations.

PiperOrigin-RevId: 570762555
  • Loading branch information
Googler authored and copybara-github committed Oct 4, 2023
1 parent 2a511c2 commit e648613
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions transpiler/java/com/google/j2cl/transpiler/backend/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,16 @@ public ImmutableList<Supplier<NormalizationPass>> getPassFactories(BackendOption
() -> new ImplementSystemGetProperty(options.getDefinesForWasm()),
NormalizeTryWithResources::new,
NormalizeCatchClauses::new,
() -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false),
NormalizeOverlayMembers::new,
NormalizeInstanceCompileTimeConstants::new,
() -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false),
() -> new NormalizeShifts(/* narrowAllToInt= */ false),
NormalizeStaticMemberQualifiers::new,
NormalizeMultiExpressions::new,

// Rewrite operations that do not have direct support in wasm into ones that have.
() -> new ExpandCompoundAssignments(/* expandAll= */ true),
InsertErasureTypeSafetyCasts::new,
// Rewrite 'a != b' to '!(a == b)'
RewriteReferenceEqualityOperations::new,
RewriteUnaryExpressions::new,
NormalizeSwitchStatements::new,
// Propagate constants needs to run after NormalizeSwitchStatements since it introduces
Expand All @@ -416,6 +414,11 @@ public ImmutableList<Supplier<NormalizationPass>> getPassFactories(BackendOption
StaticallyEvaluateStringConcatenation::new,
StaticallyEvaluateStringComparison::new,
ImplementStringConcatenation::new,
// TODO(b/288145845): Add InsertJsEnumBoxingAndUnboxingConversions here.
// Rewrite 'a != b' to '!(a == b)'
// Must run after InsertJsEnumBoxingAndUnboxingConversions.
RewriteReferenceEqualityOperations::new,
PropagateJsEnumConstants::new,
InsertNarrowingReferenceConversions::new,
() -> new InsertUnboxingConversions(/* areBooleanAndDoubleBoxed= */ true),
() -> new InsertBoxingConversions(/* areBooleanAndDoubleBoxed= */ true),
Expand Down Expand Up @@ -529,18 +532,16 @@ public ImmutableList<Supplier<NormalizationPass>> getPassFactories(BackendOption
// () -> new ImplementSystemGetProperty(options.getDefinesForWasm()),
NormalizeTryWithResources::new,
NormalizeCatchClauses::new,
() -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false),
NormalizeOverlayMembers::new,
NormalizeInstanceCompileTimeConstants::new,
() -> new NormalizeEnumClasses(/* useMakeEnumNameIndirection= */ false),
() -> new NormalizeShifts(/* narrowAllToInt= */ false),
NormalizeStaticMemberQualifiers::new,
NormalizeMultiExpressions::new,

// Rewrite operations that do not have direct support in wasm into ones that have.
() -> new ExpandCompoundAssignments(/* expandAll= */ true),
InsertErasureTypeSafetyCasts::new,
// Rewrite 'a != b' to '!(a == b)'
RewriteReferenceEqualityOperations::new,
RewriteUnaryExpressions::new,
NormalizeSwitchStatements::new,
// Propagate constants needs to run after NormalizeSwitchStatements since it introduces
Expand All @@ -550,6 +551,11 @@ public ImmutableList<Supplier<NormalizationPass>> getPassFactories(BackendOption
StaticallyEvaluateStringConcatenation::new,
StaticallyEvaluateStringComparison::new,
ImplementStringConcatenation::new,
// TODO(b/288145845): Add InsertJsEnumBoxingAndUnboxingConversions here.
// Rewrite 'a != b' to '!(a == b)'
// Must run after InsertJsEnumBoxingAndUnboxingConversions.
RewriteReferenceEqualityOperations::new,
PropagateJsEnumConstants::new,
InsertNarrowingReferenceConversions::new,
() -> new InsertUnboxingConversions(/* areBooleanAndDoubleBoxed= */ true),
() -> new InsertBoxingConversions(/* areBooleanAndDoubleBoxed= */ true),
Expand Down

0 comments on commit e648613

Please sign in to comment.