llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.04k stars 11.58k forks source link

[mlir] `FunctionOpInterfaceTrait::getFunctionType()` cause compile error #58504

Open RIvance opened 1 year ago

RIvance commented 1 year ago

Hi!

When I was trying to reproduce the FuncOp operator in the Toy example Ch2, I got a compile error:

/path/to/project/build/include/Toy/ToyOps.h.inc:202:32: error: ‘class mlir::Type’ has no member named ‘getInputs’
  202 |       return getFunctionType().getInputs();
      |                                ^~~~~~~~~

Finding out that FunctionOpInterfaceTrait::getFunctionType() returns mlir::Type instead of mlir::FunctionType, I tried to change the code in CH2/include/toy/Ops.td from

llvm::ArrayRef<mlir::Type> getArgumentTypes() 
{ 
    return getFunctionType().getInputs();
}

to

llvm::ArrayRef<mlir::Type> getArgumentTypes() 
{ 
    return getFunctionType().cast<mlir::FunctionType>().getInputs();
}

this error is gone, but another has appeared:

/path/to/llvm/build/tools/mlir/include/mlir/IR/FunctionOpInterfaces.h.inc:521:67: error: ‘class mlir::Type’ has no member named ‘clone’
  521 |       return (*static_cast<ConcreteOp *>(this)).getFunctionType().clone(inputs, results);
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~

It seems still an issue with the return type of FunctionOpInterfaceTrait::getFunctionType() since mlir::FunctionType does have a clone() method but mlir::Type does not.

This is the environment I was using when this issue occurred:

OS: Arch Linux x86_64
Kernel: linux-6.0.2
Compiler: clang 14.0.6 x86_64-pc-linux-gnu
LLVM & MLIR: 15.0.2 git
Options when compile LLVM & MLIR:
     -DLLVM_ENABLE_PROJECTS=mlir \
     -DLLVM_BUILD_EXAMPLES=ON \
     -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
     -DCMAKE_BUILD_TYPE=Debug \
     -DLLVM_ENABLE_ASSERTIONS=ON \
     -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON \
     -DLLVM_CCACHE_BUILD=OFF \
     -DLLVM_USE_SANITIZER="Address;Undefined"
llvmbot commented 1 year ago

@llvm/issue-subscribers-mlir