MLIR 22.0.0git
DebugExtensionOps.cpp
Go to the documentation of this file.
1//===- DebugExtensionOps.cpp - Debug 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
10
12#include "llvm/Support/InterleavedRange.h"
13
14using namespace mlir;
15
16#define GET_OP_CLASSES
17#include "mlir/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp.inc"
18
20transform::EmitRemarkAtOp::apply(transform::TransformRewriter &rewriter,
23 if (isa<TransformHandleTypeInterface>(getAt().getType())) {
24 auto payload = state.getPayloadOps(getAt());
25 for (Operation *op : payload)
26 op->emitRemark() << getMessage();
28 }
29
30 assert(isa<transform::TransformValueHandleTypeInterface>(getAt().getType()) &&
31 "unhandled kind of transform type");
32
33 auto describeValue = [](Diagnostic &os, Value value) {
34 os << "value handle points to ";
35 if (auto arg = llvm::dyn_cast<BlockArgument>(value)) {
36 os << "a block argument #" << arg.getArgNumber() << " in block #"
37 << std::distance(arg.getOwner()->getParent()->begin(),
38 arg.getOwner()->getIterator())
39 << " in region #" << arg.getOwner()->getParent()->getRegionNumber();
40 } else {
41 os << "an op result #" << llvm::cast<OpResult>(value).getResultNumber();
42 }
43 };
44
45 for (Value value : state.getPayloadValues(getAt())) {
46 InFlightDiagnostic diag = ::emitRemark(value.getLoc()) << getMessage();
47 describeValue(diag.attachNote(), value);
48 }
49
51}
52
54transform::EmitParamAsRemarkOp::apply(transform::TransformRewriter &rewriter,
57 std::string str;
58 llvm::raw_string_ostream os(str);
59 if (getMessage())
60 os << *getMessage() << " ";
61 os << llvm::interleaved(state.getParams(getParam()));
62 if (!getAnchor()) {
63 emitRemark() << str;
65 }
66 for (Operation *payload : state.getPayloadOps(getAnchor()))
67 ::mlir::emitRemark(payload->getLoc()) << str;
69}
static std::string diag(const llvm::Value &value)
The result of a transform IR operation application.
static DiagnosedSilenceableFailure success()
Constructs a DiagnosedSilenceableFailure in the success state.
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine.
This class represents a diagnostic that is inflight and set to be reported.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Local mapping between values defined by a specific op implementing the TransformOpInterface and the p...
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.
auto getPayloadOps(Value value) const
Returns an iterator that enumerates all ops that the given transform IR value corresponds to.
auto getPayloadValues(Value handleValue) const
Returns an iterator that enumerates all payload IR values that the given transform IR value correspon...
ArrayRef< Attribute > getParams(Value value) const
Returns the list of parameters that the given transform IR value corresponds to.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
Definition Utils.cpp:304
InFlightDiagnostic emitRemark(Location loc)
Utility method to emit a remark message using this location.