platform/upstream/llvm.git
2 years ago[mlir][vector] Remove default value in populateVectorMultiReductionLoweringPatterns
Diego Caballero [Thu, 16 Dec 2021 09:45:34 +0000 (09:45 +0000)]
[mlir][vector] Remove default value in populateVectorMultiReductionLoweringPatterns

Having a default value for the lowering strategy of the multi-reduction op has proven
to be unexpected by users. This patch is dropping the default value so that users have
to explicitly choose the lowering strategy to be applied.

Reviewed By: nicolasvasilache

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

2 years ago[Inline] Disable deferred inlining
Nikita Popov [Fri, 10 Dec 2021 08:08:57 +0000 (09:08 +0100)]
[Inline] Disable deferred inlining

After the switch to the new pass manager, we have observed multiple
instances of catastrophic inlining, where the inliner produces huge
functions with many hundreds of thousands of instructions from small
input IR. We were forced to back out the switch to the new pass
manager for this reason. This patch fixes at least one of the root
cause issues.

LLVM uses a bottom-up inliner, and the fact that functions are processed
bottom-up is not just a question of optimality -- it is an imporant
requirement to prevent runaway inlining. The premise of the current
inlining approach and cost model is that after all calls inside a function
have been inlined, it may get large enough that inlining it into its
callers is no longer considered profitable. This safeguard does not
exist if inlining doesn't happen bottom-up, as inlining the callees,
and their callees, and their callees etc. will always seem individually
profitable, and the inliner can easily flatten the whole call tree.

There are instances where we necessarily have to deviate from bottom-up
inlining: When inlining in an SCC there is no natural "bottom", so
inlining effectively happens top-down. This requires special care,
and the inliner avoids exponential blowup by ensuring that functions
in the SCC grow in a balanced way and will eventually hit the threshold.

However, there is one instance where the inlining advisor explicitly
violates the bottom-up principle: Deferred inlining tries to "defer"
inlining a call if it determines that inlining the caller into all
its call-sites would be more profitable. Something very important to
understand about deferred inlining is that it doesn't make one inlining
choice in place of another -- it effectively chooses to do both. If we
have a call chain A -> B -> C and cost modelling tells us that inlining
B -> C is profitable, but we defer this and instead inline A -> B first,
then we'll now have a call A -> C, and the cost model will (a few special
cases notwithstanding) still tell us that this is profitable. So the end
result is that we inlined *both* B and C, even though under the usual
cost model function B would have been too large to further inline after
C has been integrated into it.

Because deferred inlining violates the bottom-up invariant of the inliner,
it can result in exponential inlining. The exponential-deferred-inlining.ll
test case illustrates this on a simple example (see
https://gist.github.com/nikic/1262b5f7d27278e1b34a190ae10947f5 for a
much more catastrophic case with about 5000x size blowup). If the call
chain A -> B -> C is not a chain but a tree of calls, then we end up
deferring inlining across the tree and end up flattening everything into
the root node.

This patch proposes to address this by disabling deferred inlining
entirely (currently still behind an option). Beyond the issue of
exponential inlining, I don't think that the whole concept makes sense,
at least as long as deferred inlining still ends up inlining both call
edges.

I believe the motivation for having deferred inlining in the first place
is that you might have a small wrapper function with local linkage that
could be eliminated if inlined. This would automatically happen if there
was a single caller, due to the large "last call to local" bonus. However,
this bonus is not extended if there are multiple callers, even if we
would eventually end up inlining into all of them (if the bonus were
extended).

Now, unlike the normal inlining cost model, the deferred inlining cost
model does look at all callers, and will extend the "last call to local"
bonus if it determines that we could inline all of them as long as we
defer the current inlining decision. This makes very little sense.
The "last call to local" bonus doesn't really cost model anything.
It's basically an "infinite" bonus that ensures we always inline the
last call to a local. The fact that it's not literally infinite just
prevents inlining of huge functions, which can easily result in
scalability issues. I very much doubt that it was an intentional
cost-modelling choice to say that getting rid of a small local function
is worth adding 15000 instructions elsewhere, yet this is exactly how
this value is getting used here.

The main alternative I see to complete removal is to change deferred
inlining to an actual either/or decision. That is, to mark deferred
calls as noinline so we're actually trading off one inlining decision
against another, and not just adding a side-channel to the cost model
to do both.

Apart from fixing the catastrophic inlining case, the effect on rustc
is a modest compile-time improvement on average (up to 8% for a
parsing-type crate, where tree-like calls are expected) and pretty
neutral where run-time performance is concerned (mix of small wins
and losses, usually in the sub-1% category).

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

2 years ago[clang][deps] Squash caches for original and minimized files
Jan Svoboda [Thu, 16 Dec 2021 08:27:12 +0000 (09:27 +0100)]
[clang][deps] Squash caches for original and minimized files

The minimizing and caching filesystem used by the dependency scanner keeps minimized and original files in separate caches.

This setup is not well suited for dealing with files that are sometimes minimized and sometimes not. Such files are being stat-ed and read twice, which is wasteful and also means the two versions of the file can get "out of sync".

This patch squashes the two caches together. When a file is stat-ed or read, its original contents are populated. If a file needs to be minimized, we give the minimizer the already loaded contents instead of reading the file again.

Reviewed By: dexonsmith

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

2 years ago[ORC] Add custom object interface support to StaticLibaryDefinitionGenerator.
Lang Hames [Thu, 16 Dec 2021 06:55:02 +0000 (17:55 +1100)]
[ORC] Add custom object interface support to StaticLibaryDefinitionGenerator.

This adds a GetObjectFileInterface callback member to
StaticLibraryDefinitionGenerator, and adds an optional argument for initializing
that member to StaticLibraryDefinitionGenerator's named constructors. If not
supplied, it will default to getObjectFileInterface from ObjectFileInterface.h.

To enable testing a `-hidden-l<x>` option is added to the llvm-jitlink tool.
This allows archives to be loaded with all contained symbol visibilities demoted
to hidden.

