I want to print out the ops in a dialect. I saw that there is a “getRegisteredOperations()” function in MLIRContext, but from my understanding, it returns an array of the operation name instead of the operations. Is it possible to traverse the dialect to get the operations? Otherwise, is it possible to set up an iterator to iterate every operation in the dialect and use dump or other print function to print it out?
For example, in the toy tutorial, instead of dumping the mlir, is it possible to traverse the ToyDialect to print the ops, such as ConstantOps, TransposeOp, etc.?
This is correct, note that the RegisteredOperationName (as well as the base class OperationName) is providing a bit more information than the “name” alone (like if an op has a traits or not for example).
This does not really make sense: an “operation” exists only as an instance in the IR: that is you needs operands, results, types, attributes which are each specific to each instance of an operation.
A good analogy would be to say that the registration is like writing a C++ class (it is a “template” to create the object), while each operation will be a specific instance of it (which are not known by the dialect at all).
Welcome! Perhaps it could help if you expanded the example more. Im unsure if you are asking to have all operations in dialect printed, all operations in the input of a given dialect, or something else.
I see. Then I am thinking about saving only one operation in the AST so that the eventual IR will have only one operation. I noticed that the parser parses functions first and looks into the expressions in the functions. Is it possible to jump the function and only save one of the operations? Take the toy tutorial as an example. Can I save only the transpose operation in the multiply-transpose function so that the final IR will only have “toy.transpose” (%arg0) : (tensor<*xf64>) → tensor<*xf64>"?