LLVM 22.0.0git
OptimizedStructLayout.h File Reference

This file provides an interface for laying out a sequence of fields as a struct in a way that attempts to minimizes the total space requirements of the struct while still satisfying the layout requirements of the individual fields. More...

#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Compiler.h"
#include <utility>

Go to the source code of this file.

Classes

struct  llvm::OptimizedStructLayoutField
 A field in a structure. More...

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.

Functions

LLVM_ABI std::pair< uint64_t, Alignllvm::performOptimizedStructLayout (MutableArrayRef< OptimizedStructLayoutField > Fields)
 Compute a layout for a struct containing the given fields, making a best-effort attempt to minimize the amount of space required.

Detailed Description

This file provides an interface for laying out a sequence of fields as a struct in a way that attempts to minimizes the total space requirements of the struct while still satisfying the layout requirements of the individual fields.

The resulting layout may be substantially more compact than simply laying out the fields in their original order.

Fields may be pre-assigned fixed offsets. They may also be given sizes that are not multiples of their alignments. There is no currently no way to describe that a field has interior padding that other fields may be allocated into.

This algorithm does not claim to be "optimal" for several reasons:

  • First, it does not guarantee that the result is minimal in size. There is no known efficient algoorithm to achieve minimality for unrestricted inputs. Nonetheless, this algorithm
  • Second, there are other ways that a struct layout could be optimized besides space usage, such as locality. This layout may have a mixed impact on locality: less overall memory may be used, but adjacent fields in the original array may be moved further from one another.

Definition in file OptimizedStructLayout.h.