1
Fork 0

Never use legacy PM for writing bitcode

This commit is contained in:
Josh Stone 2022-09-18 11:53:38 -07:00
parent 38e0e8f7bb
commit d6318de13a
2 changed files with 4 additions and 18 deletions

View file

@ -31,13 +31,11 @@
#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h" #include "llvm/Transforms/IPO/FunctionImport.h"
#if LLVM_VERSION_GE(15, 0)
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#endif
#include "llvm/Transforms/Utils/AddDiscriminators.h" #include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h" #include "llvm/Transforms/Utils/FunctionImportUtils.h"
#include "llvm/LTO/LTO.h" #include "llvm/LTO/LTO.h"
#include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm-c/Transforms/PassManagerBuilder.h" #include "llvm-c/Transforms/PassManagerBuilder.h"
#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation.h"
@ -1377,11 +1375,6 @@ LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
raw_string_ostream OS(Ret->data); raw_string_ostream OS(Ret->data);
{ {
if (is_thin) { if (is_thin) {
#if LLVM_VERSION_LT(15, 0)
legacy::PassManager PM;
PM.add(createWriteThinLTOBitcodePass(OS));
PM.run(*unwrap(M));
#else
PassBuilder PB; PassBuilder PB;
LoopAnalysisManager LAM; LoopAnalysisManager LAM;
FunctionAnalysisManager FAM; FunctionAnalysisManager FAM;
@ -1395,11 +1388,8 @@ LLVMRustThinLTOBufferCreate(LLVMModuleRef M, bool is_thin) {
ModulePassManager MPM; ModulePassManager MPM;
MPM.addPass(ThinLTOBitcodeWriterPass(OS, nullptr)); MPM.addPass(ThinLTOBitcodeWriterPass(OS, nullptr));
MPM.run(*unwrap(M), MAM); MPM.run(*unwrap(M), MAM);
#endif
} else { } else {
legacy::PassManager PM; WriteBitcodeToFile(*unwrap(M), OS);
PM.add(createBitcodeWriterPass(OS));
PM.run(*unwrap(M));
} }
} }
} }

View file

@ -12,7 +12,7 @@
#include "llvm/Object/COFFImportFile.h" #include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Bitcode/BitcodeWriterPass.h" #include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/Support/Signals.h" #include "llvm/Support/Signals.h"
#include "llvm/ADT/Optional.h" #include "llvm/ADT/Optional.h"
@ -1709,11 +1709,7 @@ LLVMRustModuleBufferCreate(LLVMModuleRef M) {
auto Ret = std::make_unique<LLVMRustModuleBuffer>(); auto Ret = std::make_unique<LLVMRustModuleBuffer>();
{ {
raw_string_ostream OS(Ret->data); raw_string_ostream OS(Ret->data);
{ WriteBitcodeToFile(*unwrap(M), OS);
legacy::PassManager PM;
PM.add(createBitcodeWriterPass(OS));
PM.run(*unwrap(M));
}
} }
return Ret.release(); return Ret.release();
} }