[clang] [llvm] [clang] Support per-function [[clang::code_align(N)]] attribute. (PR #80765)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 14:31:50 PST 2024


efriedma-quic wrote:

> > I'm skeptical this actually makes sense in its current form. LLVM internally has a thing it calls a basic block, but what exactly counts is, to some extent, machine-specific, and can change from version to version.
> 
> I guess regardless of whether we call it BB alignment or label alignment, the concept is already supported on the frontend side for loops. My idea was that we could lift it to the function level, forcing all the function "labels" be aligned on a certain boundary.

Aligning the targets of branches is a different thing from what you've implemented.  There are basic blocks which are not branch targets, and there are branch targets which are not at the beginning of a basic block.  (Branch targets that aren't at the beginning of a basic block are rare on most targets, but it doesn't seem like something we should completely ignore.)

"Loop alignment" is specifically a request to override the normal compiler heuristics for aligning the loop header i.e. the target of the loop backedges.  This is best-effort; a "loop" in C code might not lower to something that actually has a header we can align.

"-malign-branch-boundary" specifically inserts padding so branch instructions don't cross a 32-byte boundary; it isn't trying to align anything.

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


More information about the cfe-commits mailing list