Files
Giacomo Vercesi 56ab47bfd2 Outline mergeBackImpl in IRHelpers
Move the body of `LLVMContainer::mergeBackImpl` in
`Support/IRHelpers.cpp` under the name `linkFunctionModules`.
2025-12-10 16:16:14 +01:00

80 lines
2.2 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include "revng/Pipeline/ContainerEnumerator.h"
#include "revng/Pipeline/Pipe.h"
inline Logger ModuleStatisticsLogger("module-statistics");
namespace pipeline {
class LLVMContainer : public EnumerableContainer<LLVMContainer> {
private:
using LinkageRestoreMap = std::map<std::string,
llvm::GlobalValue::LinkageTypes>;
public:
static const char ID;
private:
using ThisType = LLVMContainer;
private:
std::unique_ptr<llvm::Module> Module;
public:
inline static const llvm::StringRef MIMEType = "application/x.llvm.bc+zstd";
inline static const char *Name = "llvm-container";
LLVMContainer(llvm::StringRef Name,
Context *Context,
llvm::LLVMContext *LLVMContext) :
EnumerableContainer<ThisType>(*Context, Name),
Module(std::make_unique<llvm::Module>("revng.module", *LLVMContext)) {}
LLVMContainer(llvm::StringRef Name,
Context *Context,
std::unique_ptr<llvm::Module> M) :
EnumerableContainer<ThisType>(*Context, Name), Module(std::move(M)) {}
LLVMContainer &cloneFrom(const LLVMContainer &Another);
LLVMContainer &swapWith(LLVMContainer &Another);
public:
template<typename... LLVMPasses>
static PipeWrapper
wrapLLVMPasses(std::string LLVMModuleName, LLVMPasses &&...P) {
return PipeWrapper::make(GenericLLVMPipe(std::move(P)...),
{ std::move(LLVMModuleName) });
}
public:
const llvm::Module &getModule() const { return *Module; }
llvm::Module &getModule() { return *Module; }
public:
std::unique_ptr<ContainerBase>
cloneFiltered(const TargetsList &Targets) const final;
llvm::Error extractOne(llvm::raw_ostream &OS,
const Target &Target) const override;
public:
llvm::Error serialize(llvm::raw_ostream &OS) const final;
llvm::Error deserializeImpl(const llvm::MemoryBuffer &Buffer) final;
void clearImpl() final {
Module = std::make_unique<llvm::Module>("revng.module",
Module->getContext());
}
private:
void mergeBackImpl(ThisType &&OtherContainer) final;
};
} // namespace pipeline