-
Notifications
You must be signed in to change notification settings - Fork 103
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
base: main
Are you sure you want to change the base?
Conversation
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). |
@orbiri overall PR looks good as an initial approach, but as you pointed out, better if the solution can be shared between both pipelines. One natural place for this IMO would be target lowering (where we do CallConv lowering), have you tried looking into doing it at that time and/or find any issues/concerns? I'm suggesting this because it actually feels like ABI, since passing and returning bool is what actually triggers different memory/reg use of bools. If for some reason it's not a fit there, perhaps a specific pass like you suggested could be a good approach. |
I will have to check, but I’m pretty sure that having bool in a function signature is only possible if you really want a i1 representation (in registers) meaning you are either using bool in C++ or _Bool in modern C. Therefore the pass I may introduce for lowering memory semantics and the change to the lowering are not really related to ABI. Having said that, as mentioned above - I will first deep dive into the matter and return here with my findings 😇 |
@bcardosolopes I took a short tour in the target lowering code. I want to claim that since
then it would be the right choice to separate this concerns here as well. I will start working on the pass this weekend between the festivities 🦃 , hope to publish something by next one :) |
While trying to create a separate lowering pass, I realized it will require extremely complicated logic and to duplicate almost the entirety of the LLVM/MLIR lowering passes. Few of the reasons van be viewed in the uploaded DirectToLLVM commit:
In my opinion, implementing this logic in a different pass will create more "spaghetti" then duplicating the logic. I believe that I'll conclude with outlining the common functions ( Of course, still need rebasing and I want to add a couple of more tests, but we are moving forward! |
This is an RFC for changing the lowering to LLVM and MLIR to lower
cir.bool
toi1
all across the board. This dramatically simplifies the lowering logic and the lowered code as it naturally usesi1
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
andEmit 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 theTypeConvertor
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.