[Mlir-commits] [mlir] [mlir][python] Expose AsmState python side. (PR #66819)
Maksim Levental
llvmlistbot at llvm.org
Tue Sep 19 15:01:03 PDT 2023
================
@@ -3425,19 +3425,35 @@ void mlir::python::populateIRCore(py::module &m) {
kValueDunderStrDocstring)
.def(
"get_name",
- [](PyValue &self, bool useLocalScope) {
+ [](PyValue &self, std::optional<bool> useLocalScope,
+ std::optional<std::reference_wrapper<PyAsmState>> state) {
PyPrintAccumulator printAccum;
- MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
- if (useLocalScope)
- mlirOpPrintingFlagsUseLocalScope(flags);
- MlirAsmState state = mlirAsmStateCreateForValue(self.get(), flags);
- mlirValuePrintAsOperand(self.get(), state, printAccum.getCallback(),
+ MlirOpPrintingFlags flags;
+ MlirAsmState valueState;
+ // Use state if provided, else create a new state.
+ if (state) {
+ valueState = state.value().get().get();
+ // Don't allow setting using local scope and state at same time.
+ if (useLocalScope)
----------------
makslevental wrote:
yea...
```cpp
#include <iostream>
#include <optional>
int main() {
std::optional<bool> useLocalScope;
if (useLocalScope)
std::cout << "empty" << std::endl;
useLocalScope = false;
if (useLocalScope)
std::cout << "false-positive" << std::endl;
useLocalScope = true;
if (useLocalScope)
std::cout << "positive-positive" << std::endl;
return 0;
}
```
prints
```
false-positive
positive-positive
```
https://github.com/llvm/llvm-project/pull/66819
More information about the Mlir-commits
mailing list