IncludeGuardian created this revision. IncludeGuardian added a reviewer: MaskRay. Herald added subscribers: arphaman, hiraditya. Herald added a project: All. IncludeGuardian requested review of this revision. Herald added projects: LLDB, LLVM. Herald added subscribers: llvm-commits, lldb-commits.
**1st commit** [lldb] Add missing StringExtras.h includes In preparation for removing the `#include "llvm/ADT/StringExtras.h"` from the header to source file of `llvm/Support/Error.h`, first add in all the missing includes that were previously included transitively through this header. This is fixing all files missed in b0abd4893fa1 <https://reviews.llvm.org/rGb0abd4893fa1bfae7f71b6b6e98770c9b1c07620>, 39d8e6e22cd1 <https://reviews.llvm.org/rG39d8e6e22cd192db6ace37a4c842265058dcddb8>, and a11efd49266f <https://reviews.llvm.org/rGa11efd49266f6cf2a98bdf52428b0c9423158846>. --- **2nd commit** [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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D154775 Files: lldb/source/Core/SourceLocationSpec.cpp lldb/source/Plugins/Process/Linux/Procfs.cpp lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h lldb/source/Utility/DataExtractor.cpp lldb/source/Utility/Event.cpp lldb/source/Utility/FileSpec.cpp lldb/source/Utility/Scalar.cpp lldb/source/Utility/StructuredData.cpp llvm/include/llvm/Support/Error.h llvm/lib/Support/Error.cpp
Index: llvm/lib/Support/Error.cpp =================================================================== --- llvm/lib/Support/Error.cpp +++ llvm/lib/Support/Error.cpp @@ -7,27 +7,29 @@ //===----------------------------------------------------------------------===// #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 <system_error> using namespace llvm; namespace { enum class ErrorErrorCode : int { MultipleErrors = 1, FileError, InconvertibleError }; // FIXME: This class is only here to support the transition to llvm::Error. It // will be removed once this transition is complete. Clients should prefer to // deal with the Error value directly, rather than converting to error_code. class ErrorErrorCategory : public std::error_category { public: const char *name() const noexcept override { return "Error"; } std::string message(int condition) const override { switch (static_cast<ErrorErrorCode>(condition)) { case ErrorErrorCode::MultipleErrors: @@ -70,17 +72,26 @@ }); } +/// 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<std::string, 2> 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<int>(ErrorErrorCode::MultipleErrors), getErrorErrorCat()); } std::error_code inconvertibleErrorCode() { return std::error_code(static_cast<int>(ErrorErrorCode::InconvertibleError), getErrorErrorCat()); } std::error_code FileError::convertToErrorCode() const { std::error_code NestedEC = Err->convertToErrorCode(); if (NestedEC == inconvertibleErrorCode()) Index: llvm/include/llvm/Support/Error.h =================================================================== --- llvm/include/llvm/Support/Error.h +++ 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,14 +1023,8 @@ /// 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<std::string, 2> 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 /// value. Index: lldb/source/Utility/StructuredData.cpp =================================================================== --- lldb/source/Utility/StructuredData.cpp +++ lldb/source/Utility/StructuredData.cpp @@ -9,18 +9,19 @@ #include "lldb/Utility/StructuredData.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/Status.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/MemoryBuffer.h" #include <cerrno> #include <cinttypes> #include <cstdlib> using namespace lldb_private; using namespace llvm; static StructuredData::ObjectSP ParseJSONValue(json::Value &value); static StructuredData::ObjectSP ParseJSONObject(json::Object *object); static StructuredData::ObjectSP ParseJSONArray(json::Array *array); StructuredData::ObjectSP StructuredData::ParseJSON(llvm::StringRef json_text) { llvm::Expected<json::Value> value = json::parse(json_text); if (!value) { Index: lldb/source/Utility/Scalar.cpp =================================================================== --- lldb/source/Utility/Scalar.cpp +++ lldb/source/Utility/Scalar.cpp @@ -16,17 +16,18 @@ #include "lldb/lldb-types.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include <cinttypes> #include <cstdio> using namespace lldb; using namespace lldb_private; using llvm::APFloat; using llvm::APInt; using llvm::APSInt; Scalar::PromotionKey Scalar::GetPromoKey() const { switch (m_type) { case e_void: Index: lldb/source/Utility/FileSpec.cpp =================================================================== --- lldb/source/Utility/FileSpec.cpp +++ lldb/source/Utility/FileSpec.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/ErrorOr.h" Index: lldb/source/Utility/Event.cpp =================================================================== --- lldb/source/Utility/Event.cpp +++ lldb/source/Utility/Event.cpp @@ -15,35 +15,37 @@ #include "lldb/Utility/StreamString.h" #include "lldb/lldb-enumerations.h" +#include "llvm/ADT/StringExtras.h" + #include <algorithm> #include <cctype> using namespace lldb; using namespace lldb_private; #pragma mark - #pragma mark Event // Event functions Event::Event(Broadcaster *broadcaster, uint32_t event_type, EventData *data) : m_broadcaster_wp(broadcaster->GetBroadcasterImpl()), m_type(event_type), m_data_sp(data) {} Event::Event(Broadcaster *broadcaster, uint32_t event_type, const EventDataSP &event_data_sp) : m_broadcaster_wp(broadcaster->GetBroadcasterImpl()), m_type(event_type), m_data_sp(event_data_sp) {} Event::Event(uint32_t event_type, EventData *data) : m_broadcaster_wp(), m_type(event_type), m_data_sp(data) {} Event::Event(uint32_t event_type, const EventDataSP &event_data_sp) : m_broadcaster_wp(), m_type(event_type), m_data_sp(event_data_sp) {} Event::~Event() = default; void Event::Dump(Stream *s) const { Broadcaster *broadcaster; Broadcaster::BroadcasterImplSP broadcaster_impl_sp(m_broadcaster_wp.lock()); Index: lldb/source/Utility/DataExtractor.cpp =================================================================== --- lldb/source/Utility/DataExtractor.cpp +++ lldb/source/Utility/DataExtractor.cpp @@ -23,88 +23,89 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/MD5.h" #include "llvm/Support/MathExtras.h" #include <algorithm> #include <array> #include <cassert> #include <cstdint> #include <string> #include <cctype> #include <cinttypes> #include <cstring> using namespace lldb; using namespace lldb_private; static inline uint16_t ReadInt16(const unsigned char *ptr, offset_t offset) { uint16_t value; memcpy(&value, ptr + offset, 2); return value; } static inline uint32_t ReadInt32(const unsigned char *ptr, offset_t offset = 0) { uint32_t value; memcpy(&value, ptr + offset, 4); return value; } static inline uint64_t ReadInt64(const unsigned char *ptr, offset_t offset = 0) { uint64_t value; memcpy(&value, ptr + offset, 8); return value; } static inline uint16_t ReadInt16(const void *ptr) { uint16_t value; memcpy(&value, ptr, 2); return value; } static inline uint16_t ReadSwapInt16(const unsigned char *ptr, offset_t offset) { uint16_t value; memcpy(&value, ptr + offset, 2); return llvm::byteswap<uint16_t>(value); } static inline uint32_t ReadSwapInt32(const unsigned char *ptr, offset_t offset) { uint32_t value; memcpy(&value, ptr + offset, 4); return llvm::byteswap<uint32_t>(value); } static inline uint64_t ReadSwapInt64(const unsigned char *ptr, offset_t offset) { uint64_t value; memcpy(&value, ptr + offset, 8); return llvm::byteswap<uint64_t>(value); } static inline uint16_t ReadSwapInt16(const void *ptr) { uint16_t value; memcpy(&value, ptr, 2); return llvm::byteswap<uint16_t>(value); } static inline uint32_t ReadSwapInt32(const void *ptr) { uint32_t value; memcpy(&value, ptr, 4); return llvm::byteswap<uint32_t>(value); } static inline uint64_t ReadSwapInt64(const void *ptr) { uint64_t value; memcpy(&value, ptr, 8); return llvm::byteswap<uint64_t>(value); } static inline uint64_t ReadMaxInt64(const uint8_t *data, size_t byte_size, ByteOrder byte_order) { uint64_t res = 0; Index: lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h =================================================================== --- lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h +++ lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.h @@ -13,6 +13,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/IntervalMap.h" +#include "llvm/ADT/SmallString.h" #include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h" #include "llvm/DebugInfo/CodeView/StringsAndChecksums.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" Index: lldb/source/Plugins/Process/Linux/Procfs.cpp =================================================================== --- lldb/source/Plugins/Process/Linux/Procfs.cpp +++ lldb/source/Plugins/Process/Linux/Procfs.cpp @@ -8,33 +8,34 @@ #include "Procfs.h" #include "lldb/Host/linux/Support.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Threading.h" #include <optional> using namespace lldb; using namespace lldb_private; using namespace process_linux; using namespace llvm; Expected<ArrayRef<uint8_t>> lldb_private::process_linux::GetProcfsCpuInfo() { static ErrorOr<std::unique_ptr<MemoryBuffer>> cpu_info_or_err = getProcFile("cpuinfo"); if (!*cpu_info_or_err) cpu_info_or_err.getError(); MemoryBuffer &buffer = **cpu_info_or_err; return arrayRefFromStringRef(buffer.getBuffer()); } Expected<std::vector<cpu_id_t>> lldb_private::process_linux::GetAvailableLogicalCoreIDs(StringRef cpuinfo) { SmallVector<StringRef, 8> lines; cpuinfo.split(lines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); std::vector<cpu_id_t> logical_cores; for (StringRef line : lines) { std::pair<StringRef, StringRef> key_value = line.split(':'); auto key = key_value.first.trim(); Index: lldb/source/Core/SourceLocationSpec.cpp =================================================================== --- lldb/source/Core/SourceLocationSpec.cpp +++ lldb/source/Core/SourceLocationSpec.cpp @@ -8,72 +8,73 @@ #include "lldb/Core/SourceLocationSpec.h" #include "lldb/Utility/StreamString.h" +#include "llvm/ADT/StringExtras.h" #include <optional> using namespace lldb; using namespace lldb_private; SourceLocationSpec::SourceLocationSpec(FileSpec file_spec, uint32_t line, std::optional<uint16_t> column, bool check_inlines, bool exact_match) : m_declaration(file_spec, line, column.value_or(LLDB_INVALID_COLUMN_NUMBER)), m_check_inlines(check_inlines), m_exact_match(exact_match) {} SourceLocationSpec::operator bool() const { return m_declaration.IsValid(); } bool SourceLocationSpec::operator!() const { return !operator bool(); } bool SourceLocationSpec::operator==(const SourceLocationSpec &rhs) const { return m_declaration == rhs.m_declaration && m_check_inlines == rhs.GetCheckInlines() && m_exact_match == rhs.GetExactMatch(); } bool SourceLocationSpec::operator!=(const SourceLocationSpec &rhs) const { return !(*this == rhs); } bool SourceLocationSpec::operator<(const SourceLocationSpec &rhs) const { return SourceLocationSpec::Compare(*this, rhs) < 0; } Stream &lldb_private::operator<<(Stream &s, const SourceLocationSpec &loc) { loc.Dump(s); return s; } int SourceLocationSpec::Compare(const SourceLocationSpec &lhs, const SourceLocationSpec &rhs) { return Declaration::Compare(lhs.m_declaration, rhs.m_declaration); } bool SourceLocationSpec::Equal(const SourceLocationSpec &lhs, const SourceLocationSpec &rhs, bool full) { return full ? lhs == rhs : (lhs.GetFileSpec() == rhs.GetFileSpec() && lhs.GetLine() == rhs.GetLine()); } void SourceLocationSpec::Dump(Stream &s) const { s << "check inlines = " << llvm::toStringRef(m_check_inlines); s << ", exact match = " << llvm::toStringRef(m_exact_match); m_declaration.Dump(&s, true); } std::string SourceLocationSpec::GetString() const { StreamString ss; Dump(ss); return ss.GetString().str(); } std::optional<uint32_t> SourceLocationSpec::GetLine() const { uint32_t line = m_declaration.GetLine(); if (line == 0 || line == LLDB_INVALID_LINE_NUMBER) return std::nullopt; return line; } std::optional<uint16_t> SourceLocationSpec::GetColumn() const { uint16_t column = m_declaration.GetColumn(); if (column == LLDB_INVALID_COLUMN_NUMBER)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits