[llvm-branch-commits] [mlir] 4a327bd - Add call site location getter to C API
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 17 10:03:49 PST 2020
Author: George
Date: 2020-12-17T09:55:21-08:00
New Revision: 4a327bd25289efdfb1c466b119e6e55fadebfc42
URL: https://github.com/llvm/llvm-project/commit/4a327bd25289efdfb1c466b119e6e55fadebfc42
DIFF: https://github.com/llvm/llvm-project/commit/4a327bd25289efdfb1c466b119e6e55fadebfc42.diff
LOG: Add call site location getter to C API
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D93334
Added:
Modified:
mlir/include/mlir-c/IR.h
mlir/lib/CAPI/IR/IR.cpp
mlir/test/CAPI/ir.c
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h
index 74c90af5b4d5..13e32be049e4 100644
--- a/mlir/include/mlir-c/IR.h
+++ b/mlir/include/mlir-c/IR.h
@@ -147,6 +147,10 @@ MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect);
MLIR_CAPI_EXPORTED MlirLocation mlirLocationFileLineColGet(
MlirContext context, MlirStringRef filename, unsigned line, unsigned col);
+/// Creates a call site location with a callee and a caller.
+MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
+ MlirLocation caller);
+
/// Creates a location with unknown position owned by the given context.
MLIR_CAPI_EXPORTED MlirLocation mlirLocationUnknownGet(MlirContext context);
diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index c5a78a2235fc..4de39490cea0 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -116,6 +116,10 @@ MlirLocation mlirLocationFileLineColGet(MlirContext context,
FileLineColLoc::get(unwrap(filename), line, col, unwrap(context)));
}
+MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller) {
+ return wrap(CallSiteLoc::get(unwrap(callee), unwrap(caller)));
+}
+
MlirLocation mlirLocationUnknownGet(MlirContext context) {
return wrap(UnknownLoc::get(unwrap(context)));
}
diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index a785d6ab4899..434f272de059 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -1295,7 +1295,7 @@ MlirLogicalResult errorHandler(MlirDiagnostic diagnostic, void *userData) {
MlirLocation loc = mlirDiagnosticGetLocation(diagnostic);
mlirLocationPrint(loc, printToStderr, NULL);
assert(mlirDiagnosticGetNumNotes(diagnostic) == 0);
- fprintf(stderr, ">> end of diagnostic (userData: %ld)\n", (long)userData);
+ fprintf(stderr, "\n>> end of diagnostic (userData: %ld)\n", (long)userData);
return mlirLogicalResultSuccess();
}
@@ -1308,16 +1308,32 @@ void testDiagnostics() {
MlirContext ctx = mlirContextCreate();
MlirDiagnosticHandlerID id = mlirContextAttachDiagnosticHandler(
ctx, errorHandler, (void *)42, deleteUserData);
- MlirLocation loc = mlirLocationUnknownGet(ctx);
fprintf(stderr, "@test_diagnostics\n");
- mlirEmitError(loc, "test diagnostics");
+ MlirLocation unknownLoc = mlirLocationUnknownGet(ctx);
+ mlirEmitError(unknownLoc, "test diagnostics");
+ MlirLocation fileLineColLoc = mlirLocationFileLineColGet(
+ ctx, mlirStringRefCreateFromCString("file.c"), 1, 2);
+ mlirEmitError(fileLineColLoc, "test diagnostics");
+ MlirLocation callSiteLoc = mlirLocationCallSiteGet(
+ mlirLocationFileLineColGet(
+ ctx, mlirStringRefCreateFromCString("other-file.c"), 2, 3),
+ fileLineColLoc);
+ mlirEmitError(callSiteLoc, "test diagnostics");
mlirContextDetachDiagnosticHandler(ctx, id);
- mlirEmitError(loc, "more test diagnostics");
+ mlirEmitError(unknownLoc, "more test diagnostics");
// CHECK-LABEL: @test_diagnostics
// CHECK: processing diagnostic (userData: 42) <<
// CHECK: test diagnostics
// CHECK: loc(unknown)
// CHECK: >> end of diagnostic (userData: 42)
+ // CHECK: processing diagnostic (userData: 42) <<
+ // CHECK: test diagnostics
+ // CHECK: loc("file.c":1:2)
+ // CHECK: >> end of diagnostic (userData: 42)
+ // CHECK: processing diagnostic (userData: 42) <<
+ // CHECK: test diagnostics
+ // CHECK: loc(callsite("other-file.c":2:3 at "file.c":1:2))
+ // CHECK: >> end of diagnostic (userData: 42)
// CHECK: deleting user data (userData: 42)
// CHECK-NOT: processing diagnostic
// CHECK: more test diagnostics
More information about the llvm-branch-commits
mailing list