andykaylor wrote:

> We already have `array.dtor` that has per-element destyo region, so I think 
> we should align them.
> 
> Does it even make sense to have two separate operations for this?
> 
> What abous single array.dtor with optional dealloc region?

This operation is specifically representing an array delete in the source code, 
so from that perspective it's something different. They are so obviously 
related that I am uncomfortable with them having so much overlap but being 
separate operations. If we combined them, I wouldn't want to call the combined 
operation `array.dtor`, but we also have `array.ctor`, so not having an 
`array.dtor` is also awkward.

I'm starting to question the value of even having a special `cir.delete_array` 
operation. I guess it captures the high-level information about what the code 
is doing, but as I tried to think through the fully general case with a 
destructed type and potentially throwing destructors, I end up with something 
like this (using `cir.array.dtor` inside the `cir.delete_array`):

```
cir.delete_array %p : !cir.ptr<!rec_S> {
  ^bb0(%arr: !cir.ptr<!rec_S>):
    %adj_ptr, %num_elements, %cookie_size = cir.read_array_cookie %arr
    cir.cleanup.scope {
      cir.array.dtor(%arr : !cir.ptr<!cir.array<!rec_S x 42>>) {
        ^bb1(%element: !cir.ptr<!rec_S>):
          cir.call @some_dtor(%element) : (!cir.ptr<!rec_S>) -> ()
          cir.yield
      }
    } cleanup all {
      cir.call @_ZdaPvm(%adj_tr) : (!cir.ptr<!void>) -> ()
    }
  }
}
```
At that point, we've done all the codegen, so the wrapping operation is just a 
very verbose helper for analysis.

Alternatively, we could attach the `CXXDeleteExpr` from the AST to the 
operation, and start with this:

`cir.delete_array %p : !cir.ptr<!rec_S>`

then lower it to the above during `CXXABILowering`. That does mean we'd need to 
have kept the AST around, but we're already doing that for other similar cases.

https://github.com/llvm/llvm-project/pull/184827
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to