diff options
Diffstat (limited to 'llvm/include/llvm')
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfo.h | 4 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfoCOFF.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfoDarwin.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfoELF.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfoGOFF.h | 3 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfoWasm.h | 3 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCAsmInfoXCOFF.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSection.h | 6 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionCOFF.h | 7 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionDXContainer.h | 4 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionELF.h | 9 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionGOFF.h | 5 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionMachO.h | 7 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionSPIRV.h | 8 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionWasm.h | 9 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSectionXCOFF.h | 4 | ||||
-rw-r--r-- | llvm/include/llvm/MC/MCSymbolELF.h | 1 | ||||
-rw-r--r-- | llvm/include/llvm/Support/DebugLog.h | 122 | ||||
-rw-r--r-- | llvm/include/llvm/Support/ThreadPool.h | 8 |
19 files changed, 112 insertions, 96 deletions
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h index 402e12a..6c12cd3 100644 --- a/llvm/include/llvm/MC/MCAsmInfo.h +++ b/llvm/include/llvm/MC/MCAsmInfo.h @@ -35,6 +35,7 @@ class MCStreamer; class MCSubtargetInfo; class MCSymbol; class MCValue; +class Triple; class raw_ostream; namespace WinEH { @@ -485,6 +486,9 @@ public: /// syntactically correct. virtual bool isValidUnquotedName(StringRef Name) const; + virtual void printSwitchToSection(const MCSection &, uint32_t Subsection, + const Triple &, raw_ostream &) const {} + /// Return true if the .section directive should be omitted when /// emitting \p SectionName. For example: /// diff --git a/llvm/include/llvm/MC/MCAsmInfoCOFF.h b/llvm/include/llvm/MC/MCAsmInfoCOFF.h index 631b549..dc7832c 100644 --- a/llvm/include/llvm/MC/MCAsmInfoCOFF.h +++ b/llvm/include/llvm/MC/MCAsmInfoCOFF.h @@ -15,6 +15,8 @@ namespace llvm { class MCAsmInfoCOFF : public MCAsmInfo { virtual void anchor(); + void printSwitchToSection(const MCSection &, uint32_t, const Triple &, + raw_ostream &) const final; bool useCodeAlign(const MCSection &Sec) const final; protected: diff --git a/llvm/include/llvm/MC/MCAsmInfoDarwin.h b/llvm/include/llvm/MC/MCAsmInfoDarwin.h index 9bc5dd7..12bc3e9 100644 --- a/llvm/include/llvm/MC/MCAsmInfoDarwin.h +++ b/llvm/include/llvm/MC/MCAsmInfoDarwin.h @@ -21,6 +21,8 @@ namespace llvm { class MCAsmInfoDarwin : public MCAsmInfo { public: explicit MCAsmInfoDarwin(); + void printSwitchToSection(const MCSection &, uint32_t, const Triple &, + raw_ostream &) const final; bool useCodeAlign(const MCSection &Sec) const final; /// True if the section is atomized using the symbols in it. diff --git a/llvm/include/llvm/MC/MCAsmInfoELF.h b/llvm/include/llvm/MC/MCAsmInfoELF.h index 80cbf5c..c05e4ad 100644 --- a/llvm/include/llvm/MC/MCAsmInfoELF.h +++ b/llvm/include/llvm/MC/MCAsmInfoELF.h @@ -16,6 +16,8 @@ namespace llvm { class MCAsmInfoELF : public MCAsmInfo { virtual void anchor(); MCSection *getNonexecutableStackSection(MCContext &Ctx) const final; + void printSwitchToSection(const MCSection &, uint32_t, const Triple &, + raw_ostream &) const final; bool useCodeAlign(const MCSection &Sec) const final; protected: diff --git a/llvm/include/llvm/MC/MCAsmInfoGOFF.h b/llvm/include/llvm/MC/MCAsmInfoGOFF.h index 1f3b263..e62d2ae 100644 --- a/llvm/include/llvm/MC/MCAsmInfoGOFF.h +++ b/llvm/include/llvm/MC/MCAsmInfoGOFF.h @@ -19,7 +19,8 @@ namespace llvm { class MCAsmInfoGOFF : public MCAsmInfo { - virtual void anchor(); + void printSwitchToSection(const MCSection &, uint32_t, const Triple &, + raw_ostream &) const final; protected: MCAsmInfoGOFF(); diff --git a/llvm/include/llvm/MC/MCAsmInfoWasm.h b/llvm/include/llvm/MC/MCAsmInfoWasm.h index 3afc610..d98de6c 100644 --- a/llvm/include/llvm/MC/MCAsmInfoWasm.h +++ b/llvm/include/llvm/MC/MCAsmInfoWasm.h @@ -13,7 +13,8 @@ namespace llvm { class MCAsmInfoWasm : public MCAsmInfo { - virtual void anchor(); + void printSwitchToSection(const MCSection &, uint32_t, const Triple &, + raw_ostream &) const final; protected: MCAsmInfoWasm(); diff --git a/llvm/include/llvm/MC/MCAsmInfoXCOFF.h b/llvm/include/llvm/MC/MCAsmInfoXCOFF.h index 06a3fed..fd1ae82 100644 --- a/llvm/include/llvm/MC/MCAsmInfoXCOFF.h +++ b/llvm/include/llvm/MC/MCAsmInfoXCOFF.h @@ -16,6 +16,8 @@ namespace llvm { class MCAsmInfoXCOFF : public MCAsmInfo { protected: MCAsmInfoXCOFF(); + void printSwitchToSection(const MCSection &, uint32_t, const Triple &, + raw_ostream &) const final; bool useCodeAlign(const MCSection &Sec) const final; public: diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index 9378786..7989310 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -597,8 +597,6 @@ protected: StringRef Name; MCSection(StringRef Name, bool IsText, bool IsBss, MCSymbol *Begin); - // Protected non-virtual dtor prevents destroy through a base class pointer. - ~MCSection() {} public: MCSection(const MCSection &) = delete; @@ -648,10 +646,6 @@ public: void dump(DenseMap<const MCFragment *, SmallVector<const MCSymbol *, 0>> *FragToSyms = nullptr) const; - virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const = 0; - /// Check whether this section is "virtual", that is has no actual object /// file contents. bool isBssSection() const { return IsBss; } diff --git a/llvm/include/llvm/MC/MCSectionCOFF.h b/llvm/include/llvm/MC/MCSectionCOFF.h index 8df54a4..71efc41 100644 --- a/llvm/include/llvm/MC/MCSectionCOFF.h +++ b/llvm/include/llvm/MC/MCSectionCOFF.h @@ -51,6 +51,7 @@ class MCSectionCOFF final : public MCSection { private: friend class MCContext; + friend class MCAsmInfoCOFF; // The storage of Name is owned by MCContext's COFFUniquingMap. MCSectionCOFF(StringRef Name, unsigned Characteristics, MCSymbol *COMDATSymbol, int Selection, unsigned UniqueID, @@ -67,7 +68,7 @@ private: public: /// Decides whether a '.section' directive should be printed before the /// section name - bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; + bool shouldOmitSectionDirective(StringRef Name) const; unsigned getCharacteristics() const { return Characteristics; } MCSymbol *getCOMDATSymbol() const { return COMDATSymbol; } @@ -78,10 +79,6 @@ public: bool isUnique() const { return UniqueID != NonUniqueID; } unsigned getUniqueID() const { return UniqueID; } - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override; - unsigned getOrAssignWinCFISectionID(unsigned *NextID) const { if (WinCFISectionID == ~0U) WinCFISectionID = (*NextID)++; diff --git a/llvm/include/llvm/MC/MCSectionDXContainer.h b/llvm/include/llvm/MC/MCSectionDXContainer.h index 2516afa..7d8e0c5 100644 --- a/llvm/include/llvm/MC/MCSectionDXContainer.h +++ b/llvm/include/llvm/MC/MCSectionDXContainer.h @@ -25,10 +25,6 @@ class MCSectionDXContainer final : public MCSection { MCSectionDXContainer(StringRef Name, SectionKind K, MCSymbol *Begin) : MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin) {} - -public: - void printSwitchToSection(const MCAsmInfo &, const Triple &, raw_ostream &, - uint32_t) const override; }; } // end namespace llvm diff --git a/llvm/include/llvm/MC/MCSectionELF.h b/llvm/include/llvm/MC/MCSectionELF.h index 287b57c..f089dd9 100644 --- a/llvm/include/llvm/MC/MCSectionELF.h +++ b/llvm/include/llvm/MC/MCSectionELF.h @@ -52,6 +52,7 @@ class MCSectionELF final : public MCSection { private: friend class MCContext; + friend class MCAsmInfoELF; // The storage of Name is owned by MCContext's ELFUniquingMap. MCSectionELF(StringRef Name, unsigned type, unsigned flags, @@ -69,10 +70,6 @@ private: } public: - /// Decides whether a '.section' directive should be printed before the - /// section name - bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; - unsigned getType() const { return Type; } unsigned getFlags() const { return Flags; } unsigned getEntrySize() const { return EntrySize; } @@ -80,10 +77,6 @@ public: const MCSymbolELF *getGroup() const { return Group.getPointer(); } bool isComdat() const { return Group.getInt(); } - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override; - bool isUnique() const { return UniqueID != NonUniqueID; } unsigned getUniqueID() const { return UniqueID; } diff --git a/llvm/include/llvm/MC/MCSectionGOFF.h b/llvm/include/llvm/MC/MCSectionGOFF.h index 491e56b..2136148 100644 --- a/llvm/include/llvm/MC/MCSectionGOFF.h +++ b/llvm/include/llvm/MC/MCSectionGOFF.h @@ -52,6 +52,7 @@ class LLVM_ABI MCSectionGOFF final : public MCSection { mutable unsigned Emitted : 1; friend class MCContext; + friend class MCAsmInfoGOFF; friend class MCSymbolGOFF; MCSectionGOFF(StringRef Name, SectionKind K, bool IsVirtual, @@ -73,10 +74,6 @@ class LLVM_ABI MCSectionGOFF final : public MCSection { IsBSS(K.isBSS()), RequiresNonZeroLength(0), Emitted(0) {} public: - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override; - // Return the parent section. MCSectionGOFF *getParent() const { return Parent; } diff --git a/llvm/include/llvm/MC/MCSectionMachO.h b/llvm/include/llvm/MC/MCSectionMachO.h index 1588847..a65d7e0 100644 --- a/llvm/include/llvm/MC/MCSectionMachO.h +++ b/llvm/include/llvm/MC/MCSectionMachO.h @@ -23,6 +23,8 @@ namespace llvm { /// This represents a section on a Mach-O system (used by Mac OS X). On a Mac /// system, these are also described in /usr/include/mach-o/loader.h. class LLVM_ABI MCSectionMachO final : public MCSection { + friend class MCContext; + friend class MCAsmInfoDarwin; char SegmentName[16]; // Not necessarily null terminated! /// This is the SECTION_TYPE and SECTION_ATTRIBUTES field of a section, drawn @@ -42,7 +44,6 @@ class LLVM_ABI MCSectionMachO final : public MCSection { MCSectionMachO(StringRef Segment, StringRef Section, unsigned TAA, unsigned reserved2, SectionKind K, MCSymbol *Begin); - friend class MCContext; public: StringRef getSegmentName() const { @@ -76,10 +77,6 @@ public: bool &TAAParsed, // Out. unsigned &StubSize); // Out. - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override; - void allocAtoms(); const MCSymbol *getAtom(size_t I) const; void setAtom(size_t I, const MCSymbol *Sym); diff --git a/llvm/include/llvm/MC/MCSectionSPIRV.h b/llvm/include/llvm/MC/MCSectionSPIRV.h index 2b3e931..6850965 100644 --- a/llvm/include/llvm/MC/MCSectionSPIRV.h +++ b/llvm/include/llvm/MC/MCSectionSPIRV.h @@ -18,8 +18,6 @@ namespace llvm { -class MCSymbol; - class MCSectionSPIRV final : public MCSection { friend class MCContext; @@ -27,12 +25,6 @@ class MCSectionSPIRV final : public MCSection { : MCSection("", /*IsText=*/true, /*IsVirtual=*/false, /*Begin=*/nullptr) {} // TODO: Add StringRef Name to MCSectionSPIRV. - -public: - ~MCSectionSPIRV() = default; - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override {} }; } // end namespace llvm diff --git a/llvm/include/llvm/MC/MCSectionWasm.h b/llvm/include/llvm/MC/MCSectionWasm.h index 86f1418..5ec01ed 100644 --- a/llvm/include/llvm/MC/MCSectionWasm.h +++ b/llvm/include/llvm/MC/MCSectionWasm.h @@ -49,6 +49,7 @@ class MCSectionWasm final : public MCSection { // The storage of Name is owned by MCContext's WasmUniquingMap. friend class MCContext; + friend class MCAsmInfoWasm; MCSectionWasm(StringRef Name, SectionKind K, unsigned SegmentFlags, const MCSymbolWasm *Group, unsigned UniqueID, MCSymbol *Begin) : MCSection(Name, K.isText(), /*IsVirtual=*/false, Begin), @@ -57,17 +58,9 @@ class MCSectionWasm final : public MCSection { IsMetadata(K.isMetadata()), SegmentFlags(SegmentFlags) {} public: - /// Decides whether a '.section' directive should be printed before the - /// section name - bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const; - const MCSymbolWasm *getGroup() const { return Group; } unsigned getSegmentFlags() const { return SegmentFlags; } - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override; - bool isWasmData() const { return IsWasmData; } bool isMetadata() const { return IsMetadata; } diff --git a/llvm/include/llvm/MC/MCSectionXCOFF.h b/llvm/include/llvm/MC/MCSectionXCOFF.h index ca0946c..0571f95 100644 --- a/llvm/include/llvm/MC/MCSectionXCOFF.h +++ b/llvm/include/llvm/MC/MCSectionXCOFF.h @@ -31,6 +31,7 @@ namespace llvm { // implemented yet. class MCSectionXCOFF final : public MCSection { friend class MCContext; + friend class MCAsmInfoXCOFF; std::optional<XCOFF::CsectProperties> CsectProp; MCSymbolXCOFF *const QualName; @@ -111,9 +112,6 @@ public: } MCSymbolXCOFF *getQualNameSymbol() const { return QualName; } - void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, - raw_ostream &OS, - uint32_t Subsection) const override; StringRef getSymbolTableName() const { return SymbolTableName; } void setSymbolTableName(StringRef STN) { SymbolTableName = STN; } bool isMultiSymbolsAllowed() const { return MultiSymbolsAllowed; } diff --git a/llvm/include/llvm/MC/MCSymbolELF.h b/llvm/include/llvm/MC/MCSymbolELF.h index eba9964..7c271e7 100644 --- a/llvm/include/llvm/MC/MCSymbolELF.h +++ b/llvm/include/llvm/MC/MCSymbolELF.h @@ -13,6 +13,7 @@ namespace llvm { class MCSymbolELF : public MCSymbol { + friend class MCAsmInfoELF; /// An expression describing how to calculate the size of a symbol. If a /// symbol has no size this field will be NULL. const MCExpr *SymbolSize = nullptr; diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h index b1b17e3..19d3098 100644 --- a/llvm/include/llvm/Support/DebugLog.h +++ b/llvm/include/llvm/Support/DebugLog.h @@ -26,55 +26,107 @@ namespace llvm { // << "] " << "Bitset contains: " << Bitset << "\n"); #define LDBG() DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE) -#if defined(__SHORT_FILE__) -#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \ +#define DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, TYPE, FILE) \ for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \ _c = false) \ - ::llvm::impl::LogWithNewline(TYPE, __SHORT_FILE__, __LINE__, (STREAM)) + ::llvm::impl::raw_ldbg_ostream{ \ + ::llvm::impl::computePrefix(TYPE, FILE, __LINE__), (STREAM)} \ + .asLvalue() +// When __SHORT_FILE__ is not defined, the File is the full path, +// otherwise __SHORT_FILE__ is defined in CMake to provide the file name +// without the path prefix. +#if defined(__SHORT_FILE__) +#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \ + DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, TYPE, __SHORT_FILE__) #else #define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \ - for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \ - _c = false) \ - ::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM)) + DEBUGLOG_WITH_STREAM_TYPE_AND_FILE( \ + STREAM, TYPE, ::llvm::impl::LogWithNewline::getShortFileName(__FILE__)) #endif namespace impl { -class LogWithNewline { -public: - LogWithNewline(const char *debug_type, const char *file, int line, - raw_ostream &os) - : os(os) { -#if !defined(__SHORT_FILE__) - file = ::llvm::impl::LogWithNewline::getShortFileName(file); -#endif - if (debug_type) - os << "[" << debug_type << "] "; - os << file << ":" << line << " "; + +/// A raw_ostream that tracks `\n` and print the prefix. +class LLVM_ABI raw_ldbg_ostream final : public raw_ostream { + std::string Prefix; + raw_ostream &Os; + bool HasPendingNewline = true; + + /// Split the line on newlines and insert the prefix before each newline. + /// Forward everything to the underlying stream. + void write_impl(const char *Ptr, size_t Size) final { + auto Str = StringRef(Ptr, Size); + // Handle the initial prefix. + if (!Str.empty()) + writeWithPrefix(StringRef()); + + auto Eol = Str.find('\n'); + while (Eol != StringRef::npos) { + StringRef Line = Str.take_front(Eol + 1); + if (!Line.empty()) + writeWithPrefix(Line); + HasPendingNewline = true; + Str = Str.drop_front(Eol + 1); + Eol = Str.find('\n'); + } + if (!Str.empty()) + writeWithPrefix(Str); } - ~LogWithNewline() { os << '\n'; } - template <typename T> raw_ostream &operator<<(const T &t) && { - return os << t; + void emitPrefix() { Os.write(Prefix.c_str(), Prefix.size()); } + void writeWithPrefix(StringRef Str) { + if (HasPendingNewline) { + emitPrefix(); + HasPendingNewline = false; + } + Os.write(Str.data(), Str.size()); } - // Prevent copying, as this class manages newline responsibility and is - // intended for use as a temporary. - LogWithNewline(const LogWithNewline &) = delete; - LogWithNewline &operator=(const LogWithNewline &) = delete; - LogWithNewline &operator=(LogWithNewline &&) = delete; - static constexpr const char *getShortFileName(const char *path) { - // Remove the path prefix from the file name. - const char *filename = path; - for (const char *p = path; *p != '\0'; ++p) { - if (*p == '/' || *p == '\\') { - filename = p + 1; - } +public: + explicit raw_ldbg_ostream(std::string Prefix, raw_ostream &Os) + : Prefix(std::move(Prefix)), Os(Os) { + SetUnbuffered(); + } + ~raw_ldbg_ostream() final { + flushEol(); + Os << '\n'; + } + void flushEol() { + if (HasPendingNewline) { + emitPrefix(); + HasPendingNewline = false; } - return filename; } -private: - raw_ostream &os; + /// Forward the current_pos method to the underlying stream. + uint64_t current_pos() const final { return Os.tell(); } + + /// Some of the `<<` operators expect an lvalue, so we trick the type system. + raw_ldbg_ostream &asLvalue() { return *this; } }; + +/// Remove the path prefix from the file name. +static LLVM_ATTRIBUTE_UNUSED constexpr const char * +getShortFileName(const char *path) { + const char *filename = path; + for (const char *p = path; *p != '\0'; ++p) { + if (*p == '/' || *p == '\\') + filename = p + 1; + } + return filename; +} + +/// Compute the prefix for the debug log in the form of: +/// "[DebugType] File:Line " +/// Where the File is the file name without the path prefix. +static LLVM_ATTRIBUTE_UNUSED std::string +computePrefix(const char *DebugType, const char *File, int Line) { + std::string Prefix; + raw_string_ostream OsPrefix(Prefix); + if (DebugType) + OsPrefix << "[" << DebugType << "] "; + OsPrefix << File << ":" << Line << " "; + return OsPrefix.str(); +} } // end namespace impl #else // As others in Debug, When compiling without assertions, the -debug-* options diff --git a/llvm/include/llvm/Support/ThreadPool.h b/llvm/include/llvm/Support/ThreadPool.h index 9272760..c26681c 100644 --- a/llvm/include/llvm/Support/ThreadPool.h +++ b/llvm/include/llvm/Support/ThreadPool.h @@ -149,10 +149,6 @@ public: /// number of threads! unsigned getMaxConcurrency() const override { return MaxThreadCount; } - // TODO: Remove, misleading legacy name warning! - LLVM_DEPRECATED("Use getMaxConcurrency instead", "getMaxConcurrency") - unsigned getThreadCount() const { return MaxThreadCount; } - /// Returns true if the current thread is a worker thread of this thread pool. bool isWorkerThread() const; @@ -233,10 +229,6 @@ public: /// Returns always 1: there is no concurrency. unsigned getMaxConcurrency() const override { return 1; } - // TODO: Remove, misleading legacy name warning! - LLVM_DEPRECATED("Use getMaxConcurrency instead", "getMaxConcurrency") - unsigned getThreadCount() const { return 1; } - /// Returns true if the current thread is a worker thread of this thread pool. bool isWorkerThread() const; |