Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / DWARFLinkerParallel / DWARFLinkerGlobalData.h
blob78d0b5468d0495ee98bc26523fda21b5c81eed70
1 //===- DWARFLinkerGlobalData.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H
12 #include "llvm/DWARFLinkerParallel/DWARFLinker.h"
13 #include "llvm/DWARFLinkerParallel/StringPool.h"
14 #include "llvm/Support/PerThreadBumpPtrAllocator.h"
15 #include <map>
17 namespace llvm {
19 class DWARFDie;
21 namespace dwarflinker_parallel {
23 using TranslatorFuncTy = std::function<StringRef(StringRef)>;
24 using MessageHandlerTy = std::function<void(
25 const Twine &Warning, StringRef Context, const DWARFDie *DIE)>;
27 /// linking options
28 struct DWARFLinkerOptions {
29 /// DWARF version for the output.
30 uint16_t TargetDWARFVersion = 0;
32 /// Generate processing log to the standard output.
33 bool Verbose = false;
35 /// Print statistics.
36 bool Statistics = false;
38 /// Verify the input DWARF.
39 bool VerifyInputDWARF = false;
41 /// Do not emit output.
42 bool NoOutput = false;
44 /// Do not unique types according to ODR
45 bool NoODR = false;
47 /// Update index tables.
48 bool UpdateIndexTablesOnly = false;
50 /// Whether we want a static variable to force us to keep its enclosing
51 /// function.
52 bool KeepFunctionForStatic = false;
54 /// Allow to generate valid, but non deterministic output.
55 bool AllowNonDeterministicOutput = false;
57 /// Number of threads.
58 unsigned Threads = 1;
60 /// The accelerator table kinds
61 SmallVector<DWARFLinker::AccelTableKind, 1> AccelTables;
63 /// Prepend path for the clang modules.
64 std::string PrependPath;
66 /// input verification handler(it might be called asynchronously).
67 DWARFLinker::InputVerificationHandlerTy InputVerificationHandler = nullptr;
69 /// A list of all .swiftinterface files referenced by the debug
70 /// info, mapping Module name to path on disk. The entries need to
71 /// be uniqued and sorted and there are only few entries expected
72 /// per compile unit, which is why this is a std::map.
73 /// this is dsymutil specific fag.
74 ///
75 /// (it might be called asynchronously).
76 DWARFLinker::SwiftInterfacesMapTy *ParseableSwiftInterfaces = nullptr;
78 /// A list of remappings to apply to file paths.
79 ///
80 /// (it might be called asynchronously).
81 DWARFLinker::ObjectPrefixMapTy *ObjectPrefixMap = nullptr;
84 class DWARFLinkerImpl;
86 /// This class keeps data and services common for the whole linking process.
87 class LinkingGlobalData {
88 friend DWARFLinkerImpl;
90 public:
91 /// Returns global per-thread allocator.
92 parallel::PerThreadBumpPtrAllocator &getAllocator() { return Allocator; }
94 /// Returns global string pool.
95 StringPool &getStringPool() { return Strings; }
97 /// Set translation function.
98 void setTranslator(TranslatorFuncTy Translator) {
99 this->Translator = Translator;
102 /// Translate specified string.
103 StringRef translateString(StringRef String) {
104 if (Translator)
105 return Translator(String);
107 return String;
110 /// Returns linking options.
111 const DWARFLinkerOptions &getOptions() const { return Options; }
113 /// Set warning handler.
114 void setWarningHandler(MessageHandlerTy Handler) { WarningHandler = Handler; }
116 /// Set error handler.
117 void setErrorHandler(MessageHandlerTy Handler) { ErrorHandler = Handler; }
119 /// Report warning.
120 void warn(const Twine &Warning, StringRef Context,
121 const DWARFDie *DIE = nullptr) {
122 if (WarningHandler)
123 (WarningHandler)(Warning, Context, DIE);
126 /// Report warning.
127 void warn(Error Warning, StringRef Context, const DWARFDie *DIE = nullptr) {
128 handleAllErrors(std::move(Warning), [&](ErrorInfoBase &Info) {
129 warn(Info.message(), Context, DIE);
133 /// Report error.
134 void error(const Twine &Err, StringRef Context,
135 const DWARFDie *DIE = nullptr) {
136 if (ErrorHandler)
137 (ErrorHandler)(Err, Context, DIE);
140 /// Report error.
141 void error(Error Err, StringRef Context, const DWARFDie *DIE = nullptr) {
142 handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) {
143 error(Info.message(), Context, DIE);
147 protected:
148 parallel::PerThreadBumpPtrAllocator Allocator;
149 StringPool Strings;
150 TranslatorFuncTy Translator;
151 DWARFLinkerOptions Options;
152 MessageHandlerTy WarningHandler;
153 MessageHandlerTy ErrorHandler;
156 } // end of namespace dwarflinker_parallel
157 } // end namespace llvm
159 #endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERGLOBALDATA_H