1156952Sume//===- LTO.h ----------------------------------------------------*- C++ -*-===//
2156952Sume//
3156952Sume// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4156952Sume// See https://llvm.org/LICENSE.txt for license information.
5156952Sume// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6156952Sume//
7156952Sume//===----------------------------------------------------------------------===//
8156952Sume//
9156952Sume// This file provides a way to combine bitcode files into one COFF
10156952Sume// file by compiling them using LLVM.
11156952Sume//
12156952Sume// If LTO is in use, your input files are not in regular COFF files
13156952Sume// but instead LLVM bitcode files. In that case, the linker has to
14156952Sume// convert bitcode files into the native format so that we can create
15156952Sume// a COFF file that contains native code. This file provides that
16156952Sume// functionality.
17156952Sume//
18156952Sume//===----------------------------------------------------------------------===//
19156952Sume
20156952Sume#ifndef LLD_COFF_LTO_H
21156952Sume#define LLD_COFF_LTO_H
22156952Sume
23156952Sume#include "lld/Common/LLVM.h"
24156952Sume#include "llvm/ADT/DenseSet.h"
25156952Sume#include "llvm/ADT/SmallString.h"
26156952Sume#include "llvm/Support/raw_ostream.h"
27156952Sume#include <memory>
28156952Sume#include <vector>
29156952Sume
30156952Sumenamespace llvm::lto {
31156952Sumestruct Config;
32156952Sumeclass LTO;
33156952Sume}
34156952Sume
35156952Sumenamespace lld::coff {
36156952Sume
37156952Sumeclass BitcodeFile;
38156952Sumeclass InputFile;
39156952Sumeclass COFFLinkerContext;
40156952Sume
41156952Sumeclass BitcodeCompiler {
42156952Sumepublic:
43156952Sume  BitcodeCompiler(COFFLinkerContext &ctx);
44156952Sume  ~BitcodeCompiler();
45156952Sume
46156952Sume  void add(BitcodeFile &f);
47156952Sume  std::vector<InputFile *> compile();
48156952Sume
49156952Sumeprivate:
50156952Sume  std::unique_ptr<llvm::lto::LTO> ltoObj;
51156952Sume  std::vector<std::pair<std::string, SmallString<0>>> buf;
52156952Sume  std::vector<std::unique_ptr<MemoryBuffer>> files;
53156952Sume  std::vector<std::string> file_names;
54156952Sume  std::unique_ptr<llvm::raw_fd_ostream> indexFile;
55156952Sume  llvm::DenseSet<StringRef> thinIndices;
56156952Sume
57156952Sume  std::string getThinLTOOutputFile(StringRef path);
58156952Sume  llvm::lto::Config createConfig();
59156952Sume
60156952Sume  COFFLinkerContext &ctx;
61156952Sume};
62156952Sume}
63156952Sume
64156952Sume#endif
65156952Sume