2019-11-21 06:29:41 -08:00
|
|
|
//===- TestLinalgTransforms.cpp - Test Linalg transformation patterns -----===//
|
|
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-11-21 06:29:41 -08:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-11-21 06:29:41 -08:00
|
|
|
//
|
|
|
|
|
// This file implements logic for testing Linalg transformations.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
|
|
|
|
|
#include "mlir/Dialect/Linalg/Transforms/LinalgTransforms.h"
|
|
|
|
|
#include "mlir/IR/PatternMatch.h"
|
|
|
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
using namespace mlir::linalg;
|
|
|
|
|
|
|
|
|
|
namespace mlir {
|
|
|
|
|
namespace linalg {
|
|
|
|
|
namespace {
|
|
|
|
|
#include "TestLinalgTransformPatterns.h.inc"
|
|
|
|
|
} // end namespace
|
|
|
|
|
} // end namespace linalg
|
|
|
|
|
} // end namespace mlir
|
|
|
|
|
|
|
|
|
|
namespace {
|
2020-04-07 13:56:16 -07:00
|
|
|
struct TestLinalgTransforms
|
|
|
|
|
: public PassWrapper<TestLinalgTransforms, FunctionPass> {
|
2019-11-21 06:29:41 -08:00
|
|
|
void runOnFunction() override;
|
|
|
|
|
};
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
|
|
/// Apply transformations specified as patterns.
|
|
|
|
|
void TestLinalgTransforms::runOnFunction() {
|
|
|
|
|
OwningRewritePatternList patterns;
|
|
|
|
|
auto funcOp = getFunction();
|
|
|
|
|
|
|
|
|
|
// Add the generated patterns to the list.
|
|
|
|
|
linalg::populateWithGenerated(&getContext(), &patterns);
|
2020-04-05 06:54:16 +05:30
|
|
|
applyPatternsAndFoldGreedily(funcOp, patterns);
|
2019-11-21 06:29:41 -08:00
|
|
|
|
|
|
|
|
// Drop the marker.
|
|
|
|
|
funcOp.walk([](LinalgOp op) {
|
|
|
|
|
op.removeAttr(LinalgTransforms::kLinalgTransformMarker);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 09:03:40 +00:00
|
|
|
namespace mlir {
|
|
|
|
|
void registerTestLinalgTransforms() {
|
|
|
|
|
PassRegistration<TestLinalgTransforms>(
|
|
|
|
|
"test-linalg-transform-patterns",
|
|
|
|
|
"Test Linalg transformation patterns by applying them greedily.");
|
|
|
|
|
}
|
|
|
|
|
} // namespace mlir
|