[ADT] Add SmallVectorWithFlags with packed user flags
Structures that hold a SmallVector followed by a bool or a couple of
flag bits pay up to eight bytes of padding for those bits.
SmallVectorWithFlags stores one to four user flag bits in the high bits
of the capacity field, so it has the same size and inline capacity as
SmallVector.
Only capacity(), read by the growth check in push_back, masks the flags
out; begin(), end(), and size() are untouched. The cost is a maximum
capacity divided by 2^FlagBits, which with the 32-bit size type and
four flag bits is 268 million elements.
The SmallVector implementation layers take a FlagBits template
parameter, which plain SmallVector instantiates with zero bits so that
every mask folds away; its interface and codegen are unchanged. The
out-of-line growth routines stay in SmallVectorBase and remain
instantiated once per size type, with masked variants taking the
capacity mask at run time. The trade-off versus a composed
{ SmallVector, uint8_t Flags } is that the flagged container is not a
SmallVectorImpl<T>: use ArrayRef<T> for read-only interfaces and
SmallVectorWithFlagsImpl<T, FlagBits> for output parameters.
Element operations preserve flags; complete-container copy, move, and
swap include them. Equality compares flags and elements, and ordering
compares elements before flags. Comparison against ArrayRef is
intentionally not provided; convert explicitly for an element-only
comparison.
Assisted-by: Codex
Assisted-by: Claude Code
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called “LLVM”. This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.