MLIR 23.0.0git
Support.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  MlirStringRef
 A pointer to a sized fragment of a string, not necessarily null-terminated. More...
struct  MlirLogicalResult
 A logical result value, essentially a boolean with named states. More...

Macros

#define MLIR_CAPI_EXPORTED   __attribute__((visibility("default")))
#define MLIR_PYTHON_API_EXPORTED   MLIR_CAPI_EXPORTED
#define DEFINE_C_API_STRUCT(name, storage)

Typedefs

typedef struct MlirStringRef MlirStringRef
typedef void(* MlirStringCallback) (MlirStringRef, void *)
 A callback for returning string references.
typedef struct MlirLogicalResult MlirLogicalResult

Functions

 DEFINE_C_API_STRUCT (MlirLlvmThreadPool, void)
 Re-export llvm::ThreadPool so as to avoid including the LLVM C API directly.
 DEFINE_C_API_STRUCT (MlirLlvmRawFdOStream, void)
 Re-export llvm::raw_fd_ostream so as to avoid including the LLVM C API directly.
 DEFINE_C_API_STRUCT (MlirTypeID, const void)
 DEFINE_C_API_STRUCT (MlirTypeIDAllocator, void)
static MlirStringRef mlirStringRefCreate (const char *str, size_t length)
 Constructs a string reference from the pointer and length.
MLIR_CAPI_EXPORTED MlirStringRef mlirStringRefCreateFromCString (const char *str)
 Constructs a string reference from a null-terminated C string.
MLIR_CAPI_EXPORTED bool mlirStringRefEqual (MlirStringRef string, MlirStringRef other)
 Returns true if two string references are equal, false otherwise.
static bool mlirLogicalResultIsSuccess (MlirLogicalResult res)
 Checks if the given logical result represents a success.
static bool mlirLogicalResultIsFailure (MlirLogicalResult res)
 Checks if the given logical result represents a failure.
static MlirLogicalResult mlirLogicalResultSuccess (void)
 Creates a logical result representing a success.
static MlirLogicalResult mlirLogicalResultFailure (void)
 Creates a logical result representing a failure.
MLIR_CAPI_EXPORTED MlirLlvmThreadPool mlirLlvmThreadPoolCreate (void)
 Create an LLVM thread pool.
MLIR_CAPI_EXPORTED void mlirLlvmThreadPoolDestroy (MlirLlvmThreadPool pool)
 Destroy an LLVM thread pool.
MLIR_CAPI_EXPORTED MlirLlvmRawFdOStream mlirLlvmRawFdOStreamCreate (const char *path, bool binary, MlirStringCallback errorCallback, void *userData)
 Create a raw_fd_ostream for the given path.
MLIR_CAPI_EXPORTED void mlirLlvmRawFdOStreamWrite (MlirLlvmRawFdOStream stream, MlirStringRef string)
 Write a string to a raw_fd_ostream created with mlirLlvmRawFdOStreamCreate.
MLIR_CAPI_EXPORTED bool mlirLlvmRawFdOStreamIsNull (MlirLlvmRawFdOStream stream)
 Checks if a raw_fd_ostream is null.
MLIR_CAPI_EXPORTED void mlirLlvmRawFdOStreamDestroy (MlirLlvmRawFdOStream stream)
 Destroy a raw_fd_ostream created with mlirLlvmRawFdOStreamCreate.
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeIDCreate (const void *ptr)
 ptr must be 8 byte aligned and unique to a type valid for the duration of the returned type id's usage
static bool mlirTypeIDIsNull (MlirTypeID typeID)
 Checks whether a type id is null.
MLIR_CAPI_EXPORTED bool mlirTypeIDEqual (MlirTypeID typeID1, MlirTypeID typeID2)
 Checks if two type ids are equal.
MLIR_CAPI_EXPORTED size_t mlirTypeIDHashValue (MlirTypeID typeID)
 Returns the hash value of the type id.
MLIR_CAPI_EXPORTED MlirTypeIDAllocator mlirTypeIDAllocatorCreate (void)
 Creates a type id allocator for dynamic type id creation.
MLIR_CAPI_EXPORTED void mlirTypeIDAllocatorDestroy (MlirTypeIDAllocator allocator)
 Deallocates the allocator and all allocated type ids.
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeIDAllocatorAllocateTypeID (MlirTypeIDAllocator allocator)
 Allocates a type id that is valid for the lifetime of the allocator.

Macro Definition Documentation

◆ DEFINE_C_API_STRUCT

