1 //===- TestReducer.cpp - Test MLIR Reduce ---------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
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
;
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";
49 void registerTestReducer() { PassRegistration
<TestReducer
>(); }