This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add a pre-check before checking constraints of an optional attribute.
AbandonedPublic

Authored by hanchung on Mar 30 2020, 4:33 PM.

Details

Summary

When an attribute is optional and if it's missing, a mlir::Attribute() is
created to signal the missing state. In this case, it is a nullptr. This patch
adds a pre-check before checking constraints because there are bunch of
tblgen_attr.isa<...> in a condition template. Otherwise, it fails with an
assertion because it is not valid to apply isa method on a nullptr.

Diff Detail

Event Timeline

hanchung created this revision.Mar 30 2020, 4:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2020, 4:33 PM
antiagainst added inline comments.Mar 31 2020, 1:00 PM
mlir/tools/mlir-tblgen/RewriterGen.cpp
385

What happens if I have a matcher like IntValueIsFive but an op instance does not have the attribute? I would expect the match to fail but per the implementation here, it will succeed because of the check is not performed?

hanchung abandoned this revision.Mar 31 2020, 3:11 PM

Had a quick chat with @antiagainst , this is too aggressive. A proper fix might be using isa_and_nonnull for optional attribute.

With Lei's suggestion, this no longer blocks me. I'm going to close the patch. Thank you, Lei. :)