MLIR
18.0.0git
lib
Dialect
Transform
PDLExtension
PDLExtension.cpp
Go to the documentation of this file.
1
//===- PDLExtension.cpp - PDL extension for the Transform dialect ---------===//
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
9
#include "
mlir/Dialect/Transform/PDLExtension/PDLExtension.h
"
10
#include "
mlir/Dialect/PDL/IR/PDL.h
"
11
#include "
mlir/Dialect/PDL/IR/PDLTypes.h
"
12
#include "
mlir/Dialect/PDLInterp/IR/PDLInterp.h
"
13
#include "
mlir/Dialect/Transform/IR/TransformDialect.h
"
14
#include "
mlir/Dialect/Transform/PDLExtension/PDLExtensionOps.h
"
15
#include "
mlir/IR/DialectRegistry.h
"
16
17
using namespace
mlir
;
18
19
namespace
{
20
/// Implementation of the TransformHandleTypeInterface for the PDL
21
/// OperationType. Accepts any payload operation.
22
struct
PDLOperationTypeTransformHandleTypeInterfaceImpl
23
:
public
transform::TransformHandleTypeInterface::ExternalModel<
24
PDLOperationTypeTransformHandleTypeInterfaceImpl,
25
pdl::OperationType> {
26
27
/// Accept any operation.
28
DiagnosedSilenceableFailure
29
checkPayload(
Type
type,
Location
loc,
ArrayRef<Operation *>
payload)
const
{
30
return
DiagnosedSilenceableFailure::success
();
31
}
32
};
33
}
// namespace
34
35
namespace
{
36
/// PDL extension of the Transform dialect. This provides transform operations
37
/// that connect to PDL matching as well as interfaces for PDL types to be used
38
/// with Transform dialect operations.
39
class
PDLExtension :
public
transform::TransformDialectExtension
<PDLExtension> {
40
public
:
41
void
init() {
42
registerTransformOps<
43
#define GET_OP_LIST
44
#include "mlir/Dialect/Transform/PDLExtension/PDLExtensionOps.cpp.inc"
45
>();
46
47
addDialectDataInitializer<transform::PDLMatchHooks>(
48
[](
transform::PDLMatchHooks
&) {});
49
50
// Declare PDL as dependent so we can attach an interface to its type in the
51
// later step.
52
declareDependentDialect<pdl::PDLDialect>();
53
54
// PDLInterp is only relevant if we actually apply the transform IR so
55
// declare it as generated.
56
declareGeneratedDialect<pdl_interp::PDLInterpDialect>();
57
58
// Make PDL OperationType usable as a transform dialect type.
59
addCustomInitializationStep([](
MLIRContext
*context) {
60
pdl::OperationType::attachInterface<
61
PDLOperationTypeTransformHandleTypeInterfaceImpl>(*context);
62
});
63
}
64
};
65
}
// namespace
66
67
void
mlir::transform::registerPDLExtension
(
DialectRegistry
&dialectRegistry) {
68
dialectRegistry.
addExtensions
<PDLExtension>();
69
}
DialectRegistry.h
PDLExtensionOps.h
PDLExtension.h
PDLInterp.h
PDLTypes.h
TransformDialect.h
llvm::ArrayRef
Definition:
LLVM.h:45
mlir::DiagnosedSilenceableFailure
The result of a transform IR operation application.
Definition:
DiagnosedSilenceableFailure.h:38
mlir::DiagnosedSilenceableFailure::success
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
Definition:
DiagnosedSilenceableFailure.h:48
mlir::DialectRegistry
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Definition:
DialectRegistry.h:139
mlir::DialectRegistry::addExtensions
void addExtensions()
Add the given extensions to the registry.
Definition:
DialectRegistry.h:215
mlir::Location
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition:
Location.h:63
mlir::MLIRContext
MLIRContext is the top-level object for a collection of MLIR operations.
Definition:
MLIRContext.h:60
mlir::Type
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition:
Types.h:74
mlir::transform::PDLMatchHooks
PDL constraint callbacks that can be used by the PDL extension of the Transform dialect.
Definition:
PDLExtensionOps.h:28
mlir::transform::TransformDialectExtension
Base class for extensions of the Transform dialect that supports injecting operations into the Transf...
Definition:
TransformDialect.h:118
PDL.h
mlir::transform::registerPDLExtension
void registerPDLExtension(DialectRegistry &dialectRegistry)
Registers the PDL extension of the Transform dialect in the given registry.
Definition:
PDLExtension.cpp:67
mlir
Include the generated interface declarations.
Definition:
LocalAliasAnalysis.h:20
Generated on Tue Nov 28 2023 08:30:13 for MLIR by
1.9.1