platform/upstream/llvm.git
13 months ago[ARM] make execute only long call test checks more robust
Ties Stuij [Tue, 4 Jul 2023 09:50:42 +0000 (10:50 +0100)]
[ARM] make execute only long call test checks more robust

Reviewed By: olista01

Differential Revision: https://reviews.llvm.org/D154355

13 months ago[AArch64] Update SVE scheduling of some CPUs
Harvin Iriawan [Mon, 3 Jul 2023 13:41:50 +0000 (14:41 +0100)]
[AArch64] Update SVE scheduling of some CPUs

  * Update cortex-a510 and neoverse-v2 SVE scheduling so that pseudos
have the same instruction latency as original instruction.

  Differential Revision: https://reviews.llvm.org/D154084

13 months ago [AArch64] NFC : Change the way SVE pseudos are appended
Harvin Iriawan [Fri, 30 Jun 2023 16:28:19 +0000 (17:28 +0100)]
   [AArch64] NFC : Change the way SVE pseudos are appended

  * SVE pseudos don't pick up the right latency information during MI
    scheduling as the regex do not match with instruction name.

  * Move UNDEF, PSEUDO, and ZERO to the end of actual SVE instruction

  * Some CPUs *td files will be fixed in the next commit

    Differential Revision: https://reviews.llvm.org/D154232

13 months ago[ARM] generate correct code for armv6-m XO big stack operations
Ties Stuij [Tue, 4 Jul 2023 08:25:58 +0000 (09:25 +0100)]
[ARM] generate correct code for armv6-m XO big stack operations

The ARM backend codebase is dotted with places where armv6-m will generate
constant pools. Now that we can generate execute-only code for armv6-m, we need
to make sure we use the movs/lsls/adds/lsls/adds/lsls/adds pattern instead of
these.

Big stacks is one of the obvious places. In this patch we take care of two
sites:
1. take care of big stacks in prologue/epilogue
2. take care of save/tSTRspi nodes, which implicitly fixes
   emitThumbRegPlusImmInReg which is used in several frame lowering fns

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D154233

13 months ago[flang][hlfir] fix elemental subroutine calls
Tom Eccles [Fri, 30 Jun 2023 16:35:26 +0000 (16:35 +0000)]
[flang][hlfir] fix elemental subroutine calls

genElementalCall can return a null option when lowering elemental
subroutine calls (as there is no return value). Therefore
std::option::value should not be used as it will cause an
assertion failure.

This fixes uses of the mvbits intrinsic with array arguments, as used in
the gfortran test suite.

Differential Revision: https://reviews.llvm.org/D154340

13 months ago[flang][hlfir] intrinsic dynamically optional arguments
Tom Eccles [Thu, 29 Jun 2023 17:26:35 +0000 (17:26 +0000)]
[flang][hlfir] intrinsic dynamically optional arguments

This adds support for dynamically optional arguments for intrinsics
which do not have their own hlfir operations.

The functions for processing these arguments are mostly the same as the
equivalent functions in ConvertExpr.cpp. I chose not to share
implementations so that HLFIR helpers can be used here. Presumably
ConvertExpr.cpp will go away one day.

Depends on D154236

Differential Revision: https://reviews.llvm.org/D154237

13 months ago[flang][hlfir] support optional args for intrinsic ops
Tom Eccles [Wed, 28 Jun 2023 15:29:27 +0000 (15:29 +0000)]
[flang][hlfir] support optional args for intrinsic ops

This also adds support for allocatable non-optional arguments.

Of the transformational intrinsics which currently have their own hlfir
operations, all of the dynamically optional arguments are lowered as
boxes, so that is all that is implemented for now.

One alternative approach would have been to deal with the dynamically
optional arguments when lowering to FIR runtime calls. I decided not to
do this so that any passes working on the intrinsic operations would not
have to know about and handle the dynamically optional arguments.

Depends on D154235

Differential Revision: https://reviews.llvm.org/D154236

13 months ago[flang][hlfir][NFC] refactor transformational intrinsic lowering
Tom Eccles [Mon, 26 Jun 2023 17:46:15 +0000 (17:46 +0000)]
[flang][hlfir][NFC] refactor transformational intrinsic lowering

The old code had overgrown itself and become difficult to read and
modify. I've rewritten it and moved it into its own translation unit.

I moved PreparedActualArgument to the header file for the
transformational intrinsic lowering. Logically, it belongs in
ConvertCall.h, but putting it there would create a circular dependency
between HlfirIntrinsics and ConvertCall.

Differential Revision: https://reviews.llvm.org/D154235

13 months ago[CodeGen] Precommit tests for D153355
Igor Kirillov [Tue, 27 Jun 2023 10:43:15 +0000 (10:43 +0000)]
[CodeGen] Precommit tests for D153355

Differential Revision: https://reviews.llvm.org/D153856

13 months ago[IRCE][NFC] Set Index and End together inside parseRangeCheckICmp
Aleksandr Popov [Mon, 3 Jul 2023 01:07:18 +0000 (03:07 +0200)]
[IRCE][NFC] Set Index and End together inside parseRangeCheckICmp

Preparatory refactoring for the upcoming support of new range check form
to parse.

With this change we always set Index and End values together in the same
place.

parseRangeCheckICmp specification updated.

Reviewed By: skatkov
Differential Revision: https://reviews.llvm.org/D154156

13 months agoRevert "[mlir][transform] Allow arbitrary indices to be scalable"
Alexander Belyaev [Tue, 4 Jul 2023 07:40:38 +0000 (09:40 +0200)]
Revert "[mlir][transform] Allow arbitrary indices to be scalable"

This reverts commit 048764f23a380fd6f8cc562a0008dcc6095fb594.

Breaks https://lab.llvm.org/buildbot/#/builders/61/builds/45451

13 months ago[mlir-cpu-runner] Check entry function is void
Cullen Rhodes [Mon, 3 Jul 2023 14:33:13 +0000 (14:33 +0000)]
[mlir-cpu-runner] Check entry function is void

Currently crashes if function isn't void when specifiying
'-entry-point-result=void'.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D154352

13 months ago[CSKY] Optimize conditional select with CLRT/CLRF
Ben Shi [Tue, 4 Jul 2023 05:25:15 +0000 (13:25 +0800)]
[CSKY] Optimize conditional select with CLRT/CLRF

Reviewed By: zixuan-wu

