From b0a80e04f1759a1c6d7b936a16048a37f8778f72 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Mon, 8 Jun 2020 18:29:14 -0700 Subject: [PATCH] Make binary_expr and binary_compare have similar asm syntax. --- include/npcomp/Dialect/Basicpy/BasicpyOps.td | 42 ++++++++++---------- pytest/Compiler/binary_expressions.py | 24 +++++------ pytest/Compiler/comparisons.py | 2 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/include/npcomp/Dialect/Basicpy/BasicpyOps.td b/include/npcomp/Dialect/Basicpy/BasicpyOps.td index fad4a0ac0..38e90158a 100644 --- a/include/npcomp/Dialect/Basicpy/BasicpyOps.td +++ b/include/npcomp/Dialect/Basicpy/BasicpyOps.td @@ -91,20 +91,38 @@ def CompareOperationAttr : StrEnumAttr< // Ops //===----------------------------------------------------------------------===// +def Basicpy_BinaryCompareOp : Basicpy_Op<"binary_compare", []> { + let summary = "Performs a comparison between two operands"; + let description = [{ + This op performs only one step of a potentially multi-step short + circuit comparison. + See: https://docs.python.org/3/reference/expressions.html#comparisons + }]; + let arguments = (ins + AnyType:$left, + AnyType:$right, + CompareOperationAttr:$operation + ); + let results = (outs + Basicpy_BoolType:$result + ); + let assemblyFormat = "$left $operation $right attr-dict `:` type(operands)"; +} + def Basicpy_BinaryExprOp : Basicpy_Op<"binary_expr", []> { let summary = "Binary expression"; let description = [{ An expression between two operands as generated by the AST BinOp node. }]; let arguments = (ins - AnyType:$lhs, - AnyType:$rhs, + AnyType:$left, + AnyType:$right, BinaryOperationAttr:$operation ); let results = (outs AnyType:$result ); - let assemblyFormat = "$operation operands attr-dict `:` functional-type(operands, results)"; + let assemblyFormat = "$left $operation $right attr-dict `:` functional-type(operands, results)"; } def Basicpy_BoolCastOp : Basicpy_Op<"bool_cast", [NoSideEffect]> { @@ -148,24 +166,6 @@ def Basicpy_BytesConstantOp : Basicpy_Op<"bytes_constant", [ let assemblyFormat = "$value attr-dict"; } -def Basicpy_BinaryCompareOp : Basicpy_Op<"binary_compare", []> { - let summary = "Performs a comparison between two operands"; - let description = [{ - This op performs only one step of a potentially multi-step short - circuit comparison. - See: https://docs.python.org/3/reference/expressions.html#comparisons - }]; - let arguments = (ins - AnyType:$left, - AnyType:$right, - CompareOperationAttr:$operation - ); - let results = (outs - Basicpy_BoolType:$result - ); - let assemblyFormat = "$left $operation $right attr-dict `:` type(operands)"; -} - def Basicpy_SlotObjectMakeOp : Basicpy_Op<"slot_object_make", [ NoSideEffect]> { let summary = "Creates an instance of a SlotObject type"; diff --git a/pytest/Compiler/binary_expressions.py b/pytest/Compiler/binary_expressions.py index 9018b951a..3f8f4ed45 100644 --- a/pytest/Compiler/binary_expressions.py +++ b/pytest/Compiler/binary_expressions.py @@ -19,71 +19,71 @@ def add(): # CHECK: %[[B:.*]] = constant 2 : i64 a = 1 b = 2 - # CHECK: {{.*}} = basicpy.binary_expr "Add" %[[A]], %[[B]] : (i64, i64) -> !basicpy.UnknownType + # CHECK: {{.*}} = basicpy.binary_expr %[[A]] "Add" %[[B]] : (i64, i64) -> !basicpy.UnknownType return a + b # CHECK-LABEL: func @sub @import_global def sub(): - # CHECK: basicpy.binary_expr "Sub" + # CHECK: basicpy.binary_expr {{.*}} "Sub" return 4 - 2 # CHECK-LABEL: func @mult @import_global def mult(): - # CHECK: basicpy.binary_expr "Mult" + # CHECK: basicpy.binary_expr {{.*}} "Mult" return 4 * 2 # CHECK-LABEL: func @div @import_global def div(): - # CHECK: basicpy.binary_expr "Div" + # CHECK: basicpy.binary_expr {{.*}} "Div" return 4 / 2 # CHECK-LABEL: func @floor_div @import_global def floor_div(): - # CHECK: basicpy.binary_expr "FloorDiv" + # CHECK: basicpy.binary_expr {{.*}} "FloorDiv" return 4 // 2 # CHECK-LABEL: func @matmul @import_global def matmul(): - # CHECK: basicpy.binary_expr "MatMult" + # CHECK: basicpy.binary_expr {{.*}} "MatMult" return 4 @ 2 # CHECK-LABEL: func @modulo @import_global def modulo(): - # CHECK: basicpy.binary_expr "Mod" + # CHECK: basicpy.binary_expr {{.*}} "Mod" return 4 % 2 # CHECK-LABEL: func @left_shift @import_global def left_shift(): - # CHECK: basicpy.binary_expr "LShift" + # CHECK: basicpy.binary_expr {{.*}} "LShift" return 4 << 2 # CHECK-LABEL: func @right_shift @import_global def right_shift(): - # CHECK: basicpy.binary_expr "RShift" + # CHECK: basicpy.binary_expr {{.*}} "RShift" return 4 >> 2 # CHECK-LABEL: func @bit_and @import_global def bit_and(): - # CHECK: basicpy.binary_expr "BitAnd" + # CHECK: basicpy.binary_expr {{.*}} "BitAnd" return 4 & 2 # CHECK-LABEL: func @bit_xor @import_global def bit_xor(): - # CHECK: basicpy.binary_expr "BitXor" + # CHECK: basicpy.binary_expr {{.*}} "BitXor" return 4 ^ 2 # CHECK-LABEL: func @bit_or @import_global def bit_or(): - # CHECK: basicpy.binary_expr "BitOr" + # CHECK: basicpy.binary_expr {{.*}} "BitOr" return 4 | 2 diff --git a/pytest/Compiler/comparisons.py b/pytest/Compiler/comparisons.py index 00bbd835c..6812d3f91 100644 --- a/pytest/Compiler/comparisons.py +++ b/pytest/Compiler/comparisons.py @@ -132,5 +132,5 @@ def nested_short_circuit_expression(): # Verify that the (z + 5) gets nested into the if. # CHECK: scf.if {{.*}} { # CHECK-NEXT: constant 6 - # CHECK-NEXT: binary_expr "Add" + # CHECK-NEXT: binary_expr return x < y == (z + 6)