[LICM] allow MemoryAccess creation failure (#116813)
[llvm-project.git] / lld / wasm / LTO.h
blob43c7672fb5639b0da65415bc234b4b9205523675
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 wasm
10 // file by compiling them using LLVM.
12 // If LTO is in use, your input files are not in regular wasm 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 wasm file that contains native code. This file provides that
16 // functionality.
18 //===----------------------------------------------------------------------===//
20 #ifndef LLD_WASM_LTO_H
21 #define LLD_WASM_LTO_H
23 #include "Writer.h"
24 #include "lld/Common/LLVM.h"
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/Support/raw_ostream.h"
28 #include <memory>
29 #include <vector>
31 namespace llvm {
32 namespace lto {
33 class LTO;
35 } // namespace llvm
37 namespace lld::wasm {
39 class BitcodeFile;
40 class InputFile;
42 class BitcodeCompiler {
43 public:
44 BitcodeCompiler();
45 ~BitcodeCompiler();
47 void add(BitcodeFile &f);
48 std::vector<StringRef> compile();
50 private:
51 std::unique_ptr<llvm::lto::LTO> ltoObj;
52 // An array of (module name, native relocatable file content) pairs.
53 SmallVector<std::pair<std::string, SmallString<0>>, 0> buf;
54 std::vector<std::unique_ptr<MemoryBuffer>> files;
55 std::unique_ptr<llvm::raw_fd_ostream> indexFile;
56 llvm::DenseSet<StringRef> thinIndices;
58 } // namespace lld::wasm
60 #endif