Skip to content
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

add names to generated IR #969

Open
ChuanqiXu9 opened this issue Oct 14, 2024 · 6 comments
Open

add names to generated IR #969

ChuanqiXu9 opened this issue Oct 14, 2024 · 6 comments
Labels
IR difference A difference in ClangIR-generated LLVM IR that could complicate reusing original CodeGen tests

Comments

@ChuanqiXu9
Copy link
Member

Now when we generate IR from CIR, the generated codes are named by numbers, which is pretty hard to read. While we lower from the traditional pipeline, we can see the names pretty clearly. It is pretty helpful for debugging.

@smeenai
Copy link
Collaborator

smeenai commented Oct 14, 2024

@lanza and I have discussed this too. This will also be pretty important in the future when we want to start running some original CodeGen tests with ClangIR, since they assume value names will be present.

From what I understand, MLIR doesn't have the concept of value names the same way LLVM does; they're not stored in the bitcode format, for example, and just generated by the AsmPrinter on the fly instead. We'll probably need to extend the LLVMIR dialect to support this; one idea we were thinking of was an optional attribute on all operations to name the result (similar to how cir.alloca stores the variable names) that can be accessed during translation. It'd need to be discussed with upstream MLIR though.

@Lancern
Copy link
Member

Lancern commented Oct 16, 2024

Beside SSA value names, what about basic block names? MLIR does not support block names either.

@smeenai
Copy link
Collaborator

smeenai commented Oct 16, 2024

Good point, I'd forgotten about those. I'm not sure at all about the right approach for those, but hopefully the MLIR folks will have ideas.

@bcardosolopes
Copy link
Member

bcardosolopes commented Oct 16, 2024

One interesting bit is that operations with multiple return values actually get names based on tablegen, so some of the mechanism is already there.

This discussion has happened in MLIR related forums before, I don't have a digest to give, but it might be worth asking there to get an informed status quo

@smeenai
Copy link
Collaborator

smeenai commented Oct 17, 2024

I found some relevant reading: https://discourse.llvm.org/t/rfc-better-support-for-dialects-that-want-to-make-ssa-names-load-bearing/674 and https://discourse.llvm.org/t/names-in-ssa-values-for-debuggability/1041. In particular llvm/llvm-project@596da62 actually landed, but I'm not sure what the API looks like in practice.

@bcardosolopes
Copy link
Member

Haven't looked in depth, but seems like it requires changing the printers to custom ones? This is from 2020, so maybe there's something more streamlined we could use?

@smeenai smeenai added the IR difference A difference in ClangIR-generated LLVM IR that could complicate reusing original CodeGen tests label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IR difference A difference in ClangIR-generated LLVM IR that could complicate reusing original CodeGen tests
Projects
None yet
Development

No branches or pull requests

4 participants