mirror of https://github.com/llvm/torch-mlir
Make binary_expr and binary_compare have similar asm syntax.
parent
44f7e22f4d
commit
b0a80e04f1
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue