14#include "llvm/ADT/StringSet.h"
15#include "llvm/Bitcode/BitcodeReader.h"
16#include "llvm/IR/Module.h"
17#include "llvm/Linker/Linker.h"
18#include "llvm/Transforms/IPO/Internalize.h"
24 bool OnlyInternalized) {
25 if (!LinkModules.empty())
30 if (OnlyInternalized && !F.Internalize)
35 << F.Filename << BCBuf.getError().message();
41 llvm::getOwningLazyBitcodeModule(std::move(*BCBuf), Ctx);
43 llvm::handleAllErrors(
44 ModuleOrErr.takeError(), [&](llvm::ErrorInfoBase &EIB) {
45 CI.getDiagnostics().Report(diag::err_cannot_open_file)
46 << F.Filename << EIB.message();
52 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
53 F.Internalize, F.LinkFlags});
65 assert(LM.Module &&
"LinkModule does not actually have a module");
67 if (LM.PropagateAttrs)
68 for (llvm::Function &F : *LM.Module) {
74 F, CodeGenOpts, LangOpts, TargetOpts, LM.Internalize);
81 Err = llvm::Linker::linkModules(
82 M, std::move(LM.Module), LM.LinkFlags,
83 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
84 llvm::internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
85 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
89 Err = llvm::Linker::linkModules(M, std::move(LM.Module), LM.LinkFlags);
Owns the state needed to translate LLVM backend diagnostics into clang diagnostics,...
void setCurLinkModule(llvm::Module *M)
Set the module currently being linked in, used to name DK_Linker diagnostics.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::vector< BitcodeFileToLink > LinkBitcodeFiles
The files specified here are linked in to the module before optimizations.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
FileManager & getFileManager() const
Return the current file manager to the caller.
CodeGenOptions & getCodeGenOpts()
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(FileEntryRef Entry, bool isVolatile=false, bool RequiresNullTerminator=true, std::optional< int64_t > MaybeLimit=std::nullopt, bool IsText=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Options for controlling the target.
void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, const TargetOptions &TargetOpts, bool WillInternalize)
Adds attributes to F according to our CodeGenOpts and LangOpts, as though we had emitted it ourselves...
Top level wrappers for InstallAPI frontend operations.
bool loadLinkModules(CompilerInstance &CI, llvm::LLVMContext &Ctx, llvm::SmallVectorImpl< LinkModule > &LinkModules, bool OnlyInternalized)
Load every bitcode file listed in CodeGenOpts.LinkBitcodeFiles into LinkModules.
bool linkInModules(llvm::Module &M, llvm::SmallVectorImpl< LinkModule > &LinkModules, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, const TargetOptions &TargetOpts, BackendDiagnosticConsumer &DiagConsumer)
Link every module in LinkModules into M, propagating default function attributes and internalizing as...
Info about a module to link into the module currently being generated.