llvm/mlir/utils/tree-sitter-mlir/test/corpus/func.txt

================================================================================
Function prototype
================================================================================
func.func @abort()
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (func_dialect
        (symbol_ref_id)
        (func_arg_list)))))

================================================================================
Simple function using func, arith dialects
================================================================================
func.func @test_addi(%arg0 : i64, %arg1 : i64) -> i64 {
  %0 = arith.addi %arg0, %arg1 : i64
  return %0 : i64
}
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (func_dialect
        (symbol_ref_id)
        (func_arg_list
          (value_use)
          (type
            (builtin_type
              (integer_type)))
          (value_use)
          (type
            (builtin_type
              (integer_type))))
        (func_return
          (type_list_attr_parens
            (type
              (builtin_type
                (integer_type)))))
        (region
          (entry_block
            (operation
              (op_result
                (value_use))
              (custom_operation
                (arith_dialect
                  (value_use)
                  (value_use)
                  (type
                    (builtin_type
                      (integer_type))))))
            (operation
              (custom_operation
                (func_dialect
                  (value_use)
                  (type
                    (builtin_type
                      (integer_type))))))))))))

================================================================================
Function with multiple return values
================================================================================
func.func @count(%x: i64) -> (i64, i64) {
  return %x, %x: i64, i64
}
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (func_dialect
        (symbol_ref_id)
        (func_arg_list
          (value_use)
          (type
            (builtin_type
              (integer_type))))
        (func_return
          (type_list_attr_parens
            (type
              (builtin_type
                (integer_type)))
            (type
              (builtin_type
                (integer_type)))))
        (region
          (entry_block
            (operation
              (custom_operation
                (func_dialect
                  (value_use)
                  (value_use)
                  (type
                    (builtin_type
                      (integer_type)))
                  (type
                    (builtin_type
                      (integer_type))))))))))))

================================================================================
Variadic function
================================================================================
llvm.func @variadic(...)
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (llvm_dialect
        (symbol_ref_id)
        (func_arg_list
          (variadic))))))

================================================================================
Variadic function with other arguments
================================================================================
llvm.func @variadic_args(i32, i32, ...)
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (llvm_dialect
        (symbol_ref_id)
        (func_arg_list
          (type
            (builtin_type
              (integer_type)))
          (type
            (builtin_type
              (integer_type)))
          (variadic))))))

================================================================================
Generic operation in a module, with attributes
================================================================================
module {
  "llvm.func"() ({
  }) {sym_name = "foo", function_type = !llvm.func<void ()>} : () -> ()
}
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (builtin_dialect
        (region
          (entry_block
            (operation
              (generic_operation
                (string_literal)
                (region)
                (attribute
                  (dictionary_attribute
                    (attribute_entry
                      (bare_id)
                      (attribute_value
                        (string_literal)))
                    (attribute_entry
                      (bare_id)
                      (attribute_value
                        (type
                          (dialect_type
                            (pretty_dialect_item
                              (dialect_namespace)
                              (dialect_ident)
                              (pretty_dialect_item_body))))))))
                (function_type)))))))))

================================================================================
Generic operation with successor and region
================================================================================
func.func @terminator_with_regions() {
  "region"()[^bb2] ({}) : () -> ()
^bb2:
  return
}
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (func_dialect
        (symbol_ref_id)
        (func_arg_list)
        (region
          (entry_block
            (operation
              (generic_operation
                (string_literal)
                (successor
                  (caret_id))
                (region)
                (function_type))))
          (block
            (block_label
              (caret_id))
            (operation
              (custom_operation
                (func_dialect)))))))))

================================================================================
Function with private specifier, and func.call
================================================================================
func.func private @source() -> tensor<f32>
func.func @call_source() -> tensor<f32> {
  %0 = call @source() : () -> tensor<f32>
  return %0 : tensor<f32>
}
--------------------------------------------------------------------------------

(toplevel
  (operation
    (custom_operation
      (func_dialect
        (symbol_ref_id)
        (func_arg_list)
        (func_return
          (type_list_attr_parens
            (type
              (builtin_type
                (tensor_type
                  (dim_list
                    (float_type))))))))))
  (operation
    (custom_operation
      (func_dialect
        (symbol_ref_id)
        (func_arg_list)
        (func_return
          (type_list_attr_parens
            (type
              (builtin_type
                (tensor_type
                  (dim_list
                    (float_type)))))))
        (region
          (entry_block
            (operation
              (op_result
                (value_use))
              (custom_operation
                (func_dialect
                  (symbol_ref_id)
                  (function_type
                    (type
                      (builtin_type
                        (tensor_type
                          (dim_list
                            (float_type)))))))))
            (operation
              (custom_operation
                (func_dialect
                  (value_use)
                  (type
                    (builtin_type
                      (tensor_type
                        (dim_list
                          (float_type))))))))))))))