clang 23.0.0git
ModuleLinker.cpp
Go to the documentation of this file.
1//===--- ModuleLinker.cpp - Shared bitcode link helpers -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
13#include "llvm/Bitcode/BitcodeReader.h"
14#include "llvm/IR/Module.h"
15
16using namespace clang;
17
18bool clang::loadLinkModules(CompilerInstance &CI, llvm::LLVMContext &Ctx,
20 if (!LinkModules.empty())
21 return false;
22
25 auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename);
26 if (!BCBuf) {
27 CI.getDiagnostics().Report(diag::err_cannot_open_file)
28 << F.Filename << BCBuf.getError().message();
29 LinkModules.clear();
30 return true;
31 }
32
34 llvm::getOwningLazyBitcodeModule(std::move(*BCBuf), Ctx);
35 if (!ModuleOrErr) {
36 llvm::handleAllErrors(
37 ModuleOrErr.takeError(), [&](llvm::ErrorInfoBase &EIB) {
38 CI.getDiagnostics().Report(diag::err_cannot_open_file)
39 << F.Filename << EIB.message();
40 });
41 LinkModules.clear();
42 return true;
43 }
44
45 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
46 F.Internalize, F.LinkFlags});
47 }
48 return false;
49}
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,...
The JSON file list parser is used to communicate input to InstallAPI.
bool loadLinkModules(CompilerInstance &CI, llvm::LLVMContext &Ctx, llvm::SmallVectorImpl< LinkModule > &LinkModules)
Load every bitcode file listed in CodeGenOpts.LinkBitcodeFiles into LinkModules.