A subroutine may be inlined multiple times When inlining, SSA should still be respected.
()
| 234 | |
| 235 | |
| 236 | def test_inline_multiple_instances(): |
| 237 | """A subroutine may be inlined multiple times |
| 238 | |
| 239 | When inlining, SSA should still be respected. |
| 240 | """ |
| 241 | |
| 242 | @I.ir_module |
| 243 | class Before: |
| 244 | @R.function(private=True) |
| 245 | def main(A: R.Tensor): |
| 246 | B = Before.subroutine(A) |
| 247 | C = Before.subroutine(B) |
| 248 | return C |
| 249 | |
| 250 | @R.function(private=True) |
| 251 | def subroutine(A0: R.Tensor) -> R.Tensor: |
| 252 | A1 = A0 * A0 |
| 253 | A2 = A1 + A1 |
| 254 | return A2 |
| 255 | |
| 256 | @R.function(private=True) |
| 257 | def expected(A: R.Tensor): |
| 258 | # First call |
| 259 | B = A * A |
| 260 | C = B + B |
| 261 | # Second call |
| 262 | D = C * C |
| 263 | E = D + D |
| 264 | return E |
| 265 | |
| 266 | after = Before["main"].inline_functions({"subroutine": Before["subroutine"]}) |
| 267 | tvm.ir.assert_structural_equal(expected, after) |
| 268 | |
| 269 | |
| 270 | def test_inline_multiple_instances_with_distinct_static_shapes(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…