def visit_UnaryOp(self, ast_node): ic = self.fctx.ic with ic.ip, ic.loc: op = ast_node.op operand_value = self.sub_evaluate(ast_node.operand) if isinstance(op, ast.Not): # Special handling for logical-not. condition_value = basicpy_ops.AsI1Op(ic.i1_type, operand_value).result true_value = basicpy_ops.BoolConstantOp( ic.bool_type, ic.i1_true).result false_value = basicpy_ops.BoolConstantOp( ic.bool_type, ic.i1_false).result self.value = std_ops.SelectOp(ic.bool_type, condition_value, false_value, true_value).result else: self.fctx.abort("Unknown unary op %r", (ast.dump(op)))
def _emit_cmpi_and_select(lhs: Value, rhs: Value, pred: IntegerAttr) -> Value: cond = std.CmpIOp(IntegerType.get_signless(1), pred, lhs, rhs).result return std.SelectOp(lhs.type, cond, lhs, rhs).result