2021-02-02 09:59:42 +08:00
|
|
|
# -*- Python -*-
|
|
|
|
# This file is licensed under a pytorch-style license
|
|
|
|
# See frontends/pytorch/LICENSE for license information.
|
|
|
|
|
|
|
|
import torch
|
|
|
|
import torch_mlir
|
|
|
|
|
|
|
|
# RUN: %PYTHON %s | npcomp-opt | FileCheck %s
|
|
|
|
|
|
|
|
mb = torch_mlir.ModuleBuilder()
|
|
|
|
|
2021-03-02 09:24:15 +08:00
|
|
|
# CHECK-LABEL: @__torch__.f
|
2021-02-02 09:59:42 +08:00
|
|
|
@mb.import_function
|
|
|
|
@torch.jit.script
|
|
|
|
def f(b: bool, i: int):
|
2021-06-17 01:23:26 +08:00
|
|
|
# elif is modeled as a nested if, so we only need to do cursory checking.
|
|
|
|
# CHECK: torch.prim.If {{.*}} {
|
2021-02-02 09:59:42 +08:00
|
|
|
# CHECK: } else {
|
2021-06-17 01:23:26 +08:00
|
|
|
# CHECK: torch.prim.If {{.*}} {
|
2021-02-02 09:59:42 +08:00
|
|
|
# CHECK: } else {
|
|
|
|
# CHECK: }
|
|
|
|
# CHECK: }
|
|
|
|
|
|
|
|
if b:
|
|
|
|
return i + i
|
|
|
|
elif i:
|
|
|
|
return i + i * i
|
|
|
|
else:
|
|
|
|
return i * i
|
|
|
|
|
|
|
|
assert isinstance(f, torch.jit.ScriptFunction)
|
|
|
|
mb.module.operation.print()
|
|
|
|
print()
|