This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][TableGen] Fix ambiguous build methods when inferring result types.
ClosedPublic

Authored by jurahul on Jul 31 2020, 5:02 PM.

Details

Summary
  • Fix ODS framework to suppress build methods that infer result types and are ambiguous with collective variants. This applies to operations with a single variadic inputs whose result types can be inferred.
  • Extended OpBuildGenTest to test these kinds of ops.

Diff Detail

Event Timeline

jurahul created this revision.Jul 31 2020, 5:02 PM
Herald added a project: Restricted Project. · View Herald Transcript
jurahul requested review of this revision.Jul 31 2020, 5:02 PM

Seems like this will prevent the collision in the short term, but this solution doesn't seem like it will scale as builders get more complex. I'm not opposed to a special case here, but I'd feel more comfortable if there was a more general structure in place to prevent this from scaling to lots of special cases.

I agree. A more general solution might be to generate all "collective" variants first, and then have a way for the build methods that will be ambiguous with any of them automatically filtered out, so that we don't have to guard their generation, just their emission. That might need the OpMethodSignature to have more structure than the current string members. I will file a bug for this assuming folks agree.

I'm happy with filing an issue about it.

This revision is now accepted and ready to land.Aug 3 2020, 11:40 AM

Thanks. @jpienaar, waiting to give you an opportunity to look as well.

I agree. A more general solution might be to generate all "collective" variants first, and then have a way for the build methods that will be ambiguous with any of them automatically filtered out, so that we don't have to guard their generation, just their emission. That might need the OpMethodSignature to have more structure than the current string members. I will file a bug for this assuming folks agree.

Why not have opClass.newMethod flag this? If adding a new method to the class with the same signature, flag it (return nullptr or some such, depending on where the collision occurs it is either fine or an error). Start with the build methods users requested first and then add autogenerated ones as long as they don't conflict. Then we don't have to do gymnastics here. I'd say even the non-collective ones are the more user friendly ones. Although in cases of conflict it provides the same signature so perhaps it doesn't matter which one gets generated.

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
235

s/of/if/

I agree. A more general solution might be to generate all "collective" variants first, and then have a way for the build methods that will be ambiguous with any of them automatically filtered out, so that we don't have to guard their generation, just their emission. That might need the OpMethodSignature to have more structure than the current string members. I will file a bug for this assuming folks agree.

Why not have opClass.newMethod flag this? If adding a new method to the class with the same signature, flag it (return nullptr or some such, depending on where the collision occurs it is either fine or an error). Start with the build methods users requested first and then add autogenerated ones as long as they don't conflict. Then we don't have to do gymnastics here. I'd say even the non-collective ones are the more user friendly ones. Although in cases of conflict it provides the same signature so perhaps it doesn't matter which one gets generated.

That scheme would work as well. Although note ambiguity can come in 2 forms: (a) 2 different methods with exactly same signature (in which case both should be equivalent and generating any one of them is ok) and (b) 2 methods, one having a prefix of arguments as the other and the rest of the arguments in the other all have default values. In such a case, we want to preserve the second one (with more arguments). So ordering the generation of these methods will be important as well if we go with eager pruning. Otherwise, we just record all of them, and do pruning of the ambiguous ones at emission time.

jurahul updated this revision to Diff 284042.Aug 7 2020, 2:02 PM

Fix comment

jpienaar accepted this revision.Aug 10 2020, 9:52 AM

all have default values.

Oh yeah, that gets nasty in checking too. Almost makes me think of fluent style builders ;-)

LG to avoid current issues and we can refactor to avoid it in a more structured way post.

Thanks. Filed https://bugs.llvm.org/show_bug.cgi?id=47095 to tract the more general mechanism for doing this.

This revision was landed with ongoing or failed builds.Aug 10 2020, 10:05 AM
This revision was automatically updated to reflect the committed changes.