Shrink wrapping functions can improve performance for functions when the stack is unused. However, all functions where value live-ranges contain function calls are ineligible for shrink wrapping. Why?
- To avoid saving and restoring values across call-sites, LLVM allocates values with live-ranges that cross call sites to callee-saved registers
- If callee-saved registers are used, they must be saved (usually in the function prolog)
- ShrinkWrapping scans from the beginning of the function prolog to the first use of the stack. If a callee-saved register is saved to the stack in the function prolog, ShrinkWrapping will give up early.
To increase the applicability of ShrinkWrapping, this pass identifies instances where a live-range straddling a call-site prevents ShrinkWrapping. The pass switches the calling convention to CXX_FAST_TLS, that saves callee registers to virtual registers. This allows the backend to make better choices about where to save registers and in many cases avoids saving registers to the stack. The exit block is privatized for the fast and slow exit paths to allow each to be specialized independently.