From: Jacques Pienaar Date: Sat, 18 Sep 2021 13:57:51 +0000 (-0700) Subject: [mlir-c] Add getting fused loc X-Git-Tag: upstream/15.0.7~31168 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a1e569d37e04c75632633d77c7d3f0fb5126b46;p=platform%2Fupstream%2Fllvm.git [mlir-c] Add getting fused loc For creating a fused loc using array of locations and metadata. Differential Revision: https://reviews.llvm.org/D110022 --- diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h index d875e38..28a83cb 100644 --- a/mlir/include/mlir-c/IR.h +++ b/mlir/include/mlir-c/IR.h @@ -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. diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp index bbadc35..eda1763 100644 --- a/mlir/lib/CAPI/IR/IR.cpp +++ b/mlir/lib/CAPI/IR/IR.cpp @@ -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 locs; + ArrayRef 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)) diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c index d1bdb66..ebb8b0f 100644 --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -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