Skip to content

[CIR][CIRGen] Add comdat support, enabling more dso_local and comdat LLVM tagging #751

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

Merged
merged 8 commits into from
Jul 26, 2024

Conversation

ghehg
Copy link
Contributor

@ghehg ghehg commented Jul 22, 2024

This PR implements:

  1. Add comdat attribute as an optional attribute to CIR GlobalOp and FuncOp, they are of the enum ComdatSelection type because it contains all information we need. The llvm/include/llvm/IR/Comdat.h has Comdat with selectionKind and its name, add users which are set of pointers to GlobalObjects sharing the same name. The name is always the name of global object (in CIR context, the GlobalOp or FuncOp), so we don't need it. And the user set can always be collected when a transformation looks up symbol table of the module, thus not really necessary. Plus, it's not good for CIR to keep a set of pointers.
  2. Thanks to comdat support, and adding call sites of setComdat similar to what was in OG, we are able to implement canBenefitFromLocalAlias as similar as possible to GlobalValue::canBenefitFromLocalAlias()
    and this enable us to complete dso_local work by correctly setting dso_local for functions.
  3. I took back printing of dsolocal attribute of CIR, as I would fix 128+ test cases instead of 36-37 of tests (mostly adding dso_local to function prototype line in LLVM check) in this PR. printing dsolocal attribute is not really necessary as llvm IR would verify it for us.
  4. LLVM lowering of Comdat for GlobalOp

Things left to next/future PR

  1. I'd like to extend setComdat to other parts of CG like Vtable, etc.
  2. LLVM lowering of comdat for FuncOp

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.

Nice, thanks! One more comment

@bcardosolopes
Copy link
Member

The PR title also needs a space

@ghehg ghehg changed the title [CIR][CIRGen]CIR Comdat Support to enable dso_local for functions [CIR][CIRGen] CIR Comdat Support to enable dso_local for functions Jul 25, 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.

LGTM with few minor needed changes!

