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"
23 class BytecodeDialectInterface;
24 class BytecodeWriterConfig;
125 llvm::MapVector<StringRef, DialectResourceNumbering *>
resourceMap;
140 return llvm::make_pointee_range(llvm::make_second_range(dialects));
143 auto getOpNames() {
return llvm::make_pointee_range(orderedOpNames); }
144 auto getTypes() {
return llvm::make_pointee_range(orderedTypes); }
148 assert(attrs.count(attr) &&
"attribute not numbered");
149 return attrs[attr]->number;
152 assert(blockIDs.count(block) &&
"block not numbered");
153 return blockIDs[block];
156 assert(opNames.count(opName) &&
"opName not numbered");
157 return opNames[opName]->number;
160 assert(types.count(type) &&
"type not numbered");
161 return types[type]->number;
164 assert(valueIDs.count(value) &&
"value not numbered");
165 return valueIDs[value];
168 assert(dialectResources.count(resource) &&
"resource not numbered");
169 return dialectResources[resource]->number;
174 assert(regionBlockValueCounts.count(region) &&
"value not numbered");
175 return regionBlockValueCounts[region];
180 assert(blockOperationCounts.count(block) &&
"block not numbered");
181 return blockOperationCounts[block];
187 struct NumberingDialectWriter;
191 void number(
Block &block);
196 void number(
Region ®ion);
197 void number(
Type type);
203 void finalizeDialectResourceNumberings(
Operation *rootOp);
210 llvm::MapVector<StringRef, DialectNumbering *> dialects;
211 std::vector<AttributeNumbering *> orderedAttrs;
212 std::vector<OpNameNumbering *> orderedOpNames;
213 std::vector<TypeNumbering *> orderedTypes;
221 llvm::SpecificBumpPtrAllocator<AttributeNumbering> attrAllocator;
222 llvm::SpecificBumpPtrAllocator<DialectNumbering> dialectAllocator;
223 llvm::SpecificBumpPtrAllocator<OpNameNumbering> opNameAllocator;
224 llvm::SpecificBumpPtrAllocator<DialectResourceNumbering> resourceAllocator;
225 llvm::SpecificBumpPtrAllocator<TypeNumbering> typeAllocator;
238 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.
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.
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.
IRNumberingState(Operation *op)
unsigned getNumber(Attribute attr)
Return the number for the given IR unit.
unsigned getNumber(Type type)
Include the generated interface declarations.
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)