Files
clang-p2996/mlir/test/lib/Dialect/Test/TestTraits.cpp
Jeff Niu e95e94adc6 [mlir][test] Reorganize the test dialect (#89424)
This PR massively reorganizes the Test dialect's source files. It moves
manually-written op hooks into `TestOpDefs.cpp`, moves format custom
directive parsers and printers into `TestFormatUtils`, adds missing
comment blocks, and moves around where generated source files are
included for types, attributes, enums, etc. into their own source file.

This will hopefully help navigate the test dialect source code, but also
speeds up compile time of the test dialect by putting generated source
files into separate compilation units.

This also sets up the test dialect to shard its op definitions, done in
the next PR.
2024-04-22 13:42:05 -07:00

50 lines
1.7 KiB
C++

//===- TestTraits.cpp - Test trait folding --------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "TestOps.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
using namespace mlir;
using namespace test;
//===----------------------------------------------------------------------===//
// Trait Folder.
//===----------------------------------------------------------------------===//
OpFoldResult TestInvolutionTraitFailingOperationFolderOp::fold(
FoldAdaptor adaptor) {
// This failure should cause the trait fold to run instead.
return {};
}
OpFoldResult TestInvolutionTraitSuccesfulOperationFolderOp::fold(
FoldAdaptor adaptor) {
auto argumentOp = getOperand();
// The success case should cause the trait fold to be supressed.
return argumentOp.getDefiningOp() ? argumentOp : OpFoldResult{};
}
namespace {
struct TestTraitFolder
: public PassWrapper<TestTraitFolder, OperationPass<func::FuncOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTraitFolder)
StringRef getArgument() const final { return "test-trait-folder"; }
StringRef getDescription() const final { return "Run trait folding"; }
void runOnOperation() override {
(void)applyPatternsAndFoldGreedily(getOperation(),
RewritePatternSet(&getContext()));
}
};
} // namespace
namespace mlir {
void registerTestTraitsPass() { PassRegistration<TestTraitFolder>(); }
} // namespace mlir