aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support
AgeCommit message (Collapse)AuthorFilesLines
3 days[llvm][mustache] Avoid excessive hash lookups in EscapeStringStream (#160166)Paul Kirth1-8/+22
The naive char-by-char lookup performed OK, but we can skip ahead to the next match, avoiding all the extra hash lookups in the key map. Likely there is a faster method than this, but its already a 42% win in the BM_Mustache_StringRendering/Escaped benchmark, and an order of magnitude improvement for BM_Mustache_LargeOutputString. | Benchmark | Before (ns) | After (ns) | Speedup | | :--- | ---: | ---: | ---: | | `StringRendering/Escaped` | 29,440,922 | 16,583,603 | ~44% | | `LargeOutputString` | 15,139,251 | 929,891 | ~94% | | `HugeArrayIteration` | 102,148,245 | 95,943,960 | ~6% | | `PartialsRendering` | 308,330,014 | 303,556,563 | ~1.6% | Unreported benchmarks, like those for parsing, had no significant change.
3 days[NFC][LLVM] Use Unix line endings for a few source files (#160794)Rahul Joshi2-541/+541
3 days[NFC][LLVM] Fix line endings for DXILABI.cpp (#160791)Rahul Joshi1-33/+33
Fix line ending to Unix style by running dos2unix on this file.
3 days[llvm][clang] Use the VFS in `FileCollector` (#160788)Jan Svoboda1-5/+6
This PR changes `llvm::FileCollector` to use the `llvm::vfs::FileSystem` API for making file paths absolute instead of using `llvm::sys::fs::make_absolute()` directly. This matches the behavior of the compiler on most other input files.
4 daysEnable parsing of optional strings (#154364)Jacques Pienaar1-0/+17
Previously a "opt<std::optional<std::string>>>" would fail to parse/would attempt to parse option value as argument.
4 days[llvm] Add `vfs::FileSystem` to `PassBuilder` (#160188)Jan Svoboda1-7/+2
Some LLVM passes need access to the filesystem to read configuration files and similar. In some places, this is achieved by grabbing the VFS from `PGOOptions`, but some passes don't have access to these and resort to just calling `vfs::getRealFileSystem()`. This PR allows setting the VFS directly on `PassBuilder` that's able to pass it down to all passes that need it.
4 days[Support] Use list-initialization for returning pairs (#160645)Kazu Hirata4-23/+23
In C++17 and later, "return {A, B};" guarantees copy elision for a std::pair return type, ensuring the object is constructed directly in the return slot. This patch updates those instances under Support/.
4 daysImprovements to TextEncodingConverter (#142476)Abhina Sree1-5/+5
This patch addresses the follow-up comments on PR https://github.com/llvm/llvm-project/pull/138893
5 days[llvm][mustache] Add support for Triple Mustache (#159183)Paul Kirth1-11/+28
We extend the logic in tokenize() to treat the `{{{}}}` delimiters to treat it like other unescaped HTML. We do this by updating the tokenizer to treat the new tokes the same way we do for the `{{&variable}}` syntax, which avoid the need to change the parser. We also update the llvm-test-mustache-spec tool to no longer mark Triple Mustache as XFAIL.
5 days[Support] Use list-initialization for returning pairs (#160447)Kazu Hirata5-9/+9
In C++17 and later, "return {A, B};" guarantees copy elision for a std::pair return type, ensuring the object is constructed directly in the return slot. This patch updates those instances under Support/.
5 days[Remarks] YAMLRemarkSerializer: StringRef-ize apis to avoid out-of-bounds ↵Jon Roelofs1-7/+7
read footguns (#160397) In #159759, Tobias identified that because YAML IO `mapRequired` expected a null-terminated `const char * Key`, we couldn't legally pass a `StringRef` to it, as that might be length-terminated and not null-terminated. In this patch, we move all of the YAML IO functions that accept a `const char *` over to `StringRef`, avoiding that footgun altogether.
7 days[Support] Fix memory leak in `Timer.cpp` on shutdown (#159983)Alexandre Ganea1-4/+21
This used to happen in the global destruction, after `main()` has exited. Previously, we were re-creating the `llvm::TimerGlobals` object at this point. <img width="855" height="270" alt="image" src="https://github.com/user-attachments/assets/757e9416-a74a-406a-841e-d3e4cc6a69a1" />
7 days[Support] Fix some warnings in LSP Transport (#160010)Alexandre Ganea1-1/+1
When building with latest MSVC on Windows, this fixes some compile-time warnings from last week's integration in https://github.com/llvm/llvm-project/pull/157885: ``` [321/5941] Building CXX object lib\Support\LSP\CMakeFiles\LLVMSupportLSP.dir\Transport.cpp.obj C:\git\llvm-project\llvm\lib\Support\LSP\Transport.cpp(123): warning C4930: 'std::lock_guard<std::mutex> responseHandlersLock(llvm::lsp::MessageHandler::ResponseHandlerTy)': prototyped function not called (was a variable definition intended?) [384/5941] Building CXX object unittests\Support\LSP\CMakeFiles\LLVMSupportLSPTests.dir\Transport.cpp.obj C:\git\llvm-project\llvm\unittests\Support\LSP\Transport.cpp(190): warning C4804: '+=': unsafe use of type 'bool' in operation ```
10 days[KnownBits] Add setAllConflict to set all bits in Zero and One. NFC (#159815)Craig Topper1-6/+3
This is a common pattern to initialize Knownbits that occurs before loops that call intersectWith.
11 days[llvm][clang] Pass VFS to `llvm::cl` command line handling (#159174)Jan Svoboda1-11/+13
This PR passes the VFS down to `llvm::cl` functions so that they don't assume the real file system.
12 daysFix _WIN32 Wundef warning; NFC (#159301)Sven van Haastregt1-1/+1
The `_WIN32` macro is tested for defined-ness everywhere else. The instance here triggers a warning when compiling with `-Wundef`.
13 daysFix comment from https://github.com/llvm/llvm-project/pull/158719 (#159157)Hiroshi Yamauchi1-2/+1
13 daysFix ExecuteAndWait with empty environment on Windows (#158719)Hiroshi Yamauchi1-0/+4
CreateProcessW requires that the environemnt block to be always double null-terminated even with an empty environemnt. https://learn.microsoft.com/en-us/windows/win32/procthread/environment-variables The attached test fails this way without the fix. C:\Users\hiroshi\upstream\llvm-project\llvm\unittests\Support\ProgramTest.cpp(697): error: Value of: ExecutionFailed Actual: true Expected: false Couldn't execute program 'C:\Users\hiroshi\upstream\llvm-project\build\unittests\Support\SupportTests.exe': The parameter is incorrect. (0x57)
14 days[CAS] Add MappedFileRegionArena (#114099)Steven Wu2-0/+22
Add MappedFileRegionArena which can be served as a file system backed persistent memory allocator. The allocator works like a BumpPtrAllocator, and is designed to be thread safe and process safe. The implementation relies on the POSIX compliance of file system and doesn't work on all file systems. If the file system supports lazy tail (doesn't allocate disk space if the tail of the large file is not used), user has more flexibility to declare a larger capacity. The allocator works by using a atomically updated bump ptr at a location that can be customized by the user. The atomic pointer points to the next available space to allocate, and the allocator will resize/truncate to current usage once all clients closed the allocator. Windows implementation contributed by: @hjyamauchi
14 days[clang] Avoid reparsing VFS overlay files for module dep collector (#158372)Jan Svoboda1-13/+3
This PR uses the new-ish `llvm::vfs::FileSystem::visit()` interface to collect VFS overlay entries from an existing `FileSystem` instance rather than parsing the VFS YAML file anew. This prevents duplicate diagnostics as observed by `clang/test/VFS/broken-vfs-module-dep.c`.
2025-09-13[ADT] Store integers by value in Twine (NFC) (#158409)Kazu Hirata1-9/+9
This patch stores integers by value in Twine for simplicity. I don't think there is a good reason to store char, unsigned, and int by value and all the other integers by pointers.
2025-09-11[SupportLSP] Fix dependency on SupportNikita Popov1-2/+2
2025-09-11[LLVM][MLIR] Move LSP server support library from MLIR into LLVM (#157885)Bertik235-0/+1462
This is a second PR on this patch (first #155572), that fixes the linking problem for `flang-aarch64-dylib` test. The SupportLSP library was made a component library. --- This PR moves the generic Language Server Protocol (LSP) server support code that was copied from clangd into MLIR, into the LLVM tree so it can be reused by multiple subprojects. Centralizing the generic LSP support in LLVM lowers the barrier to building new LSP servers across the LLVM ecosystem and avoids each subproject maintaining its own copy. The code originated in clangd and was copied into MLIR for its LSP server. MLIR had this code seperate to be reused by all of their LSP server. This PR relocates the MLIR copy into LLVM as a shared component into LLVM/Support. If this is not a suitable place, please suggest a better one. A follow up to this move could be deduplication with the original clangd implementation and converge on a single shared LSP support library used by clangd, MLIR, and future servers. What changes mlir/include/mlir/Tools/lsp-server-support/{Logging, Protocol, Transport}.h moved to llvm/include/llvm/Support/LSP mlir/lib/Tools/lsp-server-support/{Logging, Protocol, Transport}.cpp moved to llvm/lib/Support/LSP and their namespace was changed from mlir to llvm I ran clang-tidy --fix and clang-format on the whole moved files (last two commits), as they are basically new files and should hold up to the code style used by LLVM. MLIR LSP servers where updated to include these files from their new location and account for the namespace change. This PR is made as part of the LLVM IR LSP project ([RFC](https://discourse.llvm.org/t/rfc-ir-visualization-with-vs-code-extension-using-an-lsp-server/87773))
2025-09-09Revert "[LLVM][MLIR] Move LSP server support library from MLIR into LLVM ↵Nikita Popov5-1465/+0
(#155572)" This reverts commit c0aee322f7024250fd4a2c49f56534011178d07c. This reverts commit a0b8d548fd250c92c8f9274b57e38ad3f0b215e9. Fails to link with MLIR dylib build.
2025-09-09[LLVM][MLIR] Move LSP server support library from MLIR into LLVM (#155572)Bertik235-0/+1465
This PR moves the generic Language Server Protocol (LSP) server support code that was copied from clangd into MLIR, into the LLVM tree so it can be reused by multiple subprojects. Centralizing the generic LSP support in LLVM lowers the barrier to building new LSP servers across the LLVM ecosystem and avoids each subproject maintaining its own copy. The code originated in clangd and was copied into MLIR for its LSP server. MLIR had this code seperate to be reused by all of their LSP server. This PR relocates the MLIR copy into LLVM as a shared component into `LLVM/Support`. If this is not a suitable place, please suggest a better one. A follow up to this move could be deduplication with the original clangd implementation and converge on a single shared LSP support library used by clangd, MLIR, and future servers. ### What changes * `mlir/include/mlir/Tools/lsp-server-support/{Logging, Protocol, Transport}.h` moved to `llvm/include/llvm/Support/LSP` * `mlir/lib/Tools/lsp-server-support/{Logging, Protocol, Transport}.cpp` moved to `llvm/lib/Support/LSP` and their namespace was changed from `mlir` to `llvm` I ran clang-tidy --fix and clang-format on the whole moved files (last two commits), as they are basically new files and should hold up to the code style used by LLVM. MLIR LSP servers where updated to include these files from their new location and account for the namespace change. This PR is made as part of the LLVM IR LSP project ([RFC](https://discourse.llvm.org/t/rfc-ir-visualization-with-vs-code-extension-using-an-lsp-server/87773))
2025-09-08[TypeSize] Inline conversion to uint64_t (NFC) (#157454)Nikita Popov2-23/+0
After #156336 this cast operator has become trivial, so inline it into the header. This is a minor compile-time improvement.
2025-09-08Fix thread handle leak on Windows (#156854)Lukasz Mielicki1-8/+7
2025-09-07[Support] Simplify Object::operator== (NFC) (#157311)Kazu Hirata1-10/+1
This patch simplifies Object::operator== with DenseMap::operator==.
2025-09-06[Support] Remove an unnecessary cast (NFC) (#157312)Kazu Hirata1-2/+1
dli_fname is of type const char *.
2025-09-06[Support] Request including reproduction instructions in bug report message ↵Carlos Galvez1-1/+1
(#156958) Many times people only upload the backtrace without reproduction, making it difficult to work on the issue. Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-09-06[ADT] clang-format Twine.{cpp,h} (NFC)Kazu Hirata1-18/+14
I'm planning to modify these files.
2025-09-05Support: Add vfs::OutputBackend and OutputFile to virtualize compiler ↵Steven Wu6-0/+881
outputs (#113363) Add OutputBackend and OutputFile to the `llvm::vfs` namespace for virtualizing compiler outputs. This is intended for use in Clang, The headers are: - llvm/Support/VirtualOutputConfig.h - llvm/Support/VirtualOutputError.h - llvm/Support/VirtualOutputFile.h - llvm/Support/VirtualOutputBackend.h OutputFile is moveable and owns an OutputFileImpl, which is provided by the derived OutputBackend. - OutputFileImpl::keep() and OutputFileImpl::discard() should keep or discard the output. OutputFile guarantees that exactly one of these will be called before destruction. - OutputFile::keep() and OutputFile::discard() wrap OutputFileImpl and catch usage errors such as double-close. - OutputFile::discardOnDestroy() installs an error handler for the destructor to use if the file is still open. The handler will be called if discard() fails. - OutputFile::~OutputFile() calls report_fatal_error() if none of keep(), discard(), or discardOnDestroy() has been called. It still calls OutputFileImpl::discard(). - getOS() returns the wrapped raw_pwrite_stream. For convenience, OutputFile has an implicit conversion to `raw_ostream` and `raw_ostream &operator<<(OutputFile&, T&&)`. OutputBackend can be stored in IntrusiveRefCntPtr. - Most operations are thread-safe. - clone() returns a backend that targets the same destination. All operations are thread-safe when done on different clones. - createFile() takes a path and an OutputConfig (see below) and returns an OutputFile. Backends implement createFileImpl(). OutputConfig has flags to configure the output. Backends may ignore or override flags that aren't relevant or implementable. - The initial flags are: - AtomicWrite: whether the output should appear atomically (e.g., by using a temporary file and renaming it). - CrashCleanup: whether the output should be cleaned up if there's a crash (e.g., with RemoveFileOnSignal). - ImplyCreateDirectories: whether to implicitly create missing directories in the path to the file. - Text: matches sys::fs::OF_Text. - CRLF: matches sys::fs::OF_CRLF. - Append: matches sys::fs::OF_Append and can use with AtomicWrite for atomic append. - OnlyIfDifferent: skip writting the output file if the existing file at the output path is identical to the content to be written. - Each "Flag" has `setFlag(bool)` and `bool getFlag()` and shortcuts `setFlag()` and `setNoFlag()`. The setters are `constexpr` and return `OutputConfig&` to make it easy to declare a default value for a filed in a class or struct. - Setters and getters for Binary and TextWithCRLF are derived from Text and CRLF. For convenience, sys::fs::OpenFlags can be passed directly to setOpenFlags(). This patch intentionally lacks a number of important features that have been left for follow-ups: - Set a (virtual) current working directory. - Create a directory. - Create a file or directory with a unique name (avoiding collisions with existing filenames). Patch originally by dexonsmith
2025-09-03Reapply [IR] Remove options to make scalable TypeSize access a warning (#156336)Nikita Popov3-40/+2
Reapplying now that buildbot has picked up the new configuration that does not use -treat-scalable-fixed-error-as-warning. ----- This removes the `LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS` cmake option and the `-treat-scalable-fixed-error-as-warning` opt flag. We stopped treating these as warnings by default a long time ago (62f09d788f9fc540db12f3cfa2f98760071fca96), so I don't think it makes sense to retain these options at this point. Accessing a scalable TypeSize as fixed should always result in an error.
2025-09-02Revert "[IR] Remove options to make scalable TypeSize access a warning ↵Nikita Popov3-2/+40
(#156336)" This reverts commit 8f59a946740bf8dbe2574b33eaa431fde3ce9204. Failed on clang-aarch64-sve-vls-2stage, which still uses the option.
2025-09-02[IR] Remove options to make scalable TypeSize access a warning (#156336)Nikita Popov3-40/+2
This removes the `LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS` cmake option and the `-treat-scalable-fixed-error-as-warning` opt flag. We stopped treating these as warnings by default a long time ago (62f09d788f9fc540db12f3cfa2f98760071fca96), so I don't think it makes sense to retain these options at this point. Accessing a scalable TypeSize as fixed should always result in an error.
2025-09-01[Support] Also check the value for HAVE_PTHREAD_(SETNAME/SET_NAME)_NP (#156294)Brad Smith1-2/+2
As was already done for HAVE_PTHREAD_(GETNAME/GET_NAME)_NP
2025-08-28[KnownBits] Add operator<<=(unsigned) and operator>>=(unsigned). NFC (#155751)Craig Topper1-2/+1
Add operators to shift left or right and insert unknown bits.
2025-08-26Support: Add proxies for raw_ostream and raw_pwrite_stream (#113362)Steven Wu2-0/+16
Add proxies classes for `raw_ostream` and `raw_pwrite_stream` called `raw_ostream_proxy` and `raw_pwrite_stream_proxy`. Add adaptor classes, `raw_ostream_proxy_adaptor<>` and `raw_pwrite_stream_proxy_adaptor<>`, to allow subclasses to use a different parent class than `raw_ostream` or `raw_pwrite_stream`. The adaptors are used by a future patch to help a subclass of `llvm::vfs::OutputFile`, an abstract subclass of `raw_pwrite_stream`, to proxy a `raw_fd_ostream`. Patched by dexonsmith.
2025-08-26NFC: remove some instances of deprecated capture (#154884)Jeremy Kun1-1/+1
``` warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture] ``` Co-authored-by: Jeremy Kun <j2kun@users.noreply.github.com>
2025-08-24[APFloat] Properly implement DoubleAPFloat::convertFromAPIntDavid Majnemer1-72/+149
The old implementation converted to the legacy semantics, inducing rounding and not properly handling inputs like (2^1000 + 2^200) which have have more precision than the legacy semantics can represent. Instead, we convert the integer into two floats and an error. The error is used to implement the rounding behavior. Remove related dead, untested code: convertFrom*ExtendedInteger
2025-08-23[Support] Simplify macro conditions involving __GNUC__ (NFC) (#155070)Kazu Hirata2-2/+2
We require GCC 7.4 these days, so we just need to check for defined(__GNUC__).
2025-08-21[APFloat] Properly implement DoubleAPFloat::compareAbsoluteValueDavid Majnemer1-15/+48
The prior implementation would treat X+Y and X-Y as having equal magnitude. Rework the implementation to be more resilient.
2025-08-21[llvm][Support] Fix missing-field-initializer warnings for ↵Michael Buch1-7/+19
crashreporter_annotations_t (#154716) Use `CRASHREPORTER_ANNOTATIONS_INITIALIZER` when possible, which will handle the field initialization for us. That's what we already do in compiler-rt: https://github.com/llvm/llvm-project/blob/0c480dd4b61e285bfda4de99c77da28922e64b94/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp#L799-L817 This way we won't get these warnings when the layout of crashreporter_annotations_t changes: ``` llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'blah' initializer [-Wmissing-field-initializers] = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 }; ^ 1 warning generated ```
2025-08-21[ADT] Add fshl/fshr operations to APInt (#153790)Chaitanya Koparkar1-0/+18
These operations are required for #153151.
2025-08-20Reapply "[APFloat] Fix getExactInverse for DoubleAPFloat"David Majnemer1-40/+58
The previous implementation of getExactInverse used the following check to identify powers of two: // Check that the number is a power of two by making sure that only the // integer bit is set in the significand. if (significandLSB() != semantics->precision - 1) return false; This condition verifies that the only set bit in the significand is the integer bit, which is correct for normal numbers. However, this logic is not correct for subnormal values. APFloat represents subnormal numbers by shifting the significand right while holding the exponent at its minimum value. For a power of two in the subnormal range, its single set bit will therefore be at a position lower than precision - 1. The original check would consequently fail, causing the function to determine that these numbers do not have an exact multiplicative inverse. The new logic calculated this correctly but it seems that test/CodeGen/Thumb2/mve-vcvt-fixed-to-float.ll expected the old behavior. Seeing as how getExactInverse does not have tests or documentation, we conservatively maintain (and document) this behavior. This reverts commit 47e62e846beb267aad50eb9195dfd855e160483e.
2025-08-20[NFC][CMake] quote ${CMAKE_SYSTEM_NAME} consistently (#154537)David Tenty1-2/+2
A CMake change included in CMake 4.0 makes `AIX` into a variable (similar to `APPLE`, etc.) https://gitlab.kitware.com/cmake/cmake/-/commit/ff03db6657c38c8cf992877ea66174c33d0bcb0b However, `${CMAKE_SYSTEM_NAME}` unfortunately also expands exactly to `AIX` and `if` auto-expands variable names in CMake. That means you get a double expansion if you write: `if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")` which becomes: `if (AIX MATCHES "AIX")` which is as if you wrote: `if (ON MATCHES "AIX")` You can prevent this by quoting the expansion of "${CMAKE_SYSTEM_NAME}", due to policy [CMP0054](https://cmake.org/cmake/help/latest/policy/CMP0054.html#policy:CMP0054) which is on by default in 4.0+. Most of the LLVM CMake already does this, but this PR fixes the remaining cases where we do not.
2025-08-20[FileSystem] Allow exclusive file lock (#114098)Steven Wu2-8/+29
Add parameter to file lock API to allow exclusive file lock. Both Unix and Windows support lock the file exclusively for write for one process and LLVM OnDiskCAS uses exclusive file lock to coordinate CAS creation.
2025-08-18[ADT] Refactor SmallPtrSetImplBase::swap (NFC) (#154261)Kazu Hirata1-37/+26
SmallPtrSetImplBase::swap needs to deal with four cases depending on whether LHS is small and whether RHS is small. Now, the code to swap small LHS and large RHS is symmetric with the code to swap large LHS and small RHS. This patch rearranges code so that we first take care of the case where both LHS and RHS are small. Then we compute references SmallSide and LargeSide and actually swap the two instances. This refactoing saves about 11 lines of code. Note that SmallDenseMap::swap also uses a similar trick.
2025-08-17[Support] Remove an unnecessary cast (NFC) (#154048)Kazu Hirata1-1/+1
qp is already of uint64_t.
2025-08-16[ADT] Use llvm::copy in SmallPtrSet.cpp (NFC) (#153930)Kazu Hirata1-5/+5
This patch uses llvm::copy in combination with buckets() and small_buckets().