Index: tools/llc/llc.cpp =================================================================== --- tools/llc/llc.cpp +++ tools/llc/llc.cpp @@ -96,6 +96,11 @@ cl::desc("Add comments to directives."), cl::init(true)); +static cl::opt CompileTwice( + "compile-twice", cl::Hidden, + cl::desc("Run everything twice, re-using the same pass manager."), + cl::init(false)); + static int compileModule(char **, LLVMContext &); static std::unique_ptr @@ -379,6 +384,11 @@ cl::PrintOptionValues(); PM.run(*M); + + // If requested, run the pass manager over the same module again, + // to catch any bugs due to persistent state in the passes + if (CompileTwice) + PM.run(*M); } // Declare success. Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -190,6 +190,11 @@ cl::desc("Preserve use-list order when writing LLVM assembly."), cl::init(false), cl::Hidden); +static cl::opt + RunTwice("run-twice", + cl::desc("Run all passes twice, re-using the same pass manager."), + cl::init(false), cl::Hidden); + static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... PM.add(P); @@ -598,6 +603,11 @@ // Now that we have all of the passes ready, run them. Passes.run(*M); + // If requested, run all passes again with the same pass manager to catch + // bugs caused by persistent state in the passes + if (RunTwice) + Passes.run(*M); + // Declare success. if (!NoOutput || PrintBreakpoints) Out->keep();