The ObjectLinkingLayer::setOverrideObjectFlagsWithResponsibilityFlags method is
(belatedly) hooked up, and enabled in llvm-jitlink when `-hidden-l<x>` is used
so that the demotion is also applied at symbol resolution time (avoiding any
"mismatched symbol flags" crashes).

2 years ago[llvm-jitlink] Fix a typo.
Lang Hames [Wed, 15 Dec 2021 05:58:43 +0000 (16:58 +1100)]
[llvm-jitlink] Fix a typo.

2 years ago[llvm-jitlink] Remove unused struct member.
Lang Hames [Wed, 15 Dec 2021 05:56:06 +0000 (16:56 +1100)]
[llvm-jitlink] Remove unused struct member.

2 years ago[LoopVersioning] Allow versionLoop to create plain branch inst when no runtime check...
Yueh-Ting Chen [Thu, 16 Dec 2021 08:26:20 +0000 (00:26 -0800)]
[LoopVersioning] Allow versionLoop to create plain branch inst when no runtime check is specified

After this function call, the LLVM IR would look like the following:

```
if (true)
  /* NonVersionedLoop */
else
  /* VersionedLoop */
```

Reviewed By: Whitney

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

2 years ago[llvm-c] Make LLVMConstGEP/LLVMConstInBoundsGEP opaque pointer compatible
Nikita Popov [Wed, 15 Dec 2021 08:10:18 +0000 (09:10 +0100)]
[llvm-c] Make LLVMConstGEP/LLVMConstInBoundsGEP opaque pointer compatible

Weirdly, the opaque pointer compatible variants LLVMConstGEP2 and
LLVMConstInBoundsGEP2 were already declared in the header, but not
actually implemented. This adds the missing implementations and
deprecates the incompatible functions.

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

2 years ago[clang-format] Fix tabs when using BreakBeforeTernaryOperators=false.
Marek Kurdej [Wed, 15 Dec 2021 15:34:53 +0000 (16:34 +0100)]
[clang-format] Fix tabs when using BreakBeforeTernaryOperators=false.

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

This is rather a workaround than a correct fix. To properly fix it, we'd need to find a better way to tell when not to decrease the StartOfTokenColumn.

Reviewed By: MyDeveloperDay, owenpan

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

2 years ago[ELF] maybeReportUndefined: move sym.isUndefined() check to the caller. NFC
Fangrui Song [Thu, 16 Dec 2021 08:27:19 +0000 (00:27 -0800)]
[ELF] maybeReportUndefined: move sym.isUndefined() check to the caller. NFC

Avoid a function call in the majority of cases.

2 years ago[CodeGen] Store ElementType in LValue
Nikita Popov [Wed, 15 Dec 2021 11:08:11 +0000 (12:08 +0100)]
[CodeGen] Store ElementType in LValue

Store the pointer element type inside LValue so that we can
preserve it when converting it back into an Address. Storing the
pointer element type might not be strictly required here in that
we could probably re-derive it from the QualType (which would
require CGF access though), but storing it seems like the simpler
solution.

The global register case is special and does not store an element
type, as the value is not a pointer type in that case and it's not
possible to create an Address from it.

This is the main remaining part from D103465.

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

2 years ago[sanitizer] Update global_symbols.txt
Vitaly Buka [Thu, 16 Dec 2021 08:13:57 +0000 (00:13 -0800)]
[sanitizer] Update global_symbols.txt

2 years ago[ELF] parseSymbolVersion: remove unussed pos == 0 check
Fangrui Song [Thu, 16 Dec 2021 07:59:55 +0000 (23:59 -0800)]
[ELF] parseSymbolVersion: remove unussed pos == 0 check

2 years ago[gn build] Port db5aceb97939
LLVM GN Syncbot [Thu, 16 Dec 2021 07:22:17 +0000 (07:22 +0000)]
[gn build] Port db5aceb97939

2 years ago[NFC] Expose the ReleaseModeModelRunner
Mircea Trofin [Wed, 15 Dec 2021 00:15:32 +0000 (16:15 -0800)]
[NFC] Expose the ReleaseModeModelRunner

The type was pretty much generic, just needed a bit of parameterization.

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

2 years ago[RISCV] Fold (and (not (srl X, C)), 1) to (xor (bexti X, C), 1) when have Zbs extension.
jacquesguan [Mon, 13 Dec 2021 12:46:15 +0000 (20:46 +0800)]
[RISCV] Fold (and (not (srl X, C)), 1) to (xor (bexti X, C), 1) when have Zbs extension.

When have Zbs extension, we could use bexti to fold (and (not (srl X, C)), 1) to (xor (bexti X, C), 1).

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

2 years ago[ELF] SharedFile::parse: cache symbols size for a loop. NFC
Fangrui Song [Thu, 16 Dec 2021 06:45:27 +0000 (22:45 -0800)]
[ELF] SharedFile::parse: cache symbols size for a loop. NFC

2 years ago[libc] Disable signal.h API and its users.
Siva Chandra Reddy [Wed, 15 Dec 2021 23:24:17 +0000 (23:24 +0000)]
[libc] Disable signal.h API and its users.

The signal.h header file from LLVM libc is incorrect. The signal API and
its users will be enabled once signal.h is fixed.

2 years ago[ELF] Move -l -L canonical and --library-path --library aliases
Fangrui Song [Thu, 16 Dec 2021 05:49:53 +0000 (21:49 -0800)]
[ELF] Move -l -L canonical and --library-path --library aliases

Everyone uses -l -L instead of the long option counterparts.
Make help messages attach to -L -l and (--reproduce) use them for response.txt
command line options.

2 years ago[LoopIdiom] Use utility from SE instead of local rewriter
eopXD [Wed, 15 Dec 2021 07:00:01 +0000 (23:00 -0800)]
[LoopIdiom] Use utility from SE instead of local rewriter

ScalarEvolution::applyLoopGuards shall do the work.

Reviewed By: reames

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

2 years ago[PDLL] Fix GCC5 build after D115093
River Riddle [Thu, 16 Dec 2021 03:47:59 +0000 (03:47 +0000)]
[PDLL] Fix GCC5 build after D115093

