14#ifndef LIB_MLIR_BYTECODE_WRITER_IRNUMBERING_H
15#define LIB_MLIR_BYTECODE_WRITER_IRNUMBERING_H
19#include "llvm/ADT/MapVector.h"
20#include "llvm/ADT/SetVector.h"
21#include "llvm/ADT/StringMap.h"
25class BytecodeDialectInterface;
118 const BytecodeDialectInterface *
interface =
nullptr;
127 llvm::MapVector<StringRef, DialectResourceNumbering *>
resourceMap;
158 return llvm::make_pointee_range(llvm::make_second_range(dialects));
161 auto getOpNames() {
return llvm::make_pointee_range(orderedOpNames); }
162 auto getTypes() {
return llvm::make_pointee_range(orderedTypes); }
166 assert(attrs.count(attr) &&
"attribute not numbered");
167 return attrs[attr]->number;
171 assert(blockIDs.count(block) &&
"block not numbered");
172 return blockIDs[block];
175 assert(operations.count(op) &&
"operation not numbered");
176 return operations[op]->number;
179 assert(opNames.count(opName) &&
"opName not numbered");
180 return opNames[opName]->number;
183 assert(types.count(type) &&
"type not numbered");
184 return types[type]->number;
187 assert(valueIDs.count(value) &&
"value not numbered");
188 return valueIDs[value];
191 assert(dialectResources.count(resource) &&
"resource not numbered");
192 return dialectResources[resource]->number;
197 assert(regionBlockValueCounts.count(region) &&
"value not numbered");
198 return regionBlockValueCounts[region];
203 assert(blockOperationCounts.count(block) &&
"block not numbered");
204 return blockOperationCounts[block];
209 assert(operations.count(op) &&
"operation not numbered");
210 return operations[op]->isIsolatedFromAbove.value_or(
false);
219 struct NumberingDialectWriter;
222 void computeGlobalNumberingState(
Operation *rootOp);
227 void number(
Block &block);
232 void number(
Region ®ion);
233 void number(
Type type);
239 void finalizeDialectResourceNumberings(
Operation *rootOp);
247 llvm::MapVector<StringRef, DialectNumbering *> dialects;
248 std::vector<AttributeNumbering *> orderedAttrs;
249 std::vector<OpNameNumbering *> orderedOpNames;
250 std::vector<TypeNumbering *> orderedTypes;
258 llvm::SpecificBumpPtrAllocator<AttributeNumbering> attrAllocator;
259 llvm::SpecificBumpPtrAllocator<DialectNumbering> dialectAllocator;
260 llvm::SpecificBumpPtrAllocator<OperationNumbering> opAllocator;
261 llvm::SpecificBumpPtrAllocator<OpNameNumbering> opNameAllocator;
262 llvm::SpecificBumpPtrAllocator<DialectResourceNumbering> resourceAllocator;
263 llvm::SpecificBumpPtrAllocator<TypeNumbering> typeAllocator;
276 unsigned nextValueID = 0;
This class represents an opaque handle to a dialect resource entry.
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
This class contains the configuration used for the bytecode writer.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation is the basic unit of execution within MLIR.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
IRNumberingState(Operation *op, const BytecodeWriterConfig &config)
unsigned getOperationCount(Block *block)
Return the number of operations in the given block.
unsigned getNumber(OperationName opName)
int64_t getDesiredBytecodeVersion() const
Get the set desired bytecode version to emit.
std::pair< unsigned, unsigned > getBlockValueCount(Region *region)
Return the block and value counts of the given region.
bool isIsolatedFromAbove(Operation *op)
Return if the given operation is isolated from above.
unsigned getNumber(const AsmDialectResourceHandle &resource)
unsigned getNumber(Block *block)
unsigned getNumber(Value value)
auto getDialects()
Return the numbered dialects.
unsigned getNumber(Operation *op)
unsigned getNumber(Attribute attr)
Return the number for the given IR unit.
unsigned getNumber(Type type)
Include the generated interface declarations.
llvm::SetVector< T, Vector, Set, N > SetVector
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
unsigned refCount
The number of references to this value.
AttrTypeNumbering(PointerUnion< Attribute, Type > value)
unsigned number
The number assigned to this value.
DialectNumbering * dialect
The dialect of this value.
PointerUnion< Attribute, Type > value
The concrete value.
Attribute getValue() const
AttributeNumbering(Attribute value)
This class represents a numbering entry for an Dialect.
StringRef name
The namespace of the dialect.
DialectNumbering(StringRef name, unsigned number)
unsigned number
The number assigned to the dialect.
llvm::MapVector< StringRef, DialectResourceNumbering * > resourceMap
A mapping from resource key to the corresponding resource numbering entry.
SetVector< AsmDialectResourceHandle > resources
The referenced resources of this dialect.
const OpAsmDialectInterface * asmInterface
The asm dialect interface of the dialect if defined.
std::string key
The key used to reference this resource.
DialectResourceNumbering(std::string key)
bool isDeclaration
A flag indicating if this resource is only a declaration, not a full definition.
unsigned number
The number assigned to this resource.
unsigned number
The number assigned to this operation.
OperationNumbering(unsigned number)
std::optional< bool > isIsolatedFromAbove
A flag indicating if this operation's regions are isolated.
TypeNumbering(Type value)