Differential Revision: https://reviews.llvm.org/D154409

13 months ago[CSKY][test][NFC] Add more tests of conditional select
Ben Shi [Tue, 4 Jul 2023 05:18:26 +0000 (13:18 +0800)]
[CSKY][test][NFC] Add more tests of conditional select

Reviewed By: zixuan-wu

Differential Revision: https://reviews.llvm.org/D154408

13 months ago[Flang] Use llvm_unreachable to replace assert, NFC
Kai Luo [Tue, 4 Jul 2023 07:04:34 +0000 (15:04 +0800)]
[Flang] Use llvm_unreachable to replace assert, NFC

IIUC, the `default` case should be unreachable inferred from the context.

Reviewed By: kkwli0

Differential Revision: https://reviews.llvm.org/D154344

13 months ago[mlir][SCF] Add `loop.promote_if_one_iteration` transform op
Matthias Springer [Tue, 4 Jul 2023 06:57:55 +0000 (08:57 +0200)]
[mlir][SCF] Add `loop.promote_if_one_iteration` transform op

This transform op promotes loops with one iteration. I.e., the loop op is replaced by just the loop body.

Differential Revision: https://reviews.llvm.org/D154361

13 months ago[lldb] Replace llvm::writeFileAtomically with llvm::writeToOutput API.
Haojian Wu [Mon, 3 Jul 2023 09:27:35 +0000 (11:27 +0200)]
[lldb] Replace llvm::writeFileAtomically with llvm::writeToOutput API.

Differential Revision: https://reviews.llvm.org/D154329

13 months ago[mlir][LLVM] Add alignment to LLVMFuncOp
Christian Ulmann [Tue, 4 Jul 2023 06:26:53 +0000 (06:26 +0000)]
[mlir][LLVM] Add alignment to LLVMFuncOp

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D154410

13 months ago[NFC][IRCE] Remove dead variables
Aleksandr Popov [Sun, 2 Jul 2023 18:19:23 +0000 (20:19 +0200)]
[NFC][IRCE] Remove dead variables

13 months ago[RISCV][NFC] Refactor lowerToScalableOp.
Jianjian GUAN [Wed, 28 Jun 2023 08:09:37 +0000 (16:09 +0800)]
[RISCV][NFC] Refactor lowerToScalableOp.

Refactor lowerToScalableOp to combine switch case code.

Reviewed By: frasercrmck

Differential Revision: https://reviews.llvm.org/D153948

13 months ago[mlir][LLVM] Add unnamed_addr to LLVMFuncOp
Christian Ulmann [Tue, 4 Jul 2023 05:39:35 +0000 (05:39 +0000)]
[mlir][LLVM] Add unnamed_addr to LLVMFuncOp

This commit adds LLVM's unnamed_addr enum to LLVMFuncOp.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D154360

13 months ago[CodeGen] Move lowerCopy from expandPostRA to TII
Yashwant Singh [Tue, 4 Jul 2023 03:34:46 +0000 (09:04 +0530)]
[CodeGen] Move lowerCopy from expandPostRA to TII

This will allow targets to lower their 'copy' instructions easily.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D152261

13 months ago[libc++][NFC] Remove a redundant check for building the library
Nikolas Klauser [Tue, 4 Jul 2023 01:35:07 +0000 (18:35 -0700)]
[libc++][NFC] Remove a redundant check for building the library

13 months ago[clang-format] Correctly annotate */&/&& in operator function calls
Owen Pan [Fri, 30 Jun 2023 01:14:18 +0000 (18:14 -0700)]
[clang-format] Correctly annotate */&/&& in operator function calls

Reverts 4986f3f2f220 (but keeps its unit tests) and fixes #49973
differently.

Also fixes bugs that incorrectly annotate the operator keyword as
TT_FunctionDeclarationName in function calls and as TT_Unknown in function
declarations and definitions.

Differential Revision: https://reviews.llvm.org/D154184

13 months agoAdd a flag to disable "duplicate definition of category" warnings
Akira Hatanaka [Mon, 3 Jul 2023 23:25:21 +0000 (16:25 -0700)]
Add a flag to disable "duplicate definition of category" warnings

Differential Revision: https://reviews.llvm.org/D154251

13 months ago[Attributor] Manifest attributes implied by the IR
Johannes Doerfert [Mon, 3 Jul 2023 21:02:23 +0000 (14:02 -0700)]
[Attributor] Manifest attributes implied by the IR

If an attribute is implied by the IR we do not (always) create an AA
anymore. To keep test coverage, and given the lack of a good heuristic
to decide otherwise, we will now also manifest such attributes.

13 months ago[Attributor] Make isImpliedByIR and hasAssumedIRAttr more useful
Johannes Doerfert [Sun, 2 Jul 2023 22:50:30 +0000 (15:50 -0700)]
[Attributor] Make isImpliedByIR and hasAssumedIRAttr more useful

Checking more than one attribute kind was never done and we want to
later check the IR w/o creating an AA as fallback.

13 months ago[RISCV] Support constant operand for la and lla pseudoinstruction.
Garvit Gupta [Mon, 3 Jul 2023 22:55:04 +0000 (15:55 -0700)]
[RISCV] Support constant operand for la and lla pseudoinstruction.

This patch improves compatibility with GNU assembler by adding support for
constant immediate in la and lla pseudo instruction, and expanding it in the
same way as we currently expands li pseudo instruction.

Links to discussion related to the above issue in the community -
https://github.com/riscv-non-isa/riscv-arch-test/issues/105
https://github.com/riscv-non-isa/riscv-arch-test/issues/108
https://github.com/riscv-non-isa/riscv-arch-test/issues/106

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D150133

13 months ago[RISCV] Refactor vfcvt_rm pseudo insertion case statements. NFC
Luke Lau [Fri, 30 Jun 2023 20:49:41 +0000 (21:49 +0100)]
[RISCV] Refactor vfcvt_rm pseudo insertion case statements. NFC

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154258

13 months ago[OPENMP52] Codegen support for doacross clause.
Jennifer Yu [Fri, 30 Jun 2023 01:16:25 +0000 (18:16 -0700)]
[OPENMP52] Codegen support for doacross clause.

Differential Revision: https://reviews.llvm.org/D154180

13 months ago[mlir][transform] Allow arbitrary indices to be scalable
Andrzej Warzynski [Sun, 2 Jul 2023 13:43:14 +0000 (14:43 +0100)]
[mlir][transform] Allow arbitrary indices to be scalable

