33#include "llvm/ADT/SmallPtrSet.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();
212 unwrap(flags)->elideLargeElementsAttrs(largeElementLimit);
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));
408 return wrap(UnknownLoc::getTypeID());
412 return isa<UnknownLoc>(
unwrap(location));
426 unwrap(location).print(stream);
434 return wrap(ModuleOp::create(
unwrap(location)));
441 return MlirModule{
nullptr};
442 return MlirModule{owning.
release().getOperation()};
450 return MlirModule{
nullptr};
451 return MlirModule{owning.
release().getOperation()};
489 MlirOperationState state;
491 state.location = loc;
493 state.results =
nullptr;
495 state.operands =
nullptr;
497 state.regions =
nullptr;
498 state.nSuccessors = 0;
499 state.successors =
nullptr;
500 state.nAttributes = 0;
501 state.attributes =
nullptr;
502 state.enableResultTypeInference =
false;
506#define APPEND_ELEMS(type, sizeName, elemName) \
508 (type *)realloc(state->elemName, (state->sizeName + n) * sizeof(type)); \
509 memcpy(state->elemName + state->sizeName, elemName, n * sizeof(type)); \
510 state->sizeName += n;
513 MlirType
const *results) {
518 MlirValue
const *operands) {
522 MlirRegion
const *regions) {
526 MlirBlock
const *successors) {
535 state->enableResultTypeInference =
true;
547 <<
"type inference was requested for the operation " << state.
name
548 <<
", but the operation was not registered; ensure that the dialect "
549 "containing the operation is linked into MLIR and registered with "
554 auto *inferInterface = info->getInterface<InferTypeOpInterface>();
555 if (!inferInterface) {
557 <<
"type inference was requested for the operation " << state.
name
558 <<
", but the operation does not support type inference; result "
559 "types must be specified explicitly";
566 if (!properties && info->getOpPropertyByteSize() > 0 && !attributes.empty()) {
567 auto propAlloc = std::make_unique<char[]>(info->getOpPropertyByteSize());
568 properties =
PropertyRef(info->getOpPropertiesTypeID(), propAlloc.get());
572 <<
" failed properties conversion while building "
575 if (failed(info->setOpPropertiesFromAttribute(state.
name, properties,
579 if (succeeded(inferInterface->inferReturnTypes(
588 if (succeeded(inferInterface->inferReturnTypes(
605 unwrapList(state->nOperands, state->operands, operandStorage));
607 unwrapList(state->nSuccessors, state->successors, successorStorage));
610 for (
intptr_t i = 0; i < state->nAttributes; ++i)
612 unwrap(state->attributes[i].attribute));
614 for (
intptr_t i = 0; i < state->nRegions; ++i)
615 cppState.
addRegion(std::unique_ptr<Region>(
unwrap(state->regions[i])));
617 free(state->results);
618 free(state->operands);
619 free(state->successors);
620 free(state->regions);
621 free(state->attributes);
624 if (state->enableResultTypeInference) {
625 assert(cppState.
types.empty() &&
626 "result type inference enabled and result types provided");
664 MlirContext context) {
678 if (
auto info =
unwrap(op)->getRegisteredInfo())
679 return wrap(info->getTypeID());
684 return wrap(
unwrap(op)->getName().getIdentifier());
700 return wrap(&
unwrap(op)->getRegion(
static_cast<unsigned>(pos)));
728 return wrap(
unwrap(op)->getOperand(
static_cast<unsigned>(pos)));
732 return wrap(&
unwrap(op)->getOpOperand(
static_cast<unsigned>(pos)));
736 MlirValue newValue) {
737 unwrap(op)->setOperand(
static_cast<unsigned>(pos),
unwrap(newValue));
741 MlirValue
const *operands) {
751 return wrap(
unwrap(op)->getResult(
static_cast<unsigned>(pos)));
759 return wrap(
unwrap(op)->getSuccessor(
static_cast<unsigned>(pos)));
764 std::optional<Attribute> attr =
unwrap(op)->getInherentAttr(
unwrap(name));
765 return attr.has_value();
770 std::optional<Attribute> attr =
unwrap(op)->getInherentAttr(
unwrap(name));
771 if (attr.has_value())
778 MlirAttribute attr) {
779 unwrap(op)->setInherentAttr(
785 llvm::range_size(
unwrap(op)->getDiscardableAttrs()));
791 *std::next(
unwrap(op)->getDiscardableAttrs().begin(), pos);
802 MlirAttribute attr) {
808 return !!
unwrap(op)->removeDiscardableAttr(
unwrap(name));
813 unwrap(op)->setSuccessor(
unwrap(block),
static_cast<unsigned>(pos));
831 MlirAttribute attr) {
842 unwrap(op)->print(stream);
857 unwrap(op)->print(stream);
868 MlirOperation op, MlirBytecodeWriterConfig config,
903 llvm_unreachable(
"unknown result in WalkResult::unwrap");
925 MlirValue newValue) {
941 if (cppRegion->
empty())
942 return wrap(
static_cast<Block *
>(
nullptr));
952 auto &blockList =
unwrap(region)->getBlocks();
953 blockList.insert(std::next(blockList.begin(), pos),
unwrap(block));
964 assert(
unwrap(reference)->getParent() ==
unwrap(region) &&
965 "expected reference block to belong to the region");
975 assert(
unwrap(reference)->getParent() ==
unwrap(region) &&
976 "expected reference block to belong to the region");
982 delete static_cast<Region *
>(region.ptr);
994 MlirLocation
const *locs) {
996 for (
intptr_t i = 0; i < nArgs; ++i)
1019 if (cppBlock->
empty())
1026 if (cppBlock->
empty())
1039 MlirOperation operation) {
1040 auto &opList =
unwrap(block)->getOperations();
1041 opList.insert(std::next(opList.begin(), pos),
unwrap(operation));
1045 MlirOperation reference,
1046 MlirOperation operation) {
1048 if (mlirOperationIsNull(reference)) {
1053 assert(
unwrap(reference)->getBlock() ==
unwrap(block) &&
1054 "expected reference operation to belong to the block");
1060 MlirOperation reference,
1061 MlirOperation operation) {
1062 if (mlirOperationIsNull(reference))
1065 assert(
unwrap(reference)->getBlock() ==
unwrap(block) &&
1066 "expected reference operation to belong to the block");
1075 b->getParent()->getBlocks().remove(
b);
1097 return wrap(
unwrap(block)->getArgument(
static_cast<unsigned>(pos)));
1103 unwrap(block)->print(stream);
1111 return wrap(
unwrap(block)->getSuccessor(
static_cast<unsigned>(pos)));
1116 return static_cast<intptr_t>(std::distance(
b->pred_begin(),
b->pred_end()));
1122 std::advance(it, pos);
1135 return llvm::isa<BlockArgument>(
unwrap(value));
1139 return llvm::isa<OpResult>(
unwrap(value));
1143 return wrap(llvm::dyn_cast<BlockArgument>(
unwrap(value)).getOwner());
1148 llvm::dyn_cast<BlockArgument>(
unwrap(value)).getArgNumber());
1152 if (
auto blockArg = llvm::dyn_cast<BlockArgument>(
unwrap(value)))
1153 blockArg.setType(
unwrap(type));
1157 if (
auto blockArg = llvm::dyn_cast<BlockArgument>(
unwrap(value)))
1158 blockArg.setLoc(
unwrap(loc));
1162 return wrap(llvm::dyn_cast<OpResult>(
unwrap(value)).getOwner());
1167 llvm::dyn_cast<OpResult>(
unwrap(value)).getResultNumber());
1183 unwrap(value).print(stream);
1200 return wrap(opOperand);
1209 MlirOperation *exceptions) {
1214 for (
intptr_t i = 0; i < numExceptions; ++i) {
1215 exceptionSet.insert(
unwrap(exceptions[i]));
1244 return unwrap(opOperand)->getOperandNumber();
1252 unwrap(opOperand)->getNextOperandUsingThisValue());
1257 return wrap(nextOpOperand);
1286 unwrap(type).print(stream);
1305 if (
auto typedAttr = llvm::dyn_cast<TypedAttr>(attr))
1306 return wrap(typedAttr.getType());
1325 unwrap(attr).print(stream);
1331 MlirAttribute attr) {
1368 if (!
unwrap(operation)->hasTrait<OpTrait::SymbolTable>())
1374 delete unwrap(symbolTable);
1383 MlirOperation operation) {
1388 MlirOperation operation) {
1394 MlirOperation from) {
1395 auto *cppFrom =
unwrap(from);
1396 auto *context = cppFrom->getContext();
1397 auto oldSymbolAttr = StringAttr::get(context,
unwrap(oldSymbol));
1398 auto newSymbolAttr = StringAttr::get(context,
unwrap(newSymbol));
1404 void (*callback)(MlirOperation,
bool,
1408 [&](
Operation *foundOpCpp,
bool isVisible) {
1409 callback(
wrap(foundOpCpp), isVisible,
1460 MlirOperation from) {
1465 MlirOperation from) {
1494 MlirIRMapping mapping) {
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`...
MlirBlock mlirIRMappingLookupOrNullBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block. Returns a null MlirBlock if no mapping exists.
MlirValue mlirIRMappingLookupOrDefaultValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value.
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.
MlirOperation mlirIRMappingLookupOrDefaultOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
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 mlirIRMappingMapBlock(MlirIRMapping mapping, MlirBlock from, MlirBlock to)
Maps a Block in the mapping.
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)
bool mlirOperationNameHasTrait(MlirStringRef opName, MlirTypeID traitTypeID, MlirContext context)
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.
MlirIRMapping mlirIRMappingCreate(void)
Creates a new empty IRMapping.
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.
bool mlirIRMappingContainsBlock(MlirIRMapping mapping, MlirBlock block)
Returns true if the mapping contains a mapping for the given block.
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)
MlirOperation mlirOperationCloneWithMapping(MlirOperation op, MlirIRMapping mapping)
Clones the operation with the given mapping.
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)
MlirBlock mlirIRMappingLookupOrDefaultBlock(MlirIRMapping mapping, MlirBlock from)
Looks up a mapped Block.
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 mlirIRMappingDestroy(MlirIRMapping mapping)
Destroys the given IRMapping.
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 mlirIRMappingClear(MlirIRMapping mapping)
Clears all mappings.
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)
bool mlirLocationIsAUnknown(MlirLocation location)
Checks whether the given location is an Unknown.
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.
MlirOpOperand mlirOperationGetOpOperand(MlirOperation op, intptr_t pos)
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.
void mlirIRMappingEraseOperation(MlirIRMapping mapping, MlirOperation op)
Erases an operation mapping.
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)
MlirValue mlirIRMappingLookupOrNullValue(MlirIRMapping mapping, MlirValue from)
Looks up a mapped Value. Returns a null MlirValue if no mapping exists.
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)
void mlirOperationReplaceUsesOfWith(MlirOperation op, MlirValue oldValue, MlirValue newValue)
Replace uses of 'of' value with the 'with' value inside the 'op' operation.
int mlirLocationFileLineColRangeGetEndColumn(MlirLocation location)
Getter for end_column of FileLineColRange.
MlirOperation mlirOperationCreate(MlirOperationState *state)
bool mlirIRMappingContainsOperation(MlirIRMapping mapping, MlirOperation op)
Returns true if the mapping contains a mapping for the given operation.
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.
void mlirIRMappingMapOperation(MlirIRMapping mapping, MlirOperation from, MlirOperation to)
Maps an Operation in the mapping.
bool mlirIRMappingContainsValue(MlirIRMapping mapping, MlirValue value)
Returns true if the mapping contains a mapping for the given value.
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 mlirIRMappingEraseValue(MlirIRMapping mapping, MlirValue value)
Erases a value mapping.
void mlirOperationWriteBytecode(MlirOperation op, MlirStringCallback callback, void *userData)
Same as mlirOperationPrint but writing the bytecode format.
void mlirValueDump(MlirValue value)
MlirTypeID mlirLocationUnknownGetTypeID()
TypeID Getter for Unknown.
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...
void mlirIRMappingEraseBlock(MlirIRMapping mapping, MlirBlock block)
Erases a block mapping.
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)
MlirOperation mlirIRMappingLookupOrNullOperation(MlirIRMapping mapping, MlirOperation from)
Looks up a mapped Operation.
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 mlirIRMappingMapValue(MlirIRMapping mapping, MlirValue from, MlirValue to)
Maps a Value in the mapping.
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)
This is a utility class for mapping one set of IR entities to another.
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.
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
bool hasTrait() const
Returns true if the operation was registered with a particular trait, e.g.
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, PropertyRef 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.
Type-safe wrapper around a void* for passing properties, including the properties structs of operatio...
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.
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.
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.
PropertyRef getRawProperties()
SmallVector< Type, 4 > types
Types of the results of this operation.
Region * addRegion()
Create a region that should be attached to the operation.