Is there any way to have abstract operations?

When defining operations in ODS it is convenient group like ops together by deriving from a common “abstract” op:

class X_Op<string mnemonic, list<OpTrait> traits = []> :
  Op<SomeDialect, mnemonic, traits>;

class X_ALike_Op<string mnemonic, list<OpTrait> traits = []> :
  X_Op<mnemonic, traits>;

def X_A1_Op: X_ALike_Op<"a1">;
def X_A2_Op: X_ALike_Op<"a2">;
def X_A3_Op: X_ALike_Op<"a3">;

I was thinking this construct models a generalization/specialization, but the X_ALike_Op is not present anywhere in the generated code.

I can sort of emulate this by giving such an abstract op a similarly named trait. That works but is not as nice as having the full hierarchy present like in MDE/DSL frameworks such as for instance EMF.

Is there maybe a better way to have the X_ALike_Op available in patterns or constraints?

As presently implemented, such “inheritance” is purely scoped to tablegen/generation time, as you note.

Operations can [implement interfaces] (https://mlir.llvm.org/docs/Interfaces/#attributeoperationtype-interfaces), which are “real” in the way you describe. However, we tend to view those as units of functionality, not hierarchy – although it seems the facility could be used to do what you are asking.

1 Like

Thanks! I will check it out.