2 years ago[PDLL] Fix windows build after D115093
River Riddle [Thu, 16 Dec 2021 03:23:52 +0000 (03:23 +0000)]
[PDLL] Fix windows build after D115093

2 years ago[dwarf][NFC] Move expandBundle() to MachO.h
Ellis Hoag [Wed, 15 Dec 2021 23:52:00 +0000 (15:52 -0800)]
[dwarf][NFC] Move expandBundle() to MachO.h

The function `expandBundle()` is defined both in `llvm-dwarfdump.cpp` and
`llvm-gsymutil.cpp` in the exact same way. Reduce code duplication by
moving this function to the `MachOObjectFile` class.

Reviewed By: jhenderson, clayborg

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

2 years ago[RISCV] Fix whole vector register move instruction's vector register constraint.
jacquesguan [Tue, 14 Dec 2021 11:31:31 +0000 (19:31 +0800)]
[RISCV] Fix whole vector register move instruction's vector register constraint.

According to the v-spec, the source and destination VR of vmv<nr>r.v should be aligned for the VR group size.

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

2 years ago[mlir][linalg][bufferize][NFC] Pass BufferizationState into all op interface methods
Matthias Springer [Thu, 16 Dec 2021 02:42:41 +0000 (11:42 +0900)]
[mlir][linalg][bufferize][NFC] Pass BufferizationState into all op interface methods

This allows op interface implementations to make decisions based on dialect-specific bufferization state.

This is in preparation of fixing conflict detection of CallOps in ModuleBufferization.

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

2 years ago[ThinLTO] Ignore unreachable virtual functions in WPD in thin LTO.
minglotus-6 [Thu, 16 Dec 2021 00:20:19 +0000 (00:20 +0000)]
[ThinLTO] Ignore unreachable virtual functions in WPD in thin LTO.

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

2 years ago[ELF] ObjFile<ELFT>::initializeSymbols: don't call Allocate when firstGlobal==0
Fangrui Song [Thu, 16 Dec 2021 02:21:48 +0000 (18:21 -0800)]
[ELF] ObjFile<ELFT>::initializeSymbols: don't call Allocate when firstGlobal==0

Calling `Allocate` with 0 size (when .symtab is absent, e.g.
`invalid/mips-invalid-options-descriptor.test`) may return a nullptr, which will
crash with -fsanitize=null (the underlying `Allocate` function is
LLVM_ATTRIBUTE_RETURNS_NONNULL).

2 years ago[PDLL] Add a `rewrite` statement to enable complex rewrites
River Riddle [Thu, 16 Dec 2021 01:50:03 +0000 (01:50 +0000)]
[PDLL] Add a `rewrite` statement to enable complex rewrites

The `rewrite` statement allows for rewriting a given root
operation with a block of nested rewriters. The root operation is
not implicitly erased or replaced, and any transformations to it
must be expressed within the nested rewrite block. The inner body
may contain any number of other rewrite statements, variables, or
expressions.

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

2 years ago[PDLL] Add a `replace` rewrite statement for replacing operations
River Riddle [Thu, 16 Dec 2021 01:49:46 +0000 (01:49 +0000)]
[PDLL] Add a `replace` rewrite statement for replacing operations

This statement acts as a companion to the existing `erase`
statement, and is the corresponding PDLL construct for the
`PatternRewriter::replaceOp` C++ API. This statement replaces a
given operation with a set of values.

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

2 years ago[PDLL] Add support for tuple types and expressions
River Riddle [Thu, 16 Dec 2021 01:49:29 +0000 (01:49 +0000)]
[PDLL] Add support for tuple types and expressions

Tuples are used to group multiple elements into a single
compound value. The values in a tuple can be of any type, and
do not need to be of the same type. There is also no limit to
the number of elements held by a tuple.

Tuples will be used to support multiple results from
Constraints and Rewrites (added in a followup), and will also
make it easier to support more complex primitives (such as
range based maps that can operate on multiple values).

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

2 years ago[PDLL] Add support for `op` Operation expressions
River Riddle [Thu, 16 Dec 2021 01:49:11 +0000 (01:49 +0000)]
[PDLL] Add support for `op` Operation expressions

An operation expression in PDLL represents an MLIR operation. In
the match section of a pattern, this expression models one of
the input operations to the pattern. In the rewrite section of
a pattern, this expression models one of the operations to
create. The general structure of the operation expression is very
similar to that of the "generic form" of textual MLIR assembly:

```
let root = op<my_dialect.foo>(operands: ValueRange) {attr = attr: Attr} -> (resultTypes: TypeRange);
```

For now we only model the components that are within PDL, as PDL
gains support for blocks and regions so will this expression.

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

2 years ago[PDLL] Add support for literal Attribute and Type expressions
River Riddle [Thu, 16 Dec 2021 01:48:54 +0000 (01:48 +0000)]
[PDLL] Add support for literal Attribute and Type expressions

This allows for using literal attributes and types within PDLL,
which simplifies building both constraints and rewriters. For
example, checking if an attribute is true is as simple as
`attr<"true">`.

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

2 years ago[PDLL] Add support for parsing pattern metadata
River Riddle [Thu, 16 Dec 2021 01:48:35 +0000 (01:48 +0000)]
[PDLL] Add support for parsing pattern metadata

This allows for overriding the metadata of a pattern and
providing information such as the benefit, bounded recursion,
and more in the future.

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

2 years ago[mlir][PDLL] Add an initial frontend for PDLL
River Riddle [Thu, 16 Dec 2021 01:48:19 +0000 (01:48 +0000)]
[mlir][PDLL] Add an initial frontend for PDLL

This is a new pattern rewrite frontend designed from the ground
up to support MLIR constructs, and to target PDL. This frontend
language was proposed in https://llvm.discourse.group/t/rfc-pdll-a-new-declarative-rewrite-frontend-for-mlir/4798

