Suppose we introduce a platform-independent, architecture-independent unified dialect, and a conversion dialect used for guiding conversion. what benefits will it bring us?
Since there is a unified dialect for transfer, the relationships between dialects will become clear. some platform-dependent and/or architecture-dependent dialects will be converted as downstream of unified dialect through conversion dialects, such as X86Vector, AMX, ARM_SME, ARM_SVE, NVVM, ROCDL. meanwhile, some platform-independent and/or architecture-independent dialects as upstream of unified dialect will be easier to design, such as arith, scf.
In addition, this will allow the upstream of the unified dialect to be designed according to the following two rules, which will allow users to foolishly use the upstream dialect without caring about the downstream dialect, and allow the developer to foolishly discover and create and lowering new abstractions:
- The ability of the upstream dialect is a subset of the ability of the downstream dialect.
- Code implemented in an upstream dialect is no less efficient when reduced to a downstream dialect than when the same functionality is implemented in a downstream dialect.
- For upstream of the unified dialect, MLIR can optimize code through higher level abstractions(mlir’s original ability). for example, to eliminate the transpose of transpose of a matrix.
- For downstream of the unified dialect, MLIR can optimize code through the guiding of conversion dialect. for example, convert to AVX will automatic analysis merge scalar calculations to SIMD.
the unified dialect should be low level and powerful enough. So that it can be automatically analyzed and converted according to the guiding of conversion dialect. With unified dialects as the dividing line, its upstream dialects are used to provide higher level abstractions, and its downstream dialects are used to provide machine-specific feature. the conversion will from a higher abstraction to a lower abstraction, then from lower abstraction merge to machine-specific middle abstraction.
The final dialect diagram looks like this, there may be errors due to limited knowledge:
In fact, LLVM IR fits into this unified dialect, but it is not an MLIR dialect.