14 #ifndef LIB_MLIR_BYTECODE_WRITER_IRNUMBERING_H
15 #define LIB_MLIR_BYTECODE_WRITER_IRNUMBERING_H
18 #include "llvm/ADT/MapVector.h"
19 #include "llvm/ADT/SetVector.h"
20 #include "llvm/ADT/StringMap.h"
24 class BytecodeDialectInterface;
25 class BytecodeWriterConfig;
126 llvm::MapVector<StringRef, DialectResourceNumbering *>
resourceMap;
141 return llvm::make_pointee_range(llvm::make_second_range(dialects));
144 auto getOpNames() {
return llvm::make_pointee_range(orderedOpNames); }
145 auto getTypes() {
return llvm::make_pointee_range(orderedTypes); }
149 assert(attrs.count(attr) &&
"attribute not numbered");
150 return attrs[attr]->number;
153 assert(blockIDs.count(block) &&
"block not numbered");
154 return blockIDs[block];
157 assert(operationIDs.count(op) &&
"operation not numbered");
158 return operationIDs[op];
161 assert(opNames.count(opName) &&
"opName not numbered");
162 return opNames[opName]->number;
165 assert(types.count(type) &&
"type not numbered");
166 return types[type]->number;
169 assert(valueIDs.count(value) &&
"value not numbered");
170 return valueIDs[value];
173 assert(dialectResources.count(resource) &&
"resource not numbered");
174 return dialectResources[resource]->number;
179 assert(regionBlockValueCounts.count(region) &&
"value not numbered");
180 return regionBlockValueCounts[region];
185 assert(blockOperationCounts.count(block) &&
"block not numbered");
186 return blockOperationCounts[block];
192 struct NumberingDialectWriter;
196 void number(
Block &block);
201 void number(
Region ®ion);
202 void number(
Type type);
208 void finalizeDialectResourceNumberings(
Operation *rootOp);
215 llvm::MapVector<StringRef, DialectNumbering *> dialects;
216 std::vector<AttributeNumbering *> orderedAttrs;
217 std::vector<OpNameNumbering *> orderedOpNames;
218 std::vector<TypeNumbering *> orderedTypes;
226 llvm::SpecificBumpPtrAllocator<AttributeNumbering> attrAllocator;
227 llvm::SpecificBumpPtrAllocator<DialectNumbering> dialectAllocator;
228 llvm::SpecificBumpPtrAllocator<OpNameNumbering> opNameAllocator;
229 llvm::SpecificBumpPtrAllocator<DialectResourceNumbering> resourceAllocator;
230 llvm::SpecificBumpPtrAllocator<TypeNumbering> typeAllocator;
244 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...
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...
This class manages numbering IR entities in preparation of bytecode emission.
IRNumberingState(Operation *op, const BytecodeWriterConfig &config)
unsigned getOperationCount(Block *block)
Return the number of operations in the given block.
unsigned getNumber(OperationName opName)
std::pair< unsigned, unsigned > getBlockValueCount(Region *region)
Return the block and value counts of the given region.
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)
This header declares functions that assit transformations in the MemRef dialect.
This class represents a numbering entry for an Attribute or Type.
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.
This class represents a numbering entry for a dialect resource.
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.
TypeNumbering(Type value)