10 changes: 8 additions & 2 deletions mlir/lib/Pass/PassDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@
#include "mlir/IR/Action.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/FormatVariadic.h"

namespace mlir {
/// Encapsulate the "action" of executing a single pass, used for the MLIR
/// tracing infrastructure.
struct PassExecutionAction : public tracing::ActionImpl<PassExecutionAction> {
PassExecutionAction(const Pass &pass, Operation *op) : pass(pass), op(op) {}
using Base = tracing::ActionImpl<PassExecutionAction>;
PassExecutionAction(ArrayRef<IRUnit> irUnits, const Pass &pass)
: Base(irUnits), pass(pass) {}
static constexpr StringLiteral tag = "pass-execution-action";
void print(raw_ostream &os) const override;
const Pass &getPass() const { return pass; }
Operation *getOp() const { return op; }
Operation *getOp() const {
ArrayRef<IRUnit> irUnits = getContextIRUnits();
return irUnits.empty() ? nullptr : irUnits[0].dyn_cast<Operation *>();
}

public:
const Pass &pass;
Expand Down
19 changes: 4 additions & 15 deletions mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,23 +516,12 @@ std::optional<lsp::Hover> MLIRDocument::buildHoverForOperation(

os << "Generic Form:\n\n```mlir\n";

// Temporary drop the regions of this operation so that they don't get
// printed in the output. This helps keeps the size of the output hover
// small.
SmallVector<std::unique_ptr<Region>> regions;
for (Region &region : op.op->getRegions()) {
regions.emplace_back(std::make_unique<Region>());
regions.back()->takeBody(region);
}

op.op->print(
os, OpPrintingFlags().printGenericOpForm().elideLargeElementsAttrs());
op.op->print(os, OpPrintingFlags()
.printGenericOpForm()
.elideLargeElementsAttrs()
.skipRegions());
os << "\n```\n";

// Move the regions back to the current operation.
for (Region &region : op.op->getRegions())
region.takeBody(*regions.back());

return hover;
}

Expand Down
9 changes: 5 additions & 4 deletions mlir/test/Pass/action-logging.mlir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: mlir-opt %s --log-actions-to=- -canonicalize -test-module-pass | FileCheck %s

// CHECK: [thread {{.*}}] begins (no breakpoint) Action `pass-execution-action` running `Canonicalizer` on Operation `builtin.module`
// CHECK: [thread {{.*}}] completed `pass-execution-action`
// CHECK: [thread {{.*}}] begins (no breakpoint) Action `pass-execution-action` running `(anonymous namespace)::TestModulePass` on Operation `builtin.module`
// CHECK: [thread {{.*}}] completed `pass-execution-action`
// CHECK: [thread {{.*}}] begins (no breakpoint) Action `pass-execution-action` running `Canonicalizer` on Operation `builtin.module` (module {...}
// CHECK-NEXT: [thread {{.*}}] completed `pass-execution-action`
// CHECK-NEXT: [thread {{.*}}] begins (no breakpoint) Action `pass-execution-action` running `{{.*}}TestModulePass` on Operation `builtin.module` (module {...}
// CHECK-NEXT: [thread {{.*}}] completed `pass-execution-action`
// CHECK-NOT: Action
4 changes: 2 additions & 2 deletions mlir/test/mlir-lsp-server/hover.test
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
// CHECK-NEXT: "result": {
// CHECK-NEXT: "contents": {
// CHECK-NEXT: "kind": "markdown",
// CHECK-NEXT: "value": "\"func.func\" : public @foo\n\nGeneric Form:\n\n```mlir\n\"func.func\"() ({\n}) {function_type = (i1) -> (), sym_name = \"foo\"} : () -> ()\n```\n"
// CHECK-NEXT: "value": "\"func.func\" : public @foo\n\nGeneric Form:\n\n```mlir\n\"func.func\"() ({...}) {function_type = (i1) -> (), sym_name = \"foo\"} : () -> ()\n```\n"
// CHECK-NEXT: },
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
Expand All @@ -138,7 +138,7 @@
// CHECK-NEXT: "result": {
// CHECK-NEXT: "contents": {
// CHECK-NEXT: "kind": "markdown",
// CHECK-NEXT: "value": "\"func.func\" : public @foo\n\nGeneric Form:\n\n```mlir\n\"func.func\"() ({\n}) {function_type = (i1) -> (), sym_name = \"foo\"} : () -> ()\n```\n"
// CHECK-NEXT: "value": "\"func.func\" : public @foo\n\nGeneric Form:\n\n```mlir\n\"func.func\"() ({...}) {function_type = (i1) -> (), sym_name = \"foo\"} : () -> ()\n```\n"
// CHECK-NEXT: },
// CHECK-NEXT: "range": {
// CHECK-NEXT: "end": {
Expand Down