Get it. Yes it is possible that it might resolved the problem.
This is just a personal opinion. Use process loading/unloading to erase the state is a bit like working around the problem in a non-traditional way to tackle library dependencies. Additionally, the cost can come with loading/unloading each time.
Of course, when it comes to the need of isolation, we could choose to use solutions under this vein. A simpler one could be just hide build under a PopenWorker(which brings it to another process with a similar state). I would try to use new process, instead of load/unloading if possible (as loading/unloading also comes with complications of searching the additional DLL path under env, windows/linux specific dlopen etc).
Ideally, we should be able to configure an PassManager pipeline that is somewhat invariant from the LLVM static configuration. I have not read this part deeper enough to concretely say it is possible, but Reading LLVM doc gatherUnrollingPreferences does comes with some functions parameters that specifies unrolling preferences. Of course it depends on how intertwined the LLVM codepath with the static cl option.
Another way is to invest in utility tools to reset the cl options to the desirable state when entering an RAII scope, and recovering the cl option when exiting an RAII scope. I am not that deep into llvm::cl::option
to see if that is possible, but it might worth thinking a bit about. As the cl::option
does come with operator=
, perhaps just need a way to get to the registered cl::option and do the reset(instead of calling ProcessLLVMOption)
The dummy code below shows what do I mean by that(although I am not sure how hard to get this to work, depending on how LLVM structures these options and their registration)
// hypotethsis code
void CodegenFunc() {
With<LLVMOptionScope<int>>("unroll-threshold", 10);
{
With<LLVMOptionScope<int>>("unroll-threshold", 100);
CHECK_EQ(GetLLVMOption<int>("unroll-upperbound"), 100);
}
CHECK_EQ(GetLLVMOption<int>("unroll-upperbound"), 10);
}