diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2026-01-29 14:39:34 -0800 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2026-01-29 14:39:34 -0800 |
| commit | 7b3f189a1369f9348c007730ddea953b1e68acb1 (patch) | |
| tree | 7db8969ee8a34a10b6c8ae033c939c9d653376f6 /offload/include/Shared | |
| parent | f3d6dae13ae710323a2ddbaf87af71b1abcbfada (diff) | |
| parent | 0893b70ecfc4f4aca0a20a078476d191edc1e623 (diff) | |
| download | llvm-users/pcc/spr/codegen-introduce-machinefunctiongetpreferredalignment.zip llvm-users/pcc/spr/codegen-introduce-machinefunctiongetpreferredalignment.tar.gz llvm-users/pcc/spr/codegen-introduce-machinefunctiongetpreferredalignment.tar.bz2 | |
Created using spr 1.3.6-beta.1
Diffstat (limited to 'offload/include/Shared')
| -rw-r--r-- | offload/include/Shared/Debug.h | 87 |
1 files changed, 64 insertions, 23 deletions
diff --git a/offload/include/Shared/Debug.h b/offload/include/Shared/Debug.h index f1c3386..0f98a44 100644 --- a/offload/include/Shared/Debug.h +++ b/offload/include/Shared/Debug.h @@ -45,7 +45,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Format.h" -#include "llvm/Support/circular_raw_ostream.h" +#include "llvm/Support/raw_ostream.h" /// 32-Bit field data attributes controlling information presented to the user. enum OpenMPInfoType : uint32_t { @@ -142,7 +142,7 @@ inline uint32_t getInfoLevel() { return getInfoLevelInternal().load(); } #define INFO(_flags, _id, ...) \ do { \ if (::llvm::offload::debug::isDebugEnabled()) { \ - DP(__VA_ARGS__); \ + INFO_DEBUG_INT(_flags, _id, __VA_ARGS__); \ } else if (getInfoLevel() & _flags) { \ INFO_MESSAGE(_id, __VA_ARGS__); \ } \ @@ -174,6 +174,14 @@ private: bool ShouldEmitNewLineOnDestruction; bool NeedEndNewLine = false; + /// Buffer to reduce interference between different threads + /// writing at the same time to the underlying stream. + static constexpr size_t BufferSize = 256; + llvm::SmallString<BufferSize> Buffer; + + // Stream to write into Buffer. Its flushed to Os upon destruction. + llvm::raw_svector_ostream BufferStrm; + /// If the stream is muted, writes to it are ignored bool Muted = false; @@ -203,13 +211,13 @@ private: NeedEndNewLine = true; } } - void emitPrefix() { Os.write(Prefix.c_str(), Prefix.size()); } + void emitPrefix() { BufferStrm.write(Prefix.c_str(), Prefix.size()); } void writeWithPrefix(StringRef Str) { if (ShouldPrefixNextString) { emitPrefix(); ShouldPrefixNextString = false; } - Os.write(Str.data(), Str.size()); + BufferStrm.write(Str.data(), Str.size()); } public: @@ -218,26 +226,29 @@ public: bool ShouldEmitNewLineOnDestruction = true) : Prefix(std::move(Prefix)), Os(Os), BaseLevel(BaseLevel), ShouldPrefixNextString(ShouldPrefixNextString), - ShouldEmitNewLineOnDestruction(ShouldEmitNewLineOnDestruction) { + ShouldEmitNewLineOnDestruction(ShouldEmitNewLineOnDestruction), + BufferStrm(Buffer) { SetUnbuffered(); } ~odbg_ostream() final { if (ShouldEmitNewLineOnDestruction && NeedEndNewLine) - Os << '\n'; + BufferStrm << '\n'; + Os << BufferStrm.str(); } odbg_ostream(const odbg_ostream &) = delete; odbg_ostream &operator=(const odbg_ostream &) = delete; - odbg_ostream(odbg_ostream &&other) : Os(other.Os) { + odbg_ostream(odbg_ostream &&other) : Os(other.Os), BufferStrm(Buffer) { Prefix = std::move(other.Prefix); BaseLevel = other.BaseLevel; ShouldPrefixNextString = other.ShouldPrefixNextString; ShouldEmitNewLineOnDestruction = other.ShouldEmitNewLineOnDestruction; NeedEndNewLine = other.NeedEndNewLine; Muted = other.Muted; + BufferStrm << other.BufferStrm.str(); } /// Forward the current_pos method to the underlying stream. - uint64_t current_pos() const final { return Os.tell(); } + uint64_t current_pos() const final { return BufferStrm.tell(); } /// Some of the `<<` operators expect an lvalue, so we trick the type /// system. @@ -247,17 +258,8 @@ public: void shouldMute(const OnlyLevel Filter) { Muted = BaseLevel != Filter; } }; -/// dbgs - Return a circular-buffered debug stream. -[[maybe_unused]] static llvm::raw_ostream &dbgs() { - // Do one-time initialization in a thread-safe way. - static struct dbgstream { - llvm::circular_raw_ostream strm; - - dbgstream() : strm(llvm::errs(), "*** Debug Log Output ***\n", 0) {} - } thestrm; - - return thestrm.strm; -} +/// dbgs - Return the debug stream for offload debugging (just llvm::errs()). +[[maybe_unused]] static llvm::raw_ostream &dbgs() { return llvm::errs(); } #ifdef OMPTARGET_DEBUG @@ -306,8 +308,14 @@ struct DebugSettings { return; Settings.Enabled = true; - if (EnvRef.equals_insensitive("all")) - return; + + if (EnvRef.starts_with_insensitive("all")) { + auto Spec = parseDebugFilter(EnvRef); + if (Spec.Type.equals_insensitive("all")) { + Settings.DefaultLevel = Spec.Level; + return; + } + } if (!EnvRef.getAsInteger(10, Settings.DefaultLevel)) return; @@ -618,7 +626,38 @@ static inline odbg_ostream reportErrorStream() { #define FORMAT_TO_STR(Format, ...) \ ::llvm::omp::target::debug::formatToStr(Format __VA_OPT__(, ) __VA_ARGS__) -#define DP(...) ODBG() << FORMAT_TO_STR(__VA_ARGS__); +template <uint32_t InfoId> static constexpr const char *InfoIdToODT() { + constexpr auto getId = []() { + switch (InfoId) { + case OMP_INFOTYPE_KERNEL_ARGS: + return "KernelArgs"; + case OMP_INFOTYPE_MAPPING_EXISTS: + return "MappingExists"; + case OMP_INFOTYPE_DUMP_TABLE: + return "DumpTable"; + case OMP_INFOTYPE_MAPPING_CHANGED: + return "MappingChanged"; + case OMP_INFOTYPE_PLUGIN_KERNEL: + return "PluginKernel"; + case OMP_INFOTYPE_DATA_TRANSFER: + return "DataTransfer"; + case OMP_INFOTYPE_EMPTY_MAPPING: + return "EmptyMapping"; + case OMP_INFOTYPE_ALL: + return "Default"; + } + return static_cast<const char *>(nullptr); + }; + + constexpr const char *result = getId(); + static_assert(result != nullptr, "Unknown InfoId being used"); + return result; +} + +// Transform the INFO id to the corresponding debug type and print the message +#define INFO_DEBUG_INT(_flags, _id, ...) \ + ODBG(::llvm::omp::target::debug::InfoIdToODT<_flags>()) \ + << FORMAT_TO_STR(__VA_ARGS__); // Define default format for pointers static inline raw_ostream &operator<<(raw_ostream &Os, void *Ptr) { @@ -627,9 +666,11 @@ static inline raw_ostream &operator<<(raw_ostream &Os, void *Ptr) { } #else -#define DP(...) \ + +#define INFO_DEBUG_INT(_flags, _id, ...) \ { \ } + #endif // OMPTARGET_DEBUG // New REPORT macro in the same style as ODBG |