#define DEFINE_C_API_STRUCT ( name,
storage )
Value:
struct name { \
storage *ptr; \
}; \
typedef struct name name

Definition at line 55 of file Support.h.

◆ MLIR_CAPI_EXPORTED

◆ MLIR_PYTHON_API_EXPORTED

Typedef Documentation

◆ MlirLogicalResult

typedef struct MlirLogicalResult MlirLogicalResult

Definition at line 124 of file Support.h.

◆ MlirStringCallback

typedef void(* MlirStringCallback) (MlirStringRef, void *)

A callback for returning string references.

This function is called back by the functions that need to return a reference to the portion of the string with the following arguments:

  • an MlirStringRef representing the current portion of the string
  • a pointer to user data forwarded from the printing call.

Definition at line 110 of file Support.h.

◆ MlirStringRef

typedef struct MlirStringRef MlirStringRef

Definition at line 82 of file Support.h.

Function Documentation

◆ DEFINE_C_API_STRUCT() [1/4]

DEFINE_C_API_STRUCT ( MlirLlvmRawFdOStream ,
void  )

Re-export llvm::raw_fd_ostream so as to avoid including the LLVM C API directly.

◆ DEFINE_C_API_STRUCT() [2/4]

DEFINE_C_API_STRUCT ( MlirLlvmThreadPool ,
void  )

Re-export llvm::ThreadPool so as to avoid including the LLVM C API directly.

◆ DEFINE_C_API_STRUCT() [3/4]

DEFINE_C_API_STRUCT ( MlirTypeID ,
const void  )

◆ DEFINE_C_API_STRUCT() [4/4]

DEFINE_C_API_STRUCT ( MlirTypeIDAllocator ,
void  )

◆ mlirLlvmRawFdOStreamCreate()

MLIR_CAPI_EXPORTED MlirLlvmRawFdOStream mlirLlvmRawFdOStreamCreate ( const char * path,
bool binary,
MlirStringCallback errorCallback,
void * userData )

Create a raw_fd_ostream for the given path.

This wrapper is needed because std::ostream does not provide the file sharing semantics required on Windows.

  • path: output file path.
  • binary: controls text vs binary mode.
  • errorCallback: called with an error message on failure (optional).
  • userData: forwarded to errorCallback so it can copy the error message into caller-owned storage (e.g., a std::string). On failure, returns a null stream and invokes the optional error callback with the error message.

Definition at line 43 of file Support.cpp.

References mlirStringRefCreate(), and wrap().

Referenced by mlir::PyFileAccumulator::PyFileAccumulator().

◆ mlirLlvmRawFdOStreamDestroy()

MLIR_CAPI_EXPORTED void mlirLlvmRawFdOStreamDestroy ( MlirLlvmRawFdOStream stream)

Destroy a raw_fd_ostream created with mlirLlvmRawFdOStreamCreate.

Definition at line 69 of file Support.cpp.

References unwrap().

Referenced by mlir::RAIIMlirLlvmRawFdOStream::~RAIIMlirLlvmRawFdOStream().

◆ mlirLlvmRawFdOStreamIsNull()

MLIR_CAPI_EXPORTED bool mlirLlvmRawFdOStreamIsNull ( MlirLlvmRawFdOStream stream)

Checks if a raw_fd_ostream is null.

Definition at line 65 of file Support.cpp.

Referenced by mlir::PyFileAccumulator::PyFileAccumulator().

◆ mlirLlvmRawFdOStreamWrite()

MLIR_CAPI_EXPORTED void mlirLlvmRawFdOStreamWrite ( MlirLlvmRawFdOStream stream,
MlirStringRef string )

Write a string to a raw_fd_ostream created with mlirLlvmRawFdOStreamCreate.

Definition at line 60 of file Support.cpp.

References unwrap().

◆ mlirLlvmThreadPoolCreate()

MLIR_CAPI_EXPORTED MlirLlvmThreadPool mlirLlvmThreadPoolCreate ( void )

Create an LLVM thread pool.

This is reexported here to avoid directly pulling in the LLVM headers directly.

Definition at line 30 of file Support.cpp.

References wrap().

◆ mlirLlvmThreadPoolDestroy()

MLIR_CAPI_EXPORTED void mlirLlvmThreadPoolDestroy ( MlirLlvmThreadPool pool)

Destroy an LLVM thread pool.

Definition at line 34 of file Support.cpp.

References unwrap().

◆ mlirLogicalResultFailure()

◆ mlirLogicalResultIsFailure()

