[clang-tidy][NFC]remove deps of clang in clang tidy test (#116588)
[llvm-project.git] / mlir / test / lib / Reducer / MLIRTestReducer.cpp
blob496facd3125d5cd40012fa69e3553e3bb5c51009
1 //===- TestReducer.cpp - Test MLIR Reduce ---------------------------------===//
2 //
3 // Part of the LLVM Project, 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 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a pass that reproduces errors based on trivially defined
10 // patterns. It is used as a buggy optimization pass for the purpose of testing
11 // the MLIR Reduce tool.
13 //===----------------------------------------------------------------------===//
15 #include "mlir/Pass/Pass.h"
17 using namespace mlir;
19 namespace {
21 /// This pass looks for the presence of an operation with the name
22 /// "crashOp" in the input MLIR file and crashes the mlir-opt tool if the
23 /// operation is found.
24 struct TestReducer : public PassWrapper<TestReducer, OperationPass<>> {
25 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestReducer)
27 StringRef getArgument() const final { return "test-mlir-reducer"; }
28 StringRef getDescription() const final {
29 return "Tests MLIR Reduce tool by generating failures";
31 void runOnOperation() override;
34 } // namespace
36 void TestReducer::runOnOperation() {
37 getOperation()->walk([&](Operation *op) {
38 StringRef opName = op->getName().getStringRef();
40 if (opName.contains("op_crash")) {
41 llvm::errs() << "MLIR Reducer Test generated failure: Found "
42 "\"crashOp\" operation\n";
43 exit(1);
45 });
48 namespace mlir {
49 void registerTestReducer() { PassRegistration<TestReducer>(); }
50 } // namespace mlir