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 an CIR analysis-only pipeline that uses traditional codegen #633

Closed
ChuanqiXu9 opened this issue May 29, 2024 · 6 comments · Fixed by #638
Closed

Add an CIR analysis-only pipeline that uses traditional codegen #633

ChuanqiXu9 opened this issue May 29, 2024 · 6 comments · Fixed by #638

Comments

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented May 29, 2024

This comes from https://discourse.llvm.org/t/rfc-upstreaming-clangir/76587/53

It may be helpful to have an analysis only pipeline so that users can try to use CIR actually without worrying the correctness and completeness of the CIR to LLVM IR part.

The pattern may look like:

Source -> Parser and Sema -> AST -----> CIR -----> analysis pass and transforming pass helper for analysis              
                               |
                               ------> CodeGen ------->  LLVM IR

So we can have multiple consumers for the parsed AST. One the traditional code gen part. The other one is the new introduced CIR part. We generate CIR from AST and we can perform analysis on the CIR. We can also perform some transformation passes on the CIR if these transformation passes are helpful to the analysis.

Is it possible to do so? If not, would we love to do? I think it will be pretty helpful to get more users for CIR.

@Lancern
Copy link
Member

Lancern commented May 29, 2024

Hi Chuanqi. This should be a first-class use case of clangir. You can pass -emit-cir switch to clang_cc1 to emit CIR only and avoid the CIR -> MLIR/LLVMIR part. Along the way one may still run any analysis passes and CIR -> CIR transformation passes.

clangir already has a PoC implementation of a lifetime checker, which can be found at https://github.com/llvm/clangir/blob/main/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp (but for now it might be a bit out-of-date). One can run this analysis pass via:

clang++ -cc1 -fclangir -emit-cir -fclangir-lifetime-check -o output.cir input.cpp

I like your idea about an "analysis-only" pipeline. The problem with the above pipeline is that it still run some passes that are required for CIR -> MLIR/LLVMIR but are not required for an analysis-only pipeline (LoweringPrepare is a typical one).

@ChuanqiXu9
Copy link
Member Author

Hi,

the interface looks like not the one I want.

What I want is:

clang++ input.cpp -fenable-cir-check -c -o input.o

That is, it is just normal compilation except we add some new analysis. If we can do this, it is much easier to enable CIR for real world users.

@ChuanqiXu9 ChuanqiXu9 changed the title Do we have an analysis only pipeline (avoiding 'CIR to LLVM IR' part)? Do we have an analysis only pipeline (avoiding 'CIR to LLVM IR' part) to generate the object files? May 29, 2024
@bcardosolopes
Copy link
Member

bcardosolopes commented May 29, 2024

Hi @ChuanqiXu9, thanks for clarifying your question.

Right now, if you use -fclangir you're not going to get what you want, because it will enable CIR for codegen as well, as you probably noticed, hence this issue. I guess at some point we could have a -fclangir-analysis-only or something like that to do what you are asking for.

We don't have anything like that right now because none of our users have that usecase, and we avoid adding things that there are no uses for, but nothing prevents it being added at some point. It'd be useful for instance when running the lifetime checker without changing the existing codegen path.