◆ mlirLogicalResultIsSuccess()

bool mlirLogicalResultIsSuccess ( MlirLogicalResult res)
inlinestatic

◆ mlirLogicalResultSuccess()

◆ mlirStringRefCreate()

MlirStringRef mlirStringRefCreate ( const char * str,
size_t length )
inlinestatic

Constructs a string reference from the pointer and length.

The pointer need not reference to a null-terminated string.

Definition at line 87 of file Support.h.

References MlirStringRef::length, and result.

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyConversionTarget::addIllegalDialect(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyConversionTarget::addIllegalOp(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyConversionTarget::addLegalDialect(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyConversionTarget::addLegalOp(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::gpu::ObjectAttr::bindDerived(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::llvm::StructType::bindDerived(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::transform::OperationType::bindDerived(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyInferShapedTypeOpInterface::inferReturnTypeComponents(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyInferTypeOpInterface::inferReturnTypes(), mlirGPUObjectAttrGetObject(), mlirLlvmRawFdOStreamCreate(), mlirStringRefCreateFromCString(), NB_MODULE(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populatePassManagerSubmodule(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateRewriteSubmodule(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyConcreteOpInterface< ConcreteIface >::PyConcreteOpInterface(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::toMlirStringRef(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::toMlirStringRef(), mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::toMlirStringRef(), wrap(), and mlir::detail::CallbackOstream::write_impl().

◆ mlirStringRefCreateFromCString()

MLIR_CAPI_EXPORTED MlirStringRef mlirStringRefCreateFromCString ( const char * str)

Constructs a string reference from a null-terminated C string.

Prefer mlirStringRefCreate if the length of the string is known.

Definition at line 18 of file Support.cpp.

References mlirStringRefCreate().

◆ mlirStringRefEqual()

MLIR_CAPI_EXPORTED bool mlirStringRefEqual ( MlirStringRef string,
MlirStringRef other )

Returns true if two string references are equal, false otherwise.

Definition at line 22 of file Support.cpp.

References MlirStringRef::data, and MlirStringRef::length.

◆ mlirTypeIDAllocatorAllocateTypeID()

MLIR_CAPI_EXPORTED MlirTypeID mlirTypeIDAllocatorAllocateTypeID ( MlirTypeIDAllocator allocator)

Allocates a type id that is valid for the lifetime of the allocator.

Definition at line 105 of file Support.cpp.

References unwrap(), and wrap().

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyGlobals::TypeIDAllocator::allocate().

◆ mlirTypeIDAllocatorCreate()

MLIR_CAPI_EXPORTED MlirTypeIDAllocator mlirTypeIDAllocatorCreate ( void )

Creates a type id allocator for dynamic type id creation.

Definition at line 97 of file Support.cpp.

References wrap().

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyGlobals::TypeIDAllocator::TypeIDAllocator().

◆ mlirTypeIDAllocatorDestroy()

MLIR_CAPI_EXPORTED void mlirTypeIDAllocatorDestroy ( MlirTypeIDAllocator allocator)

Deallocates the allocator and all allocated type ids.

Definition at line 101 of file Support.cpp.

References unwrap().

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::PyGlobals::TypeIDAllocator::~TypeIDAllocator().

◆ mlirTypeIDCreate()

MLIR_CAPI_EXPORTED MlirTypeID mlirTypeIDCreate ( const void * ptr)

ptr must be 8 byte aligned and unique to a type valid for the duration of the returned type id's usage

Definition at line 76 of file Support.cpp.

References mlir::TypeID::getFromOpaquePointer(), and wrap().

◆ mlirTypeIDEqual()

MLIR_CAPI_EXPORTED bool mlirTypeIDEqual ( MlirTypeID typeID1,
MlirTypeID typeID2 )

Checks if two type ids are equal.

Definition at line 85 of file Support.cpp.

References unwrap().

Referenced by mlir::python::MlirTypeIDEqual::operator()().

◆ mlirTypeIDHashValue()

MLIR_CAPI_EXPORTED size_t mlirTypeIDHashValue ( MlirTypeID typeID)

Returns the hash value of the type id.

Definition at line 89 of file Support.cpp.

References unwrap().

Referenced by mlir::python::MlirTypeIDHash::operator()(), and mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().

◆ mlirTypeIDIsNull()

bool mlirTypeIDIsNull ( MlirTypeID typeID)
inlinestatic

Checks whether a type id is null.

Definition at line 197 of file Support.h.

Referenced by mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::populateIRCore().