OSDN Git Service

[mlir] Allow for patterns to match any root kind.
authorRiver Riddle <riddleriver@gmail.com>
Thu, 18 Jun 2020 20:58:25 +0000 (13:58 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Thu, 18 Jun 2020 20:58:47 +0000 (13:58 -0700)
commit80d7ac3bc7c04975fd444e9f2806e4db224f2416
treed3de2390aa99586f31903dfd0bb9097360f8a16f
parent3e98fbf4f522bf475ae2199a29f5411c86973ce5
[mlir] Allow for patterns to match any root kind.

Traditionally patterns have always had the root operation kind hardcoded to a specific operation name. This has worked well for quite some time, but it has certain limitations that make it undesirable. For example, some lowering have the same implementation for many different operations types with a few lowering entire dialects using the same pattern implementation. This problem has led to several "solutions":
a) Provide a template implementation to the user so that they can instantiate it for each operation combination, generally requiring the inclusion of the auto-generated operation definition file.
b) Use a non-templated pattern that allows for providing the name of the operation to match
  - No one ever does this, because enumerating operation names can be cumbersome and so this quickly devolves into solution a.

This revision removes the restriction that patterns have a hardcoded root type, and allows for a class patterns that could match "any" operation type. The major downside of root-agnostic patterns is that they make certain pattern analyses more difficult, so it is still very highly encouraged that an operation specific pattern be used whenever possible.

Differential Revision: https://reviews.llvm.org/D82066
mlir/include/mlir/IR/PatternMatch.h
mlir/include/mlir/Transforms/DialectConversion.h
mlir/lib/IR/PatternMatch.cpp
mlir/lib/Transforms/DialectConversion.cpp
mlir/test/Transforms/test-legalize-unknown-root.mlir [new file with mode: 0644]
mlir/test/lib/Dialect/Test/TestPatterns.cpp