Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Add parameter/function attributes and LLVM TBAA to inform optimizer. #214

Open
nvjle opened this issue Jun 30, 2023 · 0 comments · Fixed by #213, #215 or #216
Open

Add parameter/function attributes and LLVM TBAA to inform optimizer. #214

nvjle opened this issue Jun 30, 2023 · 0 comments · Fixed by #213, #215 or #216
Labels
enhancement New feature or request

Comments

@nvjle
Copy link

nvjle commented Jun 30, 2023

This issue captures some thoughts regarding future/incremental improvements to our generated LLVM IR (from offline discussions with Jan).

We currently generate LLVM IR in the simplest and most conservative manner possible, relying on LLVM to optimize our resulting code. This is exactly the right thing to do during initial compiler implementation and bring-up. LLVM is generally doing a very good right out of the box. There is some room, however, for improvement in the way we shape the IR for LLVM to do an even better job.

We have reached a state where the compiler is generating runnable code and has some sanity testing to verify correctness. Thus we can incrementally begin optimizing our results a bit. Issue #204 is one possible way to address this by optimizing the input stackless bytecode before we ever translate it to LLVM IR. The second way (this issue) is to shape the resultant LLVM IR better.

Currently we generate mostly unadorned LLVM IR. That is, we intentionally do not add certain attributes to the resulting IR, possibly pessimizing LLVM IR optimizations later. For example, we know directly from the stackless bytecode that a & function argument is read-only, and a &mut pointer is writable. Similarly, most (if not all) pointers we pass around are known to be non-null (e.g., move-native type descriptors, etc).

We also do not yet annotate types (TBAA) so that LLVM's type-based alias analysis can do a better job. With structs, we likely need TBAA to inform the optimizer for, e.g., SROA and other transformations that depend on good alias analysis.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.