llvm-wrapper: use new pass manager for thin lto with LLVM version 15

No functional changes intended.

LLVM commit 633f5663c3 removed `createWriteThinLTOBitcodePass`.
This adapts PassWrapper similarly to the example mentioned upstream: 633f5663c3.
This commit is contained in:
Krasimir Georgiev 2022-08-16 13:02:45 +00:00
parent 14a459bf37
commit 7cba1f9eab
1 changed files with 23 additions and 2 deletions

View File

@ -31,6 +31,9 @@
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#if LLVM_VERSION_GE(15, 0)
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#endif
#include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h"
@ -1587,13 +1590,31 @@ LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
{
raw_string_ostream OS(Ret->data);
{
legacy::PassManager PM;
if (is_thin) {
#if LLVM_VERSION_LT(15, 0)
legacy::PassManager PM;
PM.add(createWriteThinLTOBitcodePass(OS));
PM.run(*unwrap(M));
#else
PassBuilder PB;
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
ModulePassManager MPM;
MPM.addPass(ThinLTOBitcodeWriterPass(OS, nullptr));
MPM.run(*unwrap(M), MAM);
#endif
} else {
legacy::PassManager PM;
PM.add(createBitcodeWriterPass(OS));
PM.run(*unwrap(M));
}
PM.run(*unwrap(M));
}
}
return Ret.release();