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;
157 return llvm::make_pointee_range(llvm::make_second_range(dialects));
160 auto getOpNames() {
return llvm::make_pointee_range(orderedOpNames); }
161 auto getTypes() {
return llvm::make_pointee_range(orderedTypes); }
165 assert(attrs.count(attr) &&
"attribute not numbered");
166 return attrs[attr]->number;
169 assert(blockIDs.count(block) &&
"block not numbered");
170 return blockIDs[block];
173 assert(operations.count(op) &&
"operation not numbered");
174 return operations[op]->number;
177 assert(opNames.count(opName) &&
"opName not numbered");
178 return opNames[opName]->number;
181 assert(types.count(type) &&
"type not numbered");
182 return types[type]->number;
185 assert(valueIDs.count(value) &&
"value not numbered");
186 return valueIDs[value];
189 assert(dialectResources.count(resource) &&
"resource not numbered");
190 return dialectResources[resource]->number;
195 assert(regionBlockValueCounts.count(region) &&
"value not numbered");
196 return regionBlockValueCounts[region];
201 assert(blockOperationCounts.count(block) &&
"block not numbered");
202 return blockOperationCounts[block];
207 assert(operations.count(op) &&
"operation not numbered");
208 return operations[op]->isIsolatedFromAbove.value_or(
false);
217 struct NumberingDialectWriter;
220 void computeGlobalNumberingState(
Operation *rootOp);
224 void number(
Block &block);
229 void number(
Region ®ion);
230 void number(
Type type);
236 void finalizeDialectResourceNumberings(
Operation *rootOp);
244 llvm::MapVector<StringRef, DialectNumbering *> dialects;
245 std::vector<AttributeNumbering *> orderedAttrs;
246 std::vector<OpNameNumbering *> orderedOpNames;
247 std::vector<TypeNumbering *> orderedTypes;
255 llvm::SpecificBumpPtrAllocator<AttributeNumbering> attrAllocator;
256 llvm::SpecificBumpPtrAllocator<DialectNumbering> dialectAllocator;
257 llvm::SpecificBumpPtrAllocator<OperationNumbering> opAllocator;
258 llvm::SpecificBumpPtrAllocator<OpNameNumbering> opNameAllocator;
259 llvm::SpecificBumpPtrAllocator<DialectResourceNumbering> resourceAllocator;
260 llvm::SpecificBumpPtrAllocator<TypeNumbering> typeAllocator;
273 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)
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.
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.
This class represents the numbering entry of an operation.
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)