[mlir-c] Add getting fused loc
authorJacques Pienaar <jpienaar@google.com>
Sat, 18 Sep 2021 13:57:51 +0000 (06:57 -0700)
committerJacques Pienaar <jpienaar@google.com>
Sat, 18 Sep 2021 13:57:51 +0000 (06:57 -0700)
For creating a fused loc using array of locations and metadata.

Differential Revision: https://reviews.llvm.org/D110022

mlir/include/mlir-c/IR.h
mlir/lib/CAPI/IR/IR.cpp
mlir/test/CAPI/ir.c

index d875e38..28a83cb 100644 (file)
@@ -162,6 +162,11 @@ MLIR_CAPI_EXPORTED MlirLocation mlirLocationFileLineColGet(
 MLIR_CAPI_EXPORTED MlirLocation mlirLocationCallSiteGet(MlirLocation callee,
                                                         MlirLocation caller);
 
+/// Creates a fused location with an array of locations and metadata.
+MLIR_CAPI_EXPORTED MlirLocation
+mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
+                     MlirLocation const *locations, MlirAttribute metadata);
+
 /// Creates a name location owned by the given context. Providing null location
 /// for childLoc is allowed and if childLoc is null location, then the behavior
 /// is the same as having unknown child location.
index bbadc35..eda1763 100644 (file)
@@ -132,6 +132,14 @@ MlirLocation mlirLocationCallSiteGet(MlirLocation callee, MlirLocation caller) {
   return wrap(Location(CallSiteLoc::get(unwrap(callee), unwrap(caller))));
 }
 
+MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
+                                  MlirLocation const *locations,
+                                  MlirAttribute metadata) {
+  SmallVector<Location, 4> locs;
+  ArrayRef<Location> unwrappedLocs = unwrapList(nLocations, locations, locs);
+  return wrap(FusedLoc::get(unwrappedLocs, unwrap(metadata), unwrap(ctx)));
+}
+
 MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name,
                                  MlirLocation childLoc) {
   if (mlirLocationIsNull(childLoc))
index d1bdb66..ebb8b0f 100644 (file)
@@ -1708,6 +1708,10 @@ void testDiagnostics() {
   MlirLocation nameLoc =
       mlirLocationNameGet(ctx, mlirStringRefCreateFromCString("named"), null);
   mlirEmitError(nameLoc, "test diagnostics");
+  MlirLocation locs[2] = {nameLoc, callSiteLoc};
+  MlirAttribute nullAttr = {0};
+  MlirLocation fusedLoc = mlirLocationFusedGet(ctx, 2, locs, nullAttr);
+  mlirEmitError(fusedLoc, "test diagnostics");
   mlirContextDetachDiagnosticHandler(ctx, id);
   mlirEmitError(unknownLoc, "more test diagnostics");
   // CHECK-LABEL: @test_diagnostics
@@ -1727,6 +1731,9 @@ void testDiagnostics() {
   // CHECK:   test diagnostics
   // CHECK:   loc("named")
   // CHECK: >> end of diagnostic (userData: 42)
+  // CHECK: processing diagnostic (userData: 42) <<
+  // CHECK:   test diagnostics
+  // CHECK:   loc(fused["named", callsite("other-file.c":2:3 at "file.c":1:2)])
   // CHECK: deleting user data (userData: 42)
   // CHECK-NOT: processing diagnostic
   // CHECK:     more test diagnostics