Running passes in transform ops + dealing with dependent dialects of those passes

I want to run a pass inside of a Transform dialect extension operation.

My pass is a conversion pass, and the dialect being converted to (my_target_dialect) is listed as a “dependentDialect” of the pass. When I execute my transform IR using something like this:

// RUN: mlir-opt -test-transform-dialect-interpreter %s

... some IR...

transform.sequence failures(propagate) {
^bb1(%arg1: !pdl.operation):
  %0 = transform.my_extension.run_conversion_pass %arg1
}

Then I get an error

LVM ERROR: Loading a dialect (my_target_dialect) while in a multi-threaded execution context

Stack trace indicates this is a result of the PassManager trying to load the pass’s dependent dialect my_target_dialect.

Which is the right answer?

  1. Declare my_target_dialect as a dependent dialect of my source dialect
  2. Declare my_target_dialect as a dependent dialect in my Transform op extension registration
  3. Something else?

My understanding is that the first two options are not really for this purpose (but they do solve the problem). The transform dialect header here specifically says that (2) shouldn’t be used for this purpose.

Perhaps the comment is meant to suggest that the declareGeneratedDialect() function should be used instead, as dialects passed to that function can be skipped if the extension is created with buildOnly = true.

Here is an instance of this function being called in IREE:

(Just a guess…)

1 Like

Oh completely missed that, thanks!

This is correct. Fixes to clarify documentation are most welcome.

@cbate note that we now have the ability to run passes and even conversions (see e.g. https://reviews.llvm.org/D157723).
This uncovered a bunch of consistency issues across conversion passes that we are still in the process of addressing but I thought I’d flag this in case it is useful to you.