This change lifts the limitation that only the trailing dimensions/sizes
in dynamic index lists can be scalable. It allows us to extend
`MaskedVectorizeOp` and `TileOp` from the Transform dialect so that the
following is allowed:

  %1, %loops:3 = transform.structured.tile %0 [[4], [4], 4]

This is also a follow up for https://reviews.llvm.org/D153372
that will enable the following (middle vector dimension is scalable):

  transform.structured.masked_vectorize %0 vector_sizes [2, [4], 8]

To facilate this change, the hooks for parsing and printing dynamic
index lists are updated accordingly (`printDynamicIndexList` and
`parseDynamicIndexList`, respectively). `MaskedVectorizeOp` and `TileOp`
are updated to include an array of attribute of bools that captures
whether the corresponding vector dimension/tile size, respectively, are
scalable or not.

This change is a part of a larger effort to enable scalable
vectorisation in Linalg. See this RFC for more context:
  * https://discourse.llvm.org/t/rfc-scalable-vectorisation-in-linalg/

Differential Revision: https://reviews.llvm.org/D154336

13 months ago[lldb] Remove old commented out code (NFC)
Dave Lee [Mon, 3 Jul 2023 21:39:29 +0000 (14:39 -0700)]
[lldb] Remove old commented out code (NFC)

Move to `DumpAddress` in c4a8a76048e91baecb5746b80b9733e4af299937.

13 months ago[LV] Break up condition in selectEpilogueVectorizationFactor loop (NFCI)
Florian Hahn [Mon, 3 Jul 2023 21:39:40 +0000 (22:39 +0100)]
[LV] Break up condition in selectEpilogueVectorizationFactor loop (NFCI)

Restructure the loop as suggested in D154264 to increase readability and
make it easier to extend.

13 months ago[lldb] SymbolFileJSON: Update outdates Text -> JSON (NFC)
Jonas Devlieghere [Wed, 28 Jun 2023 17:48:00 +0000 (10:48 -0700)]
[lldb] SymbolFileJSON: Update outdates Text -> JSON (NFC)

Originally the symbol file format was going to textual, before we
decided to use JSON. Updated the plugin name and the header guard.

13 months ago[lldb] Add two-level caching in the source manager
Jonas Devlieghere [Mon, 3 Jul 2023 21:06:57 +0000 (14:06 -0700)]
[lldb] Add two-level caching in the source manager

We recently saw an uptick in internal reports complaining that LLDB is
slow when sources on network file systems are inaccessible. I looked at
the SourceManger and its cache and I think there’s some room for
improvement in terms of reducing file system accesses:

 1. We always resolve the path.
 2. We always check the timestamp.
 3. We always recheck the file system for negative cache hits.

D153726 fixes (1) but (2) and (3) are necessary because of the cache’s
current design. Source files are cached at the debugger level which
means that the source file cache can span multiple targets and
processes. It wouldn't be correct to not reload a modified or new file
from disk.

