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

[CIR][Codegen] Adds Stack save-restore ops #346

Merged
merged 14 commits into from
Dec 21, 2023

Conversation

gitoleg
Copy link
Collaborator

@gitoleg gitoleg commented Dec 4, 2023

This PR adds cir.stack_save and cir.stack_restore operations.

@gitoleg gitoleg changed the title [CIR][Codegen] Ads Stack save-restore ops [CIR][Codegen] Adds Stack save-restore ops Dec 4, 2023
@gitoleg
Copy link
Collaborator Author

gitoleg commented Dec 15, 2023

@bcardosolopes
As we discussed earlier, we want to keep CIR clean and don't emit all this loads/stores/allocas for cir.stack_save and cir.stack_restore and postpoine it until the lowering stage. Latest changes are all about it, so please take a look at LowerToLLVM.cpp. The approach may look messy a little, but I think it's ok for the problem in question. I also added some comments.

Several words about implementation.

  1. cir.stack_save lowering. We insert llvm.alloca before and llvm.store after the llvm.stack_save.
  2. cir.stack_restore lowering. This one is a bit harder. We need to find a memory location where to load from, i.e. the llvm.alloca instruction from above. Assuming, that there is only one cir.stack_save in block, we need to find such llvm.store that has llvm.stack_save and llvm.alloca as operands. Then we insert llvm.load and use its result to create llvm.stack_restore.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comment!

mlir::Operation* findAlloca(mlir::Block& blk) const {
mlir::Operation* stackSave;

for (auto& op : blk.getOperations()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda logic seems a bit overkill just for lowering. I'm having second thoughts about this, perhaps it's just better to go for the initial approach. Let's just emit allocas in CIR like you did before and call it a day. In the future, if we care about optimizing these operations, we can work on that. I apologize for the back and forth!

@lanza lanza force-pushed the main branch 2 times, most recently from 05ffb2a to 34fceae Compare December 20, 2023 07:10
@gitoleg
Copy link
Collaborator Author

gitoleg commented Dec 20, 2023

@bcardosolopes done! now there are no extra complications in the PR!

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bcardosolopes bcardosolopes merged commit 5fc351f into llvm:main Dec 21, 2023
4 of 6 checks passed
lanza pushed a commit that referenced this pull request Jan 29, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
bcardosolopes pushed a commit that referenced this pull request Jan 31, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in #367 #346 #340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
lanza pushed a commit that referenced this pull request Mar 23, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
lanza pushed a commit that referenced this pull request Mar 23, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in #367 #346 #340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in llvm#367 llvm#346 llvm#340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in #367 #346 #340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in #367 #346 #340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in llvm#367 llvm#346 llvm#340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in #367 #346 #340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in llvm#367 llvm#346 llvm#340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in llvm#367 llvm#346 llvm#340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in llvm#367 llvm#346 llvm#340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR adds `cir.stack_save` and `cir.stack_restore` operations.
lanza pushed a commit that referenced this pull request Nov 5, 2024
This is a first PR for variable length array support. There are one (or
more :) ) ahead.

Basically, we already did lot's of preliminary job in order to land VLA
in CIR in #367 #346 #340. So now we add initial VLA support itself.

Most of the changes are taken from the original codegen, so there is
nothing to be scary of)

I added just one test, and basically that's all we can test right now.
Later, I will add more, from the original codegen tests.
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.

3 participants