MLIR 24.0.0git
MathTransformOps.cpp
Go to the documentation of this file.
1//===- MathTransformOps.cpp - Implementation of Math transform ops --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
17
18using namespace mlir;
19
20//===----------------------------------------------------------------------===//
21// Apply...PatternsOp
22//===----------------------------------------------------------------------===//
23
24void transform::ApplyF32ExpansionPatternsOp::populatePatterns(
25 RewritePatternSet &patterns) {
26 populateMathF32ExpansionPatterns(patterns, [](StringRef) { return true; });
27}
28
29void transform::ApplyPolynomialApproximationPatternsOp::populatePatterns(
30 RewritePatternSet &patterns) {
31 bool enableAvx2 = getEnableAvx2();
32 populateMathPolynomialApproximationPatterns(patterns, [&](StringRef name) {
33 // `rsqrt` requires AVX2 so always gate it.
34 return enableAvx2 || name != math::RsqrtOp::getOperationName();
35 });
36}
37
38//===----------------------------------------------------------------------===//
39// Transform op registration
40//===----------------------------------------------------------------------===//
41
42namespace {
43class MathTransformDialectExtension
45 MathTransformDialectExtension> {
46public:
47 MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(MathTransformDialectExtension)
48
49 MathTransformDialectExtension() {
50 declareGeneratedDialect<arith::ArithDialect>();
51 declareGeneratedDialect<math::MathDialect>();
52 declareGeneratedDialect<vector::VectorDialect>();
53 declareGeneratedDialect<x86::X86Dialect>();
54 registerTransformOps<
55#define GET_OP_LIST
56#include "mlir/Dialect/Math/TransformOps/MathTransformOps.cpp.inc"
57 >();
58 }
59};
60} // namespace
61
62#define GET_OP_CLASSES
63#include "mlir/Dialect/Math/TransformOps/MathTransformOps.cpp.inc"
64
66 registry.addExtensions<MathTransformDialectExtension>();
67}
#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)
Definition TypeID.h:331
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtensions()
Add the given extensions to the registry.
Base class for extensions of the Transform dialect that supports injecting operations into the Transf...
void registerTransformDialectExtension(DialectRegistry &registry)
Include the generated interface declarations.
void populateMathF32ExpansionPatterns(RewritePatternSet &patterns, llvm::function_ref< bool(StringRef)> predicate, PatternBenefit=1)
void populateMathPolynomialApproximationPatterns(RewritePatternSet &patterns, llvm::function_ref< bool(StringRef)> predicate, PatternBenefit=1)