This commit starts sketching out the base structure of the
frontend, and is intended to be a minimal starting point for
building up the language. It essentially contains support for
defining a pattern, variables, and erasing an operation. The
features mentioned in the proposal RFC (including IDE support)
will be added incrementally in followup commits.

I intend to upstream the documentation for the language in a
followup when a bit more of the pieces have been landed.

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

2 years ago[TSan][Darwin] Fix CheckAndProtect() for MappingAppleAarch64
Julian Lettner [Thu, 16 Dec 2021 01:29:08 +0000 (17:29 -0800)]
[TSan][Darwin] Fix CheckAndProtect() for MappingAppleAarch64

In the new TSan runtime refactoring this line was changed:
```
ProtectRange(MetaShadowEnd(), TraceMemBeg());
-->
ProtectRange(MetaShadowEnd(), HeapMemBeg());
```

But for `MappingAppleAarch64` the app heap comes before the shadow,
resulting in:
```
CHECK failed: tsan_platform_posix.cpp:83 "((beg)) <= ((end))" (0xe00000000, 0x200000000)
```

rdar://86521924

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

2 years ago[ELF] Change Symbol::verdefIndex from uint32_t to uint16_t
Fangrui Song [Thu, 16 Dec 2021 01:59:30 +0000 (17:59 -0800)]
[ELF] Change Symbol::verdefIndex from uint32_t to uint16_t

The SHT_GNU_version index is 16-bit, so the 32-bit value is a waste.
Technically non-default version index 0x7fff uses version index 0xffff,
but it is impossible in practice.

This change decreases sizeof(SymbolUnion) from 80 to 72 on ELF64 platforms.
Memory usage decreases by 1% when linking a large executable.

2 years agoUpdate bazel build rules to match 169ebf03ab2a6f16bfa32a36305929c7bc8e4784.
Richard Smith [Thu, 16 Dec 2021 01:46:22 +0000 (17:46 -0800)]
Update bazel build rules to match 169ebf03ab2a6f16bfa32a36305929c7bc8e4784.

2 years ago[Darwin] Remove workaround for symbolication in iOS simulator runtimes
Julian Lettner [Tue, 14 Dec 2021 23:23:48 +0000 (15:23 -0800)]
[Darwin] Remove workaround for symbolication in iOS simulator runtimes

A while ago we added some code to the sanitizer runtimes for iOS
simulators to allow `atos` (external process) to inspect the sanitized
process during report generation to enable symbolication.  This was done
by setting the `__check_mach_ports_lookup` env var early during process
startup which came with a couple of complications.

