@@ -259,7 +259,7 @@ MlirAttribute mlirLocationGetAttribute(MlirLocation location) {
259
259
}
260
260
261
261
MlirLocation mlirLocationFromAttribute (MlirAttribute attribute) {
262
- return wrap (Location (llvm::cast <LocationAttr>(unwrap (attribute))));
262
+ return wrap (Location (llvm::dyn_cast <LocationAttr>(unwrap (attribute))));
263
263
}
264
264
265
265
MlirLocation mlirLocationFileLineColGet (MlirContext context,
@@ -278,10 +278,64 @@ mlirLocationFileLineColRangeGet(MlirContext context, MlirStringRef filename,
278
278
startLine, startCol, endLine, endCol)));
279
279
}
280
280
281
+ MlirIdentifier mlirLocationFileLineColRangeGetFilename (MlirLocation location) {
282
+ return wrap (llvm::dyn_cast<FileLineColRange>(unwrap (location)).getFilename ());
283
+ }
284
+
285
+ int mlirLocationFileLineColRangeGetStartLine (MlirLocation location) {
286
+ if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap (location)))
287
+ return loc.getStartLine ();
288
+ return -1 ;
289
+ }
290
+
291
+ int mlirLocationFileLineColRangeGetStartColumn (MlirLocation location) {
292
+ if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap (location)))
293
+ return loc.getStartColumn ();
294
+ return -1 ;
295
+ }
296
+
297
+ int mlirLocationFileLineColRangeGetEndLine (MlirLocation location) {
298
+ if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap (location)))
299
+ return loc.getEndLine ();
300
+ return -1 ;
301
+ }
302
+
303
+ int mlirLocationFileLineColRangeGetEndColumn (MlirLocation location) {
304
+ if (auto loc = llvm::dyn_cast<FileLineColRange>(unwrap (location)))
305
+ return loc.getEndColumn ();
306
+ return -1 ;
307
+ }
308
+
309
+ MlirTypeID mlirLocationFileLineColRangeGetTypeID () {
310
+ return wrap (FileLineColRange::getTypeID ());
311
+ }
312
+
313
+ bool mlirLocationIsAFileLineColRange (MlirLocation location) {
314
+ return isa<FileLineColRange>(unwrap (location));
315
+ }
316
+
281
317
MlirLocation mlirLocationCallSiteGet (MlirLocation callee, MlirLocation caller) {
282
318
return wrap (Location (CallSiteLoc::get (unwrap (callee), unwrap (caller))));
283
319
}
284
320
321
+ MlirLocation mlirLocationCallSiteGetCallee (MlirLocation location) {
322
+ return wrap (
323
+ Location (llvm::dyn_cast<CallSiteLoc>(unwrap (location)).getCallee ()));
324
+ }
325
+
326
+ MlirLocation mlirLocationCallSiteGetCaller (MlirLocation location) {
327
+ return wrap (
328
+ Location (llvm::dyn_cast<CallSiteLoc>(unwrap (location)).getCaller ()));
329
+ }
330
+
331
+ MlirTypeID mlirLocationCallSiteGetTypeID () {
332
+ return wrap (CallSiteLoc::getTypeID ());
333
+ }
334
+
335
+ bool mlirLocationIsACallSite (MlirLocation location) {
336
+ return isa<CallSiteLoc>(unwrap (location));
337
+ }
338
+
285
339
MlirLocation mlirLocationFusedGet (MlirContext ctx, intptr_t nLocations,
286
340
MlirLocation const *locations,
287
341
MlirAttribute metadata) {
@@ -290,6 +344,30 @@ MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
290
344
return wrap (FusedLoc::get (unwrappedLocs, unwrap (metadata), unwrap (ctx)));
291
345
}
292
346
347
+ unsigned mlirLocationFusedGetNumLocations (MlirLocation location) {
348
+ if (auto locationsArrRef = llvm::dyn_cast<FusedLoc>(unwrap (location)))
349
+ return locationsArrRef.getLocations ().size ();
350
+ return 0 ;
351
+ }
352
+
353
+ void mlirLocationFusedGetLocations (MlirLocation location,
354
+ MlirLocation *locationsCPtr) {
355
+ if (auto locationsArrRef = llvm::dyn_cast<FusedLoc>(unwrap (location))) {
356
+ for (auto [i, location] : llvm::enumerate (locationsArrRef.getLocations ()))
357
+ locationsCPtr[i] = wrap (location);
358
+ }
359
+ }
360
+
361
+ MlirAttribute mlirLocationFusedGetMetadata (MlirLocation location) {
362
+ return wrap (llvm::dyn_cast<FusedLoc>(unwrap (location)).getMetadata ());
363
+ }
364
+
365
+ MlirTypeID mlirLocationFusedGetTypeID () { return wrap (FusedLoc::getTypeID ()); }
366
+
367
+ bool mlirLocationIsAFused (MlirLocation location) {
368
+ return isa<FusedLoc>(unwrap (location));
369
+ }
370
+
293
371
MlirLocation mlirLocationNameGet (MlirContext context, MlirStringRef name,
294
372
MlirLocation childLoc) {
295
373
if (mlirLocationIsNull (childLoc))
@@ -299,6 +377,21 @@ MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name,
299
377
StringAttr::get (unwrap (context), unwrap (name)), unwrap (childLoc))));
300
378
}
301
379
380
+ MlirIdentifier mlirLocationNameGetName (MlirLocation location) {
381
+ return wrap ((llvm::dyn_cast<NameLoc>(unwrap (location)).getName ()));
382
+ }
383
+
384
+ MlirLocation mlirLocationNameGetChildLoc (MlirLocation location) {
385
+ return wrap (
386
+ Location (llvm::dyn_cast<NameLoc>(unwrap (location)).getChildLoc ()));
387
+ }
388
+
389
+ MlirTypeID mlirLocationNameGetTypeID () { return wrap (NameLoc::getTypeID ()); }
390
+
391
+ bool mlirLocationIsAName (MlirLocation location) {
392
+ return isa<NameLoc>(unwrap (location));
393
+ }
394
+
302
395
MlirLocation mlirLocationUnknownGet (MlirContext context) {
303
396
return wrap (Location (UnknownLoc::get (unwrap (context))));
304
397
}
@@ -975,25 +1068,26 @@ bool mlirValueIsAOpResult(MlirValue value) {
975
1068
}
976
1069
977
1070
MlirBlock mlirBlockArgumentGetOwner (MlirValue value) {
978
- return wrap (llvm::cast <BlockArgument>(unwrap (value)).getOwner ());
1071
+ return wrap (llvm::dyn_cast <BlockArgument>(unwrap (value)).getOwner ());
979
1072
}
980
1073
981
1074
intptr_t mlirBlockArgumentGetArgNumber (MlirValue value) {
982
1075
return static_cast <intptr_t >(
983
- llvm::cast <BlockArgument>(unwrap (value)).getArgNumber ());
1076
+ llvm::dyn_cast <BlockArgument>(unwrap (value)).getArgNumber ());
984
1077
}
985
1078
986
1079
void mlirBlockArgumentSetType (MlirValue value, MlirType type) {
987
- llvm::cast<BlockArgument>(unwrap (value)).setType (unwrap (type));
1080
+ if (auto blockArg = llvm::dyn_cast<BlockArgument>(unwrap (value)))
1081
+ blockArg.setType (unwrap (type));
988
1082
}
989
1083
990
1084
MlirOperation mlirOpResultGetOwner (MlirValue value) {
991
- return wrap (llvm::cast <OpResult>(unwrap (value)).getOwner ());
1085
+ return wrap (llvm::dyn_cast <OpResult>(unwrap (value)).getOwner ());
992
1086
}
993
1087
994
1088
intptr_t mlirOpResultGetResultNumber (MlirValue value) {
995
1089
return static_cast <intptr_t >(
996
- llvm::cast <OpResult>(unwrap (value)).getResultNumber ());
1090
+ llvm::dyn_cast <OpResult>(unwrap (value)).getResultNumber ());
997
1091
}
998
1092
999
1093
MlirType mlirValueGetType (MlirValue value) {
@@ -1047,6 +1141,14 @@ void mlirValueReplaceAllUsesExcept(MlirValue oldValue, MlirValue newValue,
1047
1141
oldValueCpp.replaceAllUsesExcept (newValueCpp, exceptionSet);
1048
1142
}
1049
1143
1144
+ MlirLocation mlirValueGetLocation (MlirValue v) {
1145
+ return wrap (unwrap (v).getLoc ());
1146
+ }
1147
+
1148
+ MlirContext mlirValueGetContext (MlirValue v) {
1149
+ return wrap (unwrap (v).getContext ());
1150
+ }
1151
+
1050
1152
// ===----------------------------------------------------------------------===//
1051
1153
// OpOperand API.
1052
1154
// ===----------------------------------------------------------------------===//
0 commit comments