Skip to content

Commit

Permalink
[Outlining] Add loop instruction support
Browse files Browse the repository at this point in the history
Adds support for the loop instruction to be outlined and a test showing a repeat loop being outlined.

Reviewers: tlively

Reviewed By: tlively

Pull Request: #6141
  • Loading branch information
ashleynh committed Dec 7, 2023
1 parent e28efb0 commit 2049ee8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/passes/Outlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ struct ReconstructStringifyWalker
} else if (reason.getElseStart()) {
ASSERT_OK(existingBuilder.visitElse());
DBG(desc = "Else Start at ");
} else if (auto curr = reason.getLoopStart()) {
ASSERT_OK(existingBuilder.visitLoopStart(curr->loop));
DBG(desc = "Loop Start at ");
} else if (reason.getEnd()) {
ASSERT_OK(existingBuilder.visitEnd());
// Outlining performs an unnested walk of the Wasm module, visiting
Expand Down
37 changes: 37 additions & 0 deletions test/lit/passes/outlining.wast
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,40 @@
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )

;; Outline a loop
;; TODO: Ideally, a loop (like any control flow) repeated within a program can
;; be outlined by itself. Right now this is not possible since a control flow
;; is represented by a single symbol and only sequences of symbols >= 2 are
;; candidates for outlining.
(module
;; CHECK: (type $0 (func))

;; CHECK: (func $outline$ (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (loop $loop-in
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
;; CHECK-NEXT: )

;; CHECK: (func $a (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $a
(drop
(i32.const 0)
)
(loop (nop))
)
;; CHECK: (func $b (type $0)
;; CHECK-NEXT: (call $outline$)
;; CHECK-NEXT: )
(func $b
(drop
(i32.const 0)
)
(loop (nop))
)
)

0 comments on commit 2049ee8

Please sign in to comment.