[all-commits] [llvm/llvm-project] d289a9: [mlir][PDL] Add a PDL Interpreter Dialect

River Riddle via All-commits all-commits at lists.llvm.org
Wed Aug 26 05:23:59 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: d289a97f91443177b605926668512479c2cee37b
      https://github.com/llvm/llvm-project/commit/d289a97f91443177b605926668512479c2cee37b
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2020-08-26 (Wed, 26 Aug 2020)

  Changed paths:
    M mlir/include/mlir/Dialect/CMakeLists.txt
    M mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
    M mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
    A mlir/include/mlir/Dialect/PDLInterp/CMakeLists.txt
    A mlir/include/mlir/Dialect/PDLInterp/IR/CMakeLists.txt
    A mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h
    A mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
    M mlir/include/mlir/IR/Attributes.h
    M mlir/include/mlir/IR/Builders.h
    M mlir/include/mlir/IR/OpImplementation.h
    M mlir/include/mlir/InitAllDialects.h
    M mlir/lib/Dialect/CMakeLists.txt
    M mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
    M mlir/lib/Dialect/PDL/IR/PDL.cpp
    A mlir/lib/Dialect/PDLInterp/CMakeLists.txt
    A mlir/lib/Dialect/PDLInterp/IR/CMakeLists.txt
    A mlir/lib/Dialect/PDLInterp/IR/PDLInterp.cpp
    M mlir/lib/IR/Builders.cpp
    M mlir/lib/Parser/AttributeParser.cpp
    M mlir/lib/Parser/Parser.cpp
    M mlir/lib/Parser/Parser.h
    M mlir/test/Dialect/PDL/invalid.mlir
    M mlir/test/Dialect/PDL/ops.mlir
    A mlir/test/Dialect/PDLInterp/ops.mlir
    M mlir/tools/mlir-tblgen/OpFormatGen.cpp

  Log Message:
  -----------
  [mlir][PDL] Add a PDL Interpreter Dialect

The PDL Interpreter dialect provides a lower level abstraction compared to the PDL dialect, and is targeted towards low level optimization and interpreter code generation. The dialect operations encapsulates low-level pattern match and rewrite "primitives", such as navigating the IR (Operation::getOperand), creating new operations (OpBuilder::create), etc. Many of the operations within this dialect also fuse branching control flow with some form of a predicate comparison operation. This type of fusion reduces the amount of work that an interpreter must do when executing.

An example of this representation is shown below:

```mlir
// The following high level PDL pattern:
pdl.pattern : benefit(1) {
  %resultType = pdl.type
  %inputOperand = pdl.input
  %root, %results = pdl.operation "foo.op"(%inputOperand) -> %resultType
  pdl.rewrite %root {
    pdl.replace %root with (%inputOperand)
  }
}

// May be represented in the interpreter dialect as follows:
module {
  func @matcher(%arg0: !pdl.operation) {
    pdl_interp.check_operation_name of %arg0 is "foo.op" -> ^bb2, ^bb1
  ^bb1:
    pdl_interp.return
  ^bb2:
    pdl_interp.check_operand_count of %arg0 is 1 -> ^bb3, ^bb1
  ^bb3:
    pdl_interp.check_result_count of %arg0 is 1 -> ^bb4, ^bb1
  ^bb4:
    %0 = pdl_interp.get_operand 0 of %arg0
    pdl_interp.is_not_null %0 : !pdl.value -> ^bb5, ^bb1
  ^bb5:
    %1 = pdl_interp.get_result 0 of %arg0
    pdl_interp.is_not_null %1 : !pdl.value -> ^bb6, ^bb1
  ^bb6:
    pdl_interp.record_match @rewriters::@rewriter(%0, %arg0 : !pdl.value, !pdl.operation) : benefit(1), loc([%arg0]), root("foo.op") -> ^bb1
  }
  module @rewriters {
    func @rewriter(%arg0: !pdl.value, %arg1: !pdl.operation) {
      pdl_interp.replace %arg1 with(%arg0)
      pdl_interp.return
    }
  }
}
```

Differential Revision: https://reviews.llvm.org/D84579




More information about the All-commits mailing list