brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.4 KiB · 4af2d25 Raw
75 lines · plain
1# RUN: toyc-ch1 %s -emit=ast 2>&1 | FileCheck %s2 3# User defined generic function that operates on unknown shaped arguments.4def multiply_transpose(a, b) {5  return transpose(a) * transpose(b);6}7 8def main() {9  # Define a variable `a` with shape <2, 3>, initialized with the literal value.10  # The shape is inferred from the supplied literal.11  var a = [[1, 2, 3], [4, 5, 6]];12  # b is identical to a, the literal array is implicitly reshaped: defining new13  # variables is the way to reshape arrays (element count in literal must match14  # the size of specified shape).15  var b<2, 3> = [1, 2, 3, 4, 5, 6];16 17  # This call will specialize `multiply_transpose` with <2, 3> for both18  # arguments and deduce a return type of <3, 2> in initialization of `c`.19  var c = multiply_transpose(a, b);20  # A second call to `multiply_transpose` with <2, 3> for both arguments will21  # reuse the previously specialized and inferred version and return `<3, 2>`22  var d = multiply_transpose(b, a);23  # A new call with `<3, 2>` for both dimension will trigger another24  # specialization of `multiply_transpose`.25  var e = multiply_transpose(c, d);26  # Finally, calling into `multiply_transpose` with incompatible shapes27  # (<2, 3> and <3, 2>) will trigger a shape inference error.28  var f = multiply_transpose(a, c);29}30 31 32# CHECK: Module:33# CHECK-NEXT:     Function34# CHECK-NEXT:       Proto 'multiply_transpose' @{{.*}}ast.toy:4:135# CHECK-NEXT:       Params: [a, b]36# CHECK-NEXT:       Block {37# CHECK-NEXT:         Return38# CHECK-NEXT:           BinOp: * @{{.*}}ast.toy:5:2539# CHECK-NEXT:             Call 'transpose' [ @{{.*}}ast.toy:5:1040# CHECK-NEXT:               var: a @{{.*}}ast.toy:5:2041# CHECK-NEXT:             ]42# CHECK-NEXT:             Call 'transpose' [ @{{.*}}ast.toy:5:2543# CHECK-NEXT:               var: b @{{.*}}ast.toy:5:3544# CHECK-NEXT:             ]45# CHECK-NEXT:       } // Block46# CHECK-NEXT:     Function47# CHECK-NEXT:       Proto 'main' @{{.*}}ast.toy:8:148# CHECK-NEXT:       Params: []49# CHECK-NEXT:       Block {50# CHECK-NEXT:         VarDecl a<> @{{.*}}ast.toy:11:351# CHECK-NEXT:           Literal: <2, 3>[ <3>[ 1.000000e+00, 2.000000e+00, 3.000000e+00], <3>[ 4.000000e+00, 5.000000e+00, 6.000000e+00]] @{{.*}}ast.toy:11:1152# CHECK-NEXT:         VarDecl b<2, 3> @{{.*}}ast.toy:15:353# CHECK-NEXT:           Literal: <6>[ 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00, 6.000000e+00] @{{.*}}ast.toy:15:1754# CHECK-NEXT:         VarDecl c<> @{{.*}}ast.toy:19:355# CHECK-NEXT:           Call 'multiply_transpose' [ @{{.*}}ast.toy:19:1156# CHECK-NEXT:             var: a @{{.*}}ast.toy:19:3057# CHECK-NEXT:             var: b @{{.*}}ast.toy:19:3358# CHECK-NEXT:           ]59# CHECK-NEXT:         VarDecl d<> @{{.*}}ast.toy:22:360# CHECK-NEXT:           Call 'multiply_transpose' [ @{{.*}}ast.toy:22:1161# CHECK-NEXT:             var: b @{{.*}}ast.toy:22:3062# CHECK-NEXT:             var: a @{{.*}}ast.toy:22:3363# CHECK-NEXT:           ]64# CHECK-NEXT:         VarDecl e<> @{{.*}}ast.toy:25:365# CHECK-NEXT:           Call 'multiply_transpose' [ @{{.*}}ast.toy:25:1166# CHECK-NEXT:             var: c @{{.*}}ast.toy:25:3067# CHECK-NEXT:             var: d @{{.*}}ast.toy:25:3368# CHECK-NEXT:           ]69# CHECK-NEXT:         VarDecl f<> @{{.*}}ast.toy:28:370# CHECK-NEXT:           Call 'multiply_transpose' [ @{{.*}}ast.toy:28:1171# CHECK-NEXT:             var: a @{{.*}}ast.toy:28:3072# CHECK-NEXT:             var: c @{{.*}}ast.toy:28:3373# CHECK-NEXT:           ]74# CHECK-NEXT:       } // Block75