This is an archive of the discontinued LLVM Phabricator instance.

[docs][OpaquePtr] Add detail to motivations behind opaque pointers
ClosedPublic

Authored by aeubanks on May 24 2022, 10:58 AM.

Details

Diff Detail

Event Timeline

aeubanks created this revision.May 24 2022, 10:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 10:58 AM
aeubanks requested review of this revision.May 24 2022, 10:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2022, 10:58 AM
aeubanks added reviewers: Restricted Project, rnk.May 24 2022, 10:58 AM

If you want to add any of the history, looks like this is my first email proposing the direction: https://lists.llvm.org/pipermail/llvm-dev/2015-February/081822.html

aeubanks updated this revision to Diff 432024.May 25 2022, 9:25 AM

reference post from 2015

rnk added inline comments.May 25 2022, 11:59 AM
llvm/docs/OpaquePointers.rst
51–101

I believe I provided this wording suggestion, but I think it needs work.

I did a bit of digging, and if you go back to the original 2003 publication, it was explicit that the types were included with the intention that they would support optimization:

"The architecture that we propose is based on a new
language-independent low-level code representation
that preserves important type information from the
source code. ...
However, the linktime optimizer can only perform meaningful optimizations on the program if it has enough high-level
information about the program to prove that aggressive optimizations are safe. Because of this, the lowlevel code representation is typed (using a languageindependent constructive type system) and directly
exposes information about structure and array accesses to the optimizer.
...."

Originally, LLVM was a research project with a goal of enabling fancy optimizations (see the DSA paper).

As LLVM evolved into a production compiler, the community started to realize that the LLVM struct type system, or at least the way llvm-gcc used it, couldn't really be used as a sound basis for alias analysis. The DSA alias analysis was removed from LLVM in 2006.

So with that in mind, here's a wording suggestion:

LLVM's type system was originally designed to support high-level optimization. However, years of LLVM implementation experience have demonstrated that the current pointee type system design does not effectively support optimization. Memory optimization algorithms, such as SROA, GVN, and AA, generally need to look through LLVM's struct types and reason about the underlying memory offsets. The community realized that pointee types are hindering LLVM development, rather than helping it.

Pointee types provide some value to frontends because the IR verifier uses types to detect straightforward type confusion bugs. However, frontends also have to deal with the complexity of inserting bitcasts everywhere that they might be required. The current community consensus is that the costs of pointee types outweight the benefits, and that they should be removed.

rnk accepted this revision.Jun 15 2022, 4:21 PM
rnk added a subscriber: nikic.
This revision is now accepted and ready to land.Jun 15 2022, 4:21 PM
nikic accepted this revision.Jun 16 2022, 12:41 AM

Not familiar with the historical context, but looks fine to me :)

This revision was landed with ongoing or failed builds.Jun 16 2022, 10:17 AM
This revision was automatically updated to reflect the committed changes.
foad added a subscriber: foad.Jun 17 2022, 2:40 AM
foad added inline comments.
llvm/docs/OpaquePointers.rst
55

"hindrance"