Skip to content

Commit 7cba1f9

Browse files
committed
llvm-wrapper: use new pass manager for thin lto with LLVM version 15
No functional changes intended. LLVM commit llvm/llvm-project@633f566 removed `createWriteThinLTOBitcodePass`. This adapts PassWrapper similarly to the example mentioned upstream: llvm/llvm-project@633f566.
1 parent 14a459b commit 7cba1f9

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
3232
#include "llvm/Transforms/IPO/AlwaysInliner.h"
3333
#include "llvm/Transforms/IPO/FunctionImport.h"
34+
#if LLVM_VERSION_GE(15, 0)
35+
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
36+
#endif
3437
#include "llvm/Transforms/Utils/AddDiscriminators.h"
3538
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
3639
#include "llvm/LTO/LTO.h"
@@ -1587,13 +1590,31 @@ LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
15871590
{
15881591
raw_string_ostream OS(Ret->data);
15891592
{
1590-
legacy::PassManager PM;
15911593
if (is_thin) {
1594+
#if LLVM_VERSION_LT(15, 0)
1595+
legacy::PassManager PM;
15921596
PM.add(createWriteThinLTOBitcodePass(OS));
1597+
PM.run(*unwrap(M));
1598+
#else
1599+
PassBuilder PB;
1600+
LoopAnalysisManager LAM;
1601+
FunctionAnalysisManager FAM;
1602+
CGSCCAnalysisManager CGAM;
1603+
ModuleAnalysisManager MAM;
1604+
PB.registerModuleAnalyses(MAM);
1605+
PB.registerCGSCCAnalyses(CGAM);
1606+
PB.registerFunctionAnalyses(FAM);
1607+
PB.registerLoopAnalyses(LAM);
1608+
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1609+
ModulePassManager MPM;
1610+
MPM.addPass(ThinLTOBitcodeWriterPass(OS, nullptr));
1611+
MPM.run(*unwrap(M), MAM);
1612+
#endif
15931613
} else {
1614+
legacy::PassManager PM;
15941615
PM.add(createBitcodeWriterPass(OS));
1616+
PM.run(*unwrap(M));
15951617
}
1596-
PM.run(*unwrap(M));
15971618
}
15981619
}
15991620
return Ret.release();

0 commit comments

Comments
 (0)