[llvm] [C API] Add blockaddress getters to C API (PR #77390)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 10 01:30:56 PST 2024


nikic wrote:

> I have pushed some changes to deal with unnamed basic blocks. From my understanding, `blockaddress` constants can only reference unnamed basic blocks that are in the same function.

It looks like for textual IR, we allow it if the reference comes first (https://llvm.godbolt.org/z/8K7rq418Y), but forbid it when it comes later (https://llvm.godbolt.org/z/dj4n7b8zb). Presumably so we don't have to keep around the per-function-state on the off-chance of a later blockaddress reference.

> So to support that case, we clone them inside the `FunCloner` (which has access to the `BBMap` needed to look up unnamed basic blocks), or outside functions in which case we can only clone them by name as the previous version of the PR did. This also means that we only pre-declare named basic blocks, and unnamed ones are lazily cloned in `DeclareBB` as before
> 
> I added a couple more tests, for unnamed local basic blocks, and a global `blockaddress` constant. I decided to move these to a dedicated test file since they were getting to be more substantial

Hm, I'm wondering whether it wouldn't make more sense to simply add a unit to test for the blockaddress getters, instead of supporting them inside echo? Blockaddress cloning is tricky, and I'm not sure there's a lot of value trying to make echo support it correctly, at the cost of extra complexity.

https://github.com/llvm/llvm-project/pull/77390


More information about the llvm-commits mailing list