@bcardosolopes bcardosolopes changed the title [CIR][CIRGen] CIR Comdat Support to enable dso_local for functions [CIR][CIRGen] Add comdat support, enabling more dso_local and comdat LLVM tagging Jul 25, 2024
@bcardosolopes bcardosolopes merged commit 9b9c653 into llvm:main Jul 26, 2024
6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…LLVM tagging (llvm#751)

This PR implements:
1. Add comdat attribute as an optional attribute to CIR GlobalOp and
FuncOp, they are of the enum ComdatSelection type because it contains
all information we need. The
[llvm/include/llvm/IR/Comdat.h](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/include/llvm/IR/Comdat.h#L33)
has Comdat with selectionKind and its name, add users which are set of
pointers to GlobalObjects sharing the same name. The name is always the
name of global object (in CIR context, the GlobalOp or FuncOp), so we
don't need it. And the user set can always be collected when a
transformation looks up symbol table of the module, thus not really
necessary. Plus, it's not good for CIR to keep a set of pointers.
2. Thanks to comdat support, and adding call sites of setComdat similar
to what was in OG, we are able to implement canBenefitFromLocalAlias as
similar as possible to [GlobalValue::canBenefitFromLocalAlias()
](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/lib/IR/Globals.cpp#L112)
and this enable us to complete dso_local work by correctly setting
dso_local for functions.
3. I took back printing of dsolocal attribute of CIR, as I would fix
128+ test cases instead of 36-37 of tests (mostly adding dso_local to
function prototype line in LLVM check) in this PR. printing dsolocal
attribute is not really necessary as llvm IR would verify it for us.
4. LLVM lowering of Comdat for GlobalOp 


Things left to next/future PR
1. I'd like to extend setComdat to other parts of CG like Vtable, etc. 
2. LLVM lowering of comdat for FuncOp
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…LLVM tagging (llvm#751)

This PR implements:
1. Add comdat attribute as an optional attribute to CIR GlobalOp and
FuncOp, they are of the enum ComdatSelection type because it contains
all information we need. The
[llvm/include/llvm/IR/Comdat.h](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/include/llvm/IR/Comdat.h#L33)
has Comdat with selectionKind and its name, add users which are set of
pointers to GlobalObjects sharing the same name. The name is always the
name of global object (in CIR context, the GlobalOp or FuncOp), so we
don't need it. And the user set can always be collected when a
transformation looks up symbol table of the module, thus not really
necessary. Plus, it's not good for CIR to keep a set of pointers.
2. Thanks to comdat support, and adding call sites of setComdat similar
to what was in OG, we are able to implement canBenefitFromLocalAlias as
similar as possible to [GlobalValue::canBenefitFromLocalAlias()
](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/lib/IR/Globals.cpp#L112)
and this enable us to complete dso_local work by correctly setting
dso_local for functions.
3. I took back printing of dsolocal attribute of CIR, as I would fix
128+ test cases instead of 36-37 of tests (mostly adding dso_local to
function prototype line in LLVM check) in this PR. printing dsolocal
attribute is not really necessary as llvm IR would verify it for us.
4. LLVM lowering of Comdat for GlobalOp 


Things left to next/future PR
1. I'd like to extend setComdat to other parts of CG like Vtable, etc. 
2. LLVM lowering of comdat for FuncOp
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…LLVM tagging (llvm#751)

This PR implements:
1. Add comdat attribute as an optional attribute to CIR GlobalOp and
FuncOp, they are of the enum ComdatSelection type because it contains
all information we need. The
[llvm/include/llvm/IR/Comdat.h](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/include/llvm/IR/Comdat.h#L33)
has Comdat with selectionKind and its name, add users which are set of
pointers to GlobalObjects sharing the same name. The name is always the
name of global object (in CIR context, the GlobalOp or FuncOp), so we
don't need it. And the user set can always be collected when a
transformation looks up symbol table of the module, thus not really
necessary. Plus, it's not good for CIR to keep a set of pointers.
2. Thanks to comdat support, and adding call sites of setComdat similar
to what was in OG, we are able to implement canBenefitFromLocalAlias as
similar as possible to [GlobalValue::canBenefitFromLocalAlias()
](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/lib/IR/Globals.cpp#L112)
and this enable us to complete dso_local work by correctly setting
dso_local for functions.
3. I took back printing of dsolocal attribute of CIR, as I would fix
128+ test cases instead of 36-37 of tests (mostly adding dso_local to
function prototype line in LLVM check) in this PR. printing dsolocal
attribute is not really necessary as llvm IR would verify it for us.
4. LLVM lowering of Comdat for GlobalOp 


Things left to next/future PR
1. I'd like to extend setComdat to other parts of CG like Vtable, etc. 
2. LLVM lowering of comdat for FuncOp
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…LLVM tagging (llvm#751)

This PR implements:
1. Add comdat attribute as an optional attribute to CIR GlobalOp and
FuncOp, they are of the enum ComdatSelection type because it contains
all information we need. The
[llvm/include/llvm/IR/Comdat.h](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/include/llvm/IR/Comdat.h#L33)
has Comdat with selectionKind and its name, add users which are set of
pointers to GlobalObjects sharing the same name. The name is always the
name of global object (in CIR context, the GlobalOp or FuncOp), so we
don't need it. And the user set can always be collected when a
transformation looks up symbol table of the module, thus not really
necessary. Plus, it's not good for CIR to keep a set of pointers.
2. Thanks to comdat support, and adding call sites of setComdat similar
to what was in OG, we are able to implement canBenefitFromLocalAlias as
similar as possible to [GlobalValue::canBenefitFromLocalAlias()
](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/lib/IR/Globals.cpp#L112)
and this enable us to complete dso_local work by correctly setting
dso_local for functions.
3. I took back printing of dsolocal attribute of CIR, as I would fix
128+ test cases instead of 36-37 of tests (mostly adding dso_local to
function prototype line in LLVM check) in this PR. printing dsolocal
attribute is not really necessary as llvm IR would verify it for us.
4. LLVM lowering of Comdat for GlobalOp 


Things left to next/future PR
1. I'd like to extend setComdat to other parts of CG like Vtable, etc. 
2. LLVM lowering of comdat for FuncOp
lanza pushed a commit that referenced this pull request Nov 5, 2024
…LLVM tagging (#751)

This PR implements:
1. Add comdat attribute as an optional attribute to CIR GlobalOp and
FuncOp, they are of the enum ComdatSelection type because it contains
all information we need. The
[llvm/include/llvm/IR/Comdat.h](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/include/llvm/IR/Comdat.h#L33)
has Comdat with selectionKind and its name, add users which are set of
pointers to GlobalObjects sharing the same name. The name is always the
name of global object (in CIR context, the GlobalOp or FuncOp), so we
don't need it. And the user set can always be collected when a
transformation looks up symbol table of the module, thus not really
necessary. Plus, it's not good for CIR to keep a set of pointers.
2. Thanks to comdat support, and adding call sites of setComdat similar
to what was in OG, we are able to implement canBenefitFromLocalAlias as
similar as possible to [GlobalValue::canBenefitFromLocalAlias()
](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/lib/IR/Globals.cpp#L112)
and this enable us to complete dso_local work by correctly setting
dso_local for functions.
3. I took back printing of dsolocal attribute of CIR, as I would fix
128+ test cases instead of 36-37 of tests (mostly adding dso_local to
function prototype line in LLVM check) in this PR. printing dsolocal
attribute is not really necessary as llvm IR would verify it for us.
4. LLVM lowering of Comdat for GlobalOp 


Things left to next/future PR
1. I'd like to extend setComdat to other parts of CG like Vtable, etc. 
2. LLVM lowering of comdat for FuncOp
lanza pushed a commit that referenced this pull request Mar 18, 2025
…LLVM tagging (#751)

This PR implements:
1. Add comdat attribute as an optional attribute to CIR GlobalOp and
FuncOp, they are of the enum ComdatSelection type because it contains
all information we need. The
[llvm/include/llvm/IR/Comdat.h](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/include/llvm/IR/Comdat.h#L33)
has Comdat with selectionKind and its name, add users which are set of
pointers to GlobalObjects sharing the same name. The name is always the
name of global object (in CIR context, the GlobalOp or FuncOp), so we
don't need it. And the user set can always be collected when a
transformation looks up symbol table of the module, thus not really
necessary. Plus, it's not good for CIR to keep a set of pointers.
2. Thanks to comdat support, and adding call sites of setComdat similar
to what was in OG, we are able to implement canBenefitFromLocalAlias as
similar as possible to [GlobalValue::canBenefitFromLocalAlias()
](https://github.com/llvm/clangir/blob/4ea2ec38638391b964e88b77f926e0892b350e04/llvm/lib/IR/Globals.cpp#L112)
and this enable us to complete dso_local work by correctly setting
dso_local for functions.
3. I took back printing of dsolocal attribute of CIR, as I would fix
128+ test cases instead of 36-37 of tests (mostly adding dso_local to
function prototype line in LLVM check) in this PR. printing dsolocal
attribute is not really necessary as llvm IR would verify it for us.
4. LLVM lowering of Comdat for GlobalOp

Things left to next/future PR
1. I'd like to extend setComdat to other parts of CG like Vtable, etc.
2. LLVM lowering of comdat for FuncOp
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