This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Infer SubElementInterface implementations using the storage KeyTy
ClosedPublic

Authored by rriddle on Nov 3 2022, 4:07 PM.

Details

Summary

The KeyTy of attribute/type storage classes provide enough information for
automatically implementing the necessary sub element interface methods. This
removes the need for derived classes to do it themselves, which is both much
nicer and easier to handle certain invariants (e.g. null handling). In cases where
explicitly handling for parameter types is necessary, they can provide an implementation
of AttrTypeSubElementHandler to opt-in to support.

This tickles a few things alias wise, which annoyingly messes with tests that hard
code specific affine map numbers.

Diff Detail

Event Timeline

rriddle created this revision.Nov 3 2022, 4:07 PM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
rriddle requested review of this revision.Nov 3 2022, 4:07 PM

Amazing

mlir/include/mlir/IR/SubElementInterfaces.h
94

I'm not sure this is better than just indexing directly into the array and casting. This is begging for an msvc problem where

get(repl.extract<IntegerAttr>(), reply.extract<FloatAttr>());

Crashes because the argument expressions are evaluated in reverse.

mlir/include/mlir/IR/SubElementInterfaces.td
59

QQ where is derviedValue coming from?

rriddle marked 2 inline comments as done.Nov 3 2022, 5:06 PM
rriddle added inline comments.
mlir/include/mlir/IR/SubElementInterfaces.h
94

Not sure what you mean here. This is exactly what we do in a lot of cases already, given that at least for attributes they are guaranteed to be the same size. If this would break, it would have broken a long time ago. It would only break iff they could have different things in them depending on the platform, but that isn't the case here.

mlir/include/mlir/IR/SubElementInterfaces.td
59

It's a template parameter in the class (SubElementInterfaceBase), which expands to either $_attr or $_type depending on the interface.

rriddle marked 2 inline comments as done.Nov 3 2022, 5:08 PM
rriddle added inline comments.
mlir/include/mlir/IR/SubElementInterfaces.h
94

Good point re: order of evaluation (I hate C++). Will fix that.

rriddle added inline comments.Nov 3 2022, 5:53 PM
mlir/include/mlir/IR/SubElementInterfaces.h
94

Updated to check size as well (for MSVC bad times). It's really just an optimization, so we can just skip it in the cases where MSVC is dumb.

rriddle updated this revision to Diff 473093.Nov 3 2022, 6:12 PM
rriddle edited the summary of this revision. (Show Details)
Mogball accepted this revision.Nov 3 2022, 6:20 PM
This revision is now accepted and ready to land.Nov 3 2022, 6:20 PM
rriddle updated this revision to Diff 473144.Nov 4 2022, 12:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 12:28 AM