Useful for easier debugging (no need to regex out all of the stuff around the id).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
3344 | Probably this should be named something other than print but the conventional name escapes me (only thing that comes to mind is show vs print in Haskell). |
mlir/include/mlir-c/IR.h | ||
---|---|---|
780 | Can you document the arguments? In particular the parentOp here and the contract with "value" |
mlir/include/mlir-c/IR.h | ||
---|---|---|
780 | Prior I had the "get parent" stuff inside the C function and moved it out because it seemed like most of the functions in IR.cpp are "small"; your comment made me realize it's much safer/better to have them there in order to enforce the relationship. | |
mlir/lib/CAPI/IR/IR.cpp | ||
782 | Block::printAsOperand similarly prints <<UNLINKED BLOCK>> in such a case (see here). |
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
3344 | imo this should be the behaviour of __str__, and the current __str__ should be __repr__ | |
mlir/lib/CAPI/IR/IR.cpp | ||
776–780 | To get the expected result for values in nested regions I think you'll need to continue traversing up to find the top-level op, similar to here: https://github.com/llvm/llvm-project/blob/2e3cabe172c6f2eaf1f097ffeff1664b3768223a/mlir/lib/IR/AsmPrinter.cpp#L3680-L3691 | |
781–784 | In this case I think printing with AsmState(ctx) should work fine? |
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
3344 | on second thought, if the current __str__ prints the full operation, using it for __repr__ is probably not a good idea |
mlir/lib/CAPI/IR/IR.cpp | ||
---|---|---|
781–784 | nevermind, after looking at the implementation of that, it would just end up printing something similar to what you did already |
handle vals in nested regions correctly
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
3344 | I agree! I can make the change and then patch the failing lit tests if there's a consensus. |
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
3344 | f the interpretations of __repr__ and __str__ are
then I think printing only the valueid for __str__ and printing the whole op for __repr__ would be the right thing to do? I mean it doesn't matter to me as long as there's someway to print the valueid (i.e., this dunder). | |
mlir/lib/CAPI/IR/IR.cpp | ||
781–784 | With AsmState(ctx) you get %0 always I believe, which either is or isn't counterintutive. |
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
162–164 | I'm not sure this should be documented here, it seems more like a bug in the C++ API I think? | |
3344 | If you keep this as a method, how about get_name or get_id? | |
mlir/lib/CAPI/IR/IR.cpp | ||
777–778 | This traversal should happen for block args as well | |
796 | This is never freed, I'd just go back to printing the << ... >> string if that simplifies things |
mlir/include/mlir-c/IR.h | ||
---|---|---|
779–780 | The "this isn't canonical" comment doesn't seem like it should be here (documenting a bug?) | |
mlir/lib/Bindings/Python/IRCore.cpp | ||
3344 | imo get_name by itself is unambiguous and the _as_operand doesn't add anything here | |
3352 | to be consistent with ir.Operation.print | |
mlir/lib/CAPI/IR/IR.cpp | ||
771 | There's additional printing options that can affect the value id, like printGenericOpForm. If you want to support different options it seems better to just take a MlirOpPrintingFlags here (probably not worth exposing all the options python-side though, that seems easy to extend later). | |
779–780 | ||
781–786 | Values can only be OpResults or BlockArguments, so this else can't be reached. I think the check should look something like this instead | |
789 | I would add a Value::printAsOperand(raw_ostream &os, const OpPrintingFlags &flags={}) overload that does this. That would also let you share the logic here with Operation::print. | |
801–803 |
mlir/lib/Bindings/Python/IRCore.cpp | ||
---|---|---|
3347 | You'll need to call mlirOpPrintingFlagsDestroy at the end to avoid this leaking | |
3348–3350 | llvm style is to not use braces here | |
mlir/lib/IR/AsmPrinter.cpp | ||
3676–3677 | the llvm style is to use static for functions instead of anonymous namespaces | |
3699–3700 | cast() will do this assert for you |
Can you document the arguments? In particular the parentOp here and the contract with "value"