Skip to content

[CIR][CIRGen] Implement VisitCXXStdInitializerListExpr to support use of std::initializer_list #764

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 6 commits into from
Aug 13, 2024

Conversation

ghehg
Copy link
Collaborator

@ghehg ghehg commented Jul 31, 2024

implement VisitCXXStdInitializerListExpr as similar as to OG:
In order to support this implementation, made some changes to get more helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting differences:

  1. CIR introduced scope, thus extra branch
  2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but we haven't implemented FuncOP's comdat yet. I'll probably try to add it in another PR, but it's not in the scope of this PR.
  3. When defining initialized_list type, OG prefers generic type like %"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers instantiated like "%"class.std::initializer_list<const char *>" = type { ptr, ptr }"

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! Some minor nit and ready to go.

It would be nice in the future to have a cir.initlist thing - a higher level representation for this (we even have a specialized AST node). Right now it would be really hard to recognize something came from an initializer list if we lower it this early - if you want to work on that at some point it would be welcome. In that world, LoweringPrepare would then lower to what we currently get as of this PR.

@bcardosolopes bcardosolopes changed the title [CIR][CIRGen]Implement VisitCXXStdInitializerListExpr to support use of std::initializer_list [CIR][CIRGen] Implement VisitCXXStdInitializerListExpr to support use of std::initializer_list Aug 2, 2024
@bcardosolopes
Copy link
Member

There are tests failing!

@@ -959,6 +949,19 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
return create<mlir::cir::GetRuntimeMemberOp>(loc, resultTy, objectPtr,
memberPtr);
}

/// create a cir.ptr_stride operation to get access to an array element.
Copy link
Member

@bcardosolopes bcardosolopes Aug 12, 2024

Choose a reason for hiding this comment

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

Comments should in general start with upper case, please apply the change here, next comment, and try to make sure next PRs address that right away.

@bcardosolopes bcardosolopes merged commit 118f463 into llvm:main Aug 13, 2024
6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
… of std::initializer_list (llvm#764)

implement VisitCXXStdInitializerListExpr as similar as to
[OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
In order to support this implementation, made some changes to get more
helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting
differences:
1.  CIR introduced scope, thus extra branch
2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
we haven't implemented FuncOP's comdat yet. I'll probably try to add it
in another PR, but it's not in the scope of this PR.
3. When defining initialized_list type, OG prefers generic type like
%"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
instantiated like "%"class.std::initializer_list<const char *>" = type {
ptr, ptr }"
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
… of std::initializer_list (llvm#764)

implement VisitCXXStdInitializerListExpr as similar as to
[OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
In order to support this implementation, made some changes to get more
helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting
differences:
1.  CIR introduced scope, thus extra branch
2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
we haven't implemented FuncOP's comdat yet. I'll probably try to add it
in another PR, but it's not in the scope of this PR.
3. When defining initialized_list type, OG prefers generic type like
%"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
instantiated like "%"class.std::initializer_list<const char *>" = type {
ptr, ptr }"
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
… of std::initializer_list (llvm#764)

implement VisitCXXStdInitializerListExpr as similar as to
[OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
In order to support this implementation, made some changes to get more
helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting
differences:
1.  CIR introduced scope, thus extra branch
2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
we haven't implemented FuncOP's comdat yet. I'll probably try to add it
in another PR, but it's not in the scope of this PR.
3. When defining initialized_list type, OG prefers generic type like
%"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
instantiated like "%"class.std::initializer_list<const char *>" = type {
ptr, ptr }"
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
… of std::initializer_list (llvm#764)

implement VisitCXXStdInitializerListExpr as similar as to
[OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
In order to support this implementation, made some changes to get more
helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting
differences:
1.  CIR introduced scope, thus extra branch
2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
we haven't implemented FuncOP's comdat yet. I'll probably try to add it
in another PR, but it's not in the scope of this PR.
3. When defining initialized_list type, OG prefers generic type like
%"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
instantiated like "%"class.std::initializer_list<const char *>" = type {
ptr, ptr }"
lanza pushed a commit that referenced this pull request Nov 5, 2024
… of std::initializer_list (#764)

implement VisitCXXStdInitializerListExpr as similar as to
[OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
In order to support this implementation, made some changes to get more
helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting
differences:
1.  CIR introduced scope, thus extra branch
2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
we haven't implemented FuncOP's comdat yet. I'll probably try to add it
in another PR, but it's not in the scope of this PR.
3. When defining initialized_list type, OG prefers generic type like
%"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
instantiated like "%"class.std::initializer_list<const char *>" = type {
ptr, ptr }"
lanza pushed a commit that referenced this pull request Mar 18, 2025
… of std::initializer_list (#764)

implement VisitCXXStdInitializerListExpr as similar as to
[OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
In order to support this implementation, made some changes to get more
helper functions.
Also added some tests.

The generated LLVM code is most similar to OG's llvm code, 3 interesting
differences:
1.  CIR introduced scope, thus extra branch
2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
we haven't implemented FuncOP's comdat yet. I'll probably try to add it
in another PR, but it's not in the scope of this PR.
3. When defining initialized_list type, OG prefers generic type like
%"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
instantiated like "%"class.std::initializer_list<const char *>" = type {
ptr, ptr }"
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