15 #include "llvm/ADT/ScopeExit.h"
21 MlirTypeID interfaceTypeID) {
22 std::optional<RegisteredOperationName> info =
23 unwrap(operation)->getRegisteredInfo();
24 return info && info->hasInterface(
unwrap(interfaceTypeID));
29 MlirTypeID interfaceTypeID) {
32 return info && info->hasInterface(
unwrap(interfaceTypeID));
36 return wrap(InferTypeOpInterface::getInterfaceID());
40 MlirStringRef opName, MlirContext context, MlirLocation location,
41 intptr_t nOperands, MlirValue *operands, MlirAttribute attributes,
45 std::optional<RegisteredOperationName> info =
50 std::optional<Location> maybeLocation;
52 maybeLocation =
unwrap(location);
54 (void)
unwrapList(nOperands, operands, unwrappedOperands);
55 DictionaryAttr attributeDict;
57 attributeDict =
unwrap(attributes).cast<DictionaryAttr>();
64 unwrappedRegions.reserve(nRegions);
65 for (intptr_t i = 0; i < nRegions; ++i)
66 unwrappedRegions.emplace_back(
unwrap(*(regions + i)));
67 auto cleaner = llvm::make_scope_exit([&]() {
68 for (
auto ®ion : unwrappedRegions)
73 if (
failed(info->getInterface<InferTypeOpInterface>()->inferReturnTypes(
74 unwrap(context), maybeLocation, unwrappedOperands, attributeDict,
75 unwrappedRegions, inferredTypes)))
79 wrappedInferredTypes.reserve(inferredTypes.size());
80 for (
Type t : inferredTypes)
81 wrappedInferredTypes.push_back(
wrap(t));
82 callback(wrappedInferredTypes.size(), wrappedInferredTypes.data(), userData);
MlirLogicalResult mlirInferTypeOpInterfaceInferReturnTypes(MlirStringRef opName, MlirContext context, MlirLocation location, intptr_t nOperands, MlirValue *operands, MlirAttribute attributes, intptr_t nRegions, MlirRegion *regions, MlirTypesCallback callback, void *userData)
Infers the return types of the operation identified by its canonical given the arguments that will be...
bool mlirOperationImplementsInterface(MlirOperation operation, MlirTypeID interfaceTypeID)
Returns true if the given operation implements an interface identified by its TypeID.
bool mlirOperationImplementsInterfaceStatic(MlirStringRef operationName, MlirContext context, MlirTypeID interfaceTypeID)
Returns true if the operation identified by its canonical string name implements the interface identi...
MlirTypeID mlirInferTypeOpInterfaceTypeID()
Returns the interface TypeID of the InferTypeOpInterface.
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
static std::optional< RegisteredOperationName > lookup(StringRef name, MLIRContext *ctx)
Lookup the registered operation information for the given operation.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
void(* MlirTypesCallback)(intptr_t, MlirType *, void *)
These callbacks are used to return multiple types from functions while transferring ownership to the ...
static MlirLogicalResult mlirLogicalResultFailure(void)
Creates a logical result representing a failure.
static MlirLogicalResult mlirLogicalResultSuccess(void)
Creates a logical result representing a success.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
Include the generated interface declarations.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
A logical result value, essentially a boolean with named states.
A pointer to a sized fragment of a string, not necessarily null-terminated.
const char * data
Pointer to the first symbol.
size_t length
Length of the fragment.