xref: /freebsd/contrib/llvm-project/lld/ELF/LTO.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- LTO.h ----------------------------------------------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file provides a way to combine bitcode files into one ELF
10*0b57cec5SDimitry Andric // file by compiling them using LLVM.
11*0b57cec5SDimitry Andric //
12*0b57cec5SDimitry Andric // If LTO is in use, your input files are not in regular ELF files
13*0b57cec5SDimitry Andric // but instead LLVM bitcode files. In that case, the linker has to
14*0b57cec5SDimitry Andric // convert bitcode files into the native format so that we can create
15*0b57cec5SDimitry Andric // an ELF file that contains native code. This file provides that
16*0b57cec5SDimitry Andric // functionality.
17*0b57cec5SDimitry Andric //
18*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric #ifndef LLD_ELF_LTO_H
21*0b57cec5SDimitry Andric #define LLD_ELF_LTO_H
22*0b57cec5SDimitry Andric 
23*0b57cec5SDimitry Andric #include "lld/Common/LLVM.h"
24*0b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h"
25*0b57cec5SDimitry Andric #include "llvm/ADT/SmallString.h"
26*0b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
27*0b57cec5SDimitry Andric #include <memory>
28*0b57cec5SDimitry Andric #include <vector>
29*0b57cec5SDimitry Andric 
30*0b57cec5SDimitry Andric namespace llvm {
31*0b57cec5SDimitry Andric namespace lto {
32*0b57cec5SDimitry Andric class LTO;
33*0b57cec5SDimitry Andric }
34*0b57cec5SDimitry Andric } // namespace llvm
35*0b57cec5SDimitry Andric 
36*0b57cec5SDimitry Andric namespace lld {
37*0b57cec5SDimitry Andric namespace elf {
38*0b57cec5SDimitry Andric 
39*0b57cec5SDimitry Andric class BitcodeFile;
40*0b57cec5SDimitry Andric class InputFile;
41*0b57cec5SDimitry Andric class LazyObjFile;
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric class BitcodeCompiler {
44*0b57cec5SDimitry Andric public:
45*0b57cec5SDimitry Andric   BitcodeCompiler();
46*0b57cec5SDimitry Andric   ~BitcodeCompiler();
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric   void add(BitcodeFile &f);
49*0b57cec5SDimitry Andric   std::vector<InputFile *> compile();
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric private:
52*0b57cec5SDimitry Andric   std::unique_ptr<llvm::lto::LTO> ltoObj;
53*0b57cec5SDimitry Andric   std::vector<SmallString<0>> buf;
54*0b57cec5SDimitry Andric   std::vector<std::unique_ptr<MemoryBuffer>> files;
55*0b57cec5SDimitry Andric   llvm::DenseSet<StringRef> usedStartStop;
56*0b57cec5SDimitry Andric   std::unique_ptr<llvm::raw_fd_ostream> indexFile;
57*0b57cec5SDimitry Andric   llvm::DenseSet<StringRef> thinIndices;
58*0b57cec5SDimitry Andric };
59*0b57cec5SDimitry Andric } // namespace elf
60*0b57cec5SDimitry Andric } // namespace lld
61*0b57cec5SDimitry Andric 
62*0b57cec5SDimitry Andric #endif
63