clang 24.0.0git
ModuleLinker.h
Go to the documentation of this file.
1//===--- ModuleLinker.h - Shared bitcode link helpers ----------*- C++ -*-===//
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
9#ifndef LLVM_CLANG_CODEGEN_MODULELINKER_H
10#define LLVM_CLANG_CODEGEN_MODULELINKER_H
11
12#include "llvm/ADT/SmallVector.h"
13#include <memory>
14
15namespace llvm {
16class Function;
17class LLVMContext;
18class Module;
19} // namespace llvm
20
21namespace clang {
23class CodeGenOptions;
25class LangOptions;
26class TargetOptions;
27
28/// Info about a module to link into the module currently being generated.
29/// Shared between the classic clang CodeGen path and the ClangIR path.
30struct LinkModule {
31 std::unique_ptr<llvm::Module> Module;
34 unsigned LinkFlags;
35};
36
37/// Load every bitcode file listed in CodeGenOpts.LinkBitcodeFiles into
38/// \p LinkModules. With \p OnlyInternalized, skip the entries that are not
39/// internalized, the plain -mlink-bitcode-file inputs. Returns true on error
40/// (diagnostic already reported). Appends to \p LinkModules; does not clear
41/// it.
42bool loadLinkModules(CompilerInstance &CI, llvm::LLVMContext &Ctx,
44 bool OnlyInternalized);
45
46/// Link every module in \p LinkModules into \p M, propagating default
47/// function attributes and internalizing as each entry requests. Linker
48/// diagnostics are attributed to the module being linked through
49/// \p DiagConsumer. Returns true on error. Clears \p LinkModules on success.
50bool linkInModules(llvm::Module &M,
52 const CodeGenOptions &CodeGenOpts,
53 const LangOptions &LangOpts, const TargetOptions &TargetOpts,
54 BackendDiagnosticConsumer &DiagConsumer);
55
56namespace CodeGen {
57/// Adds attributes to \p F according to our \p CodeGenOpts and \p LangOpts, as
58/// though we had emitted it ourselves. We remove any attributes on F that
59/// conflict with the attributes we add here.
60///
61/// This is useful for adding attrs to bitcode modules that you want to link
62/// with but don't control, such as CUDA's libdevice. When linking with such
63/// a bitcode library, you might want to set e.g. its functions'
64/// denormal_fp_math attribute to match the attr of the functions you're
65/// codegen'ing. Otherwise, LLVM will interpret the bitcode module's lack of
66/// denormal-fp-math attrs as tantamount to denormal-fp-math=ieee, and then LLVM
67/// will propagate denormal-fp-math=ieee up to every transitive caller of a
68/// function in the bitcode library!
69///
70/// With the exception of fast-math attrs, this will only make the attributes
71/// on the function more conservative. But it's unsafe to call this on a
72/// function which relies on particular fast-math attributes for correctness.
73/// It's up to you to ensure that this is safe.
74void mergeDefaultFunctionDefinitionAttributes(llvm::Function &F,
75 const CodeGenOptions &CodeGenOpts,
76 const LangOptions &LangOpts,
77 const TargetOptions &TargetOpts,
78 bool WillInternalize);
79} // namespace CodeGen
80
81} // namespace clang
82
83#endif
Owns the state needed to translate LLVM backend diagnostics into clang diagnostics,...
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
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...
Definition CGCall.cpp:2528
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.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
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...
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
Info about a module to link into the module currently being generated.
std::unique_ptr< llvm::Module > Module