[MLIR][TableGen] What is the purpose of "XOpOperandAdaptor" classes?

I am inspecting the TableGen output for the MLIR Toy example. I see that for each Op XOp, a class called XOpOperandAdaptor is also generated. However, I don’t these classes being used anywhere. Also, the logic implemented by their methods is repeated in similar methods on the Op class itself.

I am curious to know why such adaptors are generated.

1 Like

They are used together with dialect conversion. In dialect conversion each op rewrite pattern takes in the converted input arguments as an ArrayRef<Value> arguments. So instead of using arguments[N] one can create an adaptor from arguments to use the nicer and meaningful getter methods like adaptor.some_value(), etc. There is an example in the Toy tutorial : Chapter 5: Partial Lowering to Lower-Level Dialects for Optimization - MLIR. There are also some more explanation here: Operation Definition Specification (ODS) - MLIR.

1 Like

Thanks for the clarification :+1:. I guess, I should have been a bit more patient, didn’t get that far yet in the Toy example.