forked from OSchip/llvm-project
Create TestReducer pass
- Create a pass that generates bugs based on trivially defined behavior for the purpose of testing the MLIR Reduce Tool. - Implement the functionality inside the pass to crash mlir-opt in the presence of an operation with the name "crashOp". - Register the pass as a test pass in the mlir-opt tool. Reviewed by: jpienaar Differential Revision: https://reviews.llvm.org/D83422
This commit is contained in:
parent
3a5617c02e
commit
16e9ccb2be
|
@ -2,4 +2,5 @@ add_subdirectory(DeclarativeTransforms)
|
|||
add_subdirectory(Dialect)
|
||||
add_subdirectory(IR)
|
||||
add_subdirectory(Pass)
|
||||
add_subdirectory(Reducer)
|
||||
add_subdirectory(Transforms)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Exclude tests from libMLIR.so
|
||||
add_mlir_library(MLIRTestReducer
|
||||
MLIRTestReducer.cpp
|
||||
|
||||
EXCLUDE_FROM_LIBMLIR
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
|
||||
|
||||
LINK_COMPONENTS
|
||||
Core
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRIR
|
||||
MLIRPass
|
||||
MLIRSupport
|
||||
)
|
|
@ -0,0 +1,54 @@
|
|||
//===- TestReducer.cpp - Test MLIR Reduce ---------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements a pass that reproduces errors based on trivially defined
|
||||
// patterns. It is used as a buggy optimization pass for the purpose of testing
|
||||
// the MLIR Reduce tool.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/Pass/Pass.h"
|
||||
|
||||
#define PASS_NAME "test-mlir-reducer"
|
||||
|
||||
using namespace mlir;
|
||||
|
||||
static llvm::cl::OptionCategory clOptionsCategory(PASS_NAME " options");
|
||||
|
||||
namespace {
|
||||
|
||||
/// This pass looks for for the presence of an operation with the name
|
||||
/// "crashOp" in the input MLIR file and crashes the mlir-opt tool if the
|
||||
/// operation is found.
|
||||
struct TestReducer : public PassWrapper<TestReducer, FunctionPass> {
|
||||
TestReducer() = default;
|
||||
TestReducer(const TestReducer &pass){};
|
||||
void runOnFunction() override;
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
void TestReducer::runOnFunction() {
|
||||
for (auto &op : getOperation())
|
||||
op.walk([&](Operation *op) {
|
||||
StringRef opName = op->getName().getStringRef();
|
||||
|
||||
if (opName == "test.crashOp") {
|
||||
llvm::errs() << "MLIR Reducer Test generated failure: Found "
|
||||
"\"crashOp\" operation\n";
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
namespace mlir {
|
||||
void registerTestReducer() {
|
||||
PassRegistration<TestReducer>(
|
||||
PASS_NAME, "Tests MLIR Reduce tool by generating failures");
|
||||
}
|
||||
} // namespace mlir
|
|
@ -0,0 +1,7 @@
|
|||
// RUN: mlir-opt %s
|
||||
// RUN: not mlir-opt %s -test-mlir-reducer
|
||||
|
||||
func @test() {
|
||||
"test.crashOp"() : () -> ()
|
||||
return
|
||||
}
|
|
@ -17,6 +17,7 @@ if(MLIR_INCLUDE_TESTS)
|
|||
MLIRTestDialect
|
||||
MLIRTestIR
|
||||
MLIRTestPass
|
||||
MLIRTestReducer
|
||||
MLIRTestTransforms
|
||||
)
|
||||
endif()
|
||||
|
|
|
@ -64,6 +64,7 @@ void registerTestMemRefStrideCalculation();
|
|||
void registerTestOpaqueLoc();
|
||||
void registerTestParallelismDetection();
|
||||
void registerTestPreparationPassWithAllowedMemrefResults();
|
||||
void registerTestReducer();
|
||||
void registerTestGpuParallelLoopMappingPass();
|
||||
void registerTestSCFUtilsPass();
|
||||
void registerTestVectorConversions();
|
||||
|
@ -139,6 +140,7 @@ void registerTestPasses() {
|
|||
registerTestOpaqueLoc();
|
||||
registerTestParallelismDetection();
|
||||
registerTestPreparationPassWithAllowedMemrefResults();
|
||||
registerTestReducer();
|
||||
registerTestGpuParallelLoopMappingPass();
|
||||
registerTestSCFUtilsPass();
|
||||
registerTestVectorConversions();
|
||||
|
|
Loading…
Reference in New Issue