We can however significantly reduce the number of file system accesses
by using a two level cache design: one cache at the debugger level and
one at the process level:

 - The cache at the debugger level works the way it does today. There is
   no negative cache: if we can't find the file on disk, we'll try again
   next time the cache is queried. If a cached file's timestamp changes
   or if its path remapping changes, the cached file is evicted and we
   reload it from disk.
 - The cache at the process level is design to avoid accessing the file
   system. It doesn't check the file's modification time. It caches
   negative results, so if a file didn't exist, it doesn't try to reread
   it from disk. Checking if the path remapping changed is cheap
   (doesn't involve checking the file system) and is the only way for a
   file to get evicted from the process cache.

The result of this patch is that LLDB will not show you new content if a
file is modified or created while a process is running. I would argue
that this is what most people would expect, but it is a change from how
LLDB behaves today.

For an average stop, we query the source cache 4 times. With the current
implementation, that's 4 stats to get the modification time, If the file
doesn't exist on disk, that's an additional 4 stats. Before D153726, if
the path starts with a ~ there are another additional 4 calls to
realpath. When debugging sources on a slow (network) file system, this
quickly adds up.

In addition to the two level caching, this patch also adds a source
logging channel and synchronization to the source file cache. The
logging was helpful during development and hopefully will help us triage
issues in the future. The synchronization isn't a new requirement: as
the cache is shared across targets, there is no guarantees that it can't
be accessed concurrently. The patch also fixes a bug where we would only
set the source remapping ID if the un-remapped file didn't exist, which
led to the file getting evicted from the cache on every access.

rdar://110787562

Differential revision: https://reviews.llvm.org/D153834

13 months ago[lldb][nfc] Remove redundant nullptr check
Felipe de Azevedo Piovezan [Mon, 3 Jul 2023 16:48:01 +0000 (12:48 -0400)]
[lldb][nfc] Remove redundant nullptr check

The make_shared function never returns a nullptr, as such the test for nullptr
is not needed. We also move the empty string check earlier in the if
("oso_object"), as this is cheaper than loading the object file.

Differential Revision: https://reviews.llvm.org/D154365

13 months ago[InstSimplify] Fold all global variables with initializers
Anshil Gandhi [Mon, 3 Jul 2023 21:11:04 +0000 (15:11 -0600)]
[InstSimplify] Fold all global variables with initializers

Allow computing size of interposable or externally initializable global variables.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D152145

13 months ago[libc++][Modules] std.functional.__functional.invoke and std.type_traits.underlying_t...
Ian Anderson [Sun, 4 Jun 2023 21:21:50 +0000 (14:21 -0700)]
[libc++][Modules] std.functional.__functional.invoke and std.type_traits.underlying_type can't export std.type_traits

`__functional/invoke.h` currently only includes `__type_traits/invoke.h` and not all of `type_traits`. Keep it using the specific header, and update its export. Similarly, `__type_traits/underlying_type.h` currently only includes `__type_traits/is_enum.h`, so update its export as well. This requires adding lots of export statements to the module map to keep the transitive includes working. Adding direct includes to the headers fixes `check-cxx`, but leaves many `run-buildbot generic-modules` tests failing, some even with linker errors.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D153832

13 months ago[flang] Don't warn about a NaN argument to ISNAN()
Peter Klausler [Thu, 29 Jun 2023 21:22:30 +0000 (14:22 -0700)]
[flang] Don't warn about a NaN argument to ISNAN()

Don't emit a warning when a compile-time constant argument to
ISNAN() or IEEE_IS_NAN() is a NaN.

Differential Revision: https://reviews.llvm.org/D154377

13 months ago[HIP] Pass -fno-hip-fp32-correctly-rounded-divide-sqrt to clang -cc1
Yaxun (Sam) Liu [Mon, 3 Jul 2023 18:51:51 +0000 (14:51 -0400)]
[HIP] Pass -fno-hip-fp32-correctly-rounded-divide-sqrt to clang -cc1

-fno-hip-fp32-correctly-rounded-divide-sqrt affects clang codegen
and should be passed to clang -cc1 by clang driver.

Fixes: https://github.com/llvm/llvm-project/issues/63653

Reviewed by: Matt Arsenault

Differential Revision: https://reviews.llvm.org/D154385

13 months ago[llvm-exegesis] Disable tests requiring the subprocess executor
Aiden Grossman [Mon, 3 Jul 2023 20:16:56 +0000 (13:16 -0700)]
[llvm-exegesis] Disable tests requiring the subprocess executor

This patch temporarily disables tests that require the subprocess
executor as they are currently flaky on systems that are able to run
them such as clang-cmake-x86_64-avx512-linux. Once I have a fix for the
flakiness they will be reenabled.

13 months ago[flang] Check constant POS/LEN arguments IBITS even when not both constant
Peter Klausler [Thu, 29 Jun 2023 21:02:18 +0000 (14:02 -0700)]
[flang] Check constant POS/LEN arguments IBITS even when not both constant

Apply compile-time checks to the values supplied for the POS and LEN
arguments of the IBITS intrinsic function even when only one of them
is a known constant.

Differential Revision: https://reviews.llvm.org/D154376

13 months ago[flang] Fix overflow detection for folding SUM/PRODUCT
Peter Klausler [Wed, 28 Jun 2023 23:38:08 +0000 (16:38 -0700)]
[flang] Fix overflow detection for folding SUM/PRODUCT

The overflow detection code in the templates that fold SUM and PRODUCT
was checking for overflow before performing the reduction, not after.
Fix and add tests.

Differential Revision: https://reviews.llvm.org/D154374

13 months ago[Polly][FIX] Adjust enum after D153305
Johannes Doerfert [Mon, 3 Jul 2023 19:47:31 +0000 (12:47 -0700)]
[Polly][FIX] Adjust enum after D153305

13 months ago[Attributor] Use the right argument number (call site vs callee)
Johannes Doerfert [Mon, 3 Jul 2023 06:48:02 +0000 (23:48 -0700)]
[Attributor] Use the right argument number (call site vs callee)

13 months ago[flang] More actual argument warnings
Peter Klausler [Wed, 28 Jun 2023 21:55:09 +0000 (14:55 -0700)]
[flang] More actual argument warnings

Emit warnings when CHARACTER lengths or array sizes of actual
and dummy arguments mismatch in risky ways.

Differential Revision: https://reviews.llvm.org/D154370

13 months ago[libc++] Remove support for .fail.cpp tests
Louis Dionne [Wed, 28 Jun 2023 14:45:39 +0000 (10:45 -0400)]
[libc++] Remove support for .fail.cpp tests

We want to move away from those tests and towards explicit .verify.cpp
tests, since those have a simpler model.

Differential Revision: https://reviews.llvm.org/D153982

13 months ago[mlir][Conversion/GPUCommon] Fix bug in conversion of `math` ops
Christopher Bate [Fri, 30 Jun 2023 22:04:08 +0000 (16:04 -0600)]
[mlir][Conversion/GPUCommon] Fix bug in conversion of `math` ops

The common GPU operation transformation that lowers `math` operations
to function calls in the `gpu-to-nvvm` and `gpu-to-rocdl` passes handles
`vector` types by applying the function to each scalar and returning a
new vector. However, there was a typo that results in incorrectly
accumulating the result vector, and the rewrite returns an `llvm.mlir.undef`
result instead of the correct vector. A patch is added and tests are
strengthened.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D154269

13 months ago[mlir][dataflow] Unify dependency management in AnalysisState.
Zhixun Tan [Mon, 3 Jul 2023 19:20:18 +0000 (12:20 -0700)]
[mlir][dataflow] Unify dependency management in AnalysisState.

In the MLIR dataflow analysis framework, when an `AnalysisState` is updated, it's dependents are enqueued to be visited.

Currently, there are two ways dependents are managed:

* `AnalysisState::dependents` stores a list of dependents. `DataFlowSolver::propagateIfChanged()` reads this list and enqueues them to the worklist.

* `AnalysisState::onUpdate()` allows custom logic to enqueue more to the worklist. This is called by `DataFlowSolver::propagateIfChanged()`.

This cleanup diff consolidates the two into `AnalysisState::onUpdate()`. This way, `DataFlowSolver` does not need to know the detail about `AnalysisState::dependents`, and the logic of dependency management is entirely handled by `AnalysisState`.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D154170

13 months ago[flang] Prevent lowering crash by properly updating symbol pointer
Peter Klausler [Mon, 3 Jul 2023 16:53:20 +0000 (09:53 -0700)]
[flang] Prevent lowering crash by properly updating symbol pointer

Kind of an edge case.  When a MODULE FUNCTION or SUBROUTINE
interface is defined by a MODULE PROCEDURE in the same program
unit, ensure that the symbol table pointer in the parse tree is
updated to point to the SubprogramDetails symbol for the
interface, and not left pointing to what should soon become
a dead SubprogramNameDetails symbol.

Differential Revision: https://reviews.llvm.org/D154380

13 months ago[Attributor][NFCI] Move attribute collection and manifest to Attributor
Johannes Doerfert [Fri, 30 Jun 2023 22:12:24 +0000 (15:12 -0700)]
[Attributor][NFCI] Move attribute collection and manifest to Attributor

Before, we checked and manifested attributes right in the IR. This was
bad as we modified the IR before the manifest stage. Now we can
add/remove/inspect attributes w/o going to the IR (except for the
initial query).

13 months ago[Attributor][NFCI] Manifest assumption attributes explicitly
Johannes Doerfert [Mon, 3 Jul 2023 18:30:36 +0000 (11:30 -0700)]
[Attributor][NFCI] Manifest assumption attributes explicitly

We had some custom manifest for assumption attributes but we use the
generic manifest logic. If we later decide to curb duplication (of
attributes on the call site and callee), we can do that at a single
location and for all attributes.

The test changes basically add known `llvm.assume` callee information to
the call sites.

13 months ago[Attributor][NFCI] Merge MemoryEffects explicitly
Johannes Doerfert [Fri, 30 Jun 2023 22:56:08 +0000 (15:56 -0700)]
[Attributor][NFCI] Merge MemoryEffects explicitly

We had some custom handling for existing MemoryEffects but we now move
it to the place we check other existing attributes before we manifest
new ones. If we later decide to curb duplication (of attributes on the
call site and callee), we can do that at a single location and for all
attributes.

The test changes basically add known `memory` callee information to the
call sites.

13 months ago[lldb] Fix data race when interacting with python scripts
Med Ismail Bennani [Mon, 3 Jul 2023 18:48:11 +0000 (11:48 -0700)]
[lldb] Fix data race when interacting with python scripts

This patch should fix some data races when a python script (i.e. a
Scripted Process) has a nested call to another python script (i.e. a
OperatingSystem Plugin), which can cause concurrent writes to the python
lock count.

This patch also fixes a data race happening when resetting the operating
system unique pointer.

To address these issues, both accesses is guarded by a mutex.

rdar://109413039

Differential Revision: https://reviews.llvm.org/D154271

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
13 months ago[lldb][NFCI] Target::StopHook::GetDescription should take a Stream ref instead of...
Alex Langford [Tue, 27 Jun 2023 20:48:27 +0000 (13:48 -0700)]
[lldb][NFCI] Target::StopHook::GetDescription should take a Stream ref instead of pointer

We always assume that this is valid anyway, might as well take a
reference.

Differential Revision: https://reviews.llvm.org/D153917

13 months ago[flang][runtime] Allow OPEN(n,ENCODING=) to change the encoding
Peter Klausler [Thu, 29 Jun 2023 22:19:23 +0000 (15:19 -0700)]
[flang][runtime] Allow OPEN(n,ENCODING=) to change the encoding

OPEN statements can be used to change some, but not all, attributes
of units that have already been opened.  The I/O runtime library
wasn't allowing ENCODING= to be changed.  Every other Fortran compiler
permits this usage, and it's safe and useful, so allow it.
(Otherwise there's no good way to ensure that the preconnected
unit 6 is in UTF-8 mode.)

Differential Revision: https://reviews.llvm.org/D154379

13 months ago[flang][NFC] Document semantics of an ambiguous/non-portable use case
Peter Klausler [Thu, 29 Jun 2023 20:03:14 +0000 (13:03 -0700)]
[flang][NFC] Document semantics of an ambiguous/non-portable use case

We intentionally process NAMELIST groups in a scope after having
resolved all of the names in that scope.  This means that a name
whose first appearance in a scope is in the NAMELIST group resolves
to a local object, if any, rather than to any host associated object.
The standard is unclear on this point, and there is no clear
precedent in other compilers.

This patch doesn't implement this choice -- that was done long ago --
but just documents the behavior in Extensions.md.

Differential Revision: https://reviews.llvm.org/D154375

13 months ago[flang] Warn about overflow after folding HYPOT
Peter Klausler [Wed, 28 Jun 2023 23:08:54 +0000 (16:08 -0700)]
[flang] Warn about overflow after folding HYPOT

The code that folds the intrinsic function HYPOT was neglecting to
warn the programmer about overflow when it occurs.

Differential Revision: https://reviews.llvm.org/D154371

13 months ago[lldb] Introduce a macro to mark methods as unsupported with no replacement
Alex Langford [Tue, 27 Jun 2023 22:51:27 +0000 (15:51 -0700)]
[lldb] Introduce a macro to mark methods as unsupported with no replacement

We already have LLDB_DEPRECATED which is used to mark methods as
deprecated with a message and an alternative to use instead. This is
expresses an intent of "We recognize this functionality is useful but
there are some pitfalls with the interface we have exposed."

In other cases, there are no "alternative" methods to use and the code should be
refactored to avoid using a method entirely. For example,
`SBValue::Cast` should be avoided in favor of using the expression
evaluator to perform a cast. There isn't a mechanical solution, the
recommendation is to instead refactor your code.

This commit renames the existing `LLDB_DEPRECATED` to
`LLDB_DEPRECATED_FIXME`, and adds a `LLDB_DEPRECATED` macro to cover the
second scenario.

Differential Revision: https://reviews.llvm.org/D153928

13 months ago[lldb][NFCI] Remove use of ConstString from ProcessElfCore
Alex Langford [Tue, 27 Jun 2023 01:13:38 +0000 (18:13 -0700)]
[lldb][NFCI] Remove use of ConstString from ProcessElfCore

I'm not convinced that it makes sense for the paths to be ConstStrings. We're
going to be putting them into FileSpecs (which are backed by
ConstStrings, for now) but otherwise there's no need to store them as
ConstStrings upfront.

Differential Revision: https://reviews.llvm.org/D153827

13 months ago[LSR] Add test for another normalization miscompile.
Florian Hahn [Mon, 3 Jul 2023 17:57:30 +0000 (18:57 +0100)]
[LSR] Add test for another normalization miscompile.

Based on @peixin test case shared in D153004.

13 months ago[flang][NFC] Add F2023X documentation
Peter Klausler [Thu, 22 Jun 2023 18:28:47 +0000 (11:28 -0700)]
[flang][NFC] Add F2023X documentation

Add a document that summarizes Fortran 202X's upcoming
features and their urgency for implementation.

Differential Revision: https://reviews.llvm.org/D153916

13 months ago[Attributor] Ensure we call the specialized isImpliedByIR
Johannes Doerfert [Mon, 3 Jul 2023 06:49:18 +0000 (23:49 -0700)]
[Attributor] Ensure we call the specialized isImpliedByIR

Before we ended up not calling the specialized AAType::isImpliedByIR but
the generic IRAttribute::isImpliedByIR in the IRAttribute::initialize
function.

13 months ago[Attributor][NFC] Check for the Explorer first to avoid traversing uses
Johannes Doerfert [Fri, 30 Jun 2023 17:49:06 +0000 (10:49 -0700)]
[Attributor][NFC] Check for the Explorer first to avoid traversing uses

13 months ago[Attributor][NFC] Exit manifestAttrs early if there are no attributes
Johannes Doerfert [Fri, 30 Jun 2023 22:54:58 +0000 (15:54 -0700)]
[Attributor][NFC] Exit manifestAttrs early if there are no attributes

13 months ago[MemoryEffects][NFCI] Make the MemoryEffects class reusable
Johannes Doerfert [Thu, 15 Jun 2023 04:44:24 +0000 (21:44 -0700)]
[MemoryEffects][NFCI] Make the MemoryEffects class reusable

In a follow up we will reuse the logic in MemoryEffectsBase to merge
AAMemoryLocation and AAMemoryBehavior without duplicating all the bit
fiddling code already available in MemoryEffectsBase.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D153305

13 months ago[lldb][NFCI] Change return type of GetProcessPluginName
Alex Langford [Tue, 27 Jun 2023 00:57:48 +0000 (17:57 -0700)]
[lldb][NFCI] Change return type of GetProcessPluginName

Instead of just returning a raw `const char *`, I think llvm::StringRef
would make more sense. Most of the time that we use the return value of
`GetProcessPluginName` we're passing it to `CreateProcess` which takes a
StringRef anyway.

Differential Revision: https://reviews.llvm.org/D153825

13 months ago[flang][hlfir] Evaluate actual args before impure elemental calls.
Slava Zakharin [Mon, 3 Jul 2023 15:41:28 +0000 (08:41 -0700)]
[flang][hlfir] Evaluate actual args before impure elemental calls.

Actual argument expressions must be evaluated before the invocation
of the sequence of per-element calls of an impure elemental subprogram.
Otherwise, the side effects of the calls may affect the input for
the consequent elements.
The proposed changes are described by Jean in D154174.

Reviewed By: tblah

Differential Revision: https://reviews.llvm.org/D154263

13 months ago[Flang] Mark as maybe_unused to fix warning in PPCIntrinsicCall.cpp
Kiran Chandramohan [Mon, 3 Jul 2023 16:48:12 +0000 (16:48 +0000)]
[Flang] Mark as maybe_unused to fix warning in PPCIntrinsicCall.cpp

13 months ago[LV] Prepare tests for D154261.
Florian Hahn [Mon, 3 Jul 2023 16:49:35 +0000 (17:49 +0100)]
[LV] Prepare tests for D154261.

Update trip count of test in
pr56319-vector-exit-cond-optimization-epilogue-vectorization.ll to
make sure epilogue vectorization will still trigger after D154261,
checking for the original issue.

Move the original test to limit-vf-by-tripcount.ll for testing new
functionality of D154261.

13 months ago[Flang][OpenMP] Lower allocatable or pointer in private clause
Dmitriy Smirnov [Mon, 3 Jul 2023 16:31:20 +0000 (16:31 +0000)]
[Flang][OpenMP] Lower allocatable or pointer in private clause

This patch lowers allocatables and pointers named in "private" OpenMP clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148570

13 months ago[clang-tidy] Accessing checks not done for aliases of `std::array`
Jorge Pinto Sousa [Mon, 3 Jul 2023 16:39:31 +0000 (16:39 +0000)]
[clang-tidy] Accessing checks not done for aliases of `std::array`

Index accessing checks are not performed for aliases
of `std::array`, as only `std::array` itself seems to be checked.

This patch aims to extend it for aliases such as:
 `using MyArray = std::array<int, 10>;`

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D154297

13 months ago[clang-tidy] Fix width/precision argument order in modernize-use-std-print
Mike Crowe [Mon, 3 Jul 2023 16:29:28 +0000 (16:29 +0000)]
[clang-tidy] Fix width/precision argument order in modernize-use-std-print

Victor Zverovich pointed out[1] that printf takes the field width and
precision arguments before the value to be printed whereas std::print
takes the value first (unless positional arguments are used.) Many of
the test cases in use-std-print.cpp were incorrect.

Teach the check to rotate the arguments when required to correct
this. Correct the test cases and add more.

[1] https://github.com/fmtlib/fmt/pull/3515#issuecomment-1615259893

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D154283

13 months ago[lldb][NFCI] TypeSystemClang::CreateStructForIdentifier should take a StringRef
Alex Langford [Mon, 26 Jun 2023 20:17:49 +0000 (13:17 -0700)]
[lldb][NFCI] TypeSystemClang::CreateStructForIdentifier should take a StringRef

This doesn't really use fast comparison or string uniqueness. In fact,
all of the current callers pass an empty string for type_name. The only
reason I don't remove it is because it looks like it is used downstream
for swift.

Differential Revision: https://reviews.llvm.org/D153810

13 months ago[lldb][NFCI] Remove unneeded use of ConstString in ASTResultSynthesizer
Alex Langford [Tue, 27 Jun 2023 18:37:22 +0000 (11:37 -0700)]
[lldb][NFCI] Remove unneeded use of ConstString in ASTResultSynthesizer

2/3 of the ConstStrings in this class were just to be able to log
something. Putting something in the StringPool just to log it doesn't
make a lot of sense, so let's remove them.

The remaining use is for `RegisterPersistentDecl` which is fine for now.

Differential Revision: https://reviews.llvm.org/D153905

13 months ago[flang] Add optional portability warning for upcoming Fortran 202X/3 breaking change
Peter Klausler [Fri, 30 Jun 2023 00:32:00 +0000 (17:32 -0700)]
[flang] Add optional portability warning for upcoming Fortran 202X/3 breaking change

The soon-to-be-published next revision of the ISO Fortran language standard
contains a couple of breaking changes to previous specifications that may cause
existing programs to silently change their behavior.

For the change that introduces automatic reallocation of deferred length
allocatable character scalar variables when they appear as the targets
of internal WRITE statements, as IOMSG=/ERRMSG= variables, as outputs
of INQUIRE specifiers, or as INTENT(OUT) arguments to intrinsic
procedures, this patch adds an optional portability warning.

Differential Revision: https://reviews.llvm.org/D154242

13 months ago[mlir][Interfaces] Add `promoteIfSingleIteration` to `LoopLikeOpInterface`
Matthias Springer [Mon, 3 Jul 2023 15:57:02 +0000 (17:57 +0200)]
[mlir][Interfaces] Add `promoteIfSingleIteration` to `LoopLikeOpInterface`

There are existing implementations for `scf.for`, `scf.forall` and `affine.for`. This revision adds an interface method to the `LoopLikeOpInterface`.

* `scf.forall` now implements the `LoopLikeOpInterface`.
* The implementations of `scf.for` and `scf.forall` become interface method implementations. `affine.for` remains as is for the moment. (The implementation of `promoteIfSingleIteration` depepends on helper functions from `MLIRAffineAnalysis`, which cannot be used from `MLIRAffineDialect`, where the interface is currently implemented.)
* More efficient implementations of `promoteIfSingleIteration`. In particular, the `scf.forall` operation now inlines operations instead of cloning them. This also preserves handles when used from the transform dialect.

Differential Revision: https://reviews.llvm.org/D154343

13 months ago[CodeGen] MRI call back in TargetMachine
Christudasan Devadasan [Mon, 3 Jul 2023 15:59:34 +0000 (21:29 +0530)]
[CodeGen] MRI call back in TargetMachine

It is needed for target specific initializatons.

Reviewed By: qcolombet

Differential Revision: https://reviews.llvm.org/D143758

13 months ago[Mips] Remove isMoveReg=1 from wrdsp and rddsp instructions
Yashwant Singh [Mon, 3 Jul 2023 15:23:05 +0000 (20:53 +0530)]
[Mips] Remove isMoveReg=1 from wrdsp and rddsp instructions

This is a prep patch for D150388. Treating rddsp and wrdsp as copy
instructions was causing test failures as we tried using isCopyInstr()
hook to query target-specific copy instructions for LiveRangeSplitting.

As suggested, removing 'isMoveReg = 1' from wrdsp and rddsp so they
aren't considered simple copy-like instructions for the moment.

Reviewed By: sdardis

Differential Revision: https://reviews.llvm.org/D151181

13 months ago[mlir][LLVM] Export LLVMFuncOp's GC for declarations
Christian Ulmann [Mon, 3 Jul 2023 15:14:12 +0000 (15:14 +0000)]
[mlir][LLVM] Export LLVMFuncOp's GC for declarations

This commit ensures that the garbage collector attribute of LLVMFuncOps
is exported, even when they are declarations.

13 months ago[clang][tooling] Fix early termination when there are nested expansions
Kadir Cetinkaya [Mon, 3 Jul 2023 11:29:15 +0000 (13:29 +0200)]
[clang][tooling] Fix early termination when there are nested expansions

This also does some cleanups, I am happy to undo them (or send as
separate patches):
- Change the early exit to stop only once we hit an expansion inside the
  main file, to make sure we keep following the nested expansions.
- Add more tests to cover all the cases mentioned in the implementation
- Drop the adjustments for prev/next tokens. We do the final checks
  based on the expansion locations anyway, so any intermediate mapping
  was a no-op.

Differential Revision: https://reviews.llvm.org/D154335

13 months ago[flang] Install omp_lib.h to install directory alongside modules
David Truby [Mon, 3 Jul 2023 14:50:40 +0000 (15:50 +0100)]
[flang] Install omp_lib.h to install directory alongside modules

This patch simply adds a cmake install line for omp_lib.h that was
previously missing, to put it alongisde omp_lib.mod so it can be found
by the driver.

13 months ago[SVE] Extend incp/decp testing to cover 32-bit use cases.
Paul Walker [Mon, 3 Jul 2023 13:28:35 +0000 (14:28 +0100)]
[SVE] Extend incp/decp testing to cover 32-bit use cases.

13 months ago[OpenMP] libomptarget: Don't map alignment padding to host
Joel E. Denny [Mon, 3 Jul 2023 14:23:38 +0000 (10:23 -0400)]
[OpenMP] libomptarget: Don't map alignment padding to host

In the case of partially mapped structs, libomptarget sometimes adds
padding to device allocations to ensure they are aligned properly.
However, without this patch, it considers that padding to be mapped to
the host, which can cause presence checks (e.g.,
`omp_target_is_present` or a `present` modifier) to misbehave for
unmapped parts of the struct.  This patch keeps the padding but treats
it as unmapped.  See the new test case for examples.

Reviewed By: grokos, jdoerfert

Differential Revision: https://reviews.llvm.org/D149685

13 months ago[clang] Add `__has_extension ()` for C++11 features
Mariya Podchishchaeva [Mon, 3 Jul 2023 14:05:25 +0000 (10:05 -0400)]
[clang] Add `__has_extension ()` for C++11 features

Add `__has_extension (cxx_defaulted_functions)` and
`__has_extension (cxx_default_function_template_args)` since they are
accepted in C++98 mode as extensions.

Fixes https://github.com/llvm/llvm-project/issues/61758

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D154334

13 months ago[NFC] Fix typo explicitly_convertable -> explicitly_convertible
Balazs Benics [Mon, 3 Jul 2023 14:13:02 +0000 (16:13 +0200)]
[NFC] Fix typo explicitly_convertable -> explicitly_convertible

Differential Revision: https://reviews.llvm.org/D152891

13 months agoRevert "[ARM] Adjust strd/ldrd codegen alignment requirements"
David Spickett [Mon, 3 Jul 2023 13:50:35 +0000 (13:50 +0000)]
Revert "[ARM] Adjust strd/ldrd codegen alignment requirements"

This reverts commit 92a9c30c61da7f973d55cd84fade424159b9cac9.

This has caused a test failure in the 2nd stage of Linaro's
Arm 32 bit buildbots.

LLVM::simplified-template-names.s

            7: error: Simplified template DW_AT_name could not be reconstituted:
check:10'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            8:  original: f3<unsigned char, (unsigned char)'\x00'>
check:10'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            9:  reconstituted: f3<unsigned char, (unsigned char)'\x7f'>
check:10'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I suspect a load/store is slightly off.

13 months ago[lit] Remove dead code not referenced, documented or tested anywhere
Louis Dionne [Wed, 21 Jun 2023 21:55:40 +0000 (17:55 -0400)]
[lit] Remove dead code not referenced, documented or tested anywhere

If someone encounters issues due to this patch (e.g. they are using
that test format out-of-tree), please reach out on the review and
we'll figure out a way forward.

Differential Revision: https://reviews.llvm.org/D153534

13 months ago[libc++] Move all the remaining .fail.cpp tests to .verify.cpp
Louis Dionne [Fri, 16 Jun 2023 15:04:06 +0000 (11:04 -0400)]
[libc++] Move all the remaining .fail.cpp tests to .verify.cpp

I made sure they all had some expected-error output in them. Many of
these tests would be better implemented as a positive test using SFINAE,
but this is beyond the scope of this patch.

Differential Revision: https://reviews.llvm.org/D153980

13 months ago[libc++] Add missing includes
Louis Dionne [Tue, 27 Jun 2023 14:58:19 +0000 (10:58 -0400)]
[libc++] Add missing includes

Those were found while trying to enable configurations like no-threads
and no-localization with Clang modules enabled.

Differential Revision: https://reviews.llvm.org/D153977

13 months ago[mlir][transform] Add `transform.apply_licm` op
Matthias Springer [Mon, 3 Jul 2023 13:24:35 +0000 (15:24 +0200)]
[mlir][transform] Add `transform.apply_licm` op

This op applies loop-invariant code motion to the targeted loop-like op.

Differential Revision: https://reviews.llvm.org/D154327

13 months ago[LV] Check for vector instruction in main vector loop.
Florian Hahn [Mon, 3 Jul 2023 13:16:46 +0000 (14:16 +0100)]
[LV] Check for vector instruction in main vector loop.

Update the test to check for the vectorization call in the main vector
loop, not the dead epilogue vector loop as it does currently.

13 months ago[Headers][X86] Ensure all AVX broadcast scalar load intrinsics are unaligned
Simon Pilgrim [Mon, 3 Jul 2023 13:04:12 +0000 (14:04 +0100)]
[Headers][X86] Ensure all AVX broadcast scalar load intrinsics are unaligned

Similar to the existing _mm_load1_pd/_mm_loaddup_pd and broadcast vector loads, these intrinsic should ensure the loads are unaligned and not assume type alignment

Fixes #62325

13 months ago[lldb][NFC] Simplify GetLocation_DW_OP_addr function
Felipe de Azevedo Piovezan [Fri, 30 Jun 2023 21:26:37 +0000 (17:26 -0400)]
[lldb][NFC] Simplify GetLocation_DW_OP_addr function

A very old commit (9422dd64f870dd33) changed the signature of this function in a
number of ways. This patch aims to improve it:

1. Reword the documentation, which still mentions old parameters that no longer
exist, and to elaborate upon the behavior of this function.
2. Remove the unnecessary parameter `op_addr_idx`. This parameter is odd in a
couple of ways: we never use it with a value that is non-zero, and the matching
`Update_DW_OP_addr` function doesn't use a similar parameter. We also document
that this new behavior. If we ever decide to handle multiple "DW_OP_addr", we
can introduce the complexity again.

Differential Revision: https://reviews.llvm.org/D154265

13 months ago[lldb] Skip apple accelerator table test in DWARF 5 mode
Felipe de Azevedo Piovezan [Tue, 27 Jun 2023 18:12:10 +0000 (14:12 -0400)]
[lldb] Skip apple accelerator table test in DWARF 5 mode

D68678 added a test that ensures an Apple accelerator lookup is done
efficiently. Since these tables are not used for DWARF 5, we should decorate the
test appropriately.

Differential Revision: https://reviews.llvm.org/D154268

13 months ago[clang][ExtractAPI] Add --emit-symbol-graph option
Ankur [Mon, 3 Jul 2023 11:53:07 +0000 (17:23 +0530)]
[clang][ExtractAPI] Add --emit-symbol-graph option

Add new --emit-symbol-graph=<DIR> option which generates ExtractAPI symbol
graph information of .c/.m files on regular compilation job and put them in
the provided "DIR" directory.

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D152356

13 months ago[flang] Fix codegen of subcomponents' indexing
Leandro Lupori [Thu, 29 Jun 2023 14:46:58 +0000 (14:46 +0000)]
[flang] Fix codegen of subcomponents' indexing

Identify multidimensional array indices in subcomponents and
convert them from column-major to row-major ordering.

This fixes codegen for fircg.ext_array_coor, fircg.ext_embox and,
possibly, fircg.ext_rebox.

Fixes https://github.com/llvm/llvm-project/issues/62038

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D154214

13 months ago[RISCV] Use parseDirective returning ternary status (NFC)
Sergei Barannikov [Mon, 3 Jul 2023 11:45:22 +0000 (14:45 +0300)]
[RISCV] Use parseDirective returning ternary status (NFC)

The new method was introduced in D154101.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D154276

13 months ago[mlir][Bazel] Add missing dependencies after 564713c47175d9f61fe8e18e750fb7f7b486d533
Adrian Kuegel [Mon, 3 Jul 2023 11:16:28 +0000 (13:16 +0200)]
[mlir][Bazel] Add missing dependencies after 564713c47175d9f61fe8e18e750fb7f7b486d533

13 months ago[clang-format] Fixed bad performance with enabled qualifier fixer.
Sedenion [Mon, 3 Jul 2023 10:53:28 +0000 (11:53 +0100)]
[clang-format] Fixed bad performance with enabled qualifier fixer.

This fixes github issue #57117: If the "QualifierAlignment"
option of clang-format is set to anything else but "Leave", the
"QualifierAlignmentFixer" pass gets enabled. This pass scales
quadratically with the number of preprocessor branches, i.e.
with the number of elements in TokenAnalyzer::UnwrappedLines.
The reason is that QualifierAlignmentFixer::process() generates
the UnwrappedLines, but then QualifierAlignmentFixer::analyze()
calls LeftRightQualifierAlignmentFixer::process() several times
(once for each qualifier) which again each time generates the
UnwrappedLines.

This commit gets rid of this double loop by registering the
individual LeftRightQualifierAlignmentFixer passes directly in
the top most container of passes (local variable "Passes" in
reformat()).
With this change, the original example in the github issue #57117
now takes only around 3s instead of >300s to format.

Since QualifierAlignmentFixer::analyze() got deleted, we also
no longer have the code with the NonNoOpFixes. This causes
replacements that end up not changing anything to appear in the
list of final replacements. There is a unit test to check that
this does not happen: QualifierFixerTest.NoOpQualifierReplacements.
However, it got broken at some point in time. So this commit
fixes the test. To keep the behavior that no no-op replacements
should appear from the qualifier fixer, the corresponding code
from QualifierAlignmentFixer::analyze() was moved to the top
reformat() function. Thus, is now done for **every** replacement
of every formatting pass. If no-op replacements are a problem
for the qualifier fixer, then it seems to be a good idea to
filter them out always.

See
https://github.com/llvm/llvm-project/issues/57117#issuecomment-1546716934
for some more details.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D153228