To summarize: we have no plans or intention to change -fclangir meaning, but it would be totally fine to add something like a -fclangir-analysis-only (btw, it's a rather simple change to do that).

@bcardosolopes bcardosolopes changed the title Do we have an analysis only pipeline (avoiding 'CIR to LLVM IR' part) to generate the object files? Add an analysis only pipeline that uses CIR for analysis but not for codegen (e.g. -fclangir-analysis-only) May 29, 2024
@bcardosolopes bcardosolopes changed the title Add an analysis only pipeline that uses CIR for analysis but not for codegen (e.g. -fclangir-analysis-only) Add an CIR analysis-only pipeline that uses traditional codegen (e.g. -fclangir-analysis-only) May 29, 2024
@bcardosolopes bcardosolopes changed the title Add an CIR analysis-only pipeline that uses traditional codegen (e.g. -fclangir-analysis-only) Add an CIR analysis-only pipeline that uses traditional codegen May 29, 2024
@ChuanqiXu9
Copy link
Member Author

Hi @ChuanqiXu9, thanks for clarifying your question.

Right now, if you use -fclangir you're not going to get what you want, because it will enable CIR for codegen as well, as you probably noticed, hence this issue. I guess at some point we could have a -fclangir-analysis-only or something like that to do what you are asking for.

We don't have anything like that right now because none of our users have that usecase, and we avoid adding things that there are no uses for, but nothing prevents it being added at some point. It'd be useful for instance when running the lifetime checker without changing the existing codegen path.

To summarize: we have no plans or intention to change -fclangir meaning, but it would be totally fine to add something like a -fclangir-analysis-only (btw, it's a rather simple change to do that).

Fair enough summary. I'd like to see if I can make a simple patch.

ChuanqiXu9 added a commit to ChuanqiXu9/clangir that referenced this issue May 29, 2024
@ChuanqiXu9
Copy link
Member Author

Sent #638

BTW, when I test it with a real world project (https://github.com/alibaba/async_simple), I met some crashes when generating the CIR. I'd like to work on it.

@bcardosolopes
Copy link
Member

@ChuanqiXu9 thanks the PR, will take a look soon. I bet it crashes cause we still have lots of C++ stuff to support, but being able to build async_simple would be really cool, looking forward to see your contributions

ChuanqiXu9 added a commit to ChuanqiXu9/clangir that referenced this issue Jun 3, 2024
bcardosolopes pushed a commit that referenced this issue Jun 3, 2024
Close #633.

This patch introduces `-fclangir-analysis-only` option to allow the
users to consume the AST to the CIR (and potential analysis passes, this
can be done by specifying `-Xclang -fclangir-lifetime-check=""` now or
some default value in following patches) and also generating the LLVM IR
by the traditional code gen path. This will be helpful to use CIR with
real world projects without worrying the correctness and completeness of
CIR CodeGen part.
pysuxing pushed a commit to pysuxing/llvm-project that referenced this issue Jul 17, 2024
Close llvm/clangir#633.

This patch introduces `-fclangir-analysis-only` option to allow the
users to consume the AST to the CIR (and potential analysis passes, this
can be done by specifying `-Xclang -fclangir-lifetime-check=""` now or
some default value in following patches) and also generating the LLVM IR
by the traditional code gen path. This will be helpful to use CIR with
real world projects without worrying the correctness and completeness of
CIR CodeGen part.
ChuanqiXu9 added a commit to ChuanqiXu9/clangir that referenced this issue Sep 13, 2024
Hugobros3 pushed a commit to shady-gang/clangir that referenced this issue Oct 2, 2024
Close llvm#633.

This patch introduces `-fclangir-analysis-only` option to allow the
users to consume the AST to the CIR (and potential analysis passes, this
can be done by specifying `-Xclang -fclangir-lifetime-check=""` now or
some default value in following patches) and also generating the LLVM IR
by the traditional code gen path. This will be helpful to use CIR with
real world projects without worrying the correctness and completeness of
CIR CodeGen part.
smeenai pushed a commit to smeenai/clangir that referenced this issue Oct 9, 2024
Close llvm#633.

This patch introduces `-fclangir-analysis-only` option to allow the
users to consume the AST to the CIR (and potential analysis passes, this
can be done by specifying `-Xclang -fclangir-lifetime-check=""` now or
some default value in following patches) and also generating the LLVM IR
by the traditional code gen path. This will be helpful to use CIR with
real world projects without worrying the correctness and completeness of
CIR CodeGen part.
keryell pushed a commit to keryell/clangir that referenced this issue Oct 19, 2024
Close llvm#633.

This patch introduces `-fclangir-analysis-only` option to allow the
users to consume the AST to the CIR (and potential analysis passes, this
can be done by specifying `-Xclang -fclangir-lifetime-check=""` now or
some default value in following patches) and also generating the LLVM IR
by the traditional code gen path. This will be helpful to use CIR with
real world projects without worrying the correctness and completeness of
CIR CodeGen part.
lanza pushed a commit that referenced this issue Nov 5, 2024
Close #633.

This patch introduces `-fclangir-analysis-only` option to allow the
users to consume the AST to the CIR (and potential analysis passes, this
can be done by specifying `-Xclang -fclangir-lifetime-check=""` now or
some default value in following patches) and also generating the LLVM IR
by the traditional code gen path. This will be helpful to use CIR with
real world projects without worrying the correctness and completeness of
CIR CodeGen part.
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 a pull request may close this issue.

3 participants