-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Python: Parse ModuleOp from file path #126572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#if __has_include(<filesystem>) | ||
#include <filesystem> | ||
#endif | ||
#include <optional> | ||
#include <utility> | ||
|
||
|
@@ -299,7 +302,7 @@ struct PyAttrBuilderMap { | |
return *builder; | ||
} | ||
static void dunderSetItemNamed(const std::string &attributeKind, | ||
nb::callable func, bool replace) { | ||
nb::callable func, bool replace) { | ||
PyGlobals::get().registerAttributeBuilder(attributeKind, std::move(func), | ||
replace); | ||
} | ||
|
@@ -3049,6 +3052,21 @@ void mlir::python::populateIRCore(nb::module_ &m) { | |
}, | ||
nb::arg("asm"), nb::arg("context").none() = nb::none(), | ||
kModuleParseDocstring) | ||
#if __has_include(<filesystem>) | ||
.def_static( | ||
"parse", | ||
[](const std::filesystem::path &path, | ||
DefaultingPyMlirContext context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other places in the python bindings are using either https://github.com/llvm/llvm-project/blob/main/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp#L77 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was already an overload that accepted string asm; I ended up adding a new |
||
PyMlirContext::ErrorCapture errors(context->getRef()); | ||
MlirModule module = mlirModuleCreateParseFromFile( | ||
context->get(), toMlirStringRef(path.string())); | ||
if (mlirModuleIsNull(module)) | ||
throw MLIRError("Unable to parse module assembly", errors.take()); | ||
return PyModule::forModule(module).releaseObject(); | ||
}, | ||
nb::arg("asm"), nb::arg("context").none() = nb::none(), | ||
kModuleParseDocstring) | ||
#endif | ||
.def_static( | ||
"create", | ||
[](DefaultingPyLocation loc) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's a OK solution: the test will fail on gcc7 builds.