tensor::dimOp have inferReturnTypes()

Hi
I have a question:
at the ODS, tensor::DimOp don’t define InferTypeOpInterface, at the code, also don’t attachinterface it, thanks.

PS:
inferReturnTypes() is the InferTypeOpInterface’s static method.

Correct, but it has a single simple buildable result type.

sorry, I didn’t describe the problem clearly: why tensor::DimOp have the inferReturnTypes() methond without the definition at ods and attachInterface?

It may be auto-generated, see mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp: OpEmitter::genTypeInterfaceMethods()

thanks for your reply, still a little confusion:
at the ODS(don’t define the InferTypeOpInterface ):
def Tensor_DimOp : Tensor_Op<“dim”, [
DeclareOpInterfaceMethods<OpAsmOpInterface, [“getAsmResultNames”]>,
ConditionallySpeculatable, NoMemoryEffect,
ShapedDimOpInterface]> {
}

after tablegen(it have the InferTypeOpInterface trait):
class DimOp : public ::mlir::Op<DimOp, ::mlir::OpTrait::ZeroRegions, ::mlir::OpTrait::OneResult, ::mlir::OpTrait::OneTypedResult<::mlir::IndexType>::Impl, ::mlir::OpTrait::ZeroSuccessors, ::mlir::OpTrait::NOperands<2>::Impl, ::mlir::OpTrait::OpInvariants, ::mlir::OpAsmOpInterface::Trait, ::mlir::ConditionallySpeculatable::Trait, ::mlir::MemoryEffectOpInterface::Trait, ::mlir::ShapedDimOpInterface::Trait, ::mlir::InferTypeOpInterface::Trait> {
}

why?

The trait gets added automatically when it can be generated: https://github.com/llvm/llvm-project/blob/c661c4f57613b5f85af94ee4e905708e0ba820f8/mlir/lib/TableGen/Operator.cpp#L543-L545

1 Like

Yes, if you include the interface header that says you want type Inference (which we could make even clearer) and if the return types can be easily inferred (e.g., simple buildable type, result type equals input type etc) then that trait is added (as the trait is what inference is keyed on) and the inference function generated.

1 Like

clearly now, thanks very much。

PS: about some questions about iree, discuss at this forum or at the iree’s github?

thanks