aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/DWARFLinker/Parallel/DWARFLinkerGlobalData.h
blob: 7ca81eb34f005ef54a96a87e1066f76b215dbe7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//===- DWARFLinkerGlobalData.h ----------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H
#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H

#include "TypePool.h"
#include "llvm/DWARFLinker/Parallel/DWARFLinker.h"
#include "llvm/DWARFLinker/StringPool.h"
#include "llvm/Support/PerThreadBumpPtrAllocator.h"

namespace llvm {

class DWARFDie;

namespace dwarf_linker {
namespace parallel {

using MessageHandlerTy = std::function<void(
    const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;

/// linking options
struct DWARFLinkerOptions {
  /// DWARF version for the output.
  uint16_t TargetDWARFVersion = 0;

  /// Generate processing log to the standard output.
  bool Verbose = false;

  /// Print statistics.
  bool Statistics = false;

  /// Verify the input DWARF.
  bool VerifyInputDWARF = false;

  /// Do not unique types according to ODR
  bool NoODR = false;

  /// Update index tables.
  bool UpdateIndexTablesOnly = false;

  /// Whether we want a static variable to force us to keep its enclosing
  /// function.
  bool KeepFunctionForStatic = false;

  /// Allow to generate valid, but non deterministic output.
  bool AllowNonDeterministicOutput = false;

  /// Number of threads.
  unsigned Threads = 1;

  /// The accelerator table kinds
  SmallVector<DWARFLinkerBase::AccelTableKind, 1> AccelTables;

  /// Prepend path for the clang modules.
  std::string PrependPath;

  /// input verification handler(it might be called asynchronously).
  DWARFLinkerBase::InputVerificationHandlerTy InputVerificationHandler =
      nullptr;

  /// A list of all .swiftinterface files referenced by the debug
  /// info, mapping Module name to path on disk. The entries need to
  /// be uniqued and sorted and there are only few entries expected
  /// per compile unit, which is why this is a std::map.
  /// this is dsymutil specific fag.
  ///
  /// (it might be called asynchronously).
  DWARFLinkerBase::SwiftInterfacesMapTy *ParseableSwiftInterfaces = nullptr;

  /// A list of remappings to apply to file paths.
  ///
  /// (it might be called asynchronously).
  DWARFLinkerBase::ObjectPrefixMapTy *ObjectPrefixMap = nullptr;
};

class DWARFLinkerImpl;

/// This class keeps data and services common for the whole linking process.
class LinkingGlobalData {
  friend DWARFLinkerImpl;

public:
  /// Returns global per-thread allocator.
  llvm::parallel::PerThreadBumpPtrAllocator &getAllocator() {
    return Allocator;
  }

  /// Returns global string pool.
  StringPool &getStringPool() { return Strings; }

  /// Returns linking options.
  const DWARFLinkerOptions &getOptions() const { return Options; }

  /// Set warning handler.
  void setWarningHandler(MessageHandlerTy Handler) { WarningHandler = Handler; }

  /// Set error handler.
  void setErrorHandler(MessageHandlerTy Handler) { ErrorHandler = Handler; }

  /// Report warning.
  void warn(const Twine &Warning, StringRef Context,
            const DWARFDie *DIE = nullptr) {
    if (WarningHandler)
      (WarningHandler)(Warning, Context, DIE);
  }

  /// Report warning.
  void warn(Error Warning, StringRef Context, const DWARFDie *DIE = nullptr) {
    handleAllErrors(std::move(Warning), [&](ErrorInfoBase &Info) {
      warn(Info.message(), Context, DIE);
    });
  }

  /// Report error.
  void error(const Twine &Err, StringRef Context,
             const DWARFDie *DIE = nullptr) {
    if (ErrorHandler)
      (ErrorHandler)(Err, Context, DIE);
  }

  /// Report error.
  void error(Error Err, StringRef Context, const DWARFDie *DIE = nullptr) {
    handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) {
      error(Info.message(), Context, DIE);
    });
  }

  /// Set target triple.
  void setTargetTriple(const Triple &TargetTriple) {
    this->TargetTriple = TargetTriple;
  }

  /// Optionally return target triple.
  std::optional<std::reference_wrapper<const Triple>> getTargetTriple() {
    if (TargetTriple)
      return std::cref(*TargetTriple);

    return std::nullopt;
  }

protected:
  llvm::parallel::PerThreadBumpPtrAllocator Allocator;
  StringPool Strings;
  DWARFLinkerOptions Options;
  MessageHandlerTy WarningHandler;
  MessageHandlerTy ErrorHandler;

  /// Triple for output data. May be not set if generation of output
  /// data is not requested.
  std::optional<Triple> TargetTriple;
};

} // end of namespace parallel
} // end of namespace dwarf_linker
} // end of namespace llvm

#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERGLOBALDATA_H