2376 Commits

Author SHA1 Message Date
Mehdi Amini
89abccc9a6
[MLIR] Update GreedyRewriter to use the LDBG() debug log mechanism (NFC) (#153961)
Also improve a bit the LDBG() implementation
2025-08-18 21:05:34 +00:00
Steven Wu
7e46f5db21
[Support] Add mapped_file_region::sync(), equivalent to msync (#153632) 2025-08-14 17:05:33 -07:00
Mehdi Amini
d95433bc81
Remove __SHORT_FILE__ macro definition in CMake (#152344)
This per-file macro definition on the command line breaks caching of
modules. See discussion in #150677

Instead we use a constexpr function that processes the __FILE__ macro,
but prefer also the __FILE_NAME__ macro when available (clang/gcc) to spare
compile-time in the frontend.
If the constexpr function isn't const-evaluated, it'll be only evaluated when
printing the debug message.
2025-08-07 17:56:54 +02:00
jeremyd2019
46f6e62eb9
[LLVM][Support] Fix tests on Cygwin (#151417)
Cygwin returns -1 for `getconf(_SC_ARG_MAX)`, which makes
`llvm::sys::commandLineFitsWithinSystemLimits` always return true, so
skip the `ArgumentLimit` test in that case. Skip the
`ArgumentLimitWindows` and `ResponseFileWindows` tests on Cygwin also as
it doesn't suffer from the Windows limits either.

Cygwin requires the same `dllexport` annotation as Win32 in the
`DynamicLibrary` test, so add its preprocessor check to PipSqueak.h.

Cygwin's `getcwd` function does not fail with `ENOENT` if the current
working directory is unlinked. According to POSIX issue 8, this is not
required. Skip the `PhysicalFileSystemWorkingDirFailure` test on Cygwin
as it relies on this behavior.
2025-08-01 10:35:09 -07:00
Mehdi Amini
c569c1f15f
[MLIR] Migrate pattern application / dialect conversion to the LDBG logging format (#150991)
This prefix the output with the DEBUG_TYPE.
Dialect conversion is using a ScopedPrinter, we insert the
raw_ldbg_ostream to consistently prefix each new line.
2025-08-01 14:28:58 +02:00
James Y Knight
9ddbb478ce
NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407)
This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new
object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>`
instead of `FileSystem*` or `FileSystem&`, when dealing with existing
objects.

Part of cleanup #151026.
2025-07-31 09:57:13 -04:00
Mehdi Amini
9c82f87aec
Introduce a "log level" support for DEBUG_TYPE (#150855)
This allows to set an optional integer level for a given debug type. The
string format is `type[:level]`, and the integer is interpreted as such:

- if not provided: all debugging for this debug type is enabled.
- if >0: all debug that is < to the level is enabled.
- if 0: same as for >0 but also does not disable the other debug-types,
it acts as a negative filter.

The LDBG() macro is updated to accept an optional log level to
illustrate the feature. Here is the expected behavior:

LDBG() << "A"; // Identical to LDBG(1) << "A";
LDBG(2) << "B";

With `--debug-only=some_type`: we'll see A and B in the output.  
With `--debug-only=some_type:1`: we'll see A but not B in the output. 
With `--debug-only=some_type:2`: we'll see A and B in the output. (same
with any level above 2)
With `--debug-only=some_type:0`: we'll see neither A nor B in the
output, but we'll see any other logging for other debug types.
2025-07-28 18:10:36 +02:00
Ingo Müller
a2fcf18d71
Fix DEBUGLOG_WITH_STREAM_TYPE_AND_FILE broken in #150750 (#150920)
This PR fixes the `DEBUGLOG_WITH_STREAM_TYPE_AND_FILE` macro that got
broken in #150750. That PR introduces a more sophisitaced version of
that macro and refactored some code in that process, making the
`getShortFileName` a free function instead of a class member function,
but did not adapt this macro to the refactored code.

Signed-off-by: Ingo Müller <ingomueller@google.com>
2025-07-28 13:25:09 +02:00
Mehdi Amini
1c3d6b3ec0
Implement a custom stream for LDBG macro to handle newlines (#150750)
This prints the prefix on every new line, allowing for an output that
looks like:
```
[dead-code-analysis] DeadCodeAnalysis.cpp:288 Visiting operation: func.func private @private_1() -> (i32, i32) {
[dead-code-analysis] DeadCodeAnalysis.cpp:288   %c0_i32 = arith.constant 0 : i32
[dead-code-analysis] DeadCodeAnalysis.cpp:288   %0 = arith.addi %c0_i32, %c0_i32 {tag = "one"} : i32
[dead-code-analysis] DeadCodeAnalysis.cpp:288   return %c0_i32, %0 : i32, i32
[dead-code-analysis] DeadCodeAnalysis.cpp:288 }
[dead-code-analysis] DeadCodeAnalysis.cpp:313 Visiting callable operation: func.func private @private_1() -> (i32, i32) {
[dead-code-analysis] DeadCodeAnalysis.cpp:313   %c0_i32 = arith.constant 0 : i32
[dead-code-analysis] DeadCodeAnalysis.cpp:313   %0 = arith.addi %c0_i32, %c0_i32 {tag = "one"} : i32
[dead-code-analysis] DeadCodeAnalysis.cpp:313   return %c0_i32, %0 : i32, i32
[dead-code-analysis] DeadCodeAnalysis.cpp:313 }
```
2025-07-28 00:08:44 +02:00
Mehdi Amini
3df67e8a40 Adjust LDBG output: surround DebugType between [ and ] (#150671)
This makes the output more readable by clearly showing the current debug
type as a keyword.
2025-07-25 12:31:08 -07:00
Jacques Pienaar
226fb1c246
[llvm][support] Fix DebugLogTest. (#150585)
Fails on windows with error

C2466: cannot allocate an array of constant size 0

else.
2025-07-25 10:40:41 +02:00
Jacques Pienaar
d368d117e7
[llvm][support] Add LDBG macro. (#143704)
Add macro that mirror a common usage of logging to output .This makes it easy to have
streaming log like behavior while still using the base debug logging.

I also wanted to avoid inventing a full logging library here while enabling others to change the sink without too much pain, so put it in its own header (this also avoids making Debug depend on raw_ostream beyond forward reference). The should allow a consistent dev experience without fixing the sink too much.

---------

Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2025-07-25 06:58:05 +02:00
Pavel Labath
17784e8d29
[support] Add packed_endian_specific_integral::value() (#147974)
They are already implicitly convertible to the underlying type, but that
doesn't work in some contexts, and it can be useful to get the
underlying value without needing the remember/guess the right type.

I converted a couple of call sites to demonstrate usefulness, but
there's likely more of them. I know at least of at least a few in LLDB,
but I don't want to make this a cross-project patch.
2025-07-11 08:27:58 +02:00
Pavel Labath
cd561bf1f1
[support] Make ScopedPrinter compatible with bitmask enums (#147512)
.. produced by ADT/BitmaskEnum.h.

These aren't implicitly convertible to an integer, so I needed to tweak
a couple of bitwise operations and add an explicit constructor for
HexNumber and FlagEntry.

Motivation: I'd like to use this in the SFrame data structures (#147264)
2025-07-09 09:09:57 +02:00
Pavel Labath
0a60c4ca22
[Support] Add signed operations to DataExtractor (#147261)
This is motivated by the [SFrame format](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900),
which contains several signed fields.

Having explicit signed operations makes the parsing code read better and
avoids potential surprises if e.g. a "signed" uint8_t value is converted
ta greater width.
2025-07-08 08:47:04 +02:00
Austin
a550fef906
[llvm] Use llvm::fill instead of std::fill(NFC) (#146911)
Use llvm::fill instead of std::fill
2025-07-04 14:10:28 +08:00
Rahul Joshi
d1ba2692ee
[LLVM][Clang] Enable strict mode for getTrailingObjects (#144930)
Disallow calls to templated `getTrailingObjects` if there is a single
trailing type (strict mode). Add `getTrailingObjectsNonStrict` for cases
when it's not possible to know statically if there will be a single or
multiple trailing types (like in OpenMPClause.h) to bypass the struct
checks.

This will ensure that future users of TrailingObjects class do not
accidently use the templated `getTrailingObjects` when they have a
single trailing type.
2025-06-30 07:23:34 -07:00
Kazu Hirata
f90025ebd9
[llvm] Compare std::optional<T> to values directly (NFC) (#146222)
This patch transforms:

  X && *X == Y

to:

  X == Y

where X is of std::optional<T>, and Y is of T or similar.
2025-06-28 13:04:16 -07:00
Kazu Hirata
26ec66dc18
[llvm] Use a new constructor of ArrayRef (NFC) (#146008)
ArrayRef now has a new constructor that takes a parameter whose type
has data() and size().  This patch migrates:

  ArrayRef<T>(X.data(), X.size()

to:

  ArrayRef<T>(X)
2025-06-26 23:38:12 -07:00
Kazu Hirata
3b672e1d7b
[llvm] Use "= delete" to delete constructors (NFC) (#144938)
None of the constructors touched in this patch has a corresponding
definition.  This patch explicitly deletes them with "= delete" while
moving them to the public section of respective classes.  Note that "=
delete" itself serves as documentation.

Identified with modernize-use-equals-delete.
2025-06-19 13:17:39 -07:00
Kazu Hirata
03f616eb3a
[llvm] Compare std::optional<T> to values directly (NFC) (#143340)
This patch transforms:

  X && *X == Y

to:

  X == Y

where X is of std::optional<T>, and Y is of T or similar.
2025-06-08 22:37:59 -07:00
Qinkun Bao
81bde1040c
[NFCI] Change SpecialCaseList::inSectionBlame to return pair<uint, uint> (FileIdx, LineNo). (#141540)
Accoring to the discussion in https://github.com/llvm/llvm-project/pull/140529, we need to SSCL can be created from multiple ignore list files, so we can repeat-fsanitize-ignorelist=. The change is necessary to achieve the feature described in https://github.com/llvm/llvm-project/issues/139128.
2025-05-28 00:18:37 -04:00
Qinkun Bao
1c3cff9856 [SpecialCaseList] Iterate sections and matchers in reverse order
Issue #139128 needs to find the last one in the file.

Pull Request: https://github.com/llvm/llvm-project/pull/141697
2025-05-27 18:47:09 -07:00
Vitaly Buka
8f879f85d4 [NFC][SpecialCaseList] Add unit test for line numbers 2025-05-27 17:58:13 -07:00
Akash Agrawal
ba705339ec
[LLVM] [NFC] - Remove duplicate #include headers from the files of llvm dir (#141057)
A few files of llvm dir had duplicate headers included. This patch
removes those redundancies.

---------

Co-authored-by: Akash Agrawal <akashag@qti.qualcomm.com>
2025-05-26 14:11:15 +05:30
Abhina Sree
a9ee8e4a45
Create a EncodingConverter class with both iconv and icu support. (#138893)
This patch adds a wrapper class called EncodingConverter for
ConverterEBCDIC. This class is then extended to support the ICU library
or iconv library. The ICU library currently takes priority over the
iconv library.

Relevant RFCs:

https://discourse.llvm.org/t/rfc-adding-a-charset-converter-to-the-llvm-support-library/69795

https://discourse.llvm.org/t/rfc-enabling-fexec-charset-support-to-llvm-and-clang-reposting/71512

Stacked PR to enable fexec-charset that depends on this:
https://github.com/llvm/llvm-project/pull/138895

See old PR for review and commit history:
https://github.com/llvm/llvm-project/pull/74516
2025-05-20 14:02:22 -04:00
Fangrui Song
369c409348
Support,lld: Rename misnamed F_no_mmap to F_mmap
`F_no_mmap` introduced by https://reviews.llvm.org/D69294 is misnamed.
It oughts to be `F_mmap`

When the output is a regular file or do not exist,
`--no-mmap-output-file` is the default. Relands #134787 by fixing the
lld option default. Note: changing the default to --map-output-file
would likely fail on llvm-clang-x86_64-sie-win
(https://lab.llvm.org/buildbot/#/builders/46/builds/14847)

Pull Request: https://github.com/llvm/llvm-project/pull/139836
2025-05-14 21:00:49 -07:00
Rahul Joshi
6d11b17162
[Support] Change test to use TrailingObjects API per documentation (#139319)
- Use private inheritance for TrailingObjects as recommended in
TrailingObjects.h
- No need to define `numTrailingObjects` for the last trailing type.
- Fix comment typos.
2025-05-12 10:28:09 -07:00
Cyndy Ishida
12e6622d4a
[Support] Avoid setting minor/subminor/build in VersionTuple::withMajorReplaced (#139318)
The expectation of this API is that it only changes the major version of
a preexisting version tuple. However, it was adding 0's, which caused
unintended changes in serialization or printing.

Instead, check for the existence of the non-major parts of the tuple.
2025-05-09 16:56:18 -07:00
Rahul Joshi
f4853d7a25
[LLVM][Support] Add getTrailingObjects() for single trailing type (#138970)
Add a specialization of getTrailingObjects() for a single trailing type.
This is a common case and with the specialization you don't need to
specify the single trailing type redundantly. Also add an overload for
getTrailingObjects which takes size and returns an
ArryaRef/MutableArrayRef as that's a common use case as well.
2025-05-09 12:05:02 -07:00
Rahul Joshi
7245e21e89
[NFC][Support] Add llvm::uninitialized_copy (#138174)
Add `llvm::uninitialized_copy` that accepts a range instead of start/end
iterator for the source of the copy.
2025-05-07 17:37:38 -07:00
Kazu Hirata
2f3067ed69
[llvm] Remove unused local variables (NFC) (#138454) 2025-05-04 09:38:16 -07:00
Kazu Hirata
b4fac94181
[llvm] Remove unused using decls (NFC) (#138386) 2025-05-03 07:05:02 -07:00
David Spickett
f7fdc8d0cf [llvm][Support] Disable runOnNewStack test when threading is disabled
On our buildbot https://lab.llvm.org/buildbot/#/builders/122/builds/1478,
one of the new tests added by https://github.com/llvm/llvm-project/pull/136046
failed.

This is because on non-Apple Silicon platforms, the implementation
is to start a new thread, but when threading is disabled this is the
same as calling a function normally.
2025-05-02 09:52:47 +00:00
Michael Spencer
07deaf8464
Reland: [llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (#136046)
Reland https://github.com/llvm/llvm-project/pull/133173

Clang spawns a new thread to avoid running out of stack space. This can
make debugging and performance analysis more difficult as how the
threads are connected is difficult to recover.

This patch introduces `runOnNewStack` and applies it in Clang. On
platforms that have good support for it this allocates a new stack and
moves to it using assembly. Doing split stacks like this actually runs
on most platforms, but many debuggers and unwinders reject the large or
backwards stack offsets that occur. Apple platforms and tools are known
to support this, so this only enables it there for now.
2025-04-30 19:14:15 -07:00
Kazu Hirata
8210cdd764
[llvm] Use llvm::replace (NFC) (#137481) 2025-04-26 18:18:09 -07:00
David Green
98b6f8dc69
[CostModel] Remove optional from InstructionCost::getValue() (#135596)
InstructionCost is already an optional value, containing an Invalid
state that can be checked with isValid(). There is little point in
returning another optional from getValue(). Most uses do not make use of
it being a std::optional, dereferencing the value directly (either
isValid has been checked previously or the Cost is assumed to be valid).
The one case that does in AMDGPU used value_or which has been replaced
by a isValid() check.
2025-04-23 07:46:27 +01:00
anjenner
c3f815ba82
Modify the localCache API to require an explicit commit on CachedFile… (#136121)
…Stream.

CachedFileStream has previously performed the commit step in its
destructor, but this means its only recourse for error handling is
report_fatal_error. Modify this to add an explicit commit() method, and
call this in the appropriate places with appropriate error handling for
the location.

Currently the destructor of CacheStream gives an assert failure in Debug
builds if commit() was not called. This will help track down any
remaining uses of the API that assume the old destructior behaviour. In
Release builds we fall back to the previous behaviour and call
report_fatal_error if the commit fails.

This is version 2 of this PR, superseding reverted PR
https://github.com/llvm/llvm-project/pull/115331 . I have incorporated a
change to the testcase to make it more reliable on Windows, as well as
two follow-up changes
(df79000896
and
b0baa1d8bd)
that were also reverted when 115331 was reverted.

---------

Co-authored-by: Augie Fackler <augie@google.com>
Co-authored-by: Vitaly Buka <vitalybuka@google.com>
2025-04-22 09:45:15 +01:00
Jakub Kuderski
ad6c23a7b5
[Support] Allow llvm::interleaved with custom ostream types (#136318)
This makes `llvm::interleaved` useable with ostream types that define
custom stream operators that print in a different format from
`raw_ostream`. For example, MLIR's OpAsmPrinter prints values as
operands:
6c5f50f186/mlir/include/mlir/IR/OpImplementation.h (L534-L552)
2025-04-18 12:37:16 -04:00
Jakub Kuderski
b07c88563f
[Support] Add format object for interleaved ranges (#135517)
Add two new format functions for printing ranges: `interleaved` and
`interleaved_array`.

This is meant to improve the ergonomics of printing ranges. Before this
patch, we have to either use `llvm::interleave` or write a for loop by
hand. For example:

Before:
```c++
ArrayRef<Type> types = ...;
ArrayRef<Values> values = ...;
LLVM_DEBUG({
  llvm::dbgs() << "Types: ";
  llvm::interleave_comma(llvm::dbgs(), types);
  llvm::dbgs() << "\n";
  llvm::dbgs() << "Values: [";
  llvm::interleave_comma(llvm::dbgs(), values);
  llvm::dbgs() << "]\n";
}):
```

After:
```c++
ArrayRef<Type> types = ...;
ArrayRef<Values> values = ...;
LLVM_DEBUG(llvm::dbgs() << "Types: " << interleaved(types) << "\n");
LLVM_DEBUG(llvm::dbgs() << "Values: " << interleaved_array(values) << "\n");
```

The separator and the prefix/suffix strings are customizable.
2025-04-15 23:44:33 -04:00
Daniel Thornburgh
2d98bdc12c
Revert "[llvm][clang] Allocate a new stack instead of spawning a new … (#135865)
…thread to get more stack space (#133173)"

This change breaks the Clang build on Mac AArch64.

This reverts commit d0c973a7a0149db3b71767d4c5a20a31e6a8ed5b. This
reverts commit 429a84f8a4bf559f43f50072747ef49d3e3b2cf1. This reverts
commit 4f64c80d5a23c244f942193e58ecac666c173308.
2025-04-15 14:46:55 -07:00
Michael Spencer
d0c973a7a0
[llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (#133173)
Clang spawns a new thread to avoid running out of stack space. This can
make debugging and performance analysis more difficult as how the
threads are connected is difficult to recover.

This patch introduces `runOnNewStack` and applies it in Clang. On
platforms that have good support for it this allocates a new stack and
moves to it using assembly. Doing split stacks like this actually runs
on most platforms, but many debuggers and unwinders reject the large or
backwards stack offsets that occur. Apple platforms and tools are known
to support this, so this only enables it there for now.
2025-04-15 11:19:07 -07:00
Douglas
156e2532ed
Revert "Rename F_no_mmap to F_mmap" (#134924)
Reverts llvm/llvm-project#134787

Causes the LIT test `lld\test\ELF\link-open-file.test` to fail on the
`llvm-clang-x86_64-sie-win` Build Bot. First instance of the failure
observed in: https://lab.llvm.org/buildbot/#/builders/46/builds/14847
2025-04-08 13:20:42 -07:00
Dmitry Chestnykh
d6c8e8908d
Rename F_no_mmap to F_mmap (#134787)
The `F_no_mmap` flag was introduced by
6814232429
2025-04-08 19:22:03 +03:00
Congcong Cai
a80aad2812
[YAML] fix output incorrect format for block scalar string (#132897)
After outputting block scalar string, the indent will be wrong.
This patch fixes Padding after block scalar string to ensure the correct
format of yaml.

The new added ut will fail in main.
```diff
@@ -3,4 +3,4 @@
     Just a block
     scalar doc
-scalar:          a
+  scalar:          a
 ...\n
```
2025-03-27 02:16:27 +08:00
Congcong Cai
feecb201ab
Reapply "[YAML][NFC] precommit wrong test case (#131782)" (#132936)
This reverts commit 64779455b8f4875c7de690dd4c3e324dbbcb3029.
2025-03-25 23:34:12 +08:00
Martin Storsjö
64779455b8 Revert "[YAML][NFC] precommit wrong test case (#131782)"
This reverts commit cb4ae35de0b4c19149379f16c7b279d80a669f9d.

That commit broke compilation with GCC:

../unittests/Support/YAMLIOTest.cpp:1280:20: error: explicit specialization of
template<class T> struct llvm::yaml::MappingTraits’ outside its namespace must u
se a nested-name-specifier [-fpermissive]
 1280 | template <> struct MappingTraits<V> {
      |                    ^~~~~~~~~~~~~~~~
2025-03-25 10:36:14 +02:00
Congcong Cai
cb4ae35de0
[YAML][NFC] precommit wrong test case (#131782) 2025-03-25 14:44:12 +08:00
Paul Kirth
ece59a8cb9
Reland Support for mustache templating language (#132467)
The last version of this patch had memory leaks due to using the
BumpPtrAllocator for data types that required destructors to run to
release heap memory (e.g. via std::vector and std::string). This version
avoids that by using smart pointers, and dropping support for
BumpPtrAllocator.

We should refactor this code to use the BumpPtrAllocator again, but that
can be addressed in future patches, since those are more invasive
changes that need to refactor many of the core data types to avoid
owning allocations.

Adds Support for the Mustache Templating Language. See specs here:
https://mustache.github.io/mustache.5.html This patch implements
support+tests for majority of the features of the language including:

    - Variables
    - Comments
    - Lambdas
    - Sections

This meant as a library to support places where we have to generate
HTML, such as in clang-doc.

Co-authored-by: Peter Chou <peter.chou@mail.utoronto.ca>
2025-03-24 17:23:25 -07:00
PeterChou1
08d15e3f64
Revert "reapply [llvm] add support for mustache templating language" (#131228)
This broke:

https://lab.llvm.org/buildbot/#/builders/64/builds/2486
https://lab.llvm.org/buildbot/#/builders/146/builds/2476
2025-03-13 18:08:58 -04:00