This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Add a sum type abstraction for pointer-like types.
ClosedPublic

Authored by chandlerc on Jan 2 2016, 2:49 AM.

Details

Summary

This is a much more general and powerful form of PointerUnion. It
provides a reasonably complete sum type (from type theory) for
pointer-like types. It has several significant advantages over the
existing PointerUnion infrastructure:

  1. It allows more than two pointer types to participate without awkward nesting structures.
  2. It directly exposes the tag so that it is convenient to write switches over the possible members.
  3. It can re-use the same type for multiple tag values, something that has been worked around by either abusing PointerIntPair or defining nonce types and doing unsafe pointer casting.
  4. It supports customization of the PointerLikeTypeTraits used for specific member types. This means it could (in theory) be used even with types that are over-aligned on allocation to expose larger numbers of bits to the tag.

All in all, I think it is at least complimentary to the existing
infrastructure, and a strict improvement for some use cases.

Diff Detail

Repository
rL LLVM

Event Timeline

chandlerc updated this revision to Diff 43844.Jan 2 2016, 2:49 AM
chandlerc retitled this revision from to [ADT] Add a sum type abstraction for pointer-like types..
chandlerc updated this object.
chandlerc added a reviewer: rsmith.
chandlerc added a subscriber: llvm-commits.

You can see an example usage in http://reviews.llvm.org/D15845

craig.topper added inline comments.
include/llvm/ADT/PointerSumType.h
176 ↗(On Diff #43844)

Should this say PointerSumType instead of PointerUnion?

Er, canceling ping as Justin already replied with delightful comments and I
just missed it. =D

chandlerc marked an inline comment as done.Jan 10 2016, 12:33 AM
chandlerc added inline comments.
include/llvm/ADT/PointerSumType.h
176 ↗(On Diff #43844)

Yep, good catch, will fix before i land it.

This revision was automatically updated to reflect the committed changes.
chandlerc marked an inline comment as done.