[llvm] [MachineOutliner] Preserve regmasks in calls to outlined functions (PR #120940)

Zhaoxuan Jiang via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 2 21:45:00 PST 2025


nocchijiang wrote:

I think it's necessary to pause and reach an agreement before proceeding with further changes.

To answer @MatzeB 's question first: I apologize for not posting the link to the RFC earlier: https://discourse.llvm.org/t/loh-conflicting-with-machineoutliner/83279. Here’s a summary: I plan to move AArch64CollectLOH to addPreEmitPass2 to allow the outliner to optimize more. Historically AArch64CollectLOH has made certain assumptions about its input and has accepted some trade-offs for compile-time performance (some of which I believe is actually written by @MatzeB). These will be invalidated with the proposed change.

What this PR addresses falls in the latter category: AArch64CollectLOH does not perform accurate register liveness analysis but only looks into regmasks and defs to determine if a given register is clobbered. MachineOutliner emits calls to outlined sequences, which probably contains calls to another function which clobbers caller-saved registers. This is not reflected in the defs but in the regmask. Therefore, the accuracy of regmask is key to accurate LOH emissions, which MachineOutliner lacks right now.

Regarding concerns about the `allocateRegMask` refactoring: regmask has been seriously lacking proper abstraction and encapsulation. A simple global search on `allocateRegMask` reveals a lot of instances of implementation detail leaks. We need to clearly define the aspects we want to improve in this PR; otherwise, it could become endless and extend far beyond its scope. `MutableArrayRef<uint32_t>` suggested by @kyulee-com indeed avoids explicit size reporting but offers no improvement in other aspects (initial value setting, cloning, manipulation, etc.).

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


More information about the llvm-commits mailing list