diff options
Diffstat (limited to 'include/lld/Common')
| -rw-r--r-- | include/lld/Common/Args.h | 23 | ||||
| -rw-r--r-- | include/lld/Common/Driver.h | 27 | ||||
| -rw-r--r-- | include/lld/Common/ErrorHandler.h | 98 | ||||
| -rw-r--r-- | include/lld/Common/Filesystem.h | 20 | ||||
| -rw-r--r-- | include/lld/Common/LLVM.h | 9 | ||||
| -rw-r--r-- | include/lld/Common/Memory.h | 25 | ||||
| -rw-r--r-- | include/lld/Common/Reproduce.h | 17 | ||||
| -rw-r--r-- | include/lld/Common/Strings.h | 23 | ||||
| -rw-r--r-- | include/lld/Common/TargetOptionsCommandFlags.h | 15 | ||||
| -rw-r--r-- | include/lld/Common/Threads.h | 34 | ||||
| -rw-r--r-- | include/lld/Common/Timer.h | 29 | ||||
| -rw-r--r-- | include/lld/Common/Version.h | 7 |
12 files changed, 174 insertions, 153 deletions
diff --git a/include/lld/Common/Args.h b/include/lld/Common/Args.h index 769d4840cf065..b3c8686e57e22 100644 --- a/include/lld/Common/Args.h +++ b/include/lld/Common/Args.h @@ -1,9 +1,8 @@ //===- Args.h ---------------------------------------------------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -11,6 +10,7 @@ #define LLD_ARGS_H #include "lld/Common/LLVM.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/MemoryBuffer.h" #include <vector> @@ -22,15 +22,20 @@ class InputArgList; namespace lld { namespace args { -int getInteger(llvm::opt::InputArgList &Args, unsigned Key, int Default); -std::vector<StringRef> getStrings(llvm::opt::InputArgList &Args, int Id); -uint64_t getZOptionValue(llvm::opt::InputArgList &Args, int Id, StringRef Key, +llvm::CodeGenOpt::Level getCGOptLevel(int optLevelLTO); + +int64_t getInteger(llvm::opt::InputArgList &args, unsigned key, + int64_t Default); + +std::vector<StringRef> getStrings(llvm::opt::InputArgList &args, int id); + +uint64_t getZOptionValue(llvm::opt::InputArgList &args, int id, StringRef key, uint64_t Default); -std::vector<StringRef> getLines(MemoryBufferRef MB); +std::vector<StringRef> getLines(MemoryBufferRef mb); -StringRef getFilenameWithoutExe(StringRef Path); +StringRef getFilenameWithoutExe(StringRef path); } // namespace args } // namespace lld diff --git a/include/lld/Common/Driver.h b/include/lld/Common/Driver.h index f6d92933af622..e5595952ad222 100644 --- a/include/lld/Common/Driver.h +++ b/include/lld/Common/Driver.h @@ -1,9 +1,8 @@ //===- lld/Common/Driver.h - Linker Driver Emulator -----------------------===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -15,28 +14,28 @@ namespace lld { namespace coff { -bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly, - llvm::raw_ostream &Diag = llvm::errs()); +bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, + llvm::raw_ostream &diag = llvm::errs()); } namespace mingw { -bool link(llvm::ArrayRef<const char *> Args, - llvm::raw_ostream &Diag = llvm::errs()); +bool link(llvm::ArrayRef<const char *> args, + llvm::raw_ostream &diag = llvm::errs()); } namespace elf { -bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly, - llvm::raw_ostream &Diag = llvm::errs()); +bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, + llvm::raw_ostream &diag = llvm::errs()); } namespace mach_o { -bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly, - llvm::raw_ostream &Diag = llvm::errs()); +bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, + llvm::raw_ostream &diag = llvm::errs()); } namespace wasm { -bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly, - llvm::raw_ostream &Diag = llvm::errs()); +bool link(llvm::ArrayRef<const char *> args, bool canExitEarly, + llvm::raw_ostream &diag = llvm::errs()); } } diff --git a/include/lld/Common/ErrorHandler.h b/include/lld/Common/ErrorHandler.h index c169f7b50de89..7126a7bf410ae 100644 --- a/include/lld/Common/ErrorHandler.h +++ b/include/lld/Common/ErrorHandler.h @@ -1,9 +1,8 @@ //===- ErrorHandler.h -------------------------------------------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -83,74 +82,75 @@ namespace lld { class ErrorHandler { public: - uint64_t ErrorCount = 0; - uint64_t ErrorLimit = 20; - StringRef ErrorLimitExceededMsg = "too many errors emitted, stopping now"; - StringRef LogName = "lld"; - llvm::raw_ostream *ErrorOS = &llvm::errs(); - bool ColorDiagnostics = llvm::errs().has_colors(); - bool ExitEarly = true; - bool FatalWarnings = false; - bool Verbose = false; - - void error(const Twine &Msg); - LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg); - void log(const Twine &Msg); - void message(const Twine &Msg); - void warn(const Twine &Msg); - - std::unique_ptr<llvm::FileOutputBuffer> OutputBuffer; + uint64_t errorCount = 0; + uint64_t errorLimit = 20; + StringRef errorLimitExceededMsg = "too many errors emitted, stopping now"; + StringRef logName = "lld"; + llvm::raw_ostream *errorOS = &llvm::errs(); + bool colorDiagnostics = llvm::errs().has_colors(); + bool exitEarly = true; + bool fatalWarnings = false; + bool verbose = false; + bool vsDiagnostics = false; + + void error(const Twine &msg); + LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &msg); + void log(const Twine &msg); + void message(const Twine &msg); + void warn(const Twine &msg); + + std::unique_ptr<llvm::FileOutputBuffer> outputBuffer; private: - void print(StringRef S, raw_ostream::Colors C); + void printHeader(StringRef s, raw_ostream::Colors c, const Twine &msg); }; /// Returns the default error handler. ErrorHandler &errorHandler(); -inline void error(const Twine &Msg) { errorHandler().error(Msg); } -inline LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg) { - errorHandler().fatal(Msg); +inline void error(const Twine &msg) { errorHandler().error(msg); } +inline LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &msg) { + errorHandler().fatal(msg); } -inline void log(const Twine &Msg) { errorHandler().log(Msg); } -inline void message(const Twine &Msg) { errorHandler().message(Msg); } -inline void warn(const Twine &Msg) { errorHandler().warn(Msg); } -inline uint64_t errorCount() { return errorHandler().ErrorCount; } +inline void log(const Twine &msg) { errorHandler().log(msg); } +inline void message(const Twine &msg) { errorHandler().message(msg); } +inline void warn(const Twine &msg) { errorHandler().warn(msg); } +inline uint64_t errorCount() { return errorHandler().errorCount; } -LLVM_ATTRIBUTE_NORETURN void exitLld(int Val); +LLVM_ATTRIBUTE_NORETURN void exitLld(int val); -void diagnosticHandler(const llvm::DiagnosticInfo &DI); -void checkError(Error E); +void diagnosticHandler(const llvm::DiagnosticInfo &di); +void checkError(Error e); // check functions are convenient functions to strip errors // from error-or-value objects. -template <class T> T check(ErrorOr<T> E) { - if (auto EC = E.getError()) - fatal(EC.message()); - return std::move(*E); +template <class T> T check(ErrorOr<T> e) { + if (auto ec = e.getError()) + fatal(ec.message()); + return std::move(*e); } -template <class T> T check(Expected<T> E) { - if (!E) - fatal(llvm::toString(E.takeError())); - return std::move(*E); +template <class T> T check(Expected<T> e) { + if (!e) + fatal(llvm::toString(e.takeError())); + return std::move(*e); } template <class T> -T check2(ErrorOr<T> E, llvm::function_ref<std::string()> Prefix) { - if (auto EC = E.getError()) - fatal(Prefix() + ": " + EC.message()); - return std::move(*E); +T check2(ErrorOr<T> e, llvm::function_ref<std::string()> prefix) { + if (auto ec = e.getError()) + fatal(prefix() + ": " + ec.message()); + return std::move(*e); } template <class T> -T check2(Expected<T> E, llvm::function_ref<std::string()> Prefix) { - if (!E) - fatal(Prefix() + ": " + toString(E.takeError())); - return std::move(*E); +T check2(Expected<T> e, llvm::function_ref<std::string()> prefix) { + if (!e) + fatal(prefix() + ": " + toString(e.takeError())); + return std::move(*e); } -inline std::string toString(const Twine &S) { return S.str(); } +inline std::string toString(const Twine &s) { return s.str(); } // To evaluate the second argument lazily, we use C macro. #define CHECK(E, S) check2((E), [&] { return toString(S); }) diff --git a/include/lld/Common/Filesystem.h b/include/lld/Common/Filesystem.h new file mode 100644 index 0000000000000..63a0f554a06c5 --- /dev/null +++ b/include/lld/Common/Filesystem.h @@ -0,0 +1,20 @@ +//===- Filesystem.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 LLD_FILESYSTEM_H +#define LLD_FILESYSTEM_H + +#include "lld/Common/LLVM.h" +#include <system_error> + +namespace lld { +void unlinkAsync(StringRef path); +std::error_code tryCreateFile(StringRef path); +} // namespace lld + +#endif diff --git a/include/lld/Common/LLVM.h b/include/lld/Common/LLVM.h index 95a2aa903957d..f7ed1d793ca7b 100644 --- a/include/lld/Common/LLVM.h +++ b/include/lld/Common/LLVM.h @@ -1,9 +1,8 @@ //===--- LLVM.h - Import various common LLVM datatypes ----------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -30,6 +29,7 @@ class Twine; class MemoryBuffer; class MemoryBufferRef; template <typename T> class ArrayRef; +template <typename T> class MutableArrayRef; template <unsigned InternalLen> class SmallString; template <typename T, unsigned N> class SmallVector; template <typename T> class ErrorOr; @@ -63,6 +63,7 @@ using llvm::isa; // ADT's. using llvm::ArrayRef; +using llvm::MutableArrayRef; using llvm::Error; using llvm::ErrorOr; using llvm::Expected; diff --git a/include/lld/Common/Memory.h b/include/lld/Common/Memory.h index 699f7c1654cd3..41d8f15d7b34b 100644 --- a/include/lld/Common/Memory.h +++ b/include/lld/Common/Memory.h @@ -1,9 +1,8 @@ //===- Memory.h -------------------------------------------------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -29,30 +28,30 @@ namespace lld { // Use this arena if your object doesn't have a destructor. -extern llvm::BumpPtrAllocator BAlloc; -extern llvm::StringSaver Saver; +extern llvm::BumpPtrAllocator bAlloc; +extern llvm::StringSaver saver; void freeArena(); // These two classes are hack to keep track of all // SpecificBumpPtrAllocator instances. struct SpecificAllocBase { - SpecificAllocBase() { Instances.push_back(this); } + SpecificAllocBase() { instances.push_back(this); } virtual ~SpecificAllocBase() = default; virtual void reset() = 0; - static std::vector<SpecificAllocBase *> Instances; + static std::vector<SpecificAllocBase *> instances; }; template <class T> struct SpecificAlloc : public SpecificAllocBase { - void reset() override { Alloc.DestroyAll(); } - llvm::SpecificBumpPtrAllocator<T> Alloc; + void reset() override { alloc.DestroyAll(); } + llvm::SpecificBumpPtrAllocator<T> alloc; }; // Use this arena if your object has a destructor. // Your destructor will be invoked from freeArena(). -template <typename T, typename... U> T *make(U &&... Args) { - static SpecificAlloc<T> Alloc; - return new (Alloc.Alloc.Allocate()) T(std::forward<U>(Args)...); +template <typename T, typename... U> T *make(U &&... args) { + static SpecificAlloc<T> alloc; + return new (alloc.alloc.Allocate()) T(std::forward<U>(args)...); } } // namespace lld diff --git a/include/lld/Common/Reproduce.h b/include/lld/Common/Reproduce.h index 0f425de269c7f..734d9e4011d19 100644 --- a/include/lld/Common/Reproduce.h +++ b/include/lld/Common/Reproduce.h @@ -1,9 +1,8 @@ //===- Reproduce.h - Utilities for creating reproducers ---------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -23,17 +22,13 @@ namespace lld { // Makes a given pathname an absolute path first, and then remove // beginning /. For example, "../foo.o" is converted to "home/john/foo.o", // assuming that the current directory is "/home/john/bar". -std::string relativeToRoot(StringRef Path); +std::string relativeToRoot(StringRef path); // Quote a given string if it contains a space character. -std::string quote(StringRef S); - -// Rewrite the given path if a file exists with that pathname, otherwise -// returns the original path. -std::string rewritePath(StringRef S); +std::string quote(StringRef s); // Returns the string form of the given argument. -std::string toString(const llvm::opt::Arg &Arg); +std::string toString(const llvm::opt::Arg &arg); } #endif diff --git a/include/lld/Common/Strings.h b/include/lld/Common/Strings.h index 566030e43aa64..ded22dd769bed 100644 --- a/include/lld/Common/Strings.h +++ b/include/lld/Common/Strings.h @@ -1,9 +1,8 @@ //===- Strings.h ------------------------------------------------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -20,25 +19,25 @@ namespace lld { // Returns a demangled C++ symbol name. If Name is not a mangled // name, it returns Optional::None. -llvm::Optional<std::string> demangleItanium(llvm::StringRef Name); -llvm::Optional<std::string> demangleMSVC(llvm::StringRef S); +llvm::Optional<std::string> demangleItanium(llvm::StringRef name); +llvm::Optional<std::string> demangleMSVC(llvm::StringRef s); -std::vector<uint8_t> parseHex(llvm::StringRef S); -bool isValidCIdentifier(llvm::StringRef S); +std::vector<uint8_t> parseHex(llvm::StringRef s); +bool isValidCIdentifier(llvm::StringRef s); // Write the contents of the a buffer to a file -void saveBuffer(llvm::StringRef Buffer, const llvm::Twine &Path); +void saveBuffer(llvm::StringRef buffer, const llvm::Twine &path); // This class represents multiple glob patterns. class StringMatcher { public: StringMatcher() = default; - explicit StringMatcher(llvm::ArrayRef<llvm::StringRef> Pat); + explicit StringMatcher(llvm::ArrayRef<llvm::StringRef> pat); - bool match(llvm::StringRef S) const; + bool match(llvm::StringRef s) const; private: - std::vector<llvm::GlobPattern> Patterns; + std::vector<llvm::GlobPattern> patterns; }; } // namespace lld diff --git a/include/lld/Common/TargetOptionsCommandFlags.h b/include/lld/Common/TargetOptionsCommandFlags.h index 2eaecb72759e5..9345e616f9a96 100644 --- a/include/lld/Common/TargetOptionsCommandFlags.h +++ b/include/lld/Common/TargetOptionsCommandFlags.h @@ -1,9 +1,8 @@ //===-- TargetOptionsCommandFlags.h ----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -16,8 +15,8 @@ #include "llvm/Target/TargetOptions.h" namespace lld { -llvm::TargetOptions InitTargetOptionsFromCodeGenFlags(); -llvm::Optional<llvm::CodeModel::Model> GetCodeModelFromCMModel(); -std::string GetCPUStr(); -std::vector<std::string> GetMAttrs(); +llvm::TargetOptions initTargetOptionsFromCodeGenFlags(); +llvm::Optional<llvm::CodeModel::Model> getCodeModelFromCMModel(); +std::string getCPUStr(); +std::vector<std::string> getMAttrs(); } diff --git a/include/lld/Common/Threads.h b/include/lld/Common/Threads.h index 1425abd129224..7834130fdf726 100644 --- a/include/lld/Common/Threads.h +++ b/include/lld/Common/Threads.h @@ -1,9 +1,8 @@ //===- Threads.h ------------------------------------------------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // @@ -64,21 +63,28 @@ namespace lld { -extern bool ThreadsEnabled; +extern bool threadsEnabled; + +template <typename R, class FuncTy> void parallelForEach(R &&range, FuncTy fn) { + if (threadsEnabled) + for_each(llvm::parallel::par, std::begin(range), std::end(range), fn); + else + for_each(llvm::parallel::seq, std::begin(range), std::end(range), fn); +} -template <typename R, class FuncTy> void parallelForEach(R &&Range, FuncTy Fn) { - if (ThreadsEnabled) - for_each(llvm::parallel::par, std::begin(Range), std::end(Range), Fn); +inline void parallelForEachN(size_t begin, size_t end, + llvm::function_ref<void(size_t)> fn) { + if (threadsEnabled) + for_each_n(llvm::parallel::par, begin, end, fn); else - for_each(llvm::parallel::seq, std::begin(Range), std::end(Range), Fn); + for_each_n(llvm::parallel::seq, begin, end, fn); } -inline void parallelForEachN(size_t Begin, size_t End, - llvm::function_ref<void(size_t)> Fn) { - if (ThreadsEnabled) - for_each_n(llvm::parallel::par, Begin, End, Fn); +template <typename R, class FuncTy> void parallelSort(R &&range, FuncTy fn) { + if (threadsEnabled) + sort(llvm::parallel::par, std::begin(range), std::end(range), fn); else - for_each_n(llvm::parallel::seq, Begin, End, Fn); + sort(llvm::parallel::seq, std::begin(range), std::end(range), fn); } } // namespace lld diff --git a/include/lld/Common/Timer.h b/include/lld/Common/Timer.h index 6654af6269192..4a298b04a30b5 100644 --- a/include/lld/Common/Timer.h +++ b/include/lld/Common/Timer.h @@ -1,9 +1,8 @@ //===- Timer.h ----------------------------------------------*- C++ -*-===// // -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// @@ -22,18 +21,18 @@ namespace lld { class Timer; struct ScopedTimer { - explicit ScopedTimer(Timer &T); + explicit ScopedTimer(Timer &t); ~ScopedTimer(); void stop(); - Timer *T = nullptr; + Timer *t = nullptr; }; class Timer { public: - Timer(llvm::StringRef Name, Timer &Parent); + Timer(llvm::StringRef name, Timer &parent); static Timer &root(); @@ -44,14 +43,14 @@ public: double millis() const; private: - explicit Timer(llvm::StringRef Name); - void print(int Depth, double TotalDuration, bool Recurse = true) const; - - std::chrono::time_point<std::chrono::high_resolution_clock> StartTime; - std::chrono::nanoseconds Total; - std::vector<Timer *> Children; - std::string Name; - Timer *Parent; + explicit Timer(llvm::StringRef name); + void print(int depth, double totalDuration, bool recurse = true) const; + + std::chrono::time_point<std::chrono::high_resolution_clock> startTime; + std::chrono::nanoseconds total; + std::vector<Timer *> children; + std::string name; + Timer *parent; }; } // namespace lld diff --git a/include/lld/Common/Version.h b/include/lld/Common/Version.h index 23a10ed6dbf3b..9571aa2743e5b 100644 --- a/include/lld/Common/Version.h +++ b/include/lld/Common/Version.h @@ -1,9 +1,8 @@ //===- lld/Common/Version.h - LLD Version Number ----------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// 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 // //===----------------------------------------------------------------------===// // |
