Offloading Clang's CodeGen?

Similar questions has been asked but didn’t seem to go anywhere.

Basically, in my naive understanding of Clang’s CG, one should be able to override let’s say EmitObjAction, from there, grab the generated raw IR, then offload the actual CodeGen to another process / computer.

I can see how this could be interesting because, One can offload the heavy backend process, hence resulting a much more “stable” implementation of distcc.

My current implementation goes:

  • Create my PluginASTAction that replaces the main action
  • In my Action’s ::CreateASTConsumer, return my ASTConsumer
  • In MyASTConsumer::HandleTranslationUnit:
  MyEmitObjAction action;
  CI.ExecuteAction(action);
  • In MyEmitObjAction::ExecuteAction which override the original EmitObjAction:
CodeGenAction::ExecuteAction();
std::unique_ptr<llvm::Module> M = std::move(takeModule());

Not sure what I did wrong here but it’s crashing at random places that I’m not sure how to debug