Skip to content

Instantly share code, notes, and snippets.

@makslevental
Created February 28, 2025 15:58
Show Gist options
  • Save makslevental/e24addcf89be7557646fada9af583812 to your computer and use it in GitHub Desktop.
Save makslevental/e24addcf89be7557646fada9af583812 to your computer and use it in GitHub Desktop.
MLIR_CAPI_EXPORTED MlirAttribute mlirCallSiteLocAttrGet(Location callee, Location caller, MlirContext mlirContext);
MLIR_CAPI_EXPORTED Location mlirCallSiteLocGetcallee(MlirAttribute mlirCallSiteLoc);
MLIR_CAPI_EXPORTED Location mlirCallSiteLocGetcaller(MlirAttribute mlirCallSiteLoc);
MLIR_CAPI_EXPORTED MlirAttribute mlirFileLineColRangeAttrGet(StringAttr filename, unsigned start_line, unsigned start_column, unsigned end_line, unsigned end_column, MlirContext mlirContext);
MLIR_CAPI_EXPORTED StringAttr mlirFileLineColRangeGetfilename(MlirAttribute mlirFileLineColRange);
MLIR_CAPI_EXPORTED unsigned mlirFileLineColRangeGetstart_line(MlirAttribute mlirFileLineColRange);
MLIR_CAPI_EXPORTED unsigned mlirFileLineColRangeGetstart_column(MlirAttribute mlirFileLineColRange);
MLIR_CAPI_EXPORTED unsigned mlirFileLineColRangeGetend_line(MlirAttribute mlirFileLineColRange);
MLIR_CAPI_EXPORTED unsigned mlirFileLineColRangeGetend_column(MlirAttribute mlirFileLineColRange);
MLIR_CAPI_EXPORTED MlirAttribute mlirFusedLocAttrGet(Location *locations, unsigned nlocationss, MlirAttribute metadata, MlirContext mlirContext);
MLIR_CAPI_EXPORTED void mlirFusedLocGetlocations(MlirAttribute mlirFusedLoc, Location** locationsPtr, unsigned *nlocationss);
MLIR_CAPI_EXPORTED MlirAttribute mlirFusedLocGetmetadata(MlirAttribute mlirFusedLoc);
MLIR_CAPI_EXPORTED MlirAttribute mlirNameLocAttrGet(StringAttr name, Location childLoc, MlirContext mlirContext);
MLIR_CAPI_EXPORTED StringAttr mlirNameLocGetname(MlirAttribute mlirNameLoc);
MLIR_CAPI_EXPORTED Location mlirNameLocGetchildLoc(MlirAttribute mlirNameLoc);
MLIR_CAPI_EXPORTED MlirAttribute mlirOpaqueLocAttrGet(uintptr_t underlyingLocation, TypeID underlyingTypeID, Location fallbackLocation, MlirContext mlirContext);
MLIR_CAPI_EXPORTED uintptr_t mlirOpaqueLocGetunderlyingLocation(MlirAttribute mlirOpaqueLoc);
MLIR_CAPI_EXPORTED TypeID mlirOpaqueLocGetunderlyingTypeID(MlirAttribute mlirOpaqueLoc);
MLIR_CAPI_EXPORTED Location mlirOpaqueLocGetfallbackLocation(MlirAttribute mlirOpaqueLoc);
MlirAttribute mlirCallSiteLocAttrGet(Location callee, Location caller, MlirContext mlirContext) {
mlir::MLIRContext* context = unwrap(mlirContext);
Location callee_ = callee;
Location caller_ = caller;
return wrap(CallSiteLoc::get(context, callee_, caller_));
}
Location mlirCallSiteLocGetcallee(MlirAttribute mlirCallSiteLoc) {
return llvm::cast<CallSiteLoc>(unwrap(mlirCallSiteLoc)).getCallee();
}
Location mlirCallSiteLocGetcaller(MlirAttribute mlirCallSiteLoc) {
return llvm::cast<CallSiteLoc>(unwrap(mlirCallSiteLoc)).getCaller();
}
MlirAttribute mlirFileLineColRangeAttrGet(StringAttr filename, unsigned start_line, unsigned start_column, unsigned end_line, unsigned end_column, MlirContext mlirContext) {
mlir::MLIRContext* context = unwrap(mlirContext);
StringAttr filename_ = filename;
unsigned start_line_ = start_line;
unsigned start_column_ = start_column;
unsigned end_line_ = end_line;
unsigned end_column_ = end_column;
return wrap(FileLineColRange::get(context, filename_, start_line_, start_column_, end_line_, end_column_));
}
StringAttr mlirFileLineColRangeGetfilename(MlirAttribute mlirFileLineColRange) {
return llvm::cast<FileLineColRange>(unwrap(mlirFileLineColRange)).getFilename();
}
unsigned mlirFileLineColRangeGetstart_line(MlirAttribute mlirFileLineColRange) {
return llvm::cast<FileLineColRange>(unwrap(mlirFileLineColRange)).getStartLine();
}
unsigned mlirFileLineColRangeGetstart_column(MlirAttribute mlirFileLineColRange) {
return llvm::cast<FileLineColRange>(unwrap(mlirFileLineColRange)).getStartColumn();
}
unsigned mlirFileLineColRangeGetend_line(MlirAttribute mlirFileLineColRange) {
return llvm::cast<FileLineColRange>(unwrap(mlirFileLineColRange)).getEndLine();
}
unsigned mlirFileLineColRangeGetend_column(MlirAttribute mlirFileLineColRange) {
return llvm::cast<FileLineColRange>(unwrap(mlirFileLineColRange)).getEndColumn();
}
MlirAttribute mlirFusedLocAttrGet(Location *locations, unsigned nlocationss, MlirAttribute metadata, MlirContext mlirContext) {
mlir::MLIRContext* context = unwrap(mlirContext);
::llvm::ArrayRef<Location> locations_ = {locations, nlocationss};
Attribute metadata_ = llvm::cast<Attribute>(unwrap(metadata));
return wrap(FusedLoc::get(context, locations_, metadata_));
}
void mlirFusedLocGetlocations(MlirAttribute mlirFusedLoc, Location** locationsPtr, unsigned *nlocationss) {
::llvm::ArrayRef<Location> locations = llvm::cast<FusedLoc>(unwrap(mlirFusedLoc)).getLocations();
*nlocationss = locations.size();
*locationsPtr = const_cast<Location*>(locations.data());
}
MlirAttribute mlirFusedLocGetmetadata(MlirAttribute mlirFusedLoc) {
return wrap(llvm::cast<FusedLoc>(unwrap(mlirFusedLoc)).getMetadata());
}
MlirAttribute mlirNameLocAttrGet(StringAttr name, Location childLoc, MlirContext mlirContext) {
mlir::MLIRContext* context = unwrap(mlirContext);
StringAttr name_ = name;
Location childLoc_ = childLoc;
return wrap(NameLoc::get(context, name_, childLoc_));
}
StringAttr mlirNameLocGetname(MlirAttribute mlirNameLoc) {
return llvm::cast<NameLoc>(unwrap(mlirNameLoc)).getName();
}
Location mlirNameLocGetchildLoc(MlirAttribute mlirNameLoc) {
return llvm::cast<NameLoc>(unwrap(mlirNameLoc)).getChildLoc();
}
MlirAttribute mlirOpaqueLocAttrGet(uintptr_t underlyingLocation, TypeID underlyingTypeID, Location fallbackLocation, MlirContext mlirContext) {
mlir::MLIRContext* context = unwrap(mlirContext);
uintptr_t underlyingLocation_ = underlyingLocation;
TypeID underlyingTypeID_ = underlyingTypeID;
Location fallbackLocation_ = fallbackLocation;
return wrap(OpaqueLoc::get(context, underlyingLocation_, underlyingTypeID_, fallbackLocation_));
}
uintptr_t mlirOpaqueLocGetunderlyingLocation(MlirAttribute mlirOpaqueLoc) {
return llvm::cast<OpaqueLoc>(unwrap(mlirOpaqueLoc)).getUnderlyingLocation();
}
TypeID mlirOpaqueLocGetunderlyingTypeID(MlirAttribute mlirOpaqueLoc) {
return llvm::cast<OpaqueLoc>(unwrap(mlirOpaqueLoc)).getUnderlyingTypeID();
}
Location mlirOpaqueLocGetfallbackLocation(MlirAttribute mlirOpaqueLoc) {
return llvm::cast<OpaqueLoc>(unwrap(mlirOpaqueLoc)).getFallbackLocation();
}
MLIR_CAPI_EXPORTED MlirTypeID mlirCallSiteLocGetTypeID(void);
MLIR_CAPI_EXPORTED bool isaMlirCallSiteLoc(MlirAttribute thing);
MlirTypeID mlirCallSiteLocGetTypeID() {
return wrap(CallSiteLoc::getTypeID());
}
bool isaMlirCallSiteLoc(MlirAttribute thing) {
return isa<CallSiteLoc>(unwrap(thing));
}
auto nbCallSiteLoc = mlir_attribute_subclass(m, "CallSiteLoc", isaMlirCallSiteLoc, mlirCallSiteLocGetTypeID);
nbCallSiteLoc.def_staticmethod("get", [](Location callee, Location caller, MlirContext context) {
return mlirCallSiteLocAttrGet(callee, caller, context);
}, "callee"_a, "caller"_a, "context"_a = nb::none());
nbCallSiteLoc.def_property_readonly("callee", [](MlirAttribute self) {
return mlirCallSiteLocGetcallee(self);
});
nbCallSiteLoc.def_property_readonly("caller", [](MlirAttribute self) {
return mlirCallSiteLocGetcaller(self);
});
MLIR_CAPI_EXPORTED MlirTypeID mlirFileLineColRangeGetTypeID(void);
MLIR_CAPI_EXPORTED bool isaMlirFileLineColRange(MlirAttribute thing);
MlirTypeID mlirFileLineColRangeGetTypeID() {
return wrap(FileLineColRange::getTypeID());
}
bool isaMlirFileLineColRange(MlirAttribute thing) {
return isa<FileLineColRange>(unwrap(thing));
}
auto nbFileLineColRange = mlir_attribute_subclass(m, "FileLineColRange", isaMlirFileLineColRange, mlirFileLineColRangeGetTypeID);
nbFileLineColRange.def_staticmethod("get", [](StringAttr filename, unsigned start_line, unsigned start_column, unsigned end_line, unsigned end_column, MlirContext context) {
return mlirFileLineColRangeAttrGet(filename, start_line, start_column, end_line, end_column, context);
}, "filename"_a, "start_line"_a, "start_column"_a, "end_line"_a, "end_column"_a, "context"_a = nb::none());
nbFileLineColRange.def_property_readonly("filename", [](MlirAttribute self) {
return mlirFileLineColRangeGetfilename(self);
});
nbFileLineColRange.def_property_readonly("start_line", [](MlirAttribute self) {
return mlirFileLineColRangeGetstart_line(self);
});
nbFileLineColRange.def_property_readonly("start_column", [](MlirAttribute self) {
return mlirFileLineColRangeGetstart_column(self);
});
nbFileLineColRange.def_property_readonly("end_line", [](MlirAttribute self) {
return mlirFileLineColRangeGetend_line(self);
});
nbFileLineColRange.def_property_readonly("end_column", [](MlirAttribute self) {
return mlirFileLineColRangeGetend_column(self);
});
MLIR_CAPI_EXPORTED MlirTypeID mlirFusedLocGetTypeID(void);
MLIR_CAPI_EXPORTED bool isaMlirFusedLoc(MlirAttribute thing);
MlirTypeID mlirFusedLocGetTypeID() {
return wrap(FusedLoc::getTypeID());
}
bool isaMlirFusedLoc(MlirAttribute thing) {
return isa<FusedLoc>(unwrap(thing));
}
auto nbFusedLoc = mlir_attribute_subclass(m, "FusedLoc", isaMlirFusedLoc, mlirFusedLocGetTypeID);
nbFusedLoc.def_staticmethod("get", [](std::vector<Location> &locations, MlirAttribute metadata, MlirContext context) {
return mlirFusedLocAttrGet(locations.data(), locations.size(), metadata, context);
}, "locations"_a, "metadata"_a, "context"_a = nb::none());
nbFusedLoc.def_property_readonly("locations", [](MlirAttribute self) {
unsigned nlocationss;
Location* locationsPtr;
mlirFusedLocGetlocations(self, &locationsPtr, &nlocationss);
return std::vector<Location>{locationsPtr, locationsPtr + nlocationss};
});
nbFusedLoc.def_property_readonly("metadata", [](MlirAttribute self) {
return mlirFusedLocGetmetadata(self);
});
MLIR_CAPI_EXPORTED MlirTypeID mlirNameLocGetTypeID(void);
MLIR_CAPI_EXPORTED bool isaMlirNameLoc(MlirAttribute thing);
MlirTypeID mlirNameLocGetTypeID() {
return wrap(NameLoc::getTypeID());
}
bool isaMlirNameLoc(MlirAttribute thing) {
return isa<NameLoc>(unwrap(thing));
}
auto nbNameLoc = mlir_attribute_subclass(m, "NameLoc", isaMlirNameLoc, mlirNameLocGetTypeID);
nbNameLoc.def_staticmethod("get", [](StringAttr name, Location childLoc, MlirContext context) {
return mlirNameLocAttrGet(name, childLoc, context);
}, "name"_a, "child_loc"_a, "context"_a = nb::none());
nbNameLoc.def_property_readonly("name", [](MlirAttribute self) {
return mlirNameLocGetname(self);
});
nbNameLoc.def_property_readonly("child_loc", [](MlirAttribute self) {
return mlirNameLocGetchildLoc(self);
});
MLIR_CAPI_EXPORTED MlirTypeID mlirOpaqueLocGetTypeID(void);
MLIR_CAPI_EXPORTED bool isaMlirOpaqueLoc(MlirAttribute thing);
MlirTypeID mlirOpaqueLocGetTypeID() {
return wrap(OpaqueLoc::getTypeID());
}
bool isaMlirOpaqueLoc(MlirAttribute thing) {
return isa<OpaqueLoc>(unwrap(thing));
}
auto nbOpaqueLoc = mlir_attribute_subclass(m, "OpaqueLoc", isaMlirOpaqueLoc, mlirOpaqueLocGetTypeID);
nbOpaqueLoc.def_staticmethod("get", [](uintptr_t underlyingLocation, TypeID underlyingTypeID, Location fallbackLocation, MlirContext context) {
return mlirOpaqueLocAttrGet(underlyingLocation, underlyingTypeID, fallbackLocation, context);
}, "underlying_location"_a, "underlying_type_id"_a, "fallback_location"_a, "context"_a = nb::none());
nbOpaqueLoc.def_property_readonly("underlying_location", [](MlirAttribute self) {
return mlirOpaqueLocGetunderlyingLocation(self);
});
nbOpaqueLoc.def_property_readonly("underlying_type_id", [](MlirAttribute self) {
return mlirOpaqueLocGetunderlyingTypeID(self);
});
nbOpaqueLoc.def_property_readonly("fallback_location", [](MlirAttribute self) {
return mlirOpaqueLocGetfallbackLocation(self);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment