MLIR  20.0.0git
DLTITransformOps.cpp
Go to the documentation of this file.
1 
2 //===- DLTITransformOps.cpp - Implementation of DLTI transform ops --------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
12 #include "mlir/Dialect/DLTI/DLTI.h"
16 
17 using namespace mlir;
18 using namespace mlir::transform;
19 
20 #define DEBUG_TYPE "dlti-transforms"
21 
22 //===----------------------------------------------------------------------===//
23 // QueryOp
24 //===----------------------------------------------------------------------===//
25 
26 void transform::QueryOp::getEffects(
28  onlyReadsHandle(getTargetMutable(), effects);
29  producesHandle(getOperation()->getOpResults(), effects);
30  onlyReadsPayload(effects);
31 }
32 
33 DiagnosedSilenceableFailure transform::QueryOp::applyToOne(
34  transform::TransformRewriter &rewriter, Operation *target,
37  for (Attribute key : getKeys()) {
38  if (auto strKey = dyn_cast<StringAttr>(key))
39  keys.push_back(strKey);
40  else if (auto typeKey = dyn_cast<TypeAttr>(key))
41  keys.push_back(typeKey.getValue());
42  else
43  return emitDefiniteFailure("'transform.dlti.query' keys of wrong type: "
44  "only StringAttr and TypeAttr are allowed");
45  }
46 
47  FailureOr<Attribute> result = dlti::query(target, keys, /*emitError=*/true);
48 
49  if (failed(result))
50  return emitSilenceableFailure(getLoc(),
51  "'transform.dlti.query' op failed to apply");
52 
53  results.push_back(*result);
55 }
56 
57 //===----------------------------------------------------------------------===//
58 // Transform op registration
59 //===----------------------------------------------------------------------===//
60 
61 namespace {
62 class DLTITransformDialectExtension
64  DLTITransformDialectExtension> {
65 public:
66  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(DLTITransformDialectExtension)
67 
68  using Base::Base;
69 
70  void init() {
71  registerTransformOps<
72 #define GET_OP_LIST
73 #include "mlir/Dialect/DLTI/TransformOps/DLTITransformOps.cpp.inc"
74  >();
75  }
76 };
77 } // namespace
78 
79 #define GET_OP_CLASSES
80 #include "mlir/Dialect/DLTI/TransformOps/DLTITransformOps.cpp.inc"
81 
83  registry.addExtensions<DLTITransformDialectExtension>();
84 }
#define MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(CLASS_NAME)
Definition: TypeID.h:274
Attributes are known-constant values of operations.
Definition: Attributes.h:25
The result of a transform IR operation application.
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
void addExtensions()
Add the given extensions to the registry.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
A list of results of applying a transform op with ApplyEachOpTrait to a single payload operation,...
void push_back(Operation *op)
Appends an element to the list.
Base class for extensions of the Transform dialect that supports injecting operations into the Transf...
This is a special rewriter to be used in transform op implementations, providing additional helper fu...
The state maintained across applications of various ops implementing the TransformOpInterface.
FailureOr< Attribute > query(Operation *op, ArrayRef< DataLayoutEntryKey > keys, bool emitError=false)
Perform a DLTI-query at op, recursively querying each key of keys on query interface-implementing att...
Definition: DLTI.cpp:510
void registerTransformDialectExtension(DialectRegistry &registry)
void onlyReadsPayload(SmallVectorImpl< MemoryEffects::EffectInstance > &effects)
void producesHandle(ResultRange handles, SmallVectorImpl< MemoryEffects::EffectInstance > &effects)
void onlyReadsHandle(MutableArrayRef< OpOperand > handles, SmallVectorImpl< MemoryEffects::EffectInstance > &effects)
Include the generated interface declarations.
DiagnosedSilenceableFailure emitSilenceableFailure(Location loc, const Twine &message={})
Emits a silenceable failure with the given message.
DiagnosedDefiniteFailure emitDefiniteFailure(Location loc, const Twine &message={})
Emits a definite failure with the given message.