32#include "llvm/ADT/SmallPtrSet.h"
33#include "llvm/Support/ThreadPool.h"
61 bool threadingEnabled) {
74 unwrap(context)->allowUnregisteredDialects(allow);
78 return unwrap(context)->allowsUnregisteredDialects();
81 return static_cast<intptr_t
>(
unwrap(context)->getAvailableDialects().size());
85 MlirDialectRegistry registry) {
92 return static_cast<intptr_t
>(
unwrap(context)->getLoadedDialects().size());
101 return unwrap(context)->isOperationRegistered(
unwrap(name));
105 return unwrap(context)->enableMultithreading(enable);
109 unwrap(context)->loadAllAvailableDialects();
113 MlirLlvmThreadPool threadPool) {
118 return unwrap(context)->getNumThreads();
122 return wrap(&
unwrap(context)->getThreadPool());
158 MlirOpPrintingFlags flags) {
179 MlirOpPrintingFlags flags) {
182 if (
auto result = llvm::dyn_cast<OpResult>(val)) {
185 op = llvm::cast<BlockArgument>(val).getOwner()->
getParentOp();
211 intptr_t largeElementLimit) {
212 unwrap(flags)->elideLargeElementsAttrs(largeElementLimit);
216 intptr_t largeResourceLimit) {
217 unwrap(flags)->elideLargeResourceString(largeResourceLimit);
222 unwrap(flags)->enableDebugInfo(enable, prettyForm);
226 unwrap(flags)->printGenericOpForm();
230 unwrap(flags)->printNameLocAsPrefix();
234 unwrap(flags)->useLocalScope();
238 unwrap(flags)->assumeVerified();
242 unwrap(flags)->skipRegions();
258 unwrap(flags)->setDesiredBytecodeVersion(version);
282 unsigned startLine,
unsigned startCol,
283 unsigned endLine,
unsigned endCol) {
286 startLine, startCol, endLine, endCol)));
290 return wrap(llvm::dyn_cast<FileLineColRange>(
unwrap(location)).getFilename());
294 if (
auto loc = llvm::dyn_cast<FileLineColRange>(
unwrap(location)))
295 return loc.getStartLine();
300 if (
auto loc = llvm::dyn_cast<FileLineColRange>(
unwrap(location)))
301 return loc.getStartColumn();
306 if (
auto loc = llvm::dyn_cast<FileLineColRange>(
unwrap(location)))
307 return loc.getEndLine();
312 if (
auto loc = llvm::dyn_cast<FileLineColRange>(
unwrap(location)))
313 return loc.getEndColumn();
318 return wrap(FileLineColRange::getTypeID());
322 return isa<FileLineColRange>(
unwrap(location));
331 Location(llvm::dyn_cast<CallSiteLoc>(
unwrap(location)).getCallee()));
336 Location(llvm::dyn_cast<CallSiteLoc>(
unwrap(location)).getCaller()));
340 return wrap(CallSiteLoc::getTypeID());
344 return isa<CallSiteLoc>(
unwrap(location));
348 MlirLocation
const *locations,
349 MlirAttribute metadata) {
356 if (
auto locationsArrRef = llvm::dyn_cast<FusedLoc>(
unwrap(location)))
357 return locationsArrRef.getLocations().size();
362 MlirLocation *locationsCPtr) {
363 if (
auto locationsArrRef = llvm::dyn_cast<FusedLoc>(
unwrap(location))) {
364 for (
auto [i, location] : llvm::enumerate(locationsArrRef.getLocations()))
365 locationsCPtr[i] =
wrap(location);
370 return wrap(llvm::dyn_cast<FusedLoc>(
unwrap(location)).getMetadata());
376 return isa<FusedLoc>(
unwrap(location));
380 MlirLocation childLoc) {
389 return wrap((llvm::dyn_cast<NameLoc>(
unwrap(location)).getName()));
394 Location(llvm::dyn_cast<NameLoc>(
unwrap(location)).getChildLoc()));
400 return isa<NameLoc>(
unwrap(location));
418 unwrap(location).print(stream);
426 return wrap(ModuleOp::create(
unwrap(location)));
433 return MlirModule{
nullptr};
434 return MlirModule{owning.
release().getOperation()};
442 return MlirModule{
nullptr};
443 return MlirModule{owning.
release().getOperation()};
481 MlirOperationState state;
483 state.location = loc;
485 state.results =
nullptr;
487 state.operands =
nullptr;
489 state.regions =
nullptr;
490 state.nSuccessors = 0;
491 state.successors =
nullptr;
492 state.nAttributes = 0;
493 state.attributes =
nullptr;
494 state.enableResultTypeInference =
false;
498#define APPEND_ELEMS(type, sizeName, elemName) \
500 (type *)realloc(state->elemName, (state->sizeName + n) * sizeof(type)); \
501 memcpy(state->elemName + state->sizeName, elemName, n * sizeof(type)); \
502 state->sizeName += n;
505 MlirType
const *results) {
510 MlirValue
const *operands) {
514 MlirRegion
const *regions) {
518 MlirBlock
const *successors) {
527 state->enableResultTypeInference =
true;
539 <<
"type inference was requested for the operation " << state.
name
540 <<
", but the operation was not registered; ensure that the dialect "
541 "containing the operation is linked into MLIR and registered with "
546 auto *inferInterface = info->getInterface<InferTypeOpInterface>();
547 if (!inferInterface) {
549 <<
"type inference was requested for the operation " << state.
name
550 <<
", but the operation does not support type inference; result "
551 "types must be specified explicitly";
558 if (!properties && info->getOpPropertyByteSize() > 0 && !attributes.empty()) {
559 auto prop = std::make_unique<char[]>(info->getOpPropertyByteSize());
564 <<
" failed properties conversion while building "
567 if (failed(info->setOpPropertiesFromAttribute(state.
name, properties,
571 if (succeeded(inferInterface->inferReturnTypes(
580 if (succeeded(inferInterface->inferReturnTypes(
597 unwrapList(state->nOperands, state->operands, operandStorage));
599 unwrapList(state->nSuccessors, state->successors, successorStorage));
602 for (intptr_t i = 0; i < state->nAttributes; ++i)
604 unwrap(state->attributes[i].attribute));
606 for (intptr_t i = 0; i < state->nRegions; ++i)
607 cppState.
addRegion(std::unique_ptr<Region>(
unwrap(state->regions[i])));
609 free(state->results);
610 free(state->operands);
611 free(state->successors);
612 free(state->regions);
613 free(state->attributes);
616 if (state->enableResultTypeInference) {
617 assert(cppState.
types.empty() &&
618 "result type inference enabled and result types provided");
664 if (
auto info =
unwrap(op)->getRegisteredInfo())
665 return wrap(info->getTypeID());
670 return wrap(
unwrap(op)->getName().getIdentifier());
682 return static_cast<intptr_t
>(
unwrap(op)->getNumRegions());
686 return wrap(&
unwrap(op)->getRegion(
static_cast<unsigned>(pos)));
710 return static_cast<intptr_t
>(
unwrap(op)->getNumOperands());
714 return wrap(
unwrap(op)->getOperand(
static_cast<unsigned>(pos)));
718 MlirValue newValue) {
719 unwrap(op)->setOperand(
static_cast<unsigned>(pos),
unwrap(newValue));
723 MlirValue
const *operands) {
729 return static_cast<intptr_t
>(
unwrap(op)->getNumResults());
733 return wrap(
unwrap(op)->getResult(
static_cast<unsigned>(pos)));
737 return static_cast<intptr_t
>(
unwrap(op)->getNumSuccessors());
741 return wrap(
unwrap(op)->getSuccessor(
static_cast<unsigned>(pos)));
746 std::optional<Attribute> attr =
unwrap(op)->getInherentAttr(
unwrap(name));
747 return attr.has_value();
752 std::optional<Attribute> attr =
unwrap(op)->getInherentAttr(
unwrap(name));
753 if (attr.has_value())
760 MlirAttribute attr) {
761 unwrap(op)->setInherentAttr(
766 return static_cast<intptr_t
>(
767 llvm::range_size(
unwrap(op)->getDiscardableAttrs()));
773 *std::next(
unwrap(op)->getDiscardableAttrs().begin(), pos);
784 MlirAttribute attr) {
790 return !!
unwrap(op)->removeDiscardableAttr(
unwrap(name));
795 unwrap(op)->setSuccessor(
unwrap(block),
static_cast<unsigned>(pos));
799 return static_cast<intptr_t
>(
unwrap(op)->getAttrs().size());
813 MlirAttribute attr) {
824 unwrap(op)->print(stream);
838 unwrap(op)->print(stream);
849 MlirOperation op, MlirBytecodeWriterConfig
config,
884 llvm_unreachable(
"unknown result in WalkResult::unwrap");
917 if (cppRegion->
empty())
918 return wrap(
static_cast<Block *
>(
nullptr));
928 auto &blockList =
unwrap(region)->getBlocks();
929 blockList.insert(std::next(blockList.begin(), pos),
unwrap(block));
940 assert(
unwrap(reference)->getParent() ==
unwrap(region) &&
941 "expected reference block to belong to the region");
951 assert(
unwrap(reference)->getParent() ==
unwrap(region) &&
952 "expected reference block to belong to the region");
958 delete static_cast<Region *
>(region.ptr);
970 MlirLocation
const *locs) {
972 for (intptr_t i = 0; i < nArgs; ++i)
995 if (cppBlock->
empty())
1002 if (cppBlock->
empty())
1015 MlirOperation operation) {
1016 auto &opList =
unwrap(block)->getOperations();
1017 opList.insert(std::next(opList.begin(), pos),
unwrap(operation));
1021 MlirOperation reference,
1022 MlirOperation operation) {
1024 if (mlirOperationIsNull(reference)) {
1029 assert(
unwrap(reference)->getBlock() ==
unwrap(block) &&
1030 "expected reference operation to belong to the block");
1036 MlirOperation reference,
1037 MlirOperation operation) {
1038 if (mlirOperationIsNull(reference))
1041 assert(
unwrap(reference)->getBlock() ==
unwrap(block) &&
1042 "expected reference operation to belong to the block");
1051 b->getParent()->getBlocks().remove(
b);
1055 return static_cast<intptr_t
>(
unwrap(block)->getNumArguments());
1073 return wrap(
unwrap(block)->getArgument(
static_cast<unsigned>(pos)));
1079 unwrap(block)->print(stream);
1083 return static_cast<intptr_t
>(
unwrap(block)->getNumSuccessors());
1087 return wrap(
unwrap(block)->getSuccessor(
static_cast<unsigned>(pos)));
1092 return static_cast<intptr_t
>(std::distance(
b->pred_begin(),
b->pred_end()));
1098 std::advance(it, pos);
1111 return llvm::isa<BlockArgument>(
unwrap(value));
1115 return llvm::isa<OpResult>(
unwrap(value));
1119 return wrap(llvm::dyn_cast<BlockArgument>(
unwrap(value)).getOwner());
1123 return static_cast<intptr_t
>(
1124 llvm::dyn_cast<BlockArgument>(
unwrap(value)).getArgNumber());
1128 if (
auto blockArg = llvm::dyn_cast<BlockArgument>(
unwrap(value)))
1129 blockArg.setType(
unwrap(type));
1133 if (
auto blockArg = llvm::dyn_cast<BlockArgument>(
unwrap(value)))
1134 blockArg.setLoc(
unwrap(loc));
1138 return wrap(llvm::dyn_cast<OpResult>(
unwrap(value)).getOwner());
1142 return static_cast<intptr_t
>(
1143 llvm::dyn_cast<OpResult>(
unwrap(value)).getResultNumber());
1159 unwrap(value).print(stream);
1176 return wrap(opOperand);
1184 intptr_t numExceptions,
1185 MlirOperation *exceptions) {
1190 for (intptr_t i = 0; i < numExceptions; ++i) {
1191 exceptionSet.insert(
unwrap(exceptions[i]));
1220 return unwrap(opOperand)->getOperandNumber();
1228 unwrap(opOperand)->getNextOperandUsingThisValue());
1233 return wrap(nextOpOperand);
1262 unwrap(type).print(stream);
1281 if (
auto typedAttr = llvm::dyn_cast<TypedAttr>(attr))
1282 return wrap(typedAttr.getType());
1301 unwrap(attr).print(stream);
1307 MlirAttribute attr) {
1344 if (!
unwrap(operation)->hasTrait<OpTrait::SymbolTable>())
1350 delete unwrap(symbolTable);
1359 MlirOperation operation) {
1364 MlirOperation operation) {
1370 MlirOperation from) {
1371 auto *cppFrom =
unwrap(from);
1372 auto *context = cppFrom->getContext();
1373 auto oldSymbolAttr = StringAttr::get(context,
unwrap(oldSymbol));
1374 auto newSymbolAttr = StringAttr::get(context,
unwrap(newSymbol));
1380 void (*callback)(MlirOperation,
bool,
1384 [&](
Operation *foundOpCpp,
bool isVisible) {
1385 callback(
wrap(foundOpCpp), isVisible,
unsigned mlirOpOperandGetOperandNumber(MlirOpOperand opOperand)
Returns the operand number of an op operand.
MlirLocation mlirValueGetLocation(MlirValue v)
Gets the location of the value.
void mlirContextDestroy(MlirContext context)
Takes an MLIR context owned by the caller and destroys it.
void mlirOperationDump(MlirOperation op)
Prints an operation to stderr.
MlirAttribute mlirOperationGetDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
MlirOperation mlirSymbolTableLookup(MlirSymbolTable symbolTable, MlirStringRef name)
Looks up a symbol with the given name in the given symbol table and returns the operation that corres...
MlirRegion mlirRegionCreate()
Creates a new empty region and transfers ownership to the caller.
void mlirOperationPrint(MlirOperation op, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData to callback`...
MlirContext mlirModuleGetContext(MlirModule module)
void mlirValuePrint(MlirValue value, MlirStringCallback callback, void *userData)
Prints a block by sending chunks of the string representation and forwarding userData to callback`.
MlirContext mlirLocationGetContext(MlirLocation location)
Gets the context that a location was created with.
size_t mlirModuleHashValue(MlirModule mod)
intptr_t mlirBlockGetNumPredecessors(MlirBlock block)
bool mlirLocationIsAName(MlirLocation location)
Checks whether the given location is an Name.
MlirOperation mlirOpOperandGetOwner(MlirOpOperand opOperand)
Returns the owner operation of an op operand.
bool mlirDialectEqual(MlirDialect dialect1, MlirDialect dialect2)
Checks if two dialects that belong to the same context are equal.
MlirRegion mlirRegionGetNextInOperation(MlirRegion region)
Returns the region immediately following the given region in its parent operation.
MlirLogicalResult mlirOperationWriteBytecodeWithConfig(MlirOperation op, MlirBytecodeWriterConfig config, MlirStringCallback callback, void *userData)
Same as mlirOperationWriteBytecode but with writer config and returns failure only if desired bytecod...
MlirIdentifier mlirOperationGetName(MlirOperation op)
void mlirDialectRegistryDestroy(MlirDialectRegistry registry)
Takes a dialect registry owned by the caller and destroys it.
bool mlirIdentifierEqual(MlirIdentifier ident, MlirIdentifier other)
Checks whether two identifiers are the same.
void mlirOperationPrintWithFlags(MlirOperation op, MlirOpPrintingFlags flags, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts flags controlling the printing behavior.
bool mlirValueIsABlockArgument(MlirValue value)
MlirTypeID mlirTypeGetTypeID(MlirType type)
Gets the type ID of the type.
void mlirValueReplaceAllUsesOfWith(MlirValue oldValue, MlirValue newValue)
Replace all uses of 'of' value with the 'with' value, updating anything in the IR that uses 'of' to u...
MlirValue mlirBlockAddArgument(MlirBlock block, MlirType type, MlirLocation loc)
Appends an argument of the specified type to the block.
intptr_t mlirOperationGetNumRegions(MlirOperation op)
MlirBlock mlirOperationGetBlock(MlirOperation op)
void mlirContextAppendDialectRegistry(MlirContext ctx, MlirDialectRegistry registry)
Append the contents of the given dialect registry to the registry associated with the context.
MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
void mlirBlockArgumentSetType(MlirValue value, MlirType type)
MlirLocation mlirLocationFileLineColGet(MlirContext context, MlirStringRef filename, unsigned line, unsigned col)
Creates an File/Line/Column location owned by the given context.
intptr_t mlirContextGetNumLoadedDialects(MlirContext context)
Returns the number of dialects loaded by the context.
MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
MlirStringRef mlirSymbolTableGetVisibilityAttributeName()
Returns the name of the attribute used to store symbol visibility.
void mlirOperationStateAddAttributes(MlirOperationState *state, intptr_t n, MlirNamedAttribute const *attributes)
MlirValue mlirOperationGetResult(MlirOperation op, intptr_t pos)
bool mlirLocationIsACallSite(MlirLocation location)
Checks whether the given location is an CallSite.
void mlirSymbolTableWalkSymbolTables(MlirOperation from, bool allSymUsesVisible, void(*callback)(MlirOperation, bool, void *userData), void *userData)
Walks all symbol table operations nested within, and including, op.
void mlirContextLoadAllAvailableDialects(MlirContext context)
Eagerly loads all available dialects registered with a context, making them available for use for IR ...
MlirModule mlirModuleCreateParseFromFile(MlirContext context, MlirStringRef fileName)
void mlirAttributePrint(MlirAttribute attr, MlirStringCallback callback, void *userData)
Prints a location by sending chunks of the string representation and forwarding userData to callback`...
MlirBlock mlirRegionGetFirstBlock(MlirRegion region)
Gets the first block in the region.
MlirLogicalResult mlirSymbolTableReplaceAllSymbolUses(MlirStringRef oldSymbol, MlirStringRef newSymbol, MlirOperation from)
Attempt to replace all uses that are nested within the given operation of the given symbol 'oldSymbol...
MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations, MlirLocation const *locations, MlirAttribute metadata)
Creates a fused location with an array of locations and metadata.
MlirAsmState mlirAsmStateCreateForValue(MlirValue value, MlirOpPrintingFlags flags)
intptr_t mlirOperationGetNumResults(MlirOperation op)
MlirOpOperand mlirValueGetFirstUse(MlirValue value)
Returns an op operand representing the first use of the value, or a null op operand if there are no u...
void mlirRegionInsertOwnedBlockAfter(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it after the (non-owned) reference block in the given r...
void mlirOperationDestroy(MlirOperation op)
void mlirValueReplaceAllUsesExcept(MlirValue oldValue, MlirValue newValue, intptr_t numExceptions, MlirOperation *exceptions)
Replace all uses of 'of' value with 'with' value, updating anything in the IR that uses 'of' to use '...
void mlirBlockAppendOwnedOperation(MlirBlock block, MlirOperation operation)
Takes an operation owned by the caller and appends it to the block.
MlirRegion mlirOperationGetFirstRegion(MlirOperation op)
Returns first region attached to the operation.
MlirAttribute mlirOperationGetInherentAttributeByName(MlirOperation op, MlirStringRef name)
MlirDialect mlirContextGetOrLoadDialect(MlirContext context, MlirStringRef name)
Gets the dialect instance owned by the given context using the dialect namespace to identify it,...
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
MlirStringRef mlirSymbolTableGetSymbolAttributeName()
Returns the name of the attribute used to store symbol names compatible with symbol tables.
void mlirBlockInsertOwnedOperation(MlirBlock block, intptr_t pos, MlirOperation operation)
Takes an operation owned by the caller and inserts it as pos to the block.
MlirRegion mlirBlockGetParentRegion(MlirBlock block)
Returns the region that contains this block.
MlirType mlirValueGetType(MlirValue value)
void mlirOperationMoveAfter(MlirOperation op, MlirOperation other)
Moves the given operation immediately after the other operation in its parent block.
void mlirRegionAppendOwnedBlock(MlirRegion region, MlirBlock block)
Takes a block owned by the caller and appends it to the given region.
void mlirBlockPrint(MlirBlock block, MlirStringCallback callback, void *userData)
void mlirOperationSetDiscardableAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
MlirOpPrintingFlags mlirOpPrintingFlagsCreate()
bool mlirModuleEqual(MlirModule lhs, MlirModule rhs)
void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags, intptr_t largeElementLimit)
MlirBlock mlirBlockGetNextInRegion(MlirBlock block)
Returns the block immediately following the given block in its parent region.
void mlirOperationSetSuccessor(MlirOperation op, intptr_t pos, MlirBlock block)
MlirValue mlirOpOperandGetValue(MlirOpOperand opOperand)
Returns the value of an op operand.
#define APPEND_ELEMS(type, sizeName, elemName)
bool mlirContextIsRegisteredOperation(MlirContext context, MlirStringRef name)
Returns whether the given fully-qualified operation (i.e.
MlirOperation mlirOperationGetNextInBlock(MlirOperation op)
void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable, bool prettyForm)
MlirOperation mlirModuleGetOperation(MlirModule module)
static mlir::WalkResult unwrap(MlirWalkResult result)
void mlirOpPrintingFlagsElideLargeResourceString(MlirOpPrintingFlags flags, intptr_t largeResourceLimit)
void mlirRegionInsertOwnedBlockBefore(MlirRegion region, MlirBlock reference, MlirBlock block)
Takes a block owned by the caller and inserts it before the (non-owned) reference block in the given ...
MlirValue mlirBlockGetArgument(MlirBlock block, intptr_t pos)
Returns pos-th argument of the block.
unsigned mlirLocationFusedGetNumLocations(MlirLocation location)
Getter for number of locations fused together.
MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
void mlirOpPrintingFlagsUseLocalScope(MlirOpPrintingFlags flags)
MlirTypeID mlirOperationGetTypeID(MlirOperation op)
intptr_t mlirBlockArgumentGetArgNumber(MlirValue value)
void mlirOperationWalk(MlirOperation op, MlirOperationWalkCallback callback, void *userData, MlirWalkOrder walkOrder)
Walks operation op in walkOrder and calls callback on that operation.
MlirBlock mlirOperationGetSuccessor(MlirOperation op, intptr_t pos)
void mlirBlockInsertOwnedOperationBefore(MlirBlock block, MlirOperation reference, MlirOperation operation)
Takes an operation owned by the caller and inserts it before the (non-owned) reference operation in t...
bool mlirAttributeEqual(MlirAttribute a1, MlirAttribute a2)
MlirAsmState mlirAsmStateCreateForOperation(MlirOperation op, MlirOpPrintingFlags flags)
bool mlirOperationEqual(MlirOperation op, MlirOperation other)
void mlirOperationSetInherentAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
void mlirOpPrintingFlagsAssumeVerified(MlirOpPrintingFlags flags)
bool mlirValueEqual(MlirValue value1, MlirValue value2)
MlirContext mlirIdentifierGetContext(MlirIdentifier ident)
Returns the context associated with this identifier.
void mlirBytecodeWriterConfigDestroy(MlirBytecodeWriterConfig config)
MlirBlock mlirBlockGetSuccessor(MlirBlock block, intptr_t pos)
void mlirModuleDestroy(MlirModule module)
MlirModule mlirModuleCreateEmpty(MlirLocation location)
void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags)
MlirOperation mlirOperationGetParentOperation(MlirOperation op)
void mlirRegionTakeBody(MlirRegion target, MlirRegion source)
Moves the entire content of the source region to the target region.
MlirLlvmThreadPool mlirContextGetThreadPool(MlirContext context)
Gets the thread pool of the context when enabled multithreading, otherwise an assertion is raised.
MlirValue mlirBlockInsertArgument(MlirBlock block, intptr_t pos, MlirType type, MlirLocation loc)
Inserts an argument of the specified type at a specified index to the block.
void mlirValueSetType(MlirValue value, MlirType type)
intptr_t mlirOperationGetNumSuccessors(MlirOperation op)
MlirDialect mlirAttributeGetDialect(MlirAttribute attr)
void mlirLocationPrint(MlirLocation location, MlirStringCallback callback, void *userData)
void mlirOperationSetAttributeByName(MlirOperation op, MlirStringRef name, MlirAttribute attr)
void mlirBlockDestroy(MlirBlock block)
Takes a block owned by the caller and destroys it.
void mlirRegionInsertOwnedBlock(MlirRegion region, intptr_t pos, MlirBlock block)
Takes a block owned by the caller and inserts it at pos to the given region.
void mlirOperationSetOperand(MlirOperation op, intptr_t pos, MlirValue newValue)
intptr_t mlirBlockGetNumArguments(MlirBlock block)
Returns the number of arguments of the block.
MlirTypeID mlirLocationFileLineColRangeGetTypeID()
TypeID Getter for FileLineColRange.
MlirOperation mlirOpResultGetOwner(MlirValue value)
void mlirBlockEraseArgument(MlirBlock block, unsigned index)
Erase the argument at 'index' and remove it from the argument list.
bool mlirOpOperandIsNull(MlirOpOperand opOperand)
Returns whether the op operand is null.
MlirDialect mlirTypeGetDialect(MlirType type)
Gets the dialect a type belongs to.
MlirModule mlirModuleCreateParse(MlirContext context, MlirStringRef module)
MlirContext mlirContextCreateWithRegistry(MlirDialectRegistry registry, bool threadingEnabled)
Creates an MLIR context, setting the multithreading setting explicitly and pre-loading the dialects f...
size_t mlirOperationHashValue(MlirOperation op)
void mlirContextSetAllowUnregisteredDialects(MlirContext context, bool allow)
Sets whether unregistered dialects are allowed in this context.
void mlirOperationStateAddResults(MlirOperationState *state, intptr_t n, MlirType const *results)
void mlirOperationMoveBefore(MlirOperation op, MlirOperation other)
Moves the given operation immediately before the other operation in its parent block.
static LogicalResult inferOperationTypes(OperationState &state)
MlirOperation mlirOperationClone(MlirOperation op)
void mlirValuePrintAsOperand(MlirValue value, MlirAsmState state, MlirStringCallback callback, void *userData)
Prints a value as an operand (i.e., the ValueID).
MlirBlock mlirBlockArgumentGetOwner(MlirValue value)
void mlirBlockArgumentSetLocation(MlirValue value, MlirLocation loc)
MlirDialectRegistry mlirDialectRegistryCreate()
Creates a dialect registry and transfers its ownership to the caller.
MlirValue mlirOperationGetOperand(MlirOperation op, intptr_t pos)
bool mlirContextGetAllowUnregisteredDialects(MlirContext context)
Returns whether the context allows unregistered dialects.
MlirAttribute mlirLocationGetAttribute(MlirLocation location)
Returns the underlying location attribute of this location.
MlirModule mlirModuleFromOperation(MlirOperation op)
MlirTypeID mlirLocationNameGetTypeID()
TypeID Getter for Name.
MlirLocation mlirOperationGetLocation(MlirOperation op)
bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
bool mlirContextEqual(MlirContext ctx1, MlirContext ctx2)
Checks if two contexts are equal.
MlirAttribute mlirOperationGetAttributeByName(MlirOperation op, MlirStringRef name)
bool mlirOperationIsBeforeInBlock(MlirOperation op, MlirOperation other)
Given an operation 'other' that is within the same parent block, return whether the current operation...
MlirTypeID mlirAttributeGetTypeID(MlirAttribute attr)
MlirAttribute mlirSymbolTableInsert(MlirSymbolTable symbolTable, MlirOperation operation)
Inserts the given operation into the given symbol table.
bool mlirLocationIsAFileLineColRange(MlirLocation location)
Checks whether the given location is an FileLineColRange.
intptr_t mlirOperationGetNumDiscardableAttributes(MlirOperation op)
MlirSymbolTable mlirSymbolTableCreate(MlirOperation operation)
Creates a symbol table for the given operation.
void mlirOperationStateAddOwnedRegions(MlirOperationState *state, intptr_t n, MlirRegion const *regions)
void mlirOperationSetLocation(MlirOperation op, MlirLocation loc)
MlirLocation mlirLocationUnknownGet(MlirContext context)
Creates a location with unknown position owned by the given context.
MlirLocation mlirLocationCallSiteGetCallee(MlirLocation location)
Getter for callee of CallSite.
static Operation * findParent(Operation *op, bool shouldUseLocalScope)
MlirOperation mlirBlockGetFirstOperation(MlirBlock block)
Returns the first operation in the block.
MlirType mlirAttributeGetType(MlirAttribute attribute)
bool mlirOperationRemoveDiscardableAttributeByName(MlirOperation op, MlirStringRef name)
void mlirRegionDestroy(MlirRegion region)
Takes a region owned by the caller and destroys it.
bool mlirOperationRemoveAttributeByName(MlirOperation op, MlirStringRef name)
bool mlirValueIsAOpResult(MlirValue value)
MLIR_CAPI_EXPORTED bool mlirOperationHasInherentAttributeByName(MlirOperation op, MlirStringRef name)
MlirContext mlirContextCreateWithThreading(bool threadingEnabled)
Creates an MLIR context with an explicit setting of the multithreading setting and transfers its owne...
MlirTypeID mlirLocationCallSiteGetTypeID()
TypeID Getter for CallSite.
MlirBlock mlirBlockGetPredecessor(MlirBlock block, intptr_t pos)
MlirOperation mlirBlockGetTerminator(MlirBlock block)
Returns the terminator operation in the block or null if no terminator.
bool mlirLocationEqual(MlirLocation l1, MlirLocation l2)
Checks if two locations are equal.
MlirRegion mlirOperationGetRegion(MlirOperation op, intptr_t pos)
int mlirLocationFileLineColRangeGetEndColumn(MlirLocation location)
Getter for end_column of FileLineColRange.
MlirOperation mlirOperationCreate(MlirOperationState *state)
unsigned mlirContextGetNumThreads(MlirContext context)
Gets the number of threads of the thread pool of the context when multithreading is enabled.
void mlirBytecodeWriterConfigDesiredEmitVersion(MlirBytecodeWriterConfig flags, int64_t version)
int mlirLocationFileLineColRangeGetStartColumn(MlirLocation location)
Getter for start_column of FileLineColRange.
MlirAttribute mlirAttributeParseGet(MlirContext context, MlirStringRef attr)
void mlirLocationFusedGetLocations(MlirLocation location, MlirLocation *locationsCPtr)
Getter for locations of Fused.
void mlirOperationRemoveFromParent(MlirOperation op)
void mlirSymbolTableDestroy(MlirSymbolTable symbolTable)
Destroys the symbol table created with mlirSymbolTableCreate.
intptr_t mlirBlockGetNumSuccessors(MlirBlock block)
MlirContext mlirContextCreate()
Creates an MLIR context and transfers its ownership to the caller.
void mlirOperationPrintWithState(MlirOperation op, MlirAsmState state, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but accepts AsmState controlling the printing behavior as well as caching ...
bool mlirOperationVerify(MlirOperation op)
Verify the operation and return true if it passes, false if it fails.
void mlirBlockDetach(MlirBlock block)
Detach a block from the owning region and assume ownership.
int mlirLocationFileLineColRangeGetEndLine(MlirLocation location)
Getter for end_line of FileLineColRange.
MlirNamedAttribute mlirOperationGetAttribute(MlirOperation op, intptr_t pos)
void mlirOpPrintingFlagsDestroy(MlirOpPrintingFlags flags)
MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller)
Creates a call site location with a callee and a caller.
void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
void mlirValueDump(MlirValue value)
void mlirBlockInsertOwnedOperationAfter(MlirBlock block, MlirOperation reference, MlirOperation operation)
Takes an operation owned by the caller and inserts it after the (non-owned) reference operation in th...
intptr_t mlirContextGetNumRegisteredDialects(MlirContext context)
Returns the number of dialects registered with the given context.
MlirTypeID mlirLocationFusedGetTypeID()
TypeID Getter for Fused.
void mlirOperationSetOperands(MlirOperation op, intptr_t nOperands, MlirValue const *operands)
static MLIRContext::Threading toThreadingEnum(bool threadingEnabled)
MlirIdentifier mlirLocationFileLineColRangeGetFilename(MlirLocation location)
Getter for filename of FileLineColRange.
MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
void mlirTypePrint(MlirType type, MlirStringCallback callback, void *userData)
MlirBlock mlirModuleGetBody(MlirModule module)
MlirContext mlirDialectGetContext(MlirDialect dialect)
Returns the context that owns the dialect.
bool mlirRegionEqual(MlirRegion region, MlirRegion other)
Checks whether two region handles point to the same region.
int mlirLocationFileLineColRangeGetStartLine(MlirLocation location)
Getter for start_line of FileLineColRange.
MlirOperation mlirOperationCreateParse(MlirContext context, MlirStringRef sourceStr, MlirStringRef sourceName)
MlirLocation mlirLocationCallSiteGetCaller(MlirLocation location)
Getter for caller of CallSite.
void mlirAsmStateDestroy(MlirAsmState state)
Destroys printing flags created with mlirAsmStateCreate.
MlirContext mlirOperationGetContext(MlirOperation op)
intptr_t mlirOpResultGetResultNumber(MlirValue value)
MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name, MlirLocation childLoc)
Creates a name location owned by the given context.
MlirLocation mlirLocationFileLineColRangeGet(MlirContext context, MlirStringRef filename, unsigned startLine, unsigned startCol, unsigned endLine, unsigned endCol)
Creates an File/Line/Column range location owned by the given context.
bool mlirBlockEqual(MlirBlock block, MlirBlock other)
Checks whether two blocks handles point to the same block.
bool mlirLocationIsAFused(MlirLocation location)
Checks whether the given location is an Fused.
MlirAttribute mlirLocationFusedGetMetadata(MlirLocation location)
Getter for metadata of Fused.
void mlirSymbolTableErase(MlirSymbolTable symbolTable, MlirOperation operation)
Removes the given operation from the symbol table and erases it.
MlirLocation mlirLocationNameGetChildLoc(MlirLocation location)
Getter for childLoc of Name.
MlirNamedAttribute mlirOperationGetDiscardableAttribute(MlirOperation op, intptr_t pos)
void mlirOperationStateEnableResultTypeInference(MlirOperationState *state)
void mlirOperationStateAddSuccessors(MlirOperationState *state, intptr_t n, MlirBlock const *successors)
MlirBytecodeWriterConfig mlirBytecodeWriterConfigCreate()
void mlirAttributeDump(MlirAttribute attr)
Prints the attribute to the standard error stream.
void mlirOpPrintingFlagsPrintNameLocAsPrefix(MlirOpPrintingFlags flags)
MlirIdentifier mlirLocationNameGetName(MlirLocation location)
Getter for name of Name.
MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
void mlirOpPrintingFlagsSkipRegions(MlirOpPrintingFlags flags)
void mlirOperationStateAddOperands(MlirOperationState *state, intptr_t n, MlirValue const *operands)
MlirOperationState mlirOperationStateGet(MlirStringRef name, MlirLocation loc)
MlirLocation mlirLocationFromAttribute(MlirAttribute attribute)
Creates a location from a location attribute.
MlirOperation mlirBlockGetParentOperation(MlirBlock block)
Returns the closest surrounding operation that contains this block.
MlirOpOperand mlirOpOperandGetNextUse(MlirOpOperand opOperand)
Returns an op operand representing the next use of the value, or a null op operand if there is no nex...
intptr_t mlirOperationGetNumOperands(MlirOperation op)
void mlirContextSetThreadPool(MlirContext context, MlirLlvmThreadPool threadPool)
Sets the thread pool of the context explicitly, enabling multithreading in the process.
MlirType mlirTypeParseGet(MlirContext context, MlirStringRef type)
Parses a type. The type is owned by the context.
MlirBlock mlirBlockCreate(intptr_t nArgs, MlirType const *args, MlirLocation const *locs)
Creates a new empty block with the given argument types and transfers ownership to the caller.
void mlirContextEnableMultithreading(MlirContext context, bool enable)
Set threading mode (must be set to false to mlir-print-ir-after-all).
void mlirTypeDump(MlirType type)
intptr_t mlirOperationGetNumAttributes(MlirOperation op)
MlirContext mlirValueGetContext(MlirValue v)
Gets the context that a value was created with.
static llvm::ArrayRef< CppTy > unwrapList(size_t size, CTy *first, llvm::SmallVectorImpl< CppTy > &storage)
This class provides management for the lifetime of the state used when printing the IR.
Attributes are known-constant values of operations.
MLIRContext * getContext() const
Return the context this attribute belongs to.
Block represents an ordered list of Operations.
OpListType::iterator iterator
OpListType & getOperations()
PredecessorIterator pred_iterator
This class contains the configuration used for the bytecode writer.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)
Location objects represent source locations information in MLIR.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
void reserve(size_type N)
NamedAttribute represents a combination of a name and an Attribute value.
StringAttr getName() const
Return the name of the attribute.
Attribute getValue() const
Return the value of the attribute.
This class represents an operand of an operation.
Set of flags used to control the behavior of the various IR print methods (e.g.
This class provides the API for ops that are known to be isolated from above.
This class provides the API for ops that are known to be terminators.
Simple wrapper around a void* in order to express generically how to pass in op properties through AP...
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
std::optional< RegisteredOperationName > getRegisteredInfo() const
If this operation is registered, returns the registered information, std::nullopt otherwise.
Operation is the basic unit of execution within MLIR.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
unsigned getNumRegions()
Returns the number of regions held by this operation.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
static Operation * create(Location location, OperationName name, TypeRange resultTypes, ValueRange operands, NamedAttrList &&attributes, OpaqueProperties properties, BlockRange successors, unsigned numRegions)
Create a new Operation with the specific fields.
This class acts as an owning reference to an op, and will automatically destroy the held op on destru...
OpTy release()
Release the referenced op.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
unsigned getRegionNumber()
Return the number of this region in the parent operation.
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
BlockListType::iterator iterator
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
static LogicalResult replaceAllSymbolUses(StringAttr oldSymbol, StringAttr newSymbol, Operation *from)
Attempt to replace all uses of the given symbol 'oldSymbol' with the provided symbol 'newSymbol' that...
static StringRef getVisibilityAttrName()
Return the name of the attribute used for symbol visibility.
static void walkSymbolTables(Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback)
Walks all symbol table operations nested within, and including, op.
OperandType * getOperand() const
Returns the current operands.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
bool use_empty() const
Returns true if this value has no uses.
void replaceAllUsesExcept(Value newValue, const SmallPtrSetImpl< Operation * > &exceptions)
Replace all uses of 'this' value with 'newValue', updating anything in the IR that uses 'this' to use...
void printAsOperand(raw_ostream &os, AsmState &state) const
Print this value as if it were an operand.
Location getLoc() const
Return the location of this value.
use_iterator use_begin() const
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
static WalkResult interrupt()
A simple raw ostream subclass that forwards write_impl calls to the user-supplied callback together w...
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirWalkResult(* MlirOperationWalkCallback)(MlirOperation, void *userData)
Operation walker type.
MlirWalkOrder
Traversal order for operation walk.
MlirWalkResult
Operation walk result.
@ MlirWalkResultInterrupt
static bool mlirBlockIsNull(MlirBlock block)
Checks whether a block is null.
static bool mlirLocationIsNull(MlirLocation location)
Checks if the location is null.
#define MLIR_CAPI_EXPORTED
void(* MlirStringCallback)(MlirStringRef, void *)
A callback for returning string references.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
const FrozenRewritePatternSet GreedyRewriteConfig config
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context, Type type={}, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR attribute to an MLIR context if it was valid.
LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, const ParserConfig &config, StringRef sourceName="", LocationAttr *sourceFileLoc=nullptr)
This parses the IR string and appends parsed operations to the given block.
Operation * clone(OpBuilder &b, Operation *op, TypeRange newResultTypes, ValueRange newOperands)
LogicalResult parseSourceFile(const llvm::SourceMgr &sourceMgr, Block *block, const ParserConfig &config, LocationAttr *sourceFileLoc=nullptr)
This parses the file specified by the indicated SourceMgr and appends parsed operations to the given ...
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Type parseType(llvm::StringRef typeStr, MLIRContext *context, size_t *numRead=nullptr, bool isKnownNullTerminated=false)
This parses a single MLIR type to an MLIR context if it was valid.
LogicalResult writeBytecodeToFile(Operation *op, raw_ostream &os, const BytecodeWriterConfig &config={})
Write the bytecode for the given operation to the provided output stream.
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
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.
static llvm::hash_code computeHash(Operation *op, function_ref< llvm::hash_code(Value)> hashOperands=[](Value v) { return hash_value(v);}, function_ref< llvm::hash_code(Value)> hashResults=[](Value v) { return hash_value(v);}, Flags flags=Flags::None)
Compute a hash for the given operation.
This represents an operation in an abstracted form, suitable for use with the builder APIs.
OpaqueProperties getRawProperties()
SmallVector< Value, 4 > operands
void addOperands(ValueRange newOperands)
void addAttribute(StringRef name, Attribute attr)
Add an attribute with the specified name.
void addSuccessors(Block *successor)
Adds a successor to the operation sate. successor must not be null.
void addTypes(ArrayRef< Type > newTypes)
MLIRContext * getContext() const
Get the context held by this operation state.
SmallVector< std::unique_ptr< Region >, 1 > regions
Regions that the op will hold.
SmallVector< Type, 4 > types
Types of the results of this operation.
Region * addRegion()
Create a region that should be attached to the operation.