I believe Enzyme comes close to what you describe. It works on the LLVM IR level.
https://enzyme.mit.edu