[PATCH] D71851: Use the first location in the fused location for diagnostic handler

Feng Liu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 14:35:40 PST 2020


liufengdb updated this revision to Diff 236456.
liufengdb added a comment.
Herald added subscribers: lucyrfox, mgester, arpith-jacob, nicolasvasilache.

fix the rebase error


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71851/new/

https://reviews.llvm.org/D71851

Files:
  mlir/test/IR/diagnostic-handler.mlir
  mlir/test/lib/Transforms/CMakeLists.txt
  mlir/test/lib/Transforms/TestDiagnosticHandler.cpp


Index: mlir/test/lib/Transforms/TestDiagnosticHandler.cpp
===================================================================
--- /dev/null
+++ mlir/test/lib/Transforms/TestDiagnosticHandler.cpp
@@ -0,0 +1,43 @@
+//===- TestDiagnosticHandler.cpp - Pass to test diagnostic handler --------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/StandardOps/Ops.h"
+#include "mlir/Pass/Pass.h"
+
+using namespace mlir;
+
+namespace {
+struct TestSourceMgrDiagnosticHandler : public SourceMgrDiagnosticHandler {
+  explicit TestSourceMgrDiagnosticHandler(llvm::SourceMgr &mgr,
+                                                MLIRContext *ctx)
+      : SourceMgrDiagnosticHandler(mgr, ctx, llvm::outs()) {}
+
+  void emitTestDiagnostic(Operation *op) {
+        Diagnostic diag(op->getLoc(), DiagnosticSeverity::Note);
+    emitDiagnostic(diag);
+  }
+};
+
+/// Pass that emit diagnostic for each op.
+struct TestDiagnosticHandler : public FunctionPass<TestDiagnosticHandler> {
+
+  void runOnFunction() override {
+    llvm::SourceMgr fileSourceMgr;
+        TestSourceMgrDiagnosticHandler diagHandler(fileSourceMgr, &getContext());
+    getFunction().walk([&](Operation *op) {
+      if (isa<FuncOp>(op) || op->isKnownTerminator())
+        return;
+      diagHandler.emitTestDiagnostic(op);
+    });
+  }
+};
+
+} // end anonymous namespace
+
+static PassRegistration<TestDiagnosticHandler> pass("test-diagnostic-handler",
+                                                        "emit diagnostic for ops");
Index: mlir/test/lib/Transforms/CMakeLists.txt
===================================================================
--- mlir/test/lib/Transforms/CMakeLists.txt
+++ mlir/test/lib/Transforms/CMakeLists.txt
@@ -1,6 +1,7 @@
 add_llvm_library(MLIRTestTransforms
   TestCallGraph.cpp
   TestConstantFold.cpp
+  TestDiagnosticHandler.cpp
   TestLoopFusion.cpp
   TestInlining.cpp
   TestLinalgTransforms.cpp
Index: mlir/test/IR/diagnostic-handler.mlir
===================================================================
--- /dev/null
+++ mlir/test/IR/diagnostic-handler.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt %s -test-diagnostic-handler | FileCheck %s
+// This test verifies that diagnostic handler can emit the call stack successfully.
+
+func @call_site_loc_in_fused() -> i32 {
+  // CHECK: mysource1: note:
+  // CHECK: mysource2: note: called from
+  // CHECK: mysource3: note: called from
+  %3 = constant 3 : i32 loc(fused[callsite("foo"("mysource1":0:0) at callsite("mysource2":1:0 at "mysource3":2:0)), "bar"])
+  return %3 : i32
+}
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71851.236456.patch
Type: text/x-patch
Size: 2840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200106/a24bcc4e/attachment.bin>


More information about the llvm-commits mailing list