Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matthias-springer/61fa7e65ea56490104eec684eddf6dcd to your computer and use it in GitHub Desktop.
Save matthias-springer/61fa7e65ea56490104eec684eddf6dcd to your computer and use it in GitHub Desktop.
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload"
module attributes {transform.target_tag="payload"} {
func.func @test(%f0: f32, %f1: f32, %out: memref<3xf32>) {
// Create a new tensor with [%f0, %f0, %f0].
%0 = tensor.from_elements %f0, %f0, %f0 : tensor<3xf32>
bufferization.materialize_in_destination %0 in restrict writable %out
: (tensor<3xf32>, memref<3xf32>) -> ()
func.return
}
}
transform.sequence failures(propagate) {
^bb0(%module1: !transform.any_op):
// Rewrite tensor.from_elements in destination-passing style
%from_elements = transform.structured.match ops{["tensor.from_elements"]}
in %module1 : (!transform.any_op) -> !transform.any_op
transform.structured.rewrite_in_destination_passing_style %from_elements
: (!transform.any_op) -> !transform.any_op
// Eliminate empty tensors
transform.bufferization.eliminate_empty_tensors %module1 : !transform.any_op
// Bufferize
%module2 = transform.bufferization.one_shot_bufferize %module1
: (!transform.any_op) -> !transform.any_op
// Canonicalize + CSE
transform.apply_patterns to %module2 {
transform.apply_patterns.canonicalization
} {apply_cse} : !transform.any_op
// Deallocate buffers
%module3 = transform.apply_registered_pass
"buffer-deallocation-pipeline" to %module2
: (!transform.any_op) -> !transform.any_op
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment