Files
clang-p2996/mlir/test/lib/Dialect/Test/TestTraits.cpp
ahmedsabie c0b3abd19a [MLIR] Add a foldTrait() mechanism to allow traits to define folding and test it with an Involution trait
This is the same diff as https://reviews.llvm.org/D88809/ except side effect
free check is removed for involution and a FIXME is added until the dependency
is resolved for shared builds. The old diff has more details on possible fixes.

Reviewed By: rriddle, andyly

Differential Revision: https://reviews.llvm.org/D89333
2020-10-13 21:26:21 +00:00

46 lines
1.5 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 "TestDialect.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Transforms/FoldUtils.h"
using namespace mlir;
//===----------------------------------------------------------------------===//
// Trait Folder.
//===----------------------------------------------------------------------===//
OpFoldResult TestInvolutionTraitFailingOperationFolderOp::fold(
ArrayRef<Attribute> operands) {
// This failure should cause the trait fold to run instead.
return {};
}
OpFoldResult TestInvolutionTraitSuccesfulOperationFolderOp::fold(
ArrayRef<Attribute> operands) {
auto argument_op = getOperand();
// The success case should cause the trait fold to be supressed.
return argument_op.getDefiningOp() ? argument_op : OpFoldResult{};
}
namespace {
struct TestTraitFolder : public PassWrapper<TestTraitFolder, FunctionPass> {
void runOnFunction() override {
applyPatternsAndFoldGreedily(getFunction(), {});
}
};
} // end anonymous namespace
namespace mlir {
void registerTestTraitsPass() {
PassRegistration<TestTraitFolder>("test-trait-folder", "Run trait folding");
}
} // namespace mlir