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

[RFC][CIR] Lower cir.bool to i1 #1158

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

orbiri
Copy link
Collaborator

@orbiri orbiri commented Nov 23, 2024

This is an RFC for changing the lowering to LLVM and MLIR to lower cir.bool to i1 all across the board. This dramatically simplifies the lowering logic and the lowered code as it naturally uses i1 for anything boolean.

The change involves separating between type lowering when scalars are involved and when memory is involved. This is a pattern that was inspired by clang's codegen which directly emits i1 from the AST without intermediate higher level representation like CIR has.

This also paves the way to more complex lowerings that are implemented in clang codegen through the three primitives added here: Convert Type For Memory, Emit For Memory and Emit To Memory. They are used in clang for non-trivial types like bitints but also extendible vectors.

A follow up commit to implement the same in DirectLLVM will follow. That commit will properly use the datalayout to lower bool's to memory and thus it is more extensible.


One can wonder whether we are missing an upstream core capability of the TypeConvertor which may have been helpful using some type interface to help with these delicate conversions.
P.S.
More elegant solution is to add a dedicated preparation pass to be shared between the pipelines :)

I will work on that instead unless someone thinks otherwise.

@orbiri
Copy link
Collaborator Author

orbiri commented Nov 23, 2024

Thinking more about it, I came to realize that it might be more elegant to run a dedicated preparation op pass to lower the memory semantics of cir.bool (and perhaps other types in the future).
That way the “infrastructure” could be shared between DirectLLVM and ThroughMLIR - it will just be a pass that is added to both pipelines!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant