|Version 2 (modified by gmainland, 3 years ago) (diff)|
The LLVM backend sadly includes a 'mangler'. This is a Haskell written program (well pass of GHC) that runs on the assembly code generated by the LLVM compiler. We do this as there are a few issues with communicating to LLVM exactly what we want generated as object code and so, for now, it is easiest to post-process the assembly.
Long term we ideally would submit patches to LLVM and get rid of the mangler. The work required to do that may be quite high and the patches needed potentially fairly specific to GHC. So no one has done that yet.
Below are the issues that the LLVM Mangler addresses in the assembly code.
LLVM requires that the C stack be properly aligned for spills. One Win32 the stack is 4-byte aligned, which is not enough for SSE spills, and even on x64 platforms the stack is only 16-byte aligned, which is not enough for AVX spills. When the stack is not properly aligned for spills, LLVM generates prologue/epilogue code that fiddles with the base pointer, which GHC uses as its stack pointer, and disables tail call optimization. Both are very bad. Therefore we currently tell LLVM to always assume the stack is properly aligned and then rewrite all aligned SSE/AVX move instructions to their unaligned counterparts inside the mangler.