This workaround is not required anymore and removing it fixes TSan in
the iOS simulator after the new TSan runtime landed.
(https://reviews.llvm.org/D112603)

Relevant/reverted revisions:
https://reviews.llvm.org/D78178
https://reviews.llvm.org/D78179
https://reviews.llvm.org/D78525

rdar://86472733

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

2 years ago[libc++] Enable the optimized _IsSame on GCC as well as Clang.
Arthur O'Dwyer [Fri, 3 Dec 2021 19:55:57 +0000 (14:55 -0500)]
[libc++] Enable the optimized _IsSame on GCC as well as Clang.

However, there's a problem on both GCC and Clang: they can't mangle
`__is_same(T,U)` if it appears anywhere that affects mangling. That's
a hard error. And it turns out that GCC puts dependent return types
into the mangling more aggressively than Clang, so for GCC's benefit
we need to avoid using raw `_IsSame` in the return type of
`swap(tuple&, tuple&)`. Therefore, make `__all` into a named type
instead of an alias.

If we ever need to support a compiler without the __is_same builtin,
we can make this an alias template for `is_same<T,U>::type`.

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

2 years ago[ELF] Speed up ObjFile<ELFT>::createInputSection
Fangrui Song [Thu, 16 Dec 2021 01:15:31 +0000 (17:15 -0800)]
[ELF] Speed up ObjFile<ELFT>::createInputSection

* Group ".note" section name checks
* Move shouldMerge check to the caller

2 years ago[lld-macho] Make writing map file asynchronous
Vincent Lee [Thu, 9 Dec 2021 02:25:20 +0000 (18:25 -0800)]
[lld-macho] Make writing map file asynchronous

For large applications that write to map files, writing map files can take quite
a bit of time. Sorting the biggest contributors to link times, writing map files
ranks in at 2nd place, with load input files being the biggest contributor of
link times. Avoiding writing map files on the critical path (and having its own
thread) saves ~2-3 seconds when linking chromium framework on a 16-Core
Intel Xeon W.

```
           base            diff            difference (95% CI)
sys_time   1.617 ± 0.034   1.657 ± 0.026   [  +1.5% ..   +3.5%]
user_time  28.536 ± 0.245  28.609 ± 0.180  [  -0.1% ..   +0.7%]
wall_time  23.833 ± 0.271  21.684 ± 0.194  [  -9.5% ..   -8.5%]
samples    31              24
```

Reviewed By: #lld-macho, oontvoo, int3

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

2 years ago[libc++] Reorder a comment pertaining to `struct __two`. NFC.
Arthur O'Dwyer [Thu, 16 Dec 2021 00:21:51 +0000 (19:21 -0500)]
[libc++] Reorder a comment pertaining to `struct __two`. NFC.

2 years ago[ELF] Symbol::replace: remove dead code
Fangrui Song [Thu, 16 Dec 2021 00:08:17 +0000 (16:08 -0800)]
[ELF] Symbol::replace: remove dead code

2 years ago[Verifier] Make error message precise about which variable is being diagnosed.
Yuanfang Chen [Thu, 16 Dec 2021 00:03:16 +0000 (16:03 -0800)]
[Verifier] Make error message precise about which variable is being diagnosed.

NFCI.

2 years ago[gn build] Port 2b4876157562
LLVM GN Syncbot [Wed, 15 Dec 2021 23:47:26 +0000 (23:47 +0000)]
[gn build] Port 2b4876157562

2 years agoAdd a new memory allocation rewrite pass.
Eric Schweitz [Tue, 14 Dec 2021 17:28:53 +0000 (09:28 -0800)]
Add a new memory allocation rewrite pass.

This pass can reclassify memory allocations (fir.alloca, fir.allocmem)
based on heuristics and settings. The intention is to allow better
performance and workarounds for conditions such as environments with
limited stack space.

Currently, implements two conversions from stack to heap allocation.
  1. If a stack allocation is an array larger than some threshold value
     make it a heap allocation.
  2. If a stack allocation is an array with a runtime evaluated size make
     it a heap allocation.

Add a lit test for both suboptions.

Reviewed By: PeteSteinfeld, vdonaldson

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

2 years ago[LTO][WPD] Simplify mustBeUnreachableFunction and test after D115492
Fangrui Song [Wed, 15 Dec 2021 23:43:35 +0000 (15:43 -0800)]
[LTO][WPD] Simplify mustBeUnreachableFunction and test after D115492

An well-formed IR function definition must have an entry basic block and
a well-formed IR basic block must have one terminator so the emptiness
check can be simplified.
Also simplify the test a bit.

Reviewed By: luna

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

2 years ago[gn build] Remove unhelpful default for goma_dir
Nico Weber [Wed, 15 Dec 2021 23:39:21 +0000 (18:39 -0500)]
[gn build] Remove unhelpful default for goma_dir

The default hasn't worked in over 9 months now.

Getting a friendly error message if this isn't set is more useful than getting
a bad default value.

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

2 years agoAMDGPU: Update pass pipeline test
Matt Arsenault [Wed, 15 Dec 2021 23:35:01 +0000 (18:35 -0500)]
AMDGPU: Update pass pipeline test

2 years agoInliner: Correctly merge amdgpu-unsafe-fp-atomics attribute
Matt Arsenault [Sat, 11 Dec 2021 17:04:02 +0000 (12:04 -0500)]
Inliner: Correctly merge amdgpu-unsafe-fp-atomics attribute

It seems we don't have already have any target specific attributes
handled in the inliner. Include a separate tablegen file to define the
rules, similar to the target specific intrinsics.

2 years agoAMDGPU: Add baseline test for unsafe fp atomics attribute inlining
Matt Arsenault [Sat, 11 Dec 2021 17:02:34 +0000 (12:02 -0500)]
AMDGPU: Add baseline test for unsafe fp atomics attribute inlining

2 years ago[ELF] ObjFile<ELFT>::initializeSymbols: avoid StringRefZ from undefined symbols
Fangrui Song [Wed, 15 Dec 2021 23:30:18 +0000 (15:30 -0800)]
[ELF] ObjFile<ELFT>::initializeSymbols: avoid StringRefZ from undefined symbols

2 years agoAMDGPU: Use v_accvgpr_mov_b32 when copying AGPR tuples on gfx90a
Matt Arsenault [Wed, 15 Dec 2021 16:20:33 +0000 (11:20 -0500)]
AMDGPU: Use v_accvgpr_mov_b32 when copying AGPR tuples on gfx90a

This is an optimization, but also fixes a compile failure when no free
VGPRs are available. The problem still exists for gfx908 where a
scratch register is still required. This also still exists for the
SGPR to AGPR case.

2 years agoAMDGPU: Combine is.shared/is.private of null/undef
Matt Arsenault [Mon, 13 Dec 2021 20:55:13 +0000 (15:55 -0500)]
AMDGPU: Combine is.shared/is.private of null/undef

2 years agoAMDGPU: Regenerate checks
Matt Arsenault [Wed, 15 Dec 2021 16:01:03 +0000 (11:01 -0500)]
AMDGPU: Regenerate checks

2 years agoAMDGPU: Remove AMDGPUFixFunctionBitcasts pass
Matt Arsenault [Tue, 14 Dec 2021 22:55:25 +0000 (17:55 -0500)]
AMDGPU: Remove AMDGPUFixFunctionBitcasts pass

This was a workaround for not supporting indirect calls when
instcombine didn't eliminate constant expression casts of the callee
at -O0. Indirect calls are supposed to work now, so drop the hack.

2 years ago[ELF] SymbolTable::insert: keep @@ in the name
Fangrui Song [Wed, 15 Dec 2021 23:19:35 +0000 (15:19 -0800)]
[ELF] SymbolTable::insert: keep @@ in the name

* Avoid the name truncation quirk in SymbolTable::insert: the truncated name will be replaced by @@ again.
* Allow foo and foo@@v1 in different files to be diagnosed as duplicate definition error (GNU ld behavior)
* Avoid potential redundant strlen on symbol name due to StringRefZ in ObjFile<ELFT>::initializeSymbols

2 years ago[clang-format] Remove spurious JSON binding when DisableFormat = true
Andrew Smith [Wed, 15 Dec 2021 23:08:33 +0000 (23:08 +0000)]
[clang-format] Remove spurious JSON binding when DisableFormat = true

Relevant issue: https://github.com/llvm/llvm-project/issues/52705

When the `DisableFormat` option of `clang-format` is set to `true` and a JSON file is formatted, the ephemeral variable binding that is added to the top-level object is not removed from the formatted file.  For example, this JSON:
```
{
  "key": "value"
}
```
Is reformatted to:
```
x = {
  "key": "value"
}
```
Which is not valid JSON syntax.  This fix avoids the addition of this binding when `DisableFormat` is set to `true`, ensuring that it cannot be left behind when formatting is disabled.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks

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

Fixes #52705

2 years ago[clang-format] put non-empty catch block on one line with AllowShortBlocksOnASingleLi...
mydeveloperday [Wed, 15 Dec 2021 23:05:24 +0000 (23:05 +0000)]
[clang-format] put non-empty catch block on one line with AllowShortBlocksOnASingleLine: Empty

https://github.com/llvm/llvm-project/issues/52715

Fixes #52715

`AllowShortBlocksOnASingleLine` seems to never be checked for "Empty" as such if its used it will be considered "Always" as we only ever check `AllowShortBlocksOnASingleLine != Never`

This impacts C++ as well as C# hence the slightly duplicated test.

Reviewed By: curdeius, jbcoe

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

2 years agoRemove redundant check (NFC)
Adrian Prantl [Wed, 15 Dec 2021 22:54:03 +0000 (14:54 -0800)]
Remove redundant check (NFC)

2 years agoUse StringRef instead of char* (NFC)
Adrian Prantl [Wed, 15 Dec 2021 22:48:30 +0000 (14:48 -0800)]
Use StringRef instead of char* (NFC)

2 years ago[NFC] Remove more calls to getAlignment()
Arthur Eubanks [Thu, 9 Dec 2021 21:52:44 +0000 (13:52 -0800)]
[NFC] Remove more calls to getAlignment()

These are deprecated and should be replaced with getAlign().

Some of these asserts don't do anything because Load/Store/AllocaInst never have a 0 align value.

2 years ago[FunctionComparator] Use getAlign() instead of getAlignment()
Arthur Eubanks [Thu, 9 Dec 2021 21:30:44 +0000 (13:30 -0800)]
[FunctionComparator] Use getAlign() instead of getAlignment()

getAlignment() is deprecated.

2 years ago[SafeStack] Use Align instead of uint64_t
Arthur Eubanks [Thu, 9 Dec 2021 21:20:06 +0000 (13:20 -0800)]
[SafeStack] Use Align instead of uint64_t

It is better typed, and the calls to getAlignment() are deprecated.

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

2 years ago[Debuginfod] Fix debuginfod unit test when $HOME is not writable.
Noah Shutty [Wed, 15 Dec 2021 22:13:13 +0000 (22:13 +0000)]
[Debuginfod] Fix debuginfod unit test when $HOME is not writable.

The directory returned from `cache_directory` may not be writable if the unit tests are run with limited permissions (e.g. if $HOME is not writable).
This fixes a unit test of the debuginfod client to set the cache path to the system temporary directory to avoid this issue.

Reviewed By: estewart08

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

2 years ago[MLIR] Simplex: Assert on the restoreRow return value instead of ignoring it
Arjun P [Wed, 15 Dec 2021 21:36:27 +0000 (03:06 +0530)]
[MLIR] Simplex: Assert on the restoreRow return value instead of ignoring it

Previously, the LogicalResult return value of restoreRow was being ignored in
places where it was expected to always be success. Instead, check the result
and go to an `llvm_unreachable` if it turns out to be failure.

2 years ago[mlir][Vector] Further fix to avoid infinite loop in InnerOuterDimReductionConversion
Hanhan Wang [Wed, 15 Dec 2021 21:53:47 +0000 (13:53 -0800)]
[mlir][Vector] Further fix to avoid infinite loop in InnerOuterDimReductionConversion

If all the dims are reduction dims, it is already in inner-most/outer-most
reduction form.

Reviewed By: ThomasRaoux

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

2 years ago[libc++] Implement P0798R8 (Monadic operations for std::optional)
Nikolas Klauser [Wed, 15 Dec 2021 19:54:24 +0000 (20:54 +0100)]
[libc++] Implement P0798R8 (Monadic operations for std::optional)

Implement P0798R8

Reviewed By: #libc, ldionne, Quuxplusone

Spies: tcanens, Quuxplusone, ldionne, Wmbat, arichardson, Mordante, libcxx-commits

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

2 years ago[flang] Avoid code duplication in mixed expressions
Peter Klausler [Mon, 13 Dec 2021 21:53:45 +0000 (13:53 -0800)]
[flang] Avoid code duplication in mixed expressions

Rather than represent the mixed real/complex subexpression x*(a,b)
as (x*a,x*b), use (x,0)*(a,b) to avoid a potential code duplication
in current lowering code.  Same for mixed division, and for mixed
integer*complex and integer/complex cases.

Differential Review: https://reviews.llvm.org/D115732

2 years ago[ELF] Replace make<Defined> with makeDefined. NFC
Fangrui Song [Wed, 15 Dec 2021 21:15:02 +0000 (13:15 -0800)]
[ELF] Replace make<Defined> with makeDefined. NFC

This removes SpecificAlloc<Defined> and makes my lld executable 1.5k smaller.
This drops the small memory waste due to the separate BumpPtrAllocator.

2 years ago[ELF] ObjFile<ELFT>::initializeSymbols: Simplify this->symbols[i]. NFC
Fangrui Song [Wed, 15 Dec 2021 21:02:38 +0000 (13:02 -0800)]
[ELF] ObjFile<ELFT>::initializeSymbols: Simplify this->symbols[i]. NFC

2 years ago[AST] Add more testcases to QualTypeNamesTest. NFC
Sam McCall [Wed, 15 Dec 2021 20:59:54 +0000 (21:59 +0100)]
[AST] Add more testcases to QualTypeNamesTest. NFC

These all currently pass, but are tricky cases not currently covered.
https://reviews.llvm.org/D114251 would break them in its current state.

2 years ago[AST] Fix QualTypeNamesTest, which was spuriously passing
Sam McCall [Wed, 15 Dec 2021 20:53:58 +0000 (21:53 +0100)]
[AST] Fix QualTypeNamesTest, which was spuriously passing

The empty VisitDecl() meant all assertions were skipped.
Meanwhile the assertions have rotted as some type printing has changed.

The test is still in the wrong directory, because it requires TestVisitor.h
which uses Tooling APIs.

2 years ago[ELF] ObjFile<ELFT>::initializeSymbols: Batch allocate local symbols
Fangrui Song [Wed, 15 Dec 2021 20:54:38 +0000 (12:54 -0800)]
[ELF] ObjFile<ELFT>::initializeSymbols: Batch allocate local symbols

and detangle local/global symbol initialization.

My x86-64 lld executable is 8k smaller due to the removal of SpecificAlloc<Undefined>.

2 years ago[clang-format] C# switch expression formatting differs from normal switch formatting
mydeveloperday [Wed, 15 Dec 2021 19:36:22 +0000 (19:36 +0000)]
[clang-format] C# switch expression formatting differs from normal switch formatting

https://github.com/llvm/llvm-project/issues/52677

clang-format doesn't format C# switch expressions very well.

Start with this small use case and try and improve the output. I'll look for other examples to add as tests

Reviewed By: curdeius

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

Fixes  #52677

2 years ago[gn build] Port 8179e1fd519d
LLVM GN Syncbot [Wed, 15 Dec 2021 19:34:58 +0000 (19:34 +0000)]
[gn build] Port 8179e1fd519d

2 years ago[clang][dataflow] Add simplistic constant-propagation analysis.
Yitzhak Mandelbaum [Tue, 14 Dec 2021 17:18:09 +0000 (17:18 +0000)]
[clang][dataflow] Add simplistic constant-propagation analysis.

Adds a very simple constant-propagation analysis for demo and testing purposes.

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

2 years ago[ADT] Add new type traits for type pack indexes
Scott Linder [Tue, 14 Dec 2021 19:27:36 +0000 (19:27 +0000)]
[ADT] Add new type traits for type pack indexes

Similar versions of these already exist, this effectively just just
factors them out into STLExtras. I plan to use these in future patches.

Reviewed By: dblaikie

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

2 years ago[SCEV] Add test where result depends on order loop guards are applied.
Florian Hahn [Wed, 15 Dec 2021 19:07:25 +0000 (19:07 +0000)]
[SCEV] Add test where result depends on order loop guards are applied.

This patch adds 2 test cases where we fail to determine a tight bound on
the backedge taken count because the ULT condition is applied before the
signed conditions. The order the conditions are applied impacts which
min/max folds are applied.

2 years ago[RISCV] Rename Zbs test cases to match instruction names. NFC
Craig Topper [Wed, 15 Dec 2021 19:03:57 +0000 (11:03 -0800)]
[RISCV] Rename Zbs test cases to match instruction names. NFC

The Zbs instructions uses to start with 'sb' but now start with 'b'.
Update test names accordingly.

2 years ago[SLP][NFC] Add a test for inefficient reordering, NFC.
Alexey Bataev [Wed, 15 Dec 2021 19:05:28 +0000 (11:05 -0800)]
[SLP][NFC] Add a test for inefficient reordering, NFC.

2 years ago[ASTMatchers] Make ParamIndex unsigned.
Felix Berger [Wed, 15 Dec 2021 18:35:31 +0000 (13:35 -0500)]
[ASTMatchers] Make ParamIndex unsigned.

This fixes a compiler error/warning in
https://lab.llvm.org/buildbot/#/builders/36/builds/15377.

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

Reviewed-by: sammccall
2 years ago[Sema] Mark explicit specialization declaration in a friend invalid
Yuanfang Chen [Wed, 15 Dec 2021 18:26:52 +0000 (10:26 -0800)]
[Sema] Mark explicit specialization declaration in a friend invalid

Down the path, if there is a implicit instantiation, this may trigger
the assertion "Member specialization must be an explicit specialization"
in `clang::FunctionDecl::setFunctionTemplateSpecialization`.

Reviewed By: aaron.ballman

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

2 years agoRevert "[Sema] Mark explicit specialization declaration in a friend invalid"
Yuanfang Chen [Wed, 15 Dec 2021 18:25:37 +0000 (10:25 -0800)]
Revert "[Sema] Mark explicit specialization declaration in a friend invalid"

This reverts commit 8cb6ecbc4da2b0cfd8dcf04f612dc413716d27a1.

Nothing wrong with the commit. It is missing Phabricator informations.

2 years ago[Sema] Mark explicit specialization declaration in a friend invalid
Yuanfang Chen [Tue, 14 Dec 2021 20:27:07 +0000 (12:27 -0800)]
[Sema] Mark explicit specialization declaration in a friend invalid

Down the path, if there is a implicit instantiation, this may trigger
the assertion "Member specialization must be an explicit specialization"
in `clang::FunctionDecl::setFunctionTemplateSpecialization`.

2 years ago[ELF] Slightly speed up -z keep-text-section-prefix
Fangrui Song [Wed, 15 Dec 2021 18:20:10 +0000 (10:20 -0800)]
[ELF] Slightly speed up -z keep-text-section-prefix

2 years agoTeach the backend to make references to swift_async_extendedFramePointerFlags weak...
Arnold Schwaighofer [Mon, 13 Dec 2021 20:33:15 +0000 (12:33 -0800)]
Teach the backend to make references to swift_async_extendedFramePointerFlags weak if it emits it

When references to the symbol `swift_async_extendedFramePointerFlags`
are emitted they have to be weak.

References to the symbol `swift_async_extendedFramePointerFlags` get
emitted only by frame lowering code. Therefore, the backend needs to track
references to the symbol and mark them weak.

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

2 years ago[libc][NFC][bazel] remove unneeded bzl_library
Guillaume Chatelet [Wed, 15 Dec 2021 17:50:32 +0000 (17:50 +0000)]
[libc][NFC][bazel] remove unneeded bzl_library

2 years ago[InstCombine] (~a & b & c) | ~(a | b) -> (c | ~b) & ~a
Stanislav Mekhanoshin [Wed, 15 Dec 2021 17:17:25 +0000 (09:17 -0800)]
[InstCombine] (~a & b & c) | ~(a | b) -> (c | ~b) & ~a

Transform
```
(~a & b & c) | ~(a | b) -> (c | ~b) & ~a
```
and swapped case
```
(~a | b | c) & ~(a & b) -> (c & ~b) | ~a
```

```
----------------------------------------
define i4 @src(i4 %a, i4 %b, i4 %c) {
%0:
  %or1 = or i4 %b, %a
  %not1 = xor i4 %or1, 15
  %not2 = xor i4 %a, 15
  %and1 = and i4 %b, %not2
  %and2 = and i4 %and1, %c
  %or2 = or i4 %and2, %not1
  ret i4 %or2
}
=>
define i4 @tgt(i4 %a, i4 %b, i4 %c) {
%0:
  %notb = xor i4 %b, 15
  %or = or i4 %notb, %c
  %nota = xor i4 %a, 15
  %and = and i4 %or, %nota
  ret i4 %and
}
Transformation seems to be correct!
```

```
----------------------------------------
define i4 @src(i4 %a, i4 %b, i4 %c) {
%0:
  %and1 = and i4 %b, %a
  %not1 = xor i4 %and1, 15
  %not2 = xor i4 %a, 15
  %or1 = or i4 %b, %not2
  %or2 = or i4 %or1, %c
  %and2 = and i4 %or2, %not1
  ret i4 %and2
}
=>
define i4 @tgt(i4 %a, i4 %b, i4 %c) {
%0:
  %notb = xor i4 %b, 15
  %and = and i4 %notb, %c
  %nota = xor i4 %a, 15
  %or = or i4 %and, %nota
  ret i4 %or
}
Transformation seems to be correct!
```

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

2 years ago[clang] ASTMatchers: Fix out-of-bounds access in foreachArgumentWithParamType.
Felix Berger [Wed, 24 Nov 2021 18:45:36 +0000 (13:45 -0500)]
[clang] ASTMatchers: Fix out-of-bounds access in foreachArgumentWithParamType.

The matcher crashes when a variadic function pointer is invoked because the
FunctionProtoType has fewer parameters than arguments.

Matching of non-variadic arguments now works.

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

Reviewed-by: sammccall
2 years ago[WebAssembly] Add simd-vector-trunc.ll test missing from 2a4a229
Jing Bao [Wed, 15 Dec 2021 17:22:40 +0000 (09:22 -0800)]
[WebAssembly] Add simd-vector-trunc.ll test missing from 2a4a229

This test was authored as part of the same revision, D109481, but I (tlively)
accidentally left it out when committing.

2 years ago[clang] Require x86 target for tbaa test
David Spickett [Wed, 15 Dec 2021 16:39:00 +0000 (16:39 +0000)]
[clang] Require x86 target for tbaa test

Added in https://reviews.llvm.org/D115320.
Failing on our bots that only build Arm/AArch64 targets:
https://lab.llvm.org/buildbot/#/builders/188/builds/6951

2 years ago[mlir] Flip Complex & SCF dialects to _Both (NFC)
Jacques Pienaar [Wed, 15 Dec 2021 16:21:38 +0000 (08:21 -0800)]
[mlir] Flip Complex & SCF dialects to _Both (NFC)

Following
https://llvm.discourse.group/t/psa-ods-generated-accessors-will-change-to-have-a-get-prefix-update-you-apis/4476

2 years ago[clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword...
Markus Böck [Wed, 15 Dec 2021 15:59:04 +0000 (16:59 +0100)]
[clang-tidy][#51939] Exempt placement-new expressions from 'bugprone-throw-keyword-missing'

The purpose of this checker is to flag a missing throw keyword, and does so by checking for the construction of an exception class that is then unused.
This works great except that placement new expressions are also flagged as those lead to the construction of an object as well, even though they are not temporary (as that is dependent on the storage).
This patch fixes the issue by exempting the match if it is within a placement-new.

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

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

2 years ago[LoopUnroll] Disable loop unroll when user explicitly asks for unroll-and-jam
Zaara Syeda [Wed, 15 Dec 2021 15:31:45 +0000 (15:31 +0000)]
[LoopUnroll] Disable loop unroll when user explicitly asks for unroll-and-jam

If a loop isn't forced to be unrolled, we want to avoid unrolling it when there
is an explicit unroll-and-jam pragma. This is to prevent automatic unrolling
from interfering with the user requested transformation.
Missed adding the testcase in earlier commit.

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

2 years ago[clang][deps] NFC: Move entry initialization into member functions
Jan Svoboda [Tue, 14 Dec 2021 11:36:59 +0000 (12:36 +0100)]
[clang][deps] NFC: Move entry initialization into member functions

This is a prep-patch for making `CachedFileSystemEntry` initialization more lazy.

2 years ago[OpenMP] Increase opportunity for parallel kernel launch in AMDGPUs: add multiple...
Carlo Bertolli [Wed, 15 Dec 2021 15:33:17 +0000 (15:33 +0000)]
[OpenMP] Increase opportunity for parallel kernel launch in AMDGPUs: add multiple hsa queue's per device in plugin
This patch extends the AMDGPU plugin for OpenMP target offloading from using a single HSA queue to multiple queues (four in this patch) per device. This enables concurrent threads to concurrently submit kernel launches to the same GPU.

Reviewed By: JonChesterfield

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

2 years ago[clang][deps] NFC: Use clearer wording around entry initialization
Jan Svoboda [Fri, 10 Dec 2021 13:16:29 +0000 (14:16 +0100)]
[clang][deps] NFC: Use clearer wording around entry initialization

The code and documentation around `CachedFileSystemEntry` use the following terms:
* "invalid stat" for `llvm::ErrorOr<llvm::vfs::Status>` that is *not* an error and contains an unknown status,
* "initialized entry" for an entry that contains "invalid stat",
* "valid entry" for an entry that contains "invalid stat", synonymous to "initialized" entry.

Having an entry be "valid" while it contains an "invalid" status object is counter-intuitive.
This patch cleans up the wording by referring to the status as "unknown" and to the entry as either "initialized" or "uninitialized".

2 years ago[AMDGPU] Extract helper function in AsmParser. NFC
Joe Nash [Tue, 14 Dec 2021 19:28:42 +0000 (14:28 -0500)]
[AMDGPU] Extract helper function in AsmParser. NFC

NFC refactor to extract useful helper function isRegOrInline.

Reviewed By: rampitec, dp

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

Change-Id: Ief52db9a62615c053fb5f429248657b97cb41453

2 years ago[mlir][scf] Add getNumRegionInvocations to IfOp
Mogball [Wed, 15 Dec 2021 06:42:36 +0000 (06:42 +0000)]
[mlir][scf] Add getNumRegionInvocations to IfOp

Implements the RegionBranchOpInterface method getNumRegionInvocations to `scf::IfOp` so that, when the condition is constant, the number of region executions can be analyzed by `NumberOfExecutions`.

Reviewed By: jpienaar, ftynse

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