Skip to content

[CIR][Lowering] Lower delete array to LLVM #1588

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 5 commits into from
May 7, 2025

Conversation

ahmedshakill
Copy link
Contributor

Initial implementation of lowering cir.delete.array #1285

lowered to a call to _ZdaPv keeping similarity with how Clang AST is lowered.

before

module @"/opt/tmp/input.cpp" attributes {cir.lang = #cir.lang<cxx>, cir.sob = #cir.signed_overflow_behavior<undefined>, cir.triple = "x86_64-unknown-linux-gnu", cir.type_size_info = #cir.type_size_info<char = 8, int = 32, size_t = 64>, dlti.dl_spec = #dlti.dl_spec<!llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i128 = dense<128> : vector<2xi64>, !llvm.ptr<270> = dense<32> : vector<4xi64>, f80 = dense<128> : vector<2xi64>, i1 = dense<8> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, i64 = dense<64> : vector<2xi64>, "dlti.stack_alignment" = 128 : i64, "dlti.endianness" = "little", "dlti.mangling_mode" = "e">} {
  cir.func @_Z17test_delete_arrayPi(%arg0: !cir.ptr<!s32i> loc(fused[#loc3, #loc4])) extra(#fn_attr) {
    %0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["ptr", init] {alignment = 8 : i64} loc(#loc8)
    cir.store %arg0, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> loc(#loc5)
    %1 = cir.load %0 : !cir.ptr<!cir.ptr<!s32i>>, !cir.ptr<!s32i> loc(#loc6)
    cir.delete.array %1 : <!s32i> loc(#loc6)
    cir.return loc(#loc2)
  } loc(#loc7)
} loc(#loc)

after

define dso_local void @_Z17test_delete_arrayPi(ptr %0) #0 {
  %2 = alloca ptr, i64 1, align 8
  store ptr %0, ptr %2, align 8
  %3 = load ptr, ptr %2, align 8
  call void @_ZdaPv(ptr %3)
  ret void
}

Copy link

github-actions bot commented Apr 28, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

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 first contribution and for adding support for this. Few nits and this should be ready to go.

@bcardosolopes bcardosolopes changed the title Lower delete array [CIR][Lowering] Lower delete array Apr 30, 2025
@bcardosolopes bcardosolopes changed the title [CIR][Lowering] Lower delete array [CIR][Lowering] Lower delete array to LLVM Apr 30, 2025
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 once it passes tests!

@ahmedshakill ahmedshakill requested a review from bcardosolopes May 1, 2025 05:37
@ahmedshakill
Copy link
Contributor Author

ahmedshakill commented May 1, 2025

@bcardosolopes Sorry about earlier, it seems I didn't ran git-clang-format properly. Hopefully this should be okay now.

@bcardosolopes
Copy link
Member

Dispatched another test attempt!

@bcardosolopes bcardosolopes merged commit 0678431 into llvm:main May 7, 2025
9 checks passed
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