xref: /freebsd/contrib/llvm-project/lld/COFF/LTO.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
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 COFF
10 // file by compiling them using LLVM.
11 //
12 // If LTO is in use, your input files are not in regular COFF 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 // a COFF file that contains native code. This file provides that
16 // functionality.
17 //
18 //===----------------------------------------------------------------------===//
19 
20 #ifndef LLD_COFF_LTO_H
21 #define LLD_COFF_LTO_H
22 
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>
29 
30 namespace llvm::lto {
31 struct Config;
32 class LTO;
33 }
34 
35 namespace lld::coff {
36 
37 class BitcodeFile;
38 class InputFile;
39 class COFFLinkerContext;
40 
41 class BitcodeCompiler {
42 public:
43   BitcodeCompiler(COFFLinkerContext &ctx);
44   ~BitcodeCompiler();
45 
46   void add(BitcodeFile &f);
47   std::vector<InputFile *> compile();
48 
49 private:
50   std::unique_ptr<llvm::lto::LTO> ltoObj;
51   std::vector<std::pair<std::string, SmallString<0>>> buf;
52   std::vector<std::unique_ptr<MemoryBuffer>> files;
53   std::vector<std::string> file_names;
54   std::unique_ptr<llvm::raw_fd_ostream> indexFile;
55   llvm::DenseSet<StringRef> thinIndices;
56 
57   std::string getThinLTOOutputFile(StringRef path);
58   llvm::lto::Config createConfig();
59 
60   COFFLinkerContext &ctx;
61 };
62 }
63 
64 #endif
65