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 COFF 100b57cec5SDimitry Andric // file by compiling them using LLVM. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric // If LTO is in use, your input files are not in regular COFF 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 // a COFF file that contains native code. This file provides that 160b57cec5SDimitry Andric // functionality. 170b57cec5SDimitry Andric // 180b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric #ifndef LLD_COFF_LTO_H 210b57cec5SDimitry Andric #define LLD_COFF_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 30*bdd1243dSDimitry Andric namespace llvm::lto { 31*bdd1243dSDimitry Andric struct Config; 320b57cec5SDimitry Andric class LTO; 330b57cec5SDimitry Andric } 340b57cec5SDimitry Andric 35*bdd1243dSDimitry Andric namespace lld::coff { 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric class BitcodeFile; 380b57cec5SDimitry Andric class InputFile; 39349cc55cSDimitry Andric class COFFLinkerContext; 400b57cec5SDimitry Andric 410b57cec5SDimitry Andric class BitcodeCompiler { 420b57cec5SDimitry Andric public: 43*bdd1243dSDimitry Andric BitcodeCompiler(COFFLinkerContext &ctx); 440b57cec5SDimitry Andric ~BitcodeCompiler(); 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric void add(BitcodeFile &f); 47*bdd1243dSDimitry Andric std::vector<InputFile *> compile(); 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric private: 500b57cec5SDimitry Andric std::unique_ptr<llvm::lto::LTO> ltoObj; 51*bdd1243dSDimitry Andric std::vector<std::pair<std::string, SmallString<0>>> buf; 520b57cec5SDimitry Andric std::vector<std::unique_ptr<MemoryBuffer>> files; 53*bdd1243dSDimitry Andric std::vector<std::string> file_names; 540b57cec5SDimitry Andric std::unique_ptr<llvm::raw_fd_ostream> indexFile; 550b57cec5SDimitry Andric llvm::DenseSet<StringRef> thinIndices; 56*bdd1243dSDimitry Andric 57*bdd1243dSDimitry Andric std::string getThinLTOOutputFile(StringRef path); 58*bdd1243dSDimitry Andric llvm::lto::Config createConfig(); 59*bdd1243dSDimitry Andric 60*bdd1243dSDimitry Andric COFFLinkerContext &ctx; 610b57cec5SDimitry Andric }; 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric #endif 65