1303231Sdim//===-LTO.h - LLVM Link Time Optimizer ------------------------------------===//
2303231Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6303231Sdim//
7303231Sdim//===----------------------------------------------------------------------===//
8303231Sdim//
9303231Sdim// This file declares functions and classes used to support LTO. It is intended
10303231Sdim// to be used both by LTO classes as well as by clients (gold-plugin) that
11303231Sdim// don't utilize the LTO code generator interfaces.
12303231Sdim//
13303231Sdim//===----------------------------------------------------------------------===//
14303231Sdim
15303231Sdim#ifndef LLVM_LTO_LTO_H
16303231Sdim#define LLVM_LTO_LTO_H
17303231Sdim
18314564Sdim#include "llvm/ADT/MapVector.h"
19303231Sdim#include "llvm/ADT/StringMap.h"
20314564Sdim#include "llvm/ADT/StringSet.h"
21314564Sdim#include "llvm/IR/DiagnosticInfo.h"
22303231Sdim#include "llvm/IR/ModuleSummaryIndex.h"
23353358Sdim#include "llvm/IR/RemarkStreamer.h"
24314564Sdim#include "llvm/LTO/Config.h"
25314564Sdim#include "llvm/Linker/IRMover.h"
26321369Sdim#include "llvm/Object/IRSymtab.h"
27321369Sdim#include "llvm/Support/Error.h"
28321369Sdim#include "llvm/Support/ToolOutputFile.h"
29314564Sdim#include "llvm/Support/thread.h"
30314564Sdim#include "llvm/Target/TargetOptions.h"
31314564Sdim#include "llvm/Transforms/IPO/FunctionImport.h"
32303231Sdim
33303231Sdimnamespace llvm {
34303231Sdim
35314564Sdimclass BitcodeModule;
36314564Sdimclass Error;
37303231Sdimclass LLVMContext;
38303231Sdimclass MemoryBufferRef;
39303231Sdimclass Module;
40314564Sdimclass Target;
41314564Sdimclass raw_pwrite_stream;
42303231Sdim
43344779Sdim/// Resolve linkage for prevailing symbols in the \p Index. Linkage changes
44344779Sdim/// recorded in the index and the ThinLTO backends must apply the changes to
45344779Sdim/// the module via thinLTOResolvePrevailingInModule.
46303231Sdim///
47303231Sdim/// This is done for correctness (if value exported, ensure we always
48303231Sdim/// emit a copy), and compile-time optimization (allow drop of duplicates).
49344779Sdimvoid thinLTOResolvePrevailingInIndex(
50303231Sdim    ModuleSummaryIndex &Index,
51303231Sdim    function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
52303231Sdim        isPrevailing,
53303231Sdim    function_ref<void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)>
54353358Sdim        recordNewLinkage,
55353358Sdim    const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
56303231Sdim
57303231Sdim/// Update the linkages in the given \p Index to mark exported values
58303231Sdim/// as external and non-exported values as internal. The ThinLTO backends
59303231Sdim/// must apply the changes to the Module via thinLTOInternalizeModule.
60303231Sdimvoid thinLTOInternalizeAndPromoteInIndex(
61303231Sdim    ModuleSummaryIndex &Index,
62360784Sdim    function_ref<bool(StringRef, ValueInfo)> isExported,
63360784Sdim    function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
64360784Sdim        isPrevailing);
65303231Sdim
66344779Sdim/// Computes a unique hash for the Module considering the current list of
67344779Sdim/// export/import and other global analysis results.
68344779Sdim/// The hash is produced in \p Key.
69344779Sdimvoid computeLTOCacheKey(
70344779Sdim    SmallString<40> &Key, const lto::Config &Conf,
71344779Sdim    const ModuleSummaryIndex &Index, StringRef ModuleID,
72344779Sdim    const FunctionImporter::ImportMapTy &ImportList,
73344779Sdim    const FunctionImporter::ExportSetTy &ExportList,
74344779Sdim    const std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR,
75344779Sdim    const GVSummaryMapTy &DefinedGlobals,
76344779Sdim    const std::set<GlobalValue::GUID> &CfiFunctionDefs = {},
77344779Sdim    const std::set<GlobalValue::GUID> &CfiFunctionDecls = {});
78344779Sdim
79314564Sdimnamespace lto {
80314564Sdim
81314564Sdim/// Given the original \p Path to an output file, replace any path
82314564Sdim/// prefix matching \p OldPrefix with \p NewPrefix. Also, create the
83314564Sdim/// resulting directory if it does not yet exist.
84314564Sdimstd::string getThinLTOOutputFile(const std::string &Path,
85314564Sdim                                 const std::string &OldPrefix,
86314564Sdim                                 const std::string &NewPrefix);
87314564Sdim
88321369Sdim/// Setup optimization remarks.
89327952SdimExpected<std::unique_ptr<ToolOutputFile>>
90353358SdimsetupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
91353358Sdim                         StringRef RemarksPasses, StringRef RemarksFormat,
92353358Sdim                         bool RemarksWithHotness, int Count = -1);
93321369Sdim
94353358Sdim/// Setups the output file for saving statistics.
95353358SdimExpected<std::unique_ptr<ToolOutputFile>>
96353358SdimsetupStatsFile(StringRef StatsFilename);
97353358Sdim
98314564Sdimclass LTO;
99314564Sdimstruct SymbolResolution;
100314564Sdimclass ThinBackendProc;
101314564Sdim
102321369Sdim/// An input file. This is a symbol table wrapper that only exposes the
103314564Sdim/// information that an LTO client should need in order to do symbol resolution.
104314564Sdimclass InputFile {
105321369Sdimpublic:
106321369Sdim  class Symbol;
107321369Sdim
108321369Sdimprivate:
109314564Sdim  // FIXME: Remove LTO class friendship once we have bitcode symbol tables.
110314564Sdim  friend LTO;
111314564Sdim  InputFile() = default;
112314564Sdim
113321369Sdim  std::vector<BitcodeModule> Mods;
114321369Sdim  SmallVector<char, 0> Strtab;
115321369Sdim  std::vector<Symbol> Symbols;
116314564Sdim
117321369Sdim  // [begin, end) for each module
118321369Sdim  std::vector<std::pair<size_t, size_t>> ModuleSymIndices;
119314564Sdim
120321369Sdim  StringRef TargetTriple, SourceFileName, COFFLinkerOpts;
121353358Sdim  std::vector<StringRef> DependentLibraries;
122321369Sdim  std::vector<StringRef> ComdatTable;
123321369Sdim
124314564Sdimpublic:
125314564Sdim  ~InputFile();
126314564Sdim
127314564Sdim  /// Create an InputFile.
128314564Sdim  static Expected<std::unique_ptr<InputFile>> create(MemoryBufferRef Object);
129314564Sdim
130321369Sdim  /// The purpose of this class is to only expose the symbol information that an
131321369Sdim  /// LTO client should need in order to do symbol resolution.
132321369Sdim  class Symbol : irsymtab::Symbol {
133314564Sdim    friend LTO;
134314564Sdim
135314564Sdim  public:
136321369Sdim    Symbol(const irsymtab::Symbol &S) : irsymtab::Symbol(S) {}
137314564Sdim
138321369Sdim    using irsymtab::Symbol::isUndefined;
139321369Sdim    using irsymtab::Symbol::isCommon;
140321369Sdim    using irsymtab::Symbol::isWeak;
141321369Sdim    using irsymtab::Symbol::isIndirect;
142321369Sdim    using irsymtab::Symbol::getName;
143353358Sdim    using irsymtab::Symbol::getIRName;
144321369Sdim    using irsymtab::Symbol::getVisibility;
145321369Sdim    using irsymtab::Symbol::canBeOmittedFromSymbolTable;
146321369Sdim    using irsymtab::Symbol::isTLS;
147321369Sdim    using irsymtab::Symbol::getComdatIndex;
148321369Sdim    using irsymtab::Symbol::getCommonSize;
149321369Sdim    using irsymtab::Symbol::getCommonAlignment;
150321369Sdim    using irsymtab::Symbol::getCOFFWeakExternalFallback;
151327952Sdim    using irsymtab::Symbol::getSectionName;
152321369Sdim    using irsymtab::Symbol::isExecutable;
153353358Sdim    using irsymtab::Symbol::isUsed;
154314564Sdim  };
155314564Sdim
156321369Sdim  /// A range over the symbols in this InputFile.
157321369Sdim  ArrayRef<Symbol> symbols() const { return Symbols; }
158314564Sdim
159321369Sdim  /// Returns linker options specified in the input file.
160321369Sdim  StringRef getCOFFLinkerOpts() const { return COFFLinkerOpts; }
161314564Sdim
162353358Sdim  /// Returns dependent library specifiers from the input file.
163353358Sdim  ArrayRef<StringRef> getDependentLibraries() const { return DependentLibraries; }
164353358Sdim
165314564Sdim  /// Returns the path to the InputFile.
166314564Sdim  StringRef getName() const;
167314564Sdim
168321369Sdim  /// Returns the input file's target triple.
169321369Sdim  StringRef getTargetTriple() const { return TargetTriple; }
170321369Sdim
171314564Sdim  /// Returns the source file path specified at compile time.
172321369Sdim  StringRef getSourceFileName() const { return SourceFileName; }
173314564Sdim
174314564Sdim  // Returns a table with all the comdats used by this file.
175321369Sdim  ArrayRef<StringRef> getComdatTable() const { return ComdatTable; }
176314564Sdim
177353358Sdim  // Returns the only BitcodeModule from InputFile.
178353358Sdim  BitcodeModule &getSingleBitcodeModule();
179353358Sdim
180314564Sdimprivate:
181321369Sdim  ArrayRef<Symbol> module_symbols(unsigned I) const {
182321369Sdim    const auto &Indices = ModuleSymIndices[I];
183321369Sdim    return {Symbols.data() + Indices.first, Symbols.data() + Indices.second};
184321369Sdim  }
185314564Sdim};
186314564Sdim
187314564Sdim/// This class wraps an output stream for a native object. Most clients should
188314564Sdim/// just be able to return an instance of this base class from the stream
189314564Sdim/// callback, but if a client needs to perform some action after the stream is
190314564Sdim/// written to, that can be done by deriving from this class and overriding the
191314564Sdim/// destructor.
192314564Sdimclass NativeObjectStream {
193314564Sdimpublic:
194314564Sdim  NativeObjectStream(std::unique_ptr<raw_pwrite_stream> OS) : OS(std::move(OS)) {}
195314564Sdim  std::unique_ptr<raw_pwrite_stream> OS;
196314564Sdim  virtual ~NativeObjectStream() = default;
197314564Sdim};
198314564Sdim
199314564Sdim/// This type defines the callback to add a native object that is generated on
200314564Sdim/// the fly.
201314564Sdim///
202314564Sdim/// Stream callbacks must be thread safe.
203353358Sdimusing AddStreamFn =
204353358Sdim    std::function<std::unique_ptr<NativeObjectStream>(unsigned Task)>;
205314564Sdim
206314564Sdim/// This is the type of a native object cache. To request an item from the
207314564Sdim/// cache, pass a unique string as the Key. For hits, the cached file will be
208314564Sdim/// added to the link and this function will return AddStreamFn(). For misses,
209314564Sdim/// the cache will return a stream callback which must be called at most once to
210314564Sdim/// produce content for the stream. The native object stream produced by the
211314564Sdim/// stream callback will add the file to the link after the stream is written
212314564Sdim/// to.
213314564Sdim///
214314564Sdim/// Clients generally look like this:
215314564Sdim///
216314564Sdim/// if (AddStreamFn AddStream = Cache(Task, Key))
217314564Sdim///   ProduceContent(AddStream);
218353358Sdimusing NativeObjectCache =
219353358Sdim    std::function<AddStreamFn(unsigned Task, StringRef Key)>;
220314564Sdim
221314564Sdim/// A ThinBackend defines what happens after the thin-link phase during ThinLTO.
222314564Sdim/// The details of this type definition aren't important; clients can only
223314564Sdim/// create a ThinBackend using one of the create*ThinBackend() functions below.
224353358Sdimusing ThinBackend = std::function<std::unique_ptr<ThinBackendProc>(
225360784Sdim    const Config &C, ModuleSummaryIndex &CombinedIndex,
226314564Sdim    StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
227353358Sdim    AddStreamFn AddStream, NativeObjectCache Cache)>;
228314564Sdim
229314564Sdim/// This ThinBackend runs the individual backend jobs in-process.
230314564SdimThinBackend createInProcessThinBackend(unsigned ParallelismLevel);
231314564Sdim
232314564Sdim/// This ThinBackend writes individual module indexes to files, instead of
233314564Sdim/// running the individual backend jobs. This backend is for distributed builds
234314564Sdim/// where separate processes will invoke the real backends.
235314564Sdim///
236314564Sdim/// To find the path to write the index to, the backend checks if the path has a
237314564Sdim/// prefix of OldPrefix; if so, it replaces that prefix with NewPrefix. It then
238314564Sdim/// appends ".thinlto.bc" and writes the index to that path. If
239314564Sdim/// ShouldEmitImportsFiles is true it also writes a list of imported files to a
240314564Sdim/// similar path with ".imports" appended instead.
241341825Sdim/// LinkedObjectsFile is an output stream to write the list of object files for
242341825Sdim/// the final ThinLTO linking. Can be nullptr.
243341825Sdim/// OnWrite is callback which receives module identifier and notifies LTO user
244341825Sdim/// that index file for the module (and optionally imports file) was created.
245341825Sdimusing IndexWriteCallback = std::function<void(const std::string &)>;
246314564SdimThinBackend createWriteIndexesThinBackend(std::string OldPrefix,
247314564Sdim                                          std::string NewPrefix,
248314564Sdim                                          bool ShouldEmitImportsFiles,
249341825Sdim                                          raw_fd_ostream *LinkedObjectsFile,
250341825Sdim                                          IndexWriteCallback OnWrite);
251314564Sdim
252314564Sdim/// This class implements a resolution-based interface to LLVM's LTO
253314564Sdim/// functionality. It supports regular LTO, parallel LTO code generation and
254314564Sdim/// ThinLTO. You can use it from a linker in the following way:
255314564Sdim/// - Set hooks and code generation options (see lto::Config struct defined in
256314564Sdim///   Config.h), and use the lto::Config object to create an lto::LTO object.
257314564Sdim/// - Create lto::InputFile objects using lto::InputFile::create(), then use
258314564Sdim///   the symbols() function to enumerate its symbols and compute a resolution
259314564Sdim///   for each symbol (see SymbolResolution below).
260314564Sdim/// - After the linker has visited each input file (and each regular object
261314564Sdim///   file) and computed a resolution for each symbol, take each lto::InputFile
262314564Sdim///   and pass it and an array of symbol resolutions to the add() function.
263314564Sdim/// - Call the getMaxTasks() function to get an upper bound on the number of
264314564Sdim///   native object files that LTO may add to the link.
265314564Sdim/// - Call the run() function. This function will use the supplied AddStream
266314564Sdim///   and Cache functions to add up to getMaxTasks() native object files to
267314564Sdim///   the link.
268314564Sdimclass LTO {
269314564Sdim  friend InputFile;
270314564Sdim
271314564Sdimpublic:
272314564Sdim  /// Create an LTO object. A default constructed LTO object has a reasonable
273314564Sdim  /// production configuration, but you can customize it by passing arguments to
274314564Sdim  /// this constructor.
275314564Sdim  /// FIXME: We do currently require the DiagHandler field to be set in Conf.
276314564Sdim  /// Until that is fixed, a Config argument is required.
277314564Sdim  LTO(Config Conf, ThinBackend Backend = nullptr,
278314564Sdim      unsigned ParallelCodeGenParallelismLevel = 1);
279314564Sdim  ~LTO();
280314564Sdim
281314564Sdim  /// Add an input file to the LTO link, using the provided symbol resolutions.
282314564Sdim  /// The symbol resolutions must appear in the enumeration order given by
283314564Sdim  /// InputFile::symbols().
284314564Sdim  Error add(std::unique_ptr<InputFile> Obj, ArrayRef<SymbolResolution> Res);
285314564Sdim
286314564Sdim  /// Returns an upper bound on the number of tasks that the client may expect.
287314564Sdim  /// This may only be called after all IR object files have been added. For a
288314564Sdim  /// full description of tasks see LTOBackend.h.
289314564Sdim  unsigned getMaxTasks() const;
290314564Sdim
291314564Sdim  /// Runs the LTO pipeline. This function calls the supplied AddStream
292314564Sdim  /// function to add native object files to the link.
293314564Sdim  ///
294314564Sdim  /// The Cache parameter is optional. If supplied, it will be used to cache
295314564Sdim  /// native object files and add them to the link.
296314564Sdim  ///
297314564Sdim  /// The client will receive at most one callback (via either AddStream or
298314564Sdim  /// Cache) for each task identifier.
299314564Sdim  Error run(AddStreamFn AddStream, NativeObjectCache Cache = nullptr);
300314564Sdim
301360784Sdim  /// Static method that returns a list of libcall symbols that can be generated
302360784Sdim  /// by LTO but might not be visible from bitcode symbol table.
303360784Sdim  static ArrayRef<const char*> getRuntimeLibcallSymbols();
304360784Sdim
305314564Sdimprivate:
306314564Sdim  Config Conf;
307314564Sdim
308314564Sdim  struct RegularLTOState {
309360784Sdim    RegularLTOState(unsigned ParallelCodeGenParallelismLevel,
310360784Sdim                    const Config &Conf);
311314564Sdim    struct CommonResolution {
312314564Sdim      uint64_t Size = 0;
313360784Sdim      MaybeAlign Align;
314314564Sdim      /// Record if at least one instance of the common was marked as prevailing
315314564Sdim      bool Prevailing = false;
316314564Sdim    };
317314564Sdim    std::map<std::string, CommonResolution> Commons;
318314564Sdim
319314564Sdim    unsigned ParallelCodeGenParallelismLevel;
320314564Sdim    LTOLLVMContext Ctx;
321314564Sdim    std::unique_ptr<Module> CombinedModule;
322314564Sdim    std::unique_ptr<IRMover> Mover;
323321369Sdim
324321369Sdim    // This stores the information about a regular LTO module that we have added
325321369Sdim    // to the link. It will either be linked immediately (for modules without
326321369Sdim    // summaries) or after summary-based dead stripping (for modules with
327321369Sdim    // summaries).
328321369Sdim    struct AddedModule {
329321369Sdim      std::unique_ptr<Module> M;
330321369Sdim      std::vector<GlobalValue *> Keep;
331321369Sdim    };
332321369Sdim    std::vector<AddedModule> ModsWithSummaries;
333314564Sdim  } RegularLTO;
334314564Sdim
335314564Sdim  struct ThinLTOState {
336314564Sdim    ThinLTOState(ThinBackend Backend);
337314564Sdim
338314564Sdim    ThinBackend Backend;
339314564Sdim    ModuleSummaryIndex CombinedIndex;
340314564Sdim    MapVector<StringRef, BitcodeModule> ModuleMap;
341314564Sdim    DenseMap<GlobalValue::GUID, StringRef> PrevailingModuleForGUID;
342314564Sdim  } ThinLTO;
343314564Sdim
344314564Sdim  // The global resolution for a particular (mangled) symbol name. This is in
345314564Sdim  // particular necessary to track whether each symbol can be internalized.
346314564Sdim  // Because any input file may introduce a new cross-partition reference, we
347314564Sdim  // cannot make any final internalization decisions until all input files have
348314564Sdim  // been added and the client has called run(). During run() we apply
349314564Sdim  // internalization decisions either directly to the module (for regular LTO)
350314564Sdim  // or to the combined index (for ThinLTO).
351314564Sdim  struct GlobalResolution {
352314564Sdim    /// The unmangled name of the global.
353314564Sdim    std::string IRName;
354314564Sdim
355321369Sdim    /// Keep track if the symbol is visible outside of a module with a summary
356321369Sdim    /// (i.e. in either a regular object or a regular LTO module without a
357321369Sdim    /// summary).
358321369Sdim    bool VisibleOutsideSummary = false;
359314564Sdim
360314564Sdim    bool UnnamedAddr = true;
361314564Sdim
362341825Sdim    /// True if module contains the prevailing definition.
363341825Sdim    bool Prevailing = false;
364341825Sdim
365341825Sdim    /// Returns true if module contains the prevailing definition and symbol is
366341825Sdim    /// an IR symbol. For example when module-level inline asm block is used,
367341825Sdim    /// symbol can be prevailing in module but have no IR name.
368341825Sdim    bool isPrevailingIRSymbol() const { return Prevailing && !IRName.empty(); }
369341825Sdim
370314564Sdim    /// This field keeps track of the partition number of this global. The
371314564Sdim    /// regular LTO object is partition 0, while each ThinLTO object has its own
372314564Sdim    /// partition number from 1 onwards.
373314564Sdim    ///
374314564Sdim    /// Any global that is defined or used by more than one partition, or that
375314564Sdim    /// is referenced externally, may not be internalized.
376314564Sdim    ///
377314564Sdim    /// Partitions generally have a one-to-one correspondence with tasks, except
378314564Sdim    /// that we use partition 0 for all parallel LTO code generation partitions.
379314564Sdim    /// Any partitioning of the combined LTO object is done internally by the
380314564Sdim    /// LTO backend.
381314564Sdim    unsigned Partition = Unknown;
382314564Sdim
383314564Sdim    /// Special partition numbers.
384314564Sdim    enum : unsigned {
385314564Sdim      /// A partition number has not yet been assigned to this global.
386314564Sdim      Unknown = -1u,
387314564Sdim
388314564Sdim      /// This global is either used by more than one partition or has an
389314564Sdim      /// external reference, and therefore cannot be internalized.
390314564Sdim      External = -2u,
391314564Sdim
392314564Sdim      /// The RegularLTO partition
393314564Sdim      RegularLTO = 0,
394314564Sdim    };
395314564Sdim  };
396314564Sdim
397314564Sdim  // Global mapping from mangled symbol names to resolutions.
398314564Sdim  StringMap<GlobalResolution> GlobalResolutions;
399314564Sdim
400321369Sdim  void addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
401321369Sdim                            ArrayRef<SymbolResolution> Res, unsigned Partition,
402321369Sdim                            bool InSummary);
403314564Sdim
404314564Sdim  // These functions take a range of symbol resolutions [ResI, ResE) and consume
405314564Sdim  // the resolutions used by a single input module by incrementing ResI. After
406314564Sdim  // these functions return, [ResI, ResE) will refer to the resolution range for
407314564Sdim  // the remaining modules in the InputFile.
408321369Sdim  Error addModule(InputFile &Input, unsigned ModI,
409314564Sdim                  const SymbolResolution *&ResI, const SymbolResolution *ResE);
410321369Sdim
411321369Sdim  Expected<RegularLTOState::AddedModule>
412321369Sdim  addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
413321369Sdim                const SymbolResolution *&ResI, const SymbolResolution *ResE);
414321369Sdim  Error linkRegularLTO(RegularLTOState::AddedModule Mod,
415321369Sdim                       bool LivenessFromIndex);
416321369Sdim
417321369Sdim  Error addThinLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
418314564Sdim                   const SymbolResolution *&ResI, const SymbolResolution *ResE);
419314564Sdim
420314564Sdim  Error runRegularLTO(AddStreamFn AddStream);
421353358Sdim  Error runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache,
422353358Sdim                   const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
423314564Sdim
424353358Sdim  Error checkPartiallySplit();
425353358Sdim
426314564Sdim  mutable bool CalledGetMaxTasks = false;
427344779Sdim
428344779Sdim  // Use Optional to distinguish false from not yet initialized.
429344779Sdim  Optional<bool> EnableSplitLTOUnit;
430314564Sdim};
431314564Sdim
432314564Sdim/// The resolution for a symbol. The linker must provide a SymbolResolution for
433314564Sdim/// each global symbol based on its internal resolution of that symbol.
434314564Sdimstruct SymbolResolution {
435314564Sdim  SymbolResolution()
436321369Sdim      : Prevailing(0), FinalDefinitionInLinkageUnit(0), VisibleToRegularObj(0),
437321369Sdim        LinkerRedefined(0) {}
438321369Sdim
439314564Sdim  /// The linker has chosen this definition of the symbol.
440314564Sdim  unsigned Prevailing : 1;
441314564Sdim
442314564Sdim  /// The definition of this symbol is unpreemptable at runtime and is known to
443314564Sdim  /// be in this linkage unit.
444314564Sdim  unsigned FinalDefinitionInLinkageUnit : 1;
445314564Sdim
446314564Sdim  /// The definition of this symbol is visible outside of the LTO unit.
447314564Sdim  unsigned VisibleToRegularObj : 1;
448321369Sdim
449321369Sdim  /// Linker redefined version of the symbol which appeared in -wrap or -defsym
450321369Sdim  /// linker option.
451321369Sdim  unsigned LinkerRedefined : 1;
452314564Sdim};
453314564Sdim
454314564Sdim} // namespace lto
455314564Sdim} // namespace llvm
456314564Sdim
457303231Sdim#endif
458