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

Recommit [CIR][Pipeline] Support -fclangir-analysis-only #832

Merged
merged 8 commits into from
Sep 18, 2024

Conversation

ChuanqiXu9
Copy link
Member

@ChuanqiXu9 ChuanqiXu9 commented Sep 12, 2024

Reland #638

This was reverted due to #655. I tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:

  • Move the definition of cir::CIRGenConsumer to clang/include/clang/CIRFrontendAction/CIRGenConsumer.h, and leave its HandleTranslationUnit interface is left empty. So that cir::CIRGenConsumer won't need to depend on CodeGen any more.
  • Change the old definition of cir::CIRGenConsumer in clang/lib/CIR/FrontendAction/CIRGenAction.cpp and to CIRLoweringConsumer, inherited from cir::CIRGenConsumer, which implements the original HandleTranslationUnit interface.

I feel this may improve the readability more even without my original patch.

@ChuanqiXu9
Copy link
Member Author

I didn't understand why the CI fails on windows. The log says:

FAILED: tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CodeGenAction.cpp.obj 
sccache C:\PROGRA~2\MICROS~2\2019\ENTERP~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  /nologo /TP -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -ID:\a\clangir\clangir\build\tools\clang\lib\CodeGen -ID:\a\clangir\clangir\clang\lib\CodeGen -ID:\a\clangir\clangir\clang\include -ID:\a\clangir\clangir\build\tools\clang\include -ID:\a\clangir\clangir\build\include -ID:\a\clangir\clangir\llvm\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -w14062 -we4238 /Gw /O2 /Ob2  -std:c++17 -MD  /EHs-c- /GR- -UNDEBUG /showIncludes /Fotools\clang\lib\CodeGen\CMakeFiles\obj.clangCodeGen.dir\CodeGenAction.cpp.obj /Fdtools\clang\lib\CodeGen\CMakeFiles\obj.clangCodeGen.dir\ /FS -c D:\a\clangir\clangir\clang\lib\CodeGen\CodeGenAction.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\memory(3089): error C2027: use of undefined type 'mlir::MLIRContext'
D:\a\clangir\clangir\clang\include\clang/CIRFrontendAction/CIRGenAction.h(21): note: see declaration of 'mlir::MLIRContext'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\memory(3088): note: while compiling class template member function 'void std::default_delete<mlir::MLIRContext>::operator ()(_Ty *) noexcept const'
        with
        [
            _Ty=mlir::MLIRContext
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\memory(3198): note: see reference to function template instantiation 'void std::default_delete<mlir::MLIRContext>::operator ()(_Ty *) noexcept const' being compiled
        with
        [
            _Ty=mlir::MLIRContext
        ]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\memory(3125): note: see reference to class template instantiation 'std::default_delete<mlir::MLIRContext>' being compiled
D:\a\clangir\clangir\clang\include\clang/CIR/CIRGenerator.h(72): note: see reference to class template instantiation 'std::unique_ptr<mlir::MLIRContext,std::default_delete<mlir::MLIRContext>>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\memory(3089): error C2338: can't delete an incomplete type
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\memory(3090): warning C4150: deletion of pointer to incomplete type 'mlir::MLIRContext'; no destructor called
D:\a\clangir\clangir\clang\include\clang/CIRFrontendAction/CIRGenAction.h(21): note: see declaration of 'mlir::MLIRContext'

but I didn't touch MLIRContext and the definition of mlir::MLIRContext should be visible in the CodeGenAction.cpp. @lanza @bcardosolopes would you like to take a look?

@bcardosolopes
Copy link
Member

@ChuanqiXu9 I haven't seen this one before, it's not even related to ClangIR, very weird. Maybe it was a fluke? Try update the PR with something that triggers testing again, let's see if it reproduces

@ChuanqiXu9 ChuanqiXu9 force-pushed the AnalysisOnly branch 3 times, most recently from b54c3b4 to 75edb18 Compare September 13, 2024 03:35
@ChuanqiXu9
Copy link
Member Author

@ChuanqiXu9 I haven't seen this one before, it's not even related to ClangIR, very weird. Maybe it was a fluke? Try update the PR with something that triggers testing again, let's see if it reproduces

Maybe some MSVC implementation details.. I solved it by adding the MLIR include dir in CodeGen conditionally. Now this is ready to review.


#if CLANG_ENABLE_CIR
if (CI.getFrontendOpts().ClangIRAnalysisOnly)
AdditionalConsumers.push_back(cir::createCIRAnalysisOnlyConsumer(CI));
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit uncomfortable with touching anything under clang/lib/CodeGen, this is going to be a hassle to upstream / convince maintainers. Can't this be done instead in the opposite way? In CIRGenAction.cpp we could dispatch the classic CodeGen if the pipeline is asking for LLVM codegen and -fclangir-analysis-only is ON. Have you tried that and found any issue?

Copy link
Member Author

@ChuanqiXu9 ChuanqiXu9 Sep 14, 2024

Choose a reason for hiding this comment

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

I'm a bit uncomfortable with touching anything under clang/lib/CodeGen

This is the style we did for modules. It shows it is pretty stable.

Can't this be done instead in the opposite way?

But if you really want, we can do it. We just need to introduce more lines of code. Please see the newest commit.

Copy link
Member

@bcardosolopes bcardosolopes Sep 16, 2024

Choose a reason for hiding this comment

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

This is the style we did for modules. It shows it is pretty stable.

The approach is sound, my point is more about trying to minimize clang changes outside CIR dirs, so for the time being is less invasive to the rest of the codebase,

But if you really want, we can do it. We just need to introduce more lines of code. Please see the newest commit.

This looks great, 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.

Thanks for the updates! Looks mostly good, one question remaining (and couple nits to address)

@bcardosolopes
Copy link
Member

The bot failure is unrelated (#829), please ignore it

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 e437114 into llvm:main Sep 18, 2024
5 of 6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
Reland llvm#638

This was reverted due to llvm#655. I
tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:
- Move the definition of `cir::CIRGenConsumer` to
`clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
`HandleTranslationUnit` interface is left empty. So that
`cir::CIRGenConsumer` won't need to depend on CodeGen any more.
- Change the old definition of `cir::CIRGenConsumer` in
`clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
`CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
implements the original `HandleTranslationUnit` interface.

I feel this may improve the readability more even without my original
patch.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
Reland llvm#638

This was reverted due to llvm#655. I
tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:
- Move the definition of `cir::CIRGenConsumer` to
`clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
`HandleTranslationUnit` interface is left empty. So that
`cir::CIRGenConsumer` won't need to depend on CodeGen any more.
- Change the old definition of `cir::CIRGenConsumer` in
`clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
`CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
implements the original `HandleTranslationUnit` interface.

I feel this may improve the readability more even without my original
patch.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
Reland llvm#638

This was reverted due to llvm#655. I
tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:
- Move the definition of `cir::CIRGenConsumer` to
`clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
`HandleTranslationUnit` interface is left empty. So that
`cir::CIRGenConsumer` won't need to depend on CodeGen any more.
- Change the old definition of `cir::CIRGenConsumer` in
`clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
`CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
implements the original `HandleTranslationUnit` interface.

I feel this may improve the readability more even without my original
patch.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
Reland llvm#638

This was reverted due to llvm#655. I
tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:
- Move the definition of `cir::CIRGenConsumer` to
`clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
`HandleTranslationUnit` interface is left empty. So that
`cir::CIRGenConsumer` won't need to depend on CodeGen any more.
- Change the old definition of `cir::CIRGenConsumer` in
`clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
`CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
implements the original `HandleTranslationUnit` interface.

I feel this may improve the readability more even without my original
patch.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
Reland llvm#638

This was reverted due to llvm#655. I
tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:
- Move the definition of `cir::CIRGenConsumer` to
`clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
`HandleTranslationUnit` interface is left empty. So that
`cir::CIRGenConsumer` won't need to depend on CodeGen any more.
- Change the old definition of `cir::CIRGenConsumer` in
`clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
`CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
implements the original `HandleTranslationUnit` interface.

I feel this may improve the readability more even without my original
patch.
lanza pushed a commit that referenced this pull request Nov 5, 2024
Reland #638

This was reverted due to #655. I
tried to address the problem in the newest commit.

The changes of the PR since the last landed one includes:
- Move the definition of `cir::CIRGenConsumer` to
`clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
`HandleTranslationUnit` interface is left empty. So that
`cir::CIRGenConsumer` won't need to depend on CodeGen any more.
- Change the old definition of `cir::CIRGenConsumer` in
`clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
`CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
implements the original `HandleTranslationUnit` interface.

I feel this may improve the readability more even without my original
patch.
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.

2 participants