From ae2e1ded061f9b2efa7f06580de2dd75814a322d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Apr 2023 04:09:22 -0400 Subject: [PATCH 6/7] Port LLVMGoWriteThinLTOBitcodeToMemoryBuffer to new Pass Manager Signed-off-by: Elliott Sales de Andrade --- backports.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backports.cpp b/backports.cpp index b9a41e8..c3d80a1 100644 --- a/backports.cpp +++ b/backports.cpp @@ -1,12 +1,20 @@ #include "backports.h" #include "llvm/IR/Instructions.h" +#if LLVM_VERSION_MAJOR >= 16 +#include "llvm/IR/PassManager.h" +#include "llvm/Analysis/LoopAnalysisManager.h" +#include "llvm/Analysis/CGSCCPassManager.h" +#include "llvm/Passes/PassBuilder.h" +#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" +#else #include "llvm/IR/LegacyPassManager.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" +#endif #include "llvm/IR/Module.h" #include "llvm/Pass.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Transforms/IPO.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm-c/DebugInfo.h" void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetadataRef MD) { @@ -19,8 +27,24 @@ void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetad LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M) { std::string Data; llvm::raw_string_ostream OS(Data); +#if LLVM_VERSION_MAJOR >= 16 + llvm::LoopAnalysisManager LAM; + llvm::FunctionAnalysisManager FAM; + llvm::CGSCCAnalysisManager CGAM; + llvm::ModuleAnalysisManager MAM; + llvm::PassBuilder PB; + PB.registerModuleAnalyses(MAM); + PB.registerCGSCCAnalyses(CGAM); + PB.registerFunctionAnalyses(FAM); + PB.registerLoopAnalyses(LAM); + PB.crossRegisterProxies(LAM, FAM, CGAM, MAM); + llvm::ModulePassManager MPM; + MPM.addPass(llvm::ThinLTOBitcodeWriterPass(OS, nullptr)); + MPM.run(*llvm::unwrap(M), MAM); +#else llvm::legacy::PassManager PM; PM.add(createWriteThinLTOBitcodePass(OS)); PM.run(*llvm::unwrap(M)); +#endif return llvm::wrap(llvm::MemoryBuffer::getMemBufferCopy(OS.str()).release()); } -- 2.39.2