@@ -259,7 +259,7 @@ MlirAttribute mlirLocationGetAttribute(MlirLocation location) {
259259}
260260
261261MlirLocation mlirLocationFromAttribute (MlirAttribute attribute) {
262- return wrap (Location (llvm::cast <LocationAttr>(unwrap (attribute))));
262+ return wrap (Location (llvm::dyn_cast <LocationAttr>(unwrap (attribute))));
263263}
264264
265265MlirLocation mlirLocationFileLineColGet (MlirContext context,
@@ -278,10 +278,64 @@ mlirLocationFileLineColRangeGet(MlirContext context, MlirStringRef filename,
278278 startLine, startCol, endLine, endCol)));
279279}
280280
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+
281317MlirLocation mlirLocationCallSiteGet (MlirLocation callee, MlirLocation caller) {
282318 return wrap (Location (CallSiteLoc::get (unwrap (callee), unwrap (caller))));
283319}
284320
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+
285339MlirLocation mlirLocationFusedGet (MlirContext ctx, intptr_t nLocations,
286340 MlirLocation const *locations,
287341 MlirAttribute metadata) {
@@ -290,6 +344,30 @@ MlirLocation mlirLocationFusedGet(MlirContext ctx, intptr_t nLocations,
290344 return wrap (FusedLoc::get (unwrappedLocs, unwrap (metadata), unwrap (ctx)));
291345}
292346
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+
293371MlirLocation mlirLocationNameGet (MlirContext context, MlirStringRef name,
294372 MlirLocation childLoc) {
295373 if (mlirLocationIsNull (childLoc))
@@ -299,6 +377,21 @@ MlirLocation mlirLocationNameGet(MlirContext context, MlirStringRef name,
299377 StringAttr::get (unwrap (context), unwrap (name)), unwrap (childLoc))));
300378}
301379
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+
302395MlirLocation mlirLocationUnknownGet (MlirContext context) {
303396 return wrap (Location (UnknownLoc::get (unwrap (context))));
304397}
@@ -975,25 +1068,26 @@ bool mlirValueIsAOpResult(MlirValue value) {
9751068}
9761069
9771070MlirBlock mlirBlockArgumentGetOwner (MlirValue value) {
978- return wrap (llvm::cast <BlockArgument>(unwrap (value)).getOwner ());
1071+ return wrap (llvm::dyn_cast <BlockArgument>(unwrap (value)).getOwner ());
9791072}
9801073
9811074intptr_t mlirBlockArgumentGetArgNumber (MlirValue value) {
9821075 return static_cast <intptr_t >(
983- llvm::cast <BlockArgument>(unwrap (value)).getArgNumber ());
1076+ llvm::dyn_cast <BlockArgument>(unwrap (value)).getArgNumber ());
9841077}
9851078
9861079void 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));
9881082}
9891083
9901084MlirOperation mlirOpResultGetOwner (MlirValue value) {
991- return wrap (llvm::cast <OpResult>(unwrap (value)).getOwner ());
1085+ return wrap (llvm::dyn_cast <OpResult>(unwrap (value)).getOwner ());
9921086}
9931087
9941088intptr_t mlirOpResultGetResultNumber (MlirValue value) {
9951089 return static_cast <intptr_t >(
996- llvm::cast <OpResult>(unwrap (value)).getResultNumber ());
1090+ llvm::dyn_cast <OpResult>(unwrap (value)).getResultNumber ());
9971091}
9981092
9991093MlirType mlirValueGetType (MlirValue value) {
@@ -1047,6 +1141,14 @@ void mlirValueReplaceAllUsesExcept(MlirValue oldValue, MlirValue newValue,
10471141 oldValueCpp.replaceAllUsesExcept (newValueCpp, exceptionSet);
10481142}
10491143
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+
10501152// ===----------------------------------------------------------------------===//
10511153// OpOperand API.
10521154// ===----------------------------------------------------------------------===//
0 commit comments