Generic dialect conversion pass exercised by LLVM IR lowering
authorAlex Zinenko <zinenko@google.com>
Fri, 25 Jan 2019 20:46:53 +0000 (12:46 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 22:37:23 +0000 (15:37 -0700)
commit6d37a255e2e445671e30b7471283b985cbb34727
treeeceae9808e2a115207ecf99ad4ee274b2f825d4d
parentd9ce382fc9b05953b730ea7476c2dfeb862c6638
Generic dialect conversion pass exercised by LLVM IR lowering

This commit introduces a generic dialect conversion/lowering/legalization pass
and illustrates it on StandardOps->LLVMIR conversion.

It partially reuses the PatternRewriter infrastructure and adds the following
functionality:
- an actual pass;
- non-default pattern constructors;
- one-to-many rewrites;
- rewriting terminators with successors;
- not applying patterns iteratively (unlike the existing greedy rewrite driver);
- ability to change function signature;
- ability to change basic block argument types.

The latter two things required, given the existing API, to create new functions
in the same module.  Eventually, this should converge with the rest of
PatternRewriter.  However, we may want to keep two pass versions: "heavy" with
function/block argument conversion and "light" that only touches operations.

This pass creates new functions within a module as a means to change function
signature, then creates new blocks with converted argument types in the new
function.  Then, it traverses the CFG in DFS-preorder to make sure defs are
converted before uses in the dominated blocks.  The generic pass has a minimal
interface with two hooks: one to fill in the set of patterns, and another one
to convert types for functions and blocks.  The patterns are defined as
separate classes that can be table-generated in the future.

The LLVM IR lowering pass partially inherits from the existing LLVM IR
translator, in particular for type conversion.  It defines a conversion pattern
template, instantiated for different operations, and is a good candidate for
tablegen.  The lowering does not yet support loads and stores and is not
connected to the translator as it would have broken the existing flows.  Future
patches will add missing support before switching the translator in a single
patch.

PiperOrigin-RevId: 230951202
mlir/g3doc/Passes.md
mlir/include/mlir/LLVMIR/llvm_ops.td
mlir/include/mlir/Transforms/DialectConversion.h [new file with mode: 0644]
mlir/include/mlir/Transforms/Passes.h
mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp [new file with mode: 0644]
mlir/lib/Transforms/DialectConversion.cpp [new file with mode: 0644]
mlir/test/LLVMIR/convert-to-llvmir.mlir [new file with mode: 0644]