From: Elliot Goodrich Date: Sat, 8 Jul 2023 09:16:12 +0000 (+0100) Subject: [Support] Move StringExtras.h include from Error.h to Error.cpp X-Git-Tag: upstream/17.0.6~1794 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3900860b386aa666eb03738d81fdc13afd647925;p=platform%2Fupstream%2Fllvm.git [Support] Move StringExtras.h include from Error.h to Error.cpp Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D155178 --- diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h index 0f1b6321762d..2292770a97c4 100644 --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -14,8 +14,6 @@ #define LLVM_SUPPORT_ERROR_H #include "llvm-c/Error.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/abi-breaking.h" #include "llvm/Support/AlignOf.h" @@ -1025,13 +1023,7 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner = {}); /// Write all error messages (if any) in E to a string. The newline character /// is used to separate error messages. -inline std::string toString(Error E) { - SmallVector Errors; - handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { - Errors.push_back(EI.message()); - }); - return join(Errors.begin(), Errors.end(), "\n"); -} +std::string toString(Error E); /// Consume a Error without doing anything. This method should be used /// only where an error can be considered a reasonable and expected return diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp index b339b708d906..21d591530b41 100644 --- a/llvm/lib/Support/Error.cpp +++ b/llvm/lib/Support/Error.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Error.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorHandling.h" #include @@ -70,6 +72,15 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) { }); } +/// Write all error messages (if any) in E to a string. The newline character +/// is used to separate error messages. +std::string toString(Error E) { + SmallVector Errors; + handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) { + Errors.push_back(EI.message()); + }); + return join(Errors.begin(), Errors.end(), "\n"); +} std::error_code ErrorList::convertToErrorCode() const { return std::error_code(static_cast(ErrorErrorCode::MultipleErrors),