This adds an implementation for compile as well as compile-and-link, but not link. For compile-and-link we rely on clang to orchestrate both similarly to how the tests use it today.
Btw, I also wrote something like this in D55430. (Zachary asked me to do it, but it looks like he missed the review request. :P)
I think my version is more complete, though I am missing lto support, because I couldn't be bothered to figure out how it works. But if all that's needed is to add -flto=thin, then I can easily integrate that.
@labath: Sorry, I didn't miss it, I just forgot about it (that's not much better, I know). I'll look today. If Pavel's is more complete let's use that as a starting point, although TBH I'm fine going with either one.