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.