xref: /freebsd/contrib/llvm-project/lld/ELF/LTO.h (revision 7a6dacaca14b62ca4b74406814becb87a3fefac0)
10b57cec5SDimitry Andric //===- LTO.h ----------------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file provides a way to combine bitcode files into one ELF
100b57cec5SDimitry Andric // file by compiling them using LLVM.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric // If LTO is in use, your input files are not in regular ELF files
130b57cec5SDimitry Andric // but instead LLVM bitcode files. In that case, the linker has to
140b57cec5SDimitry Andric // convert bitcode files into the native format so that we can create
150b57cec5SDimitry Andric // an ELF file that contains native code. This file provides that
160b57cec5SDimitry Andric // functionality.
170b57cec5SDimitry Andric //
180b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric #ifndef LLD_ELF_LTO_H
210b57cec5SDimitry Andric #define LLD_ELF_LTO_H
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric #include "lld/Common/LLVM.h"
240b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h"
250b57cec5SDimitry Andric #include "llvm/ADT/SmallString.h"
260b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
270b57cec5SDimitry Andric #include <memory>
280b57cec5SDimitry Andric #include <vector>
290b57cec5SDimitry Andric 
30bdd1243dSDimitry Andric namespace llvm::lto {
310b57cec5SDimitry Andric class LTO;
320b57cec5SDimitry Andric }
330b57cec5SDimitry Andric 
34bdd1243dSDimitry Andric namespace lld::elf {
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric class BitcodeFile;
370b57cec5SDimitry Andric class InputFile;
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric class BitcodeCompiler {
400b57cec5SDimitry Andric public:
410b57cec5SDimitry Andric   BitcodeCompiler();
420b57cec5SDimitry Andric   ~BitcodeCompiler();
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   void add(BitcodeFile &f);
450b57cec5SDimitry Andric   std::vector<InputFile *> compile();
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric private:
480b57cec5SDimitry Andric   std::unique_ptr<llvm::lto::LTO> ltoObj;
49*7a6dacacSDimitry Andric   // An array of (module name, native relocatable file content) pairs.
50*7a6dacacSDimitry Andric   SmallVector<std::pair<std::string, SmallString<0>>, 0> buf;
510b57cec5SDimitry Andric   std::vector<std::unique_ptr<MemoryBuffer>> files;
52*7a6dacacSDimitry Andric   SmallVector<std::string, 0> filenames;
530b57cec5SDimitry Andric   llvm::DenseSet<StringRef> usedStartStop;
540b57cec5SDimitry Andric   std::unique_ptr<llvm::raw_fd_ostream> indexFile;
550b57cec5SDimitry Andric   llvm::DenseSet<StringRef> thinIndices;
560b57cec5SDimitry Andric };
57bdd1243dSDimitry Andric } // namespace lld::elf
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric #endif
60