MLIR  19.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 
14 
15 using namespace mlir;
16 
17 #define GET_OP_CLASSES
18 #include "mlir/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp.inc"
19 
21 transform::DebugEmitRemarkAtOp::apply(transform::TransformRewriter &rewriter,
24  if (isa<TransformHandleTypeInterface>(getAt().getType())) {
25  auto payload = state.getPayloadOps(getAt());
26  for (Operation *op : payload)
27  op->emitRemark() << getMessage();
29  }
30 
31  assert(isa<transform::TransformValueHandleTypeInterface>(getAt().getType()) &&
32  "unhandled kind of transform type");
33 
34  auto describeValue = [](Diagnostic &os, Value value) {
35  os << "value handle points to ";
36  if (auto arg = llvm::dyn_cast<BlockArgument>(value)) {
37  os << "a block argument #" << arg.getArgNumber() << " in block #"
38  << std::distance(arg.getOwner()->getParent()->begin(),
39  arg.getOwner()->getIterator())
40  << " in region #" << arg.getOwner()->getParent()->getRegionNumber();
41  } else {
42  os << "an op result #" << llvm::cast<OpResult>(value).getResultNumber();
43  }
44  };
45 
46  for (Value value : state.getPayloadValues(getAt())) {
47  InFlightDiagnostic diag = ::emitRemark(value.getLoc()) << getMessage();
48  describeValue(diag.attachNote(), value);
49  }
50 
52 }
53 
54 DiagnosedSilenceableFailure transform::DebugEmitParamAsRemarkOp::apply(
57  std::string str;
58  llvm::raw_string_ostream os(str);
59  if (getMessage())
60  os << *getMessage() << " ";
61  llvm::interleaveComma(state.getParams(getParam()), os);
62  if (!getAnchor()) {
63  emitRemark() << os.str();
65  }
66  for (Operation *payload : state.getPayloadOps(getAnchor()))
67  ::mlir::emitRemark(payload->getLoc()) << os.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.
Definition: Diagnostics.h:156
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:308
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
InFlightDiagnostic emitRemark(const Twine &message={})
Emit a remark about this operation, reporting up to any diagnostic handlers that may be listening.
Definition: Operation.cpp:289
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.
Include the generated interface declarations.
InFlightDiagnostic emitRemark(Location loc)
Utility method to emit a remark message using this location.