mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 01:07:04 +08:00
Implement the Reduction Tree Pass framework as part of the MLIR Reduce tool. This is a parametarizable pass that allows for the implementation of custom reductions passes in the tool. Implement the FunctionReducer class as an example of a Reducer class parameter for the instantiation of a Reduction Tree Pass. Create a pass pipeline with a Reduction Tree Pass with the FunctionReducer class specified as parameter. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D83969
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
//===- Tester.cpp ---------------------------------------------------------===//
|
|
//
|
|
// 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 defines the Tester class used in the MLIR Reduce tool.
|
|
//
|
|
// A Tester object is passed as an argument to the reduction passes and it is
|
|
// used to run the interestigness testing script on the different generated
|
|
// reduced variants of the test case.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Reducer/Tester.h"
|
|
|
|
using namespace mlir;
|
|
|
|
Tester::Tester(StringRef scriptName, ArrayRef<std::string> scriptArgs)
|
|
: testScript(scriptName), testScriptArgs(scriptArgs) {}
|
|
|
|
/// Runs the interestingness testing script on a MLIR test case file. Returns
|
|
/// true if the interesting behavior is present in the test case or false
|
|
/// otherwise.
|
|
bool Tester::isInteresting(StringRef testCase) const {
|
|
|
|
std::vector<StringRef> testerArgs;
|
|
testerArgs.push_back(testCase);
|
|
|
|
for (const std::string &arg : testScriptArgs)
|
|
testerArgs.push_back(arg);
|
|
|
|
testerArgs.push_back(testCase);
|
|
|
|
std::string errMsg;
|
|
int result = llvm::sys::ExecuteAndWait(
|
|
testScript, testerArgs, /*Env=*/None, /*Redirects=*/None,
|
|
/*SecondsToWait=*/0, /*MemoryLimit=*/0, &errMsg);
|
|
|
|
if (result < 0)
|
|
llvm::report_fatal_error("Error running interestingness test: " + errMsg,
|
|
false);
|
|
|
|
if (!result)
|
|
return false;
|
|
|
|
return true;
|
|
}
|