This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Simplify a few cast implementations
ClosedPublic

Authored by rkayaith on Jan 29 2023, 8:40 PM.

Details

Summary

{Attribute,Type}::classof are never actually called at runtime due to
the early exit in their CastInfo implementations. By using `if
constexpr` we can avoid needing to define them.

We also don't need to check is_same_v here, since this is already
covered by is_base_of_v.

Diff Detail

Event Timeline

rkayaith created this revision.Jan 29 2023, 8:40 PM
Herald added a project: Restricted Project. · View Herald Transcript
rkayaith retitled this revision from [mlir] Remove unnecessary classof functions to [mlir] Remove unnecessary classof definitions.Jan 29 2023, 9:30 PM
rkayaith edited the summary of this revision. (Show Details)
rkayaith published this revision for review.Jan 29 2023, 9:46 PM
rriddle accepted this revision.Jan 29 2023, 10:09 PM
This revision is now accepted and ready to land.Jan 29 2023, 10:09 PM
rkayaith added inline comments.Jan 31 2023, 11:04 AM
mlir/include/mlir/IR/Attributes.h
394

On second look I'm not sure why is_same_v is used here, since is_base_of_v<T, T> is already true for the types we care about: https://en.cppreference.com/w/cpp/types/is_base_of

rkayaith updated this revision to Diff 493807.Jan 31 2023, 6:39 PM
rkayaith retitled this revision from [mlir] Remove unnecessary classof definitions to [mlir] Simplify a few cast implementations.
rkayaith edited the summary of this revision. (Show Details)

remove is_same_v check

This revision was automatically updated to reflect the committed changes.

FYI, we get a lot of

/workdir/llvm-project/mlir/include/mlir/IR/Attributes.h:391:49: warning: parameter 'ty' set but not used [-Wunused-but-set-parameter]
  391 |   static inline bool isPossible(mlir::Attribute ty) {

warning as it appears that ty is not seen as used. Would it be possible to add a fake use?
Apologies as it may be compiler specific

FYI, we get a lot of

/workdir/llvm-project/mlir/include/mlir/IR/Attributes.h:391:49: warning: parameter 'ty' set but not used [-Wunused-but-set-parameter]
  391 |   static inline bool isPossible(mlir::Attribute ty) {

warning as it appears that ty is not seen as used. Would it be possible to add a fake use?
Apologies as it may be compiler specific

Which compiler are you using? It's a bit unfortunate it warns here. I'm not sure exactly what the policy is for warnings, but if your compiler falls under LLVM's supported compilers (https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library) then it seems reasonable to me to work around it.

Here is what our virtual machine is using:

--   System                    : Linux
--   C++ compiler              : /usr/bin/c++
--   C++ compiler version      : 9.3.0

and

root@1250b049ac2b:~/workspace/atests/ops# /usr/bin/c++ -v
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

I am not sure how we arrived at this compiler, I can check if that can be changed or not. It is what we use to deliver onnx-mlir on our x86 / Power / Z linux machines at IBM.

AlexEichenberger added a comment.EditedFeb 15 2023, 6:59 AM

I see from your convenient link that our gcc compiler 9.3.0 which is more recent than the minimum recommendation of LLVM which is 7.1

I see from your convenient link that our gcc compiler 9.3.0 which is more recent than the minimum recommendation of LLVM which is 7.1

I pushed 82ae83a8487df0747195d1abbda11920fda11eb8 to silence these.