Assign a unique name to each IR operation
lucas-rami opened this issue · 0 comments
By default, MLIR operations do not have unique names (though all operations, even of the same type, are easily differentiable in memory). However, in the hardware world, it is traditional for netlist-like representations to give a unique name to each component; in our case, this means giving a unique name to each IR operation. Unique names are convenient for many things and necessary for others, like back-annotating the IR through some external text-based data format (support for which will come very soon to Dynamatic). As such, we propose to attach a string attribute to each operation to hold its unique name throughout the Dynamatic compilation flow. Note that operation which already posses a unique name of some sort (e.g., handshake::FuncOp
) may be excluded from this system.
We care for this naming system to have the following properties.
- Uniqueness. The obvious one. All operation names must be unique throughout the IR's in-memory existence. After printing the IR to a file, names of transiently present operations are necessary lost so further processing may reuse names previously held by no-longer present operations.
- Persistence. After being set for the first time, an operation cannot change its name throughout its lifetime.
- Customization. Users must be able to manually define a unique name (or a unique name template) for new operations they create during IR transformations.
- Ease-of-use. It should be easy to ask the naming system to attach unique names to all currently unnamed operations, or to verify that all existing operations are named.
Currently, we provide a way to generate unique operation names on demand and in a deterministic manner using the NameUniquer
. This should be repurposed (and vastly improved) as an analysis pass that manages the names of all operations; performing caching, verification, providing unique names to yet unnamed operations, etc. This analysis will need to be loaded by all passes that may add an operation to the IR so that it can verify that all newly added operations are named (and to name them if they are not) at the end. Passes may also wish to make it one of their pre-condition that all operations in the input IR are named. As such, most passes currently present in Dynamatic will need to be modified.