github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/third_party/mlir/include/mlir-c/Core.h (about)

     1  /*===-- mlir-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
     2  |*                                                                            *|
     3  |* Copyright 2019 The MLIR Authors.                                           *|
     4  |*                                                                            *|
     5  |* Licensed under the Apache License, Version 2.0 (the "License");            *|
     6  |* you may not use this file except in compliance with the License.           *|
     7  |* You may obtain a copy of the License at                                    *|
     8  |*                                                                            *|
     9  |*   http://www.apache.org/licenses/LICENSE-2.0                               *|
    10  |*                                                                            *|
    11  |* Unless required by applicable law or agreed to in writing, software        *|
    12  |* distributed under the License is distributed on an "AS IS" BASIS,          *|
    13  |* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *|
    14  |* See the License for the specific language governing permissions and        *|
    15  |* limitations under the License.                                             *|
    16  |*                                                                            *|
    17  |*===----------------------------------------------------------------------===*|
    18  |*                                                                            *|
    19  |* This header declares the C interface to MLIR.                              *|
    20  |*                                                                            *|
    21  \*===----------------------------------------------------------------------===*/
    22  #ifndef MLIR_C_CORE_H
    23  #define MLIR_C_CORE_H
    24  
    25  #ifdef __cplusplus
    26  #include <cstdint>
    27  extern "C" {
    28  #else
    29  #include <stdint.h>
    30  #endif
    31  
    32  /// Opaque MLIR types.
    33  /// Opaque C type for mlir::MLIRContext*.
    34  typedef void *mlir_context_t;
    35  /// Opaque C type for mlir::Type.
    36  typedef const void *mlir_type_t;
    37  /// Opaque C type for mlir::FuncOp.
    38  typedef void *mlir_func_t;
    39  /// Opaque C type for mlir::Attribute.
    40  typedef const void *mlir_attr_t;
    41  
    42  /// Simple C lists for non-owning mlir Opaque C types.
    43  /// Recommended usage is construction from the `data()` and `size()` of a scoped
    44  /// owning SmallVectorImpl<...> and passing to one of the C functions declared
    45  /// later in this file.
    46  /// Once the function returns and the proper EDSC has been constructed,
    47  /// resources are freed by exiting the scope.
    48  typedef struct {
    49    int64_t *values;
    50    uint64_t n;
    51  } int64_list_t;
    52  
    53  typedef struct {
    54    mlir_type_t *types;
    55    uint64_t n;
    56  } mlir_type_list_t;
    57  
    58  typedef struct {
    59    const char *name;
    60    mlir_attr_t value;
    61  } mlir_named_attr_t;
    62  
    63  typedef struct {
    64    mlir_named_attr_t *list;
    65    uint64_t n;
    66  } mlir_named_attr_list_t;
    67  
    68  /// Minimal C API for exposing EDSCs to Swift, Python and other languages.
    69  
    70  /// Returns a simple scalar mlir::Type using the following convention:
    71  ///   - makeScalarType(c, "bf16") return an `mlir::FloatType::getBF16`
    72  ///   - makeScalarType(c, "f16") return an `mlir::FloatType::getF16`
    73  ///   - makeScalarType(c, "f32") return an `mlir::FloatType::getF32`
    74  ///   - makeScalarType(c, "f64") return an `mlir::FloatType::getF64`
    75  ///   - makeScalarType(c, "index") return an `mlir::IndexType::get`
    76  ///   - makeScalarType(c, "i", bitwidth) return an
    77  ///     `mlir::IntegerType::get(bitwidth)`
    78  ///
    79  /// No other combinations are currently supported.
    80  mlir_type_t makeScalarType(mlir_context_t context, const char *name,
    81                             unsigned bitwidth);
    82  
    83  /// Returns an `mlir::MemRefType` of the element type `elemType` and shape
    84  /// `sizes`.
    85  mlir_type_t makeMemRefType(mlir_context_t context, mlir_type_t elemType,
    86                             int64_list_t sizes);
    87  
    88  /// Returns an `mlir::FunctionType` of the element type `elemType` and shape
    89  /// `sizes`.
    90  mlir_type_t makeFunctionType(mlir_context_t context, mlir_type_list_t inputs,
    91                               mlir_type_list_t outputs);
    92  
    93  /// Returns an `mlir::IndexType`.
    94  mlir_type_t makeIndexType(mlir_context_t context);
    95  
    96  /// Returns an `mlir::IntegerAttr` of the specified type that contains the given
    97  /// value.
    98  mlir_attr_t makeIntegerAttr(mlir_type_t type, int64_t value);
    99  
   100  /// Returns an `mlir::BoolAttr` with the given value.
   101  mlir_attr_t makeBoolAttr(mlir_context_t context, bool value);
   102  
   103  /// Returns the arity of `function`.
   104  unsigned getFunctionArity(mlir_func_t function);
   105  
   106  /// Returns the rank of the `function` argument at position `pos`.
   107  /// If the argument is of MemRefType, this returns the rank of the MemRef.
   108  /// Otherwise returns `0`.
   109  /// TODO(ntv): support more than MemRefType and scalar Type.
   110  unsigned getRankOfFunctionArgument(mlir_func_t function, unsigned pos);
   111  
   112  /// Returns an opaque mlir::Type of the `function` argument at position `pos`.
   113  mlir_type_t getTypeOfFunctionArgument(mlir_func_t function, unsigned pos);
   114  
   115  #ifdef __cplusplus
   116  } // end extern "C"
   117  #endif
   118  
   119  #endif // MLIR_C_CORE_H