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][ThroughMLIR] Support lowering cir.condition and cir.while to scf.condition, scf.while #636

Merged
merged 15 commits into from
Jun 7, 2024

Conversation

GaoXiangYa
Copy link
Contributor

This pr intruduces CIRConditionLowering and CIRWhileLowering for lowering to scf.

@GaoXiangYa GaoXiangYa changed the title [CIR]PThroughMLIR] Support lowering cir.condition and cir.while to scf.condition, scf.while [CIR][ThroughMLIR] Support lowering cir.condition and cir.while to scf.condition, scf.while May 29, 2024
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.

Looks great, minor nit.

// RUN: FileCheck %s --input-file %t.mlir

!s32i = !cir.int<s, 32>
module {
Copy link
Member

Choose a reason for hiding this comment

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

Please either add a comment with the C/C++ code we could use to regen this test in case CIR changes significantly or add a test coming from C/C++ source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will add some comment and test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, I add a test coming from C source , can you review it?

@bcardosolopes
Copy link
Member

@ShivaChen can you review this and let us know if anything should be done regarding the loop canonicalization pass?

@ShivaChen
Copy link
Contributor

@ShivaChen can you review this and let us know if anything should be done regarding the loop canonicalization pass?

Sure, I'll take a look.

@GaoXiangYa
Copy link
Contributor Author

Hello, if you have review the code, and agree with me, I want to try to move the CIRWhileOpLowering to LowerCIRLoopToSCF.cpp file. @ShivaChen

@ShivaChen
Copy link
Contributor

Hello, if you have review the code, and agree with me, I want to try to move the CIRWhileOpLowering to LowerCIRLoopToSCF.cpp file. @ShivaChen

Yes, I agree LowerCIRLoopToSCF.cpp could be right place to go. Thanks!

@ShivaChen
Copy link
Contributor

@ShivaChen can you review this and let us know if anything should be done regarding the loop canonicalization pass?

It seems cir.while to scf.while have one to one mapping.
cir.while.cond -> scf.while.before,
cir.while.body -> scf.while.after
cir.condition -> scf.condition
So I assume the canonicalization might not require.

#include "llvm/Analysis/RegionInfo.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: does the new adding include lines are required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These files are generated by clangd’s auto-completion, and I believe they are not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello, I have moved the CIRWhileOpLowering to LoweringSCFLoop.cpp , can you review it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we remove the un-required including lines?

Copy link
Contributor

@ShivaChen ShivaChen left a comment

Choose a reason for hiding this comment

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

The motivation of SCFLoop class is to collect loop upper bound, lower bound and step which would be needed for SCFForOp. Given that SCFWhileOp didn't require these operands, should we avoid use SCFLoop for SCFWhileOp?

#include "llvm/Analysis/RegionInfo.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we remove the un-required including lines?

@GaoXiangYa
Copy link
Contributor Author

Do you mean I add a SCFWhileLoop class ? And I will delete the header file. @ShivaChen

@ShivaChen
Copy link
Contributor

Do you mean I add a SCFWhileLoop class ? And I will delete the header file. @ShivaChen

I think the way you implement CIRWhileOpLowering in e882b20
make sense to me.
We could introduce new class if we think there are more analysis need to be done in the future.

@@ -965,6 +973,27 @@ class CIRYieldOpLowering
}
};

class CIRConditionOpLowering
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems ConditionOp only be used for loops. Should we move to LowerCIRLoopToSCF.cpp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I move the CIRConditionOpLowering to LoweriCIRLoopToSCF

@ShivaChen
Copy link
Contributor

Could you remove the changes of deleting empty lines and include headers in LowerCIRToMLIR.cpp?

@GaoXiangYa
Copy link
Contributor Author

Sorry , comparing with the old LowerCIRToMLIR.cpp , I don`t find some empty lines, and I have already deleted the un-used header files. @ShivaChen

@ShivaChen
Copy link
Contributor

Sorry , comparing with the old LowerCIRToMLIR.cpp , I don`t find some empty lines, and I have already deleted the un-used header files. @ShivaChen

It seems I could see when clicking File Chagned on the web page but it could be a nit-picking.
Overall it's LGTM. Please wait for @bcardosolopes for another look. Thanks!

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. It'd be best not to touch random lines next PRs, you can probably set you IDE to only format changed lines.

Thanks for the review @ShivaChen

@bcardosolopes bcardosolopes merged commit 7c87502 into llvm:main Jun 7, 2024
6 checks passed
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
…f.condition, scf.while (llvm#636)

This pr intruduces CIRConditionLowering and CIRWhileLowering for
lowering to scf.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…f.condition, scf.while (llvm#636)

This pr intruduces CIRConditionLowering and CIRWhileLowering for
lowering to scf.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…f.condition, scf.while (llvm#636)

This pr intruduces CIRConditionLowering and CIRWhileLowering for
lowering to scf.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…f.condition, scf.while (llvm#636)

This pr intruduces CIRConditionLowering and CIRWhileLowering for
lowering to scf.
lanza pushed a commit that referenced this pull request Nov 5, 2024
…f.condition, scf.while (#636)

This pr intruduces CIRConditionLowering and CIRWhileLowering for
lowering to scf.
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