Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / ELF / LTO.h
blob7ab654101f2487d5dfcdf42509fc5549679367ba
1 //===- LTO.h ----------------------------------------------------*- 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 // This file provides a way to combine bitcode files into one ELF
10 // file by compiling them using LLVM.
12 // If LTO is in use, your input files are not in regular ELF files
13 // but instead LLVM bitcode files. In that case, the linker has to
14 // convert bitcode files into the native format so that we can create
15 // an ELF file that contains native code. This file provides that
16 // functionality.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLD_ELF_LTO_H
21 #define LLD_ELF_LTO_H
23 #include "lld/Common/LLVM.h"
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include <memory>
28 #include <vector>
30 namespace llvm::lto {
31 class LTO;
34 namespace lld::elf {
36 class BitcodeFile;
37 class InputFile;
39 class BitcodeCompiler {
40 public:
41 BitcodeCompiler();
42 ~BitcodeCompiler();
44 void add(BitcodeFile &f);
45 std::vector<InputFile *> compile();
47 private:
48 std::unique_ptr<llvm::lto::LTO> ltoObj;
49 std::vector<SmallString<0>> buf;
50 std::vector<std::unique_ptr<MemoryBuffer>> files;
51 llvm::DenseSet<StringRef> usedStartStop;
52 std::unique_ptr<llvm::raw_fd_ostream> indexFile;
53 llvm::DenseSet<StringRef> thinIndices;
55 } // namespace lld::elf
57 #endif