Skip to content

Commit 9d71a85

Browse files
Alex-Wenggclaude
andcommitted
[Codegen] Move ErrorCheckingTrackingListener out of iree-dialects (#24466)
Relocate ErrorCheckingTrackingListener into Codegen/Common (namespace mlir::iree_compiler) and repoint its users in the Common and LLVMGPU transform extensions. Drop the StructuredTransformOpsExtension registration and includes from CommonDialectRegistration and Interfaces: its transform ops (transform.iree.register_match_callbacks/match_callback/take_first/emit_remark) have no production users and their tests were removed in #24500. Build deps are updated accordingly. Progress toward retiring the iree-dialects dependency. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5fac8b2 commit 9d71a85

14 files changed

Lines changed: 98 additions & 27 deletions

File tree

compiler/src/iree/compiler/Codegen/Common/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ iree_compiler_cc_library(
103103
"EncodingUtils.cpp",
104104
"EraseDeadAllocAndStores.cpp",
105105
"EraseHALDescriptorTypeFromMemRef.cpp",
106+
"ErrorCheckingTrackingListener.cpp",
106107
"FastMathPatterns.cpp",
107108
"FissionTransferOpsInControlFlow.cpp",
108109
"FlattenMemRefSubspan.cpp",
@@ -190,6 +191,7 @@ iree_compiler_cc_library(
190191
"CombineLayoutTransformation.h",
191192
"EmulateNarrowType.h",
192193
"EncodingUtils.h",
194+
"ErrorCheckingTrackingListener.h",
193195
"FastMathPatterns.h",
194196
"PassUtils.h",
195197
"Passes.h",
@@ -234,7 +236,6 @@ iree_compiler_cc_library(
234236
"//compiler/src/iree/compiler/Dialect/Util/IR",
235237
"//compiler/src/iree/compiler/Dialect/Util/Transforms",
236238
"//compiler/src/iree/compiler/Utils",
237-
"//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
238239
"@llvm-project//llvm:Support",
239240
"@llvm-project//mlir:AMDGPUDialect",
240241
"@llvm-project//mlir:AMDGPUTransforms",
@@ -331,7 +332,6 @@ iree_compiler_cc_library(
331332
"//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
332333
"//compiler/src/iree/compiler/Dialect/LinalgExt/TransformExtensions:LinalgExtExtensions",
333334
"//compiler/src/iree/compiler/Dialect/TensorExt/IR",
334-
"//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
335335
"//compiler/src/iree/compiler/Codegen/Dialect/VectorExt/IR:IREEVectorExtDialect",
336336
"@llvm-project//mlir:AffineDialect",
337337
"@llvm-project//mlir:AffineUtils",
@@ -376,7 +376,6 @@ iree_compiler_cc_library(
376376
"@llvm-project//mlir:Support",
377377
"@llvm-project//mlir:DialectUtils",
378378
# TransformExtensions (needed for registration in the pass)
379-
"//llvm-external-projects/iree-dialects:IREEDialectsTransforms",
380379
"//compiler/src/iree/compiler/Codegen/Common/TransformExtensions:CommonExtensions",
381380
"//compiler/src/iree/compiler/Codegen/LLVMCPU/TransformExtensions:LLVMCPUExtensions",
382381
"//compiler/src/iree/compiler/Codegen/LLVMGPU/TransformExtensions:LLVMGPUExtensions",

compiler/src/iree/compiler/Codegen/Common/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ iree_cc_library(
5656
"CombineLayoutTransformation.h"
5757
"EmulateNarrowType.h"
5858
"EncodingUtils.h"
59+
"ErrorCheckingTrackingListener.h"
5960
"FastMathPatterns.h"
6061
"PassUtils.h"
6162
"Passes.h"
@@ -96,6 +97,7 @@ iree_cc_library(
9697
"EncodingUtils.cpp"
9798
"EraseDeadAllocAndStores.cpp"
9899
"EraseHALDescriptorTypeFromMemRef.cpp"
100+
"ErrorCheckingTrackingListener.cpp"
99101
"FastMathPatterns.cpp"
100102
"FissionTransferOpsInControlFlow.cpp"
101103
"FlattenMemRefSubspan.cpp"
@@ -180,7 +182,6 @@ iree_cc_library(
180182
DEPS
181183
::PassHeaders
182184
::PassesIncGen
183-
IREELinalgTransformDialect
184185
LLVMSupport
185186
MLIRAMDGPUDialect
186187
MLIRAMDGPUTransforms
@@ -286,8 +287,6 @@ iree_cc_library(
286287
::Common
287288
::PassHeaders
288289
::PassesIncGen
289-
IREEDialectsTransforms
290-
IREELinalgTransformDialect
291290
LLVMSupport
292291
MLIRAMDGPUTransforms
293292
MLIRAffineDialect

compiler/src/iree/compiler/Codegen/Common/CommonDialectRegistration.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
#include "iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.h"
87
#include "iree/compiler/Codegen/Common/TransformExtensions/CommonExtensions.h"
98
#include "iree/compiler/Codegen/Dialect/Codegen/IR/IREECodegenDialect.h"
109
#include "iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUDialect.h"
@@ -97,8 +96,7 @@ void registerTransformDialectTranslationDependentDialects(
9796
vector::registerBufferizableOpInterfaceExternalModels(registry);
9897

9998
registry.addExtensions<
100-
mlir::iree_compiler::IREE::LinalgExt::LinalgExtTransformOpsExtension,
101-
transform_ext::StructuredTransformOpsExtension>();
99+
mlir::iree_compiler::IREE::LinalgExt::LinalgExtTransformOpsExtension>();
102100
iree_compiler::registerTransformDialectCommonExtension(registry);
103101
iree_compiler::registerTransformDialectLLVMCPUExtension(registry);
104102
iree_compiler::registerTransformDialectLLVMGPUExtension(registry);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2022 The IREE Authors
2+
//
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#include "iree/compiler/Codegen/Common/ErrorCheckingTrackingListener.h"
8+
9+
#include "mlir/Dialect/SCF/IR/SCF.h"
10+
#include "llvm/Support/Debug.h"
11+
12+
#define DEBUG_TYPE "iree-codegen-error-checking-tracking-listener"
13+
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
14+
15+
namespace mlir::iree_compiler {
16+
17+
void ErrorCheckingTrackingListener::notifyPayloadReplacementNotFound(
18+
Operation *op, ValueRange values, DiagnosedSilenceableFailure &&diag) {
19+
// Certain ops can dropped safely.
20+
if (isa<scf::ForOp>(op)) {
21+
LLVM_DEBUG(DBGS() << "Silently dropping scf.for op mapping\n");
22+
return;
23+
}
24+
25+
SmallVector<Diagnostic> diags;
26+
diag.takeDiagnostics(diags);
27+
if (!status.succeeded()) {
28+
status.takeDiagnostics(diags);
29+
}
30+
status = DiagnosedSilenceableFailure::silenceableFailure(std::move(diags));
31+
32+
status = emitSilenceableFailure(
33+
getTransformOp(), "!!! tracking listener failed to find replacement op");
34+
status.attachNote(op->getLoc()) << "replaced op";
35+
for (Value v : values) {
36+
status.attachNote(v.getLoc()) << "replacement value";
37+
}
38+
}
39+
40+
} // namespace mlir::iree_compiler
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2022 The IREE Authors
2+
//
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#ifndef IREE_COMPILER_CODEGEN_COMMON_ERRORCHECKINGTRACKINGLISTENER_H_
8+
#define IREE_COMPILER_CODEGEN_COMMON_ERRORCHECKINGTRACKINGLISTENER_H_
9+
10+
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
11+
12+
namespace mlir::iree_compiler {
13+
14+
/// A tracking listener for tensor IR that checks for payload replacement
15+
/// errors.
16+
class ErrorCheckingTrackingListener : public transform::TrackingListener {
17+
public:
18+
using transform::TrackingListener::TrackingListener;
19+
20+
~ErrorCheckingTrackingListener() override {
21+
assert(status.succeeded() && "must check listener error state");
22+
}
23+
24+
/// Return "true" if this tracking listener had a failure.
25+
bool failed() const { return !status.succeeded(); }
26+
27+
/// Check and return the current error state of this listener. In case of a
28+
/// failure state, only the most recent error is returned. Afterwards, resets
29+
/// the error state.
30+
DiagnosedSilenceableFailure checkAndResetError() {
31+
DiagnosedSilenceableFailure result(std::move(status));
32+
status = DiagnosedSilenceableFailure::success();
33+
return result;
34+
}
35+
36+
private:
37+
void
38+
notifyPayloadReplacementNotFound(Operation *op, ValueRange values,
39+
DiagnosedSilenceableFailure &&diag) override;
40+
41+
/// The error state of this listener. "Success" indicates that no error
42+
/// happened so far. Otherwise, the status contains the most recent error.
43+
DiagnosedSilenceableFailure status = DiagnosedSilenceableFailure::success();
44+
};
45+
46+
} // namespace mlir::iree_compiler
47+
48+
#endif // IREE_COMPILER_CODEGEN_COMMON_ERRORCHECKINGTRACKINGLISTENER_H_

compiler/src/iree/compiler/Codegen/Common/TransformExtensions/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ iree_compiler_cc_library(
7575
"//compiler/src/iree/compiler/Codegen/Utils",
7676
"//compiler/src/iree/compiler/Dialect/HAL/IR",
7777
"//compiler/src/iree/compiler/Dialect/LinalgExt/IR",
78-
"//llvm-external-projects/iree-dialects:IREEDialectsTransforms",
79-
"//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
8078
"@llvm-project//llvm:Support",
8179
"@llvm-project//mlir:AffineDialect",
8280
"@llvm-project//mlir:AffineUtils",

compiler/src/iree/compiler/Codegen/Common/TransformExtensions/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ iree_cc_library(
3131
"CommonExtensionsOps.cpp.inc"
3232
DEPS
3333
::CommonExtensionsOpGen
34-
IREEDialectsTransforms
35-
IREELinalgTransformDialect
3634
LLVMSupport
3735
MLIRAffineDialect
3836
MLIRAffineUtils

compiler/src/iree/compiler/Codegen/Common/TransformExtensions/CommonExtensions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
#include "CommonExtensions.h"
88

9-
#include "iree-dialects/Dialect/LinalgTransform/StructuredTransformOpsExt.h"
10-
#include "iree-dialects/Transforms/TransformMatchers.h"
9+
#include "iree/compiler/Codegen/Common/ErrorCheckingTrackingListener.h"
1110
#include "iree/compiler/Codegen/Common/GPU/GPUPatterns.h"
1211
#include "iree/compiler/Codegen/Common/GPU/GPUVectorDistribution.h"
1312
#include "iree/compiler/Codegen/Common/GPU/Passes.h"
@@ -48,6 +47,7 @@
4847
#include "mlir/Dialect/SCF/Utils/Utils.h"
4948
#include "mlir/Dialect/Tensor/IR/Tensor.h"
5049
#include "mlir/Dialect/Tensor/Transforms/Transforms.h"
50+
#include "mlir/Dialect/Transform/IR/TransformTypes.h"
5151
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
5252
#include "mlir/Dialect/Utils/StaticValueUtils.h"
5353
#include "mlir/Dialect/Vector/IR/VectorOps.h"

compiler/src/iree/compiler/Codegen/Interfaces/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ iree_compiler_cc_library(
6161
"//compiler/src/iree/compiler/Codegen/Dialect/PCF/ExternalInterfaces:ExternalModels",
6262
"//compiler/src/iree/compiler/Codegen/ExternalInterfaces:ExternalModels",
6363
"//compiler/src/iree/compiler/Dialect/LinalgExt/TransformExtensions:LinalgExtExtensions",
64-
"//llvm-external-projects/iree-dialects:IREELinalgTransformDialect",
6564
"@llvm-project//mlir:IR",
6665
"@llvm-project//mlir:LinalgTransforms",
6766
"@llvm-project//mlir:SideEffectInterfaces",

compiler/src/iree/compiler/Codegen/Interfaces/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ iree_cc_library(
2525
::TensorMaskingOpInterface
2626
::UKernelOpInterface
2727
::VectorizableOpInterface
28-
IREELinalgTransformDialect
2928
MLIRAMDGPUDialect
3029
MLIRAffineDialect
3130
MLIRAffineTransformOps

0 commit comments

Comments
 (0)