The other day while I was reducing a test case, I found the need for some generic ops that I can use to stand-in for arbitrary other ops Say I’m debugging an op, which I suspect to be the cause of an error:
%7861 = "some.op"(%7855, %7832) : (!some.type, !some.other_type) -> !yet.another_type
... computation that uses %7861
While reducing the test case, one natural thing is to replace “some.op” with a dummy op that creates the value %7861 (or in general there might be multiple results as well). We don’t seem to have a std op that lets me do that. I propose a std.source
op that lets us do that.
%7861 = source : !yet.another_type
... computation that uses %7861
The same applies to a “sink” op. Consider the same starting IR snippet as above, but now we believe there is something about the use of %7855
which is problematic. Then I can delete the op and replace it with just
sink %7855 : !some.type
Ops with these semantics are also useful for testing passes. For many scenarios one can use function arguments / returns as “source”/“sink”, but in the presence of control flow that approach falls down.
In LLVM-land (or when reducing at the C++ level), we typically would spell them as external functions, but in MLIR that’s not always possible, since there is an open-ended notion of what a “function” could be. Depending on the context it’s not obvious (or just not possible) how to create a “call to an external function”.
Just as in the case of LLVM test case reduction with external functions, there is never any intent to actually execute the code at runtime. It’s just a structural device to tickle a compiler bug.
Another option here is to just use an op in an unregistered dialect. That works somewhat well, but requires passing -mlir-allow-unregistered dialect
and is generally more typing and cognitive overhead. Also, I made the std.source
op in the patch be NoSideEffect (which I think is usually what is desired), which is not possible with an unregistered op. (also, the test dialect is not linked in by most users of MLIR, so having these ops there doesn’t materially help)
What do folks think?