Common property for several operations (original) (raw)
We have defined several operations and they all share a common property. I would like to have a common base class that defines this property that I can inherit from, but there seems to be no good mechanism - what approach should I take?
Currently we have implemented it by using attributes by name + an interface to it, but that seems inefficient.
Ideally I’d like to say something like this:
class BaseOp<string mnemonic, list<Trait> traits = []>
: Op<Our_Dialect, mnemonic, traits>
{
let arguments = (ins I64Prop:$prop1);
}
def ChildOp : BaseOp<"some", []> {
let arguments = (ins I64Prop:$prop2);
}
And then prop1 and prop2 would be available from ChildOp. Today it is only prop2; prop1 seems to be not generated at all.
ftynse June 5, 2025, 9:24am 2
You can do something like:
class BaseOp {
let commonArgs = (ins ...);
}
class DerivedOp : BaseOp {
let localArgs = (ins ...);
let arguments = !con(localArgs, commonArgs)
}
check out 1 TableGen Programmer’s Reference — LLVM 21.0.0git documentation for information on tablegen operators.
I ended up using the above suggestion with tiny updates:
class BaseOp {
dag commonArgs = (ins ...);
}
def DerivedOp : BaseOp {
dag localArgs = (ins ...);
let arguments = !con(localArgs, commonArgs);
}