brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 496facd Raw
51 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements a pass that reproduces errors based on trivially defined10// patterns. It is used as a buggy optimization pass for the purpose of testing11// the MLIR Reduce tool.12//13//===----------------------------------------------------------------------===//14 15#include "mlir/Pass/Pass.h"16 17using namespace mlir;18 19namespace {20 21/// This pass looks for the presence of an operation with the name22/// "crashOp" in the input MLIR file and crashes the mlir-opt tool if the23/// operation is found.24struct TestReducer : public PassWrapper<TestReducer, OperationPass<>> {25  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestReducer)26 27  StringRef getArgument() const final { return "test-mlir-reducer"; }28  StringRef getDescription() const final {29    return "Tests MLIR Reduce tool by generating failures";30  }31  void runOnOperation() override;32};33 34} // namespace35 36void TestReducer::runOnOperation() {37  getOperation()->walk([&](Operation *op) {38    StringRef opName = op->getName().getStringRef();39 40    if (opName.contains("op_crash")) {41      llvm::errs() << "MLIR Reducer Test generated failure: Found "42                      "\"crashOp\" operation\n";43      exit(1);44    }45  });46}47 48namespace mlir {49void registerTestReducer() { PassRegistration<TestReducer>(); }50} // namespace mlir51