Mozilla did something similar to this based on gcc once: https://lwn.net/Articles/370717/