llvm-project
adc79c09 - [mlir][tosa] Fix crash in validation pass when dialect is not loaded (#173449)

Commit
22 days ago
[mlir][tosa] Fix crash in validation pass when dialect is not loaded (#173449) ## Summary This PR fixes #173370 in the `tosa-validate` pass that occurs when the input IR does not contain any TOSA operations. **Crash Message:** ```text LLVM ERROR: can't create Attribute 'mlir::tosa::TargetEnvAttr' because storage uniquer isn't initialized: the dialect was likely not loaded, or the attribute wasn't added with addAttributes<...>() in the Dialect::initialize() method. ``` ## Problem When `mlir-opt` parses an input file without TOSA operations, the `TosaDialect` is not lazily loaded. However, the `TosaValidation` pass previously called `lookupTargetEnvOrDefault` (which attempts to create a `TargetEnvAttr`) before checking if the dialect was loaded. This resulted in an assertion failure because the attribute storage uniquer was not initialized. ## Solution I resolved the issue by placing the `TosaDialect` declaration at the very top of `runOnOperation`. This ensures that `lookupTargetEnvOrDefault` is not accessed when the dialect is uninitialized, preventing the crash. ## Test Added two test in `mlir/test/Dialect/Tosa/tosa_validation_init.mlir`. First case is without TOSA operation. ``` // CHECK-LABEL: func.func @test_validation_pass_init func.func @test_validation_pass_init(%arg0: tensor<1xf32>) -> tensor<1xf32> { // CHECK: math.asin %0 = math.asin %arg0 : tensor<1xf32> return %0 : tensor<1xf32> } ``` Second case is with TOSA Operation. ``` // CHECK-LABEL: func.func @test_tosa_ops func.func @test_tosa_ops(%arg0: tensor<1x2x3x4xf32>, %arg1: tensor<1x2x3x4xf32>) -> tensor<1x2x3x4xf32> { // CHECK: tosa.add %0 = tosa.add %arg0, %arg1 : (tensor<1x2x3x4xf32>, tensor<1x2x3x4xf32>) -> tensor<1x2x3x4xf32> return %0 : tensor<1x2x3x4xf32> } ```
Author
Parents
Loading