platform/upstream/llvm.git
3 years ago[flang][nfc] Simplify CMake
Andrzej Warzynski [Mon, 12 Jul 2021 14:55:47 +0000 (14:55 +0000)]
[flang][nfc] Simplify CMake

Folds `list(APPEND <list> [<element>...])` into the definition of
`<list>`.

3 years ago[mlir][tosa] Added more shape inference for tosa ops
Rob Suderman [Sat, 3 Jul 2021 00:00:20 +0000 (17:00 -0700)]
[mlir][tosa] Added more shape inference for tosa ops

Added shape inference for:
- scatter
- gather
- transpose
- slice
- pad
- concat
- reduction operations

Also updated reshape for more aggressive shape inference.

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

3 years ago[test] Move AMDGPU reloc test from Object to tools/llvm-readobj and simplify it
Fangrui Song [Mon, 12 Jul 2021 17:04:31 +0000 (10:04 -0700)]
[test] Move AMDGPU reloc test from Object to tools/llvm-readobj and simplify it

We already have some reloc-types-elf-*.test serving the similar purpose.

Reviewed By: jhenderson

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

3 years ago[AIX] Emit version string in .file directive
Jinsong Ji [Mon, 12 Jul 2021 03:37:06 +0000 (03:37 +0000)]
[AIX] Emit version string in .file directive

AIX .file directive support including compiler version string.
https://www.ibm.com/docs/en/aix/7.2?topic=ops-file-pseudo-op

This patch adds the support so that it will be easier to identify build
compiler in objects.

Reviewed By: #powerpc, shchenz

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

3 years ago[ARM] Expand types in VQDMULH tests. NFC
David Green [Mon, 12 Jul 2021 16:56:11 +0000 (17:56 +0100)]
[ARM] Expand types in VQDMULH tests. NFC

3 years ago[OpenMP] Remove TSAN annotations from libomp
Joachim Protze [Fri, 4 Jun 2021 12:05:05 +0000 (14:05 +0200)]
[OpenMP] Remove TSAN annotations from libomp

The annotations in libomp were never built by default. The annotations are
also superseded by the annotations which the OMPT tool libarcher.so provides.
With respect to libarcher, libomp behaves as if libarcher would be the last
element of OMP_TOOL_LIBARARIES. I.e., if no other OMPT tool gets active,
libarcher will check if an OpenMP application is built with TSan.

Since libarcher gets loaded by default, enabling LIBOMP_TSAN_SUPPORT would
result in redundant annotations for TSan, which slightly differ in details
and coverage (e.g. task dependencies are not handled well by the annotations
in libomp).

This patch removes all TSan annotations from the OpenMP runtime code.

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

3 years ago[libc++] Remove random [[nodiscard]] in the test suite
Louis Dionne [Mon, 12 Jul 2021 16:31:51 +0000 (12:31 -0400)]
[libc++] Remove random [[nodiscard]] in the test suite

3 years ago[PowerPC] Implement trap and conversion builtins for XL compatibility
Albion Fung [Mon, 12 Jul 2021 03:16:27 +0000 (22:16 -0500)]
[PowerPC] Implement trap and conversion builtins for XL compatibility

This patch implements trap and FP to and from double conversions. The builtins
generate code that mirror what is generated from the XL compiler. Intrinsics
are named conventionally with builtin_ppc, but are aliased to provide the same
builtin names as the XL compiler.

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

3 years ago[llvm-objcopy] Improve performance of long pattern lists
Fangrui Song [Mon, 12 Jul 2021 16:03:33 +0000 (09:03 -0700)]
[llvm-objcopy] Improve performance of long pattern lists

Some users use a long list of fixed patterns (PR50404) and
O(|patterns|*|symbols|) can be too slow. Such usage typically does not use
--regex or --wildcard. We can use a DenseSet<CachedHashStringRef> to optimize
name lookups.

Reviewed By: jhenderson

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

3 years agosanitizer_common: Suppress another thread safety warning
Benjamin Kramer [Mon, 12 Jul 2021 15:55:49 +0000 (17:55 +0200)]
sanitizer_common: Suppress another thread safety warning

Another follow-up to 0da172b1766e1559ef677aa836dce4f1995dfef3

compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'CandidateTSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:95:21: note: mutex acquired here
      CandidateTSD->lock();
                    ^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'TSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:101:8: note: mutex acquired here
  TSD->lock();
       ^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'TSDs[Index].Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:80:23: note: mutex acquired here
      if (TSDs[Index].tryLock()) {
                      ^

3 years agosanitizer_common: Fix the build for platforms that use shared TSDs
Benjamin Kramer [Mon, 12 Jul 2021 15:47:46 +0000 (17:47 +0200)]
sanitizer_common: Fix the build for platforms that use shared TSDs

Looks like an oversight in 0da172b1766e1559ef677aa836dce4f1995dfef3

compiler-rt/lib/scudo/scudo_tsd_shared.inc:53:1: error: mutex 'TSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.inc:49:12: note: mutex acquired here
  if (TSD->tryLock())
           ^

3 years ago[langref] attempt to clarify semantics of inttoptr/ptrtoint for non-integral types
Philip Reames [Mon, 12 Jul 2021 15:47:42 +0000 (08:47 -0700)]
[langref] attempt to clarify semantics of inttoptr/ptrtoint for non-integral types

In review discussion on D104322, Eli and Roman quite reasonable raised concerns about the LangRef not really providing a precise definition for inttoptr/ptrtoint on non-integral types. These had previously been disallowed, but I'd pragmatically allowed them in ac81cb7e6. This is my attempt to improve the situation.

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

3 years ago[Altivec] Use signed comparison for vec_all_* and vec_any_* interfaces
Bardia Mahjour [Mon, 12 Jul 2021 15:41:16 +0000 (11:41 -0400)]
[Altivec] Use signed comparison for vec_all_* and vec_any_* interfaces

We are currently being inconsistent in using signed vs unsigned comparisons for
vec_all_* and vec_any_* interfaces that use vector bool types. For example we
use signed comparison for vec_all_ge(vector signed char, vector bool char) but
unsigned comparison for when the arguments are swapped. GCC and XL use signed
comparison instead. This patch makes clang consistent with itself and with XL
and GCC.

Reviewed By: nemanjai

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

3 years agoReland "[clang-repl] Implement partial translation units and error recovery."
Vassil Vassilev [Mon, 12 Jul 2021 13:35:20 +0000 (13:35 +0000)]
Reland "[clang-repl] Implement partial translation units and error recovery."

Original commit message:

[clang-repl] Implement partial translation units and error recovery.

https://reviews.llvm.org/D96033 contained a discussion regarding efficient
modeling of error recovery. @rjmccall has outlined the key ideas:

Conceptually, we can split the translation unit into a sequence of partial
translation units (PTUs). Every declaration will be associated with a unique PTU
that owns it.

The first key insight here is that the owning PTU isn't always the "active"
(most recent) PTU, and it isn't always the PTU that the declaration
"comes from". A new declaration (that isn't a redeclaration or specialization of
anything) does belong to the active PTU. A template specialization, however,
belongs to the most recent PTU of all the declarations in its signature - mostly
that means that it can be pulled into a more recent PTU by its template
arguments.

The second key insight is that processing a PTU might extend an earlier PTU.
Rolling back the later PTU shouldn't throw that extension away. For example, if
the second PTU defines a template, and the third PTU requires that template to
be instantiated at float, that template specialization is still part of the
second PTU. Similarly, if the fifth PTU uses an inline function belonging to the
fourth, that definition still belongs to the fourth. When we go to emit code in
a new PTU, we map each declaration we have to emit back to its owning PTU and
emit it in a new module for just the extensions to that PTU. We keep track of
all the modules we've emitted for a PTU so that we can unload them all if we
decide to roll it back.

Most declarations/definitions will only refer to entities from the same or
earlier PTUs. However, it is possible (primarily by defining a
previously-declared entity, but also through templates or ADL) for an entity
that belongs to one PTU to refer to something from a later PTU. We will have to
keep track of this and prevent unwinding to later PTU when we recognize it.
Fortunately, this should be very rare; and crucially, we don't have to do the
bookkeeping for this if we've only got one PTU, e.g. in normal compilation.
Otherwise, PTUs after the first just need to record enough metadata to be able
to revert any changes they've made to declarations belonging to earlier PTUs,
e.g. to redeclaration chains or template specialization lists.

It should even eventually be possible for PTUs to provide their own slab
allocators which can be thrown away as part of rolling back the PTU. We can
maintain a notion of the active allocator and allocate things like Stmt/Expr
nodes in it, temporarily changing it to the appropriate PTU whenever we go to do
something like instantiate a function template. More care will be required when
allocating declarations and types, though.

We would want the PTU to be efficiently recoverable from a Decl; I'm not sure
how best to do that. An easy option that would cover most declarations would be
to make multiple TranslationUnitDecls and parent the declarations appropriately,
but I don't think that's good enough for things like member function templates,
since an instantiation of that would still be parented by its original class.
Maybe we can work this into the DC chain somehow, like how lexical DCs are.

We add a different kind of translation unit `TU_Incremental` which is a
complete translation unit that we might nonetheless incrementally extend later.
Because it is complete (and we might want to generate code for it), we do
perform template instantiation, but because it might be extended later, we don't
warn if it declares or uses undefined internal-linkage symbols.

This patch teaches clang-repl how to recover from errors by disconnecting the
most recent PTU and update the primary PTU lookup tables. For instance:

```./clang-repl
clang-repl> int i = 12; error;
In file included from <<< inputs >>>:1:
input_line_0:1:13: error: C++ requires a type specifier for all declarations
int i = 12; error;
            ^
error: Parsing failed.
clang-repl> int i = 13; extern "C" int printf(const char*,...);
clang-repl> auto r1 = printf("i=%d\n", i);
i=13
clang-repl> quit
```

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

3 years ago[SelectionDAG] Simplify PromoteIntRes_INSERT_SUBVECTOR to only handle result
Bradley Smith [Thu, 8 Jul 2021 11:28:38 +0000 (11:28 +0000)]
[SelectionDAG] Simplify PromoteIntRes_INSERT_SUBVECTOR to only handle result

Let other parts of legalization handle the rest of the node, this allows
re-use of existing optimizations elsewhere.

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

3 years ago[lld/mac] Make tbd files in one test valid
Nico Weber [Mon, 12 Jul 2021 15:12:11 +0000 (11:12 -0400)]
[lld/mac] Make tbd files in one test valid

No behavior change, but ld64 can't load .tbd files without the
trailing `...`, so include them to make it easier to run tests
with l64 too.

3 years ago[libc++] Test on Clang ToT by default
Louis Dionne [Mon, 12 Jul 2021 15:10:59 +0000 (11:10 -0400)]
[libc++] Test on Clang ToT by default

This is what ffccf96e90d6b should have enabled, however the symlink
in the Docker image was not pointing to the right compiler, so we were
testing with Clang 12 instead of ToT.

3 years ago[SLP] add test for multiple logical reductions; NFC
Sanjay Patel [Mon, 12 Jul 2021 13:49:59 +0000 (09:49 -0400)]
[SLP] add test for multiple logical reductions; NFC

More coverage for:
D105730

3 years agosanitizer_common: support printing __m128i type
Dmitry Vyukov [Mon, 10 May 2021 13:35:14 +0000 (15:35 +0200)]
sanitizer_common: support printing __m128i type

__m128i is vector SSE type used in tsan.
It's handy to be able to print it for debugging.

Reviewed By: vitalybuka

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

3 years agoRemove unused parameter from parseMSInlineAsm.
Simon Tatham [Mon, 12 Jul 2021 14:05:12 +0000 (15:05 +0100)]
Remove unused parameter from parseMSInlineAsm.

No implementation uses the `LocCookie` parameter at all. Errors are
reported from inside that function by `llvm::SourceMgr`, and the
instance of that at the clang call site arranges to pass the error
messages back to a `ClangAsmParserCallback`, which is where the clang
SourceLocation for the error is computed.

(This is part of a patch series working towards the ability to make
SourceLocation into a 64-bit type to handle larger translation units.
But this particular change seems beneficial in its own right.)

Reviewed By: miyuki

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

3 years ago[analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by...
Abbas Sabra [Mon, 12 Jul 2021 14:04:56 +0000 (17:04 +0300)]
[analyzer] LoopUnrolling: fix crash when a loop counter is captured in a lambda by reference

Reviewed By: vsavchenko

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

3 years ago[AArch64] Silence unused variable warning. NFC.
Benjamin Kramer [Mon, 12 Jul 2021 14:01:11 +0000 (16:01 +0200)]
[AArch64] Silence unused variable warning. NFC.

AArch64ISelLowering.cpp:15167:8: warning: unused variable 'OpCode' [-Wunused-variable]
  auto OpCode = N->getOpcode();
       ^

3 years ago[libc++] NFC: Fix synopsis comments and sort includes in ranges
Louis Dionne [Mon, 12 Jul 2021 13:54:53 +0000 (09:54 -0400)]
[libc++] NFC: Fix synopsis comments and sort includes in ranges

3 years ago[clang-tidy] performance-unnecessary-copy-initialization: Disable structured bindings.
Felix Berger [Fri, 9 Jul 2021 19:53:40 +0000 (15:53 -0400)]
[clang-tidy] performance-unnecessary-copy-initialization: Disable structured bindings.

Structured bindings can currently trigger the check and lead to a wrong
fix. Because the DecompositionDecl itself is not used and the check does not
iterate through its the decl's bindings to verify whether the bindings' holding
vars are used this leads to the whole statement to be deleted.

To support structured bindings properly 3 cases would need to be considered.

  1. All holding vars are not used -> The statement can be deleted.
  2. All holding vars are used as const or not used -> auto can be converted to const auto&.
  3. Neither case is true -> leave unchanged.

In the check we'll have to separate the logic that determines this from the code
that produces the diagnostic and fixes and first determine which of the cases
we're dealing with before creating fixes.

Since this is a bigger refactoring we'll disable structured bindings for now to
prevent incorrect fixes.

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

Reviewed-by: ymandel
3 years agosanitizer_common: allow COMMON_INTERCEPTOR_ENTER to use labels
Dmitry Vyukov [Sun, 11 Jul 2021 12:25:40 +0000 (14:25 +0200)]
sanitizer_common: allow COMMON_INTERCEPTOR_ENTER to use labels

The memcpy interceptor is the only one that uses COMMON_INTERCEPTOR_ENTER
more than once in a single function. This does not allow COMMON_INTERCEPTOR_ENTER
to use labels, because they are global for the whole function (not block scoped).
Don't include COMMON_INTERCEPTOR_ENTER code twice.

Reviewed By: melver

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

3 years ago[lldb][NFC] Use ArrayRef in TypeSystemClang::SetFunctionParameters
Raphael Isemann [Mon, 12 Jul 2021 13:16:44 +0000 (15:16 +0200)]
[lldb][NFC] Use ArrayRef in TypeSystemClang::SetFunctionParameters

The implementation converts the pointer/size pair anyway back to ArrayRef.

3 years ago[MLIR][StandardToLLVM] Move `copyUnrankedDescriptors` to pattern
Frederik Gossen [Mon, 12 Jul 2021 13:14:25 +0000 (15:14 +0200)]
[MLIR][StandardToLLVM] Move `copyUnrankedDescriptors` to pattern

Make the function `copyUnrankedDescriptors` accessible in
`ConvertToLLVMPattern`.

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

3 years ago[AArch64] Add target features for Armv9-A Scalable Matrix Extension (SME)
Cullen Rhodes [Mon, 12 Jul 2021 10:58:36 +0000 (10:58 +0000)]
[AArch64] Add target features for Armv9-A Scalable Matrix Extension (SME)

First patch in a series adding MC layer support for the Arm Scalable
Matrix Extension.

This patch adds the following features:

    sme, sme-i64, sme-f64

The sme-i64 and sme-f64 flags are for the optional I16I64 and F64F64
features.

If a target supports I16I64 then the following instructions are
implemented:

  * 64-bit integer ADDHA and ADDVA variants (D105570).
  * SMOPA, SMOPS, SUMOPA, SUMOPS, UMOPA, UMOPS, USMOPA, and USMOPS
    instructions that accumulate 16-bit integer outer products into 64-bit
    integer tiles.

If a target supports F64F64 then the FMOPA and FMOPS instructions that
accumulate double-precision floating-point outer products into
double-precision tiles are implemented.

Outer products are implemented in D105571.

The reference can be found here:
https://developer.arm.com/documentation/ddi0602/2021-06

Reviewed By: CarolineConcatto

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

3 years agoFix warning '-Wparentheses'. NFC.
Michael Liao [Mon, 12 Jul 2021 13:23:59 +0000 (09:23 -0400)]
Fix warning '-Wparentheses'. NFC.

3 years ago[SystemZ] Bugfix for the 'N' code for inline asm operand.
Jonas Paulsson [Sat, 10 Jul 2021 09:15:12 +0000 (11:15 +0200)]
[SystemZ]  Bugfix for the 'N' code for inline asm operand.

Don't use a local MachineOperand copy in SystemZAsmPrinter::PrintAsmOperand()
and change the register as it may break the MRI tracking of register
uses. Use an MCOperand instead.

Review: Ulrich Weigand

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

3 years ago[InstCombine] reduce signbit test of logic ops to cmp with zero
Sanjay Patel [Mon, 12 Jul 2021 12:58:05 +0000 (08:58 -0400)]
[InstCombine] reduce signbit test of logic ops to cmp with zero

This is the pattern from the description of:
https://llvm.org/PR50816

There might be a way to generalize this to a smaller or more
generic pattern, but I have not found it yet.

https://alive2.llvm.org/ce/z/ShzJoF

define i1 @src(i8 %x) {
  %add = add i8 %x, -1
  %xor = xor i8 %x, -1
  %and = and i8 %add, %xor
  %r = icmp slt i8 %and, 0
  ret i1 %r
}

define i1 @tgt(i8 %x) {
  %r = icmp eq i8 %x, 0
  ret i1 %r
}

3 years ago[InstCombine][tests] add tests for signbit + logic; NFC
Sanjay Patel [Mon, 12 Jul 2021 12:43:29 +0000 (08:43 -0400)]
[InstCombine][tests] add tests for signbit + logic; NFC

PR50816

3 years ago[mlir][linalg][python] Add auto-generated file warning (NFC).
Tobias Gysi [Mon, 12 Jul 2021 12:31:30 +0000 (12:31 +0000)]
[mlir][linalg][python] Add auto-generated file warning (NFC).

Annotate LinalgNamedStructuredOps.yaml with a comment stating the file is auto-generated and should not be edited manually.

Reviewed By: nicolasvasilache

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

3 years ago[CostModel][X86] Adjust truncate SSE/AVX legalized costs based on llvm-mca reports.
Simon Pilgrim [Mon, 12 Jul 2021 11:29:35 +0000 (12:29 +0100)]
[CostModel][X86] Adjust truncate SSE/AVX legalized costs based on llvm-mca reports.

Update truncation costs based on the worst case costs from the script in D103695.

Move to using legalized types wherever possible, which allows us to prune the cost tables.

3 years ago[gn build] port 0da172b1766e more
Nico Weber [Mon, 12 Jul 2021 12:50:11 +0000 (08:50 -0400)]
[gn build] port 0da172b1766e more

3 years ago[AArch64] Set the latency of Cortex-A55 stores to 1
David Green [Mon, 12 Jul 2021 12:39:21 +0000 (13:39 +0100)]
[AArch64] Set the latency of Cortex-A55 stores to 1

This sets the latency of stores to 1 in the Cortex-A55 scheduling model,
to better match the values given in the software optimization guide.

The latency of a store in normal llvm scheduling does not appear to have
a lot of uses. If the store has no outputs then the latency is somewhat
meaningless (and pre/post increment update operands use the WriteAdr
write for those operands instead). The one place it does alter things is
the latency between a store and the end of the scheduling region, which
can in turn have an effect on the critical path length. As a result a
latency of 1 is more correct and offers ever-so-slightly better
scheduling of instructions near the end of the block.

They are marked as RetireOOO to keep the llvm-mca from introducing
stalls where non would exist.

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

3 years ago[gn build] (semi-manually) port 0da172b1766e
Nico Weber [Mon, 12 Jul 2021 12:15:59 +0000 (08:15 -0400)]
[gn build] (semi-manually) port 0da172b1766e

3 years agoPartially implement P1401R5 (Narrowing contextual conversions to bool)
Corentin Jabot [Mon, 12 Jul 2021 12:03:51 +0000 (08:03 -0400)]
Partially implement P1401R5 (Narrowing contextual conversions to bool)

Support Narrowing conversions to bool in if constexpr condition
under C++23 language mode.

Only if constexpr is implemented as the behavior of static_assert
is already conforming. Still need to work on explicit(bool) to
complete support.

3 years agosanitizer_common: fix 32-bit build
Dmitry Vyukov [Mon, 12 Jul 2021 11:57:14 +0000 (13:57 +0200)]
sanitizer_common: fix 32-bit build

https://reviews.llvm.org/D105716 enabled thread safety annotations,
and that broke 32-bit build:
https://green.lab.llvm.org/green/job/lldb-cmake/33604/consoleFull#-77815080549ba4694-19c4-4d7e-bec5-911270d8a58c

1. Enable thread-safety analysis in unit tests
(this catches the breakage even in 64-bit mode).
2. Add NO_THREAD_SAFETY_ANALYSIS to sanitizer_allocator_primary32.h
to unbreak the build.

Reviewed By: melver

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

3 years agoFix the Clang documentation builder; NFC.
Aaron Ballman [Mon, 12 Jul 2021 11:58:06 +0000 (07:58 -0400)]
Fix the Clang documentation builder; NFC.

It was broken three days ago by the changes in D95561.

3 years ago[lldb/Target] Fix event handling during process launch
Med Ismail Bennani [Mon, 12 Jul 2021 11:32:07 +0000 (12:32 +0100)]
[lldb/Target] Fix event handling during process launch

This patch fixes process event handling when the events are broadcasted
at launch. To do so, the patch introduces a new listener to fetch events
by hand off the event queue and then resending them ensure the event ordering.

Differental Revision: https://reviews.llvm.org/D105698

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
3 years ago[RS4GC] Use one DVCache for both inlineGetBaseAndOffset() and insertParsePoints()
Yevgeny Rouban [Mon, 12 Jul 2021 11:06:06 +0000 (18:06 +0700)]
[RS4GC] Use one DVCache for both inlineGetBaseAndOffset() and insertParsePoints()

This new test demonstrates a case where a base ptr is generated
twice for the same value: the first one is generated while
the gc.get.pointer.base() is inlined, the second is generated
for the statepoint. This happens because the methods
inlineGetBaseAndOffset() and insertParsePoints() do not share
their defining value cache used by the findBasePointer() method.

Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D103240

3 years ago[RS4GC] Add a test to demonstrate duplication of base generation. NFC
Yevgeny Rouban [Mon, 12 Jul 2021 10:35:10 +0000 (17:35 +0700)]
[RS4GC] Add a test to demonstrate duplication of base generation. NFC

This new test demonstrates a case where a base ptr is generated
twice for the same value: the first one is generated while
the gc.get.pointer.base() is inlined, the second is generated
for the statepoint. This happens because the methods
inlineGetBaseAndOffset() and insertParsePoints() do not share
their defining value cache used by the findBasePointer() method.

Reviewed By: reames
Differential Revision: https://reviews.llvm.org/D103238

3 years ago[PowerPC] Fix rounding mode for vec_round in altivec.h
Nemanja Ivanovic [Mon, 12 Jul 2021 10:49:12 +0000 (05:49 -0500)]
[PowerPC] Fix rounding mode for vec_round in altivec.h

The function is supposed to be the equivalent of rint() (as in
round to nearest, ties to even) rather than round() (round to
nearest, ties away from zero). In fact, the instruction we emit
without VSX is vrfin which is correct. However, with VSX we emit
xvrspi which is the equivalent of round() and therefore incorrect.
Since there is no equivalent VSX instruction, simply use vrfin
regardless of availability of VSX.

3 years agosanitizer_common: make sem_trywait as non-blocking
Dmitry Vyukov [Sun, 11 Jul 2021 12:43:31 +0000 (14:43 +0200)]
sanitizer_common: make sem_trywait as non-blocking

sem_trywait never blocks.
Use REAL instead of COMMON_INTERCEPTOR_BLOCK_REAL.

Reviewed By: melver

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

3 years agosanitizer_common: remove debugging logic from the internal allocator
Dmitry Vyukov [Sun, 11 Jul 2021 12:51:58 +0000 (14:51 +0200)]
sanitizer_common: remove debugging logic from the internal allocator

The internal allocator adds 8-byte header for debugging purposes.
The problem with it is that it's not possible to allocate nicely-sized
objects without a significant overhead. For example, if we allocate
512-byte objects, that will be rounded up to 768 or something.
This logic migrated from tsan where it was added during initial development,
I don't remember that it ever caught anything (we don't do bugs!).
Remove it so that it's possible to allocate nicely-sized objects
without overheads.

Reviewed By: melver

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

3 years ago[OpenMP] Support OpenMP 5.1 attributes
Aaron Ballman [Mon, 12 Jul 2021 10:51:19 +0000 (06:51 -0400)]
[OpenMP] Support OpenMP 5.1 attributes

OpenMP 5.1 added support for writing OpenMP directives using [[]]
syntax in addition to using #pragma and this introduces support for the
new syntax.

In OpenMP, the attributes take one of two forms:
[[omp::directive(...)]] or [[omp::sequence(...)]]. A directive
attribute contains an OpenMP directive clause that is identical to the
analogous #pragma syntax. A sequence attribute can contain either
sequence or directive arguments and is used to ensure that the
attributes are processed sequentially for situations where the order of
the attributes matter (remember:
https://eel.is/c++draft/dcl.attr.grammar#4.sentence-4).

The approach taken here is somewhat novel and deserves mention. We
could refactor much of the OpenMP parsing logic to work for either
pragma annotation tokens or for attribute clauses. It would be a fair
amount of effort to share the logic for both, but it's certainly
doable. However, the semantic attribute system is not designed to
handle the arbitrarily complex arguments that OpenMP directives
contain. Adding support to thread the novel parsed information until we
can produce a semantic attribute would be considerably more effort.
What's more, existing OpenMP constructs are not (often) represented as
semantic attributes. So doing this through Attr.td would be a massive
undertaking that would likely only benefit OpenMP and comes with
additional risks. Rather than walk down that path, I am taking
advantage of the fact that the syntax of the directives within the
directive clause is identical to that of the #pragma form. Once the
parser recognizes that we're processing an OpenMP attribute, it caches
all of the directive argument tokens and then replays them as though
the user wrote a pragma. This reuses the same OpenMP parsing and
semantic logic directly, but does come with a risk if the OpenMP
committee decides to purposefully diverge their pragma and attribute
syntaxes. So, despite this being a novel approach that does token
replay, I think it's actually a better approach than trying to do this
through the declarative syntax in Attr.td.

3 years ago[mlir][Linalg] Improve comprehensive bufferization for scf.yield.
Nicolas Vasilache [Mon, 12 Jul 2021 10:10:26 +0000 (10:10 +0000)]
[mlir][Linalg] Improve comprehensive bufferization for scf.yield.

Previously, comprehensive bufferization of scf.yield did not have enough information
to detect whether an enclosing scf::for bbargs would bufferize to a buffer equivalent
to that of the matching scf::yield operand.
As a consequence a separate sanity check step would be required to determine whether
bufferization occured properly.
This late check would miss the case of calling a function in an loop.

Instead, we now pass and update aliasInfo during bufferization and it is possible to
imrpove bufferization of scf::yield and drop that post-pass check.

Add an example use case that was failing previously.
This slightly modifies the error conditions, which are also updated as part of this
revision.

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

3 years agosanitizer_common: use 0 for empty stack id
Dmitry Vyukov [Sun, 11 Jul 2021 12:46:09 +0000 (14:46 +0200)]
sanitizer_common: use 0 for empty stack id

We use 0 for empty stack id from stack depot.
Deadlock detector 1 is the only place that uses -1
as a special case. Use 0 because there is a number
of checks of the form "if (stack id) ...".

Reviewed By: melver

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

3 years ago[llvm][sve] Lowering for VLS truncating stores
David Truby [Mon, 12 Jul 2021 09:55:11 +0000 (10:55 +0100)]
[llvm][sve] Lowering for VLS truncating stores

This adds custom lowering for truncating stores when operating on
fixed length vectors in SVE. It also includes a DAG combine to
fold extends followed by truncating stores into non-truncating
stores in order to prevent this pattern appearing once truncating
stores are supported.

Currently truncating stores are not used in certain cases where
the size of the vector is larger than the target vector width.

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

3 years ago[OpenMP][OMPT] Fix compile-time assertion in ompt-multiplex.h
Joachim Protze [Mon, 12 Jul 2021 10:12:09 +0000 (12:12 +0200)]
[OpenMP][OMPT] Fix compile-time assertion in ompt-multiplex.h

The compile-time assertion is supposed to prevent double-free caused by
unexpected combination of preprocessor defines passed by an OMPT tool.
The current defines are not used, so this patch replaces the check with
macros actually used in ompt-multiplex.h

Reported by: Semih Burak

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

3 years ago[PowerPC] Remove unnecessary 64-bit guards from altivec.h
Nemanja Ivanovic [Mon, 12 Jul 2021 03:08:31 +0000 (22:08 -0500)]
[PowerPC] Remove unnecessary 64-bit guards from altivec.h

A number of functions in the header have guards for 64-bit only
that were presumably added as some of the functions in the blocks
use vector __int128 which is only available in 64-bit mode.
A more appropriate guard (__SIZEOF_INT128__) has been added for
those functions since, making the 64-bit guards redundant.
This patch removes those guards as they inadvertently guard code
that uses vector long long which does not actually require 64-bit
mode.

3 years agosanitizer_common: add thread safety annotations
Dmitry Vyukov [Fri, 9 Jul 2021 17:29:41 +0000 (19:29 +0200)]
sanitizer_common: add thread safety annotations

Enable clang Thread Safety Analysis for sanitizers:
https://clang.llvm.org/docs/ThreadSafetyAnalysis.html

Thread Safety Analysis can detect inconsistent locking,
deadlocks and data races. Without GUARDED_BY annotations
it has limited value. But this does all the heavy lifting
to enable analysis and allows to add GUARDED_BY incrementally.

Reviewed By: melver

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

3 years agosanitizer_common: rename Mutex to MutexState
Dmitry Vyukov [Sun, 11 Jul 2021 12:17:52 +0000 (14:17 +0200)]
sanitizer_common: rename Mutex to MutexState

We have 3 different mutexes (RWMutex, BlockingMutex __tsan::Mutex),
each with own set of downsides. I want to unify them under a name Mutex.
But it will conflict with Mutex in the deadlock detector,
which is a way too generic name. Rename it to MutexState.

Reviewed By: melver

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

3 years ago[LLDB] Testsuite: Add helper to check for AArch64 target
Muhammad Omair Javaid [Mon, 12 Jul 2021 09:18:18 +0000 (14:18 +0500)]
[LLDB] Testsuite: Add helper to check for AArch64 target

This patch adds a helper function to test target architecture is
AArch64 or not. This also tightens isAArch64* helpers by adding an
extra architecture check.

Reviewed By: DavidSpickett

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

3 years ago[mlir] factor math-to-llvm out of standard-to-llvm
Alex Zinenko [Fri, 9 Jul 2021 14:41:36 +0000 (16:41 +0200)]
[mlir] factor math-to-llvm out of standard-to-llvm

After the Math has been split out of the Standard dialect, the
conversion to the LLVM dialect remained as a huge monolithic pass.
This is undesirable for the same complexity management reasons as having
a huge Standard dialect itself, and is even more confusing given the
existence of a separate dialect. Extract the conversion of the Math
dialect operations to LLVM into a separate library and a separate
conversion pass.

Reviewed By: silvas

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

3 years ago[LV] Ignore candidate VFs with invalid costs.
Sander de Smalen [Mon, 12 Jul 2021 08:32:15 +0000 (09:32 +0100)]
[LV] Ignore candidate VFs with invalid costs.

This follows on from discussion on the mailing-list:
  https://lists.llvm.org/pipermail/llvm-dev/2021-June/151047.html

to interpret an Invalid cost as 'infinitely expensive', as this
simplifies some of the legalization issues with scalable vectors.

Reviewed By: dmgreen

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

3 years ago[X86][SSE] X86ISD::FSETCC nodes (cmpss/cmpsd) return a 0/-1 allbits signbits result
Simon Pilgrim [Mon, 12 Jul 2021 08:56:59 +0000 (09:56 +0100)]
[X86][SSE] X86ISD::FSETCC nodes (cmpss/cmpsd) return a 0/-1 allbits signbits result

Annoyingly, i686 cmpsd handling still fails to remove the unnecessary neg(and(x,1))

3 years ago[X86][SSE] Add signbit tests to show cmpss/cmpsd ops not recognised as 'allbits'...
Simon Pilgrim [Mon, 12 Jul 2021 08:40:59 +0000 (09:40 +0100)]
[X86][SSE] Add signbit tests to show cmpss/cmpsd ops not recognised as 'allbits' results.

3 years ago[analyzer][NFC] Display the correct function name even in crash dumps
Balazs Benics [Mon, 12 Jul 2021 07:06:46 +0000 (09:06 +0200)]
[analyzer][NFC] Display the correct function name even in crash dumps

The `-analyzer-display-progress` displayed the function name of the
currently analyzed function. It differs in C and C++. In C++, it
prints the argument types as well in a comma-separated list.
While in C, only the function name is displayed, without the brackets.
E.g.:

  C++: foo(), foo(int, float)
  C:   foo

In crash traces, the analyzer dumps the location contexts, but the
string is not enough for `-analyze-function` in C++ mode.
This patch addresses the issue by dumping the proper function names
even in stack traces.

Reviewed By: NoQ

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

3 years ago[llvm-exegesis] Fix compilation with old libpfm versions.
Clement Courbet [Thu, 8 Jul 2021 08:52:35 +0000 (10:52 +0200)]
[llvm-exegesis] Fix compilation with old libpfm versions.

Do not try include `perfmon/perf_event.h` when we are not sure that it
exists.

Fixes PR51017.

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

3 years ago[AArch64] De-capitalize some Emit* functions
Fangrui Song [Mon, 12 Jul 2021 05:05:39 +0000 (22:05 -0700)]
[AArch64] De-capitalize some Emit* functions

AsmParser/AsmPrinter/Streamer are mostly consistent on emit* functions now.

3 years ago[LLDB] Only build TestWatchTaggedAddress.py on aarch64 PAC targets
Muhammad Omair Javaid [Mon, 12 Jul 2021 03:38:08 +0000 (08:38 +0500)]
[LLDB] Only build TestWatchTaggedAddress.py on aarch64 PAC targets

This patch fixes buildbot failures caused by TestWatchTaggedAddress.py

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

3 years ago[mlir] Fix broadcasting check with 1 values
Jacques Pienaar [Mon, 12 Jul 2021 03:41:33 +0000 (20:41 -0700)]
[mlir] Fix broadcasting check with 1 values

The trait was inconsistent with the other broadcasting logic here. And
also fix printing here to use ? rather than -1 in the error.

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

3 years agoSupport AArch64/Linux watchpoint on tagged addresses
Muhammad Omair Javaid [Mon, 12 Jul 2021 02:06:34 +0000 (07:06 +0500)]
Support AArch64/Linux watchpoint on tagged addresses

AArch64 architecture support virtual addresses with some of the top bits ignored.
These ignored bits can host memory tags or bit masks that can serve to check for
authentication of address integrity. We need to clear away the top ignored bits
from watchpoint address to reliably hit and set watchpoints on addresses
containing tags or masks in their top bits.

This patch adds support to watch tagged addresses on AArch64/Linux.

Reviewed By: DavidSpickett

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

3 years ago[llvm][Inliner] Templatize PriorityInlineOrder
Liqiang Tao [Mon, 12 Jul 2021 02:28:17 +0000 (10:28 +0800)]
[llvm][Inliner] Templatize PriorityInlineOrder

The patch templatize PriorityInlinerOrder so that it can accept any type priority metric.

Reviewed By: kazu

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

3 years ago[lld-macho][nfc] Fix YAML input in compact-unwind-sym-relocs.s
Jez Ng [Mon, 12 Jul 2021 01:34:31 +0000 (21:34 -0400)]
[lld-macho][nfc] Fix YAML input in compact-unwind-sym-relocs.s

* Adjust strsize so llvm-objdump doesn't complain about it extending
  past the end of file
* Remove symbol that was referencing a deleted section
* Adjust n_sect of the remaining `_main` symbol to point at the right
  section

3 years ago[OpenMP] Create and use `__kmpc_is_generic_main_thread`
Johannes Doerfert [Thu, 1 Jul 2021 05:21:26 +0000 (00:21 -0500)]
[OpenMP] Create and use `__kmpc_is_generic_main_thread`

In order to fold calls based on high-level knowledge and control flow
tracking it helps to expose the information as a runtime call. The
logic: `!SPMD && getTID() == getMasterTID()` was used in various places
and is now encapsulated in `__kmpc_is_generic_main_thread`. As part of
this rewrite we replaced eager computation of arguments with on-demand
computation, especially helpful if the calls can be folded and arguments
don't need to be computed consequently.

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

3 years ago[OpenMP] Simplify variable sharing and increase shared memory size
Johannes Doerfert [Sun, 11 Jul 2021 00:01:56 +0000 (19:01 -0500)]
[OpenMP] Simplify variable sharing and increase shared memory size

In order to avoid malloc/free, up to NUM_SHARED_VARIABLES_IN_SHARED_MEM
(=64) variables are communicated in dedicated shared memory instead. The
simplification does avoid the need for an "init" and requires "deinit"
only if we ever communicate more than NUM_SHARED_VARIABLES_IN_SHARED_MEM
variables.

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

3 years ago[Attributor][NFCI] Add UsedAssumedInformation to more interfaces
Johannes Doerfert [Sat, 10 Jul 2021 00:09:40 +0000 (19:09 -0500)]
[Attributor][NFCI] Add UsedAssumedInformation to more interfaces

As with other Attributor interfaces we often want to know if assumed
information was used to answer a query. This is important if only
known information is allowed or if known information can lead to an
early fixpoint. The users have been adjusted but none of them utilizes
the new information yet.

3 years ago[IndVars] Don't widen pointers in WidenIV::getWideRecurrence
Eli Friedman [Mon, 12 Jul 2021 00:00:14 +0000 (17:00 -0700)]
[IndVars] Don't widen pointers in WidenIV::getWideRecurrence

It's not a reasonable transform, and calling getSignExtendExpr() on a
pointer hits an assertion.

3 years ago[lld-macho][nfc] clang-format
Jez Ng [Sun, 11 Jul 2021 22:36:59 +0000 (18:36 -0400)]
[lld-macho][nfc] clang-format

3 years ago[lld-macho][nfc] Remove unnecessary llvm:: namespace prefixes
Jez Ng [Sun, 11 Jul 2021 22:35:45 +0000 (18:35 -0400)]
[lld-macho][nfc] Remove unnecessary llvm:: namespace prefixes

3 years ago[lld-macho][nfc] Avoid using std::map for PlatformKinds
Jez Ng [Sun, 11 Jul 2021 22:24:53 +0000 (18:24 -0400)]
[lld-macho][nfc] Avoid using std::map for PlatformKinds

The mappings we were using had a small number of keys, so a vector is
probably better. This allows us to remove the last usage of std::map in
our codebase.

I also used `removeSimulator` to simplify the code a bit further.

Reviewed By: #lld-macho, thakis

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

3 years ago[VPlan] Remove default arg from getVPValue (NFC).
Florian Hahn [Sun, 11 Jul 2021 20:00:44 +0000 (22:00 +0200)]
[VPlan] Remove default arg from getVPValue (NFC).

The const version of VPValue::getVPValue still had a default value for
the value index. Remove the default value and use getVPSingleValue
instead, which is the proper function.

3 years ago[RISCV] Add tests for suboptimal handling of negative constants for i32 uaddo/usubo...
Craig Topper [Sun, 11 Jul 2021 19:31:02 +0000 (12:31 -0700)]
[RISCV] Add tests for suboptimal handling of negative constants for i32 uaddo/usubo on RV64. NFC

We end up zero extending constants when we promote to i64. We
should sign extend instead to allow use of addiw or improve
constant materialization.

3 years ago[RISCV] Add tests for suboptimal handling of negative constants on the LHS of i32...
Craig Topper [Sun, 11 Jul 2021 17:34:49 +0000 (10:34 -0700)]
[RISCV] Add tests for suboptimal handling of negative constants on the LHS of i32 shifts/rotates/subtracts on RV64. NFC

The constants end up getting zero extended to i64, but sign extend
would be better for constant materialization. We're using W
instructions so either behavior is correct since the upper bits
aren't read.

3 years ago[lld/mac] Unbreak objc.s after 6e05c1cd5f98
Nico Weber [Sun, 11 Jul 2021 17:57:07 +0000 (13:57 -0400)]
[lld/mac] Unbreak objc.s after 6e05c1cd5f98

3 years ago[lld/mac] Always reference dyld_stub_binder when linked with libSystem
Nico Weber [Sun, 11 Jul 2021 17:13:34 +0000 (13:13 -0400)]
[lld/mac] Always reference dyld_stub_binder when linked with libSystem

lld currently only references dyld_stub_binder when it's needed.
ld64 always references it when libSystem is linked.
Match ld64.

The (somewhat lame) motivation is that `nm` on a binary without any
export writes a "no symbols" warning to stderr, and this change makes
it so that every binary in practice has at least a reference to
dyld_stub_binder, which suppresses that.

Every "real" output file will reference dyld_stub_binder, so most
of the time this shouldn't make much of a difference. And if you
really don't want to have this reference for whatever reason, you
can stop passing -lSystem, like you have to for ld64 anyways.

(After linking any dylib, we dump the exported list of symbols to
a txt file with `nm` and only relink downstream deps if that txt
file changes. A nicer fix is to make lld optionally write .tbd files
with the public interface of a linked dylib and use that instead,
but for now the txt files are what we do.)

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

3 years ago[RISCV] Remove stale FIXME from a test. NFC
Craig Topper [Sun, 11 Jul 2021 17:25:05 +0000 (10:25 -0700)]
[RISCV] Remove stale FIXME from a test. NFC

sext has been used for sltu/sltiu since e0e62e97.

3 years ago[DivRemPairs] Add an initial case for hoisting to a common predecessor.
Craig Topper [Sun, 11 Jul 2021 17:03:05 +0000 (10:03 -0700)]
[DivRemPairs] Add an initial case for hoisting to a common predecessor.

This patch adds support for hoisting the division and maybe the
remainder for control flow graphs like this.

```
PredBB
  |  \
  |  Rem
  |  /
 Div
```

If we have DivRem we'll hoist both to PredBB. If not we'll just
hoist Div and expand Rem using the Div.

This improves our codegen for something like this

```
__uint128_t udivmodti4(__uint128_t dividend, __uint128_t divisor, __uint128_t *remainder) {
    if (remainder != 0)
        *remainder = dividend % divisor;
    return dividend / divisor;
}
```

Reviewed By: spatel, lebedev.ri

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

3 years ago[lld/mac] Use normal Undefined machinery for dyld_stub_binder lookup
Nico Weber [Sun, 11 Jul 2021 16:35:38 +0000 (12:35 -0400)]
[lld/mac] Use normal Undefined machinery for dyld_stub_binder lookup

This is for aesthetic reasons, I'm not aware of anything that needs
this in practice. It does have a few effects:

- `-undefined dynamic_lookup` now has an effect for dyld_stub_binder.
  This matches ld64.

- `-U dyld_stub_binder` now works like you'd expect (it doesn't work in ld64).

- The error message for a missing dyld_stub_binder symbol now looks like
  other undefined reference symbols, it changes from

      symbol dyld_stub_binder not found (normally in libSystem.dylib). Needed to perform lazy binding.

  to

      error: undefined symbol: dyld_stub_binder
      >>> referenced by lazy binding (normally in libSystem.dylib)

Also add test coverage for that error message.

But in practice, this should have no interesting effects since everything links
in dyld_stub_binder via libSystem anyways.

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

3 years ago[ARM] Add lowering of uadd_sat to uq{add|sub}8 and uq{add|sub}16
Daniel Egger [Sun, 11 Jul 2021 14:58:11 +0000 (15:58 +0100)]
[ARM] Add lowering of uadd_sat to uq{add|sub}8 and uq{add|sub}16

This follow the lead of https://reviews.llvm.org/D68974 to add lowering
of unsigned saturated addition/subtraction.

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

3 years agoRevert "[clang-repl] Implement partial translation units and error recovery."
Vassil Vassilev [Sun, 11 Jul 2021 14:39:26 +0000 (14:39 +0000)]
Revert "[clang-repl] Implement partial translation units and error recovery."

This reverts commit 6775fc6ffa3ca1c36b20c25fa4e7f48f81213cf2.

It also reverts "[lldb] Fix compilation by adjusting to the new ASTContext signature."

This reverts commit 03a3f86071c10a1f6cbbf7375aa6fe9d94168972.

We see some failures on the lldb infrastructure, these changes might play a role
in it. Let's revert it now and see if the bots will become green.

Ref: https://reviews.llvm.org/D104918

3 years ago[Analysis] Remove unused declaration isPotentiallyReachableFromMany (NFC)
Kazu Hirata [Sun, 11 Jul 2021 14:10:11 +0000 (07:10 -0700)]
[Analysis] Remove unused declaration isPotentiallyReachableFromMany (NFC)

3 years ago[IfCvt] Don't use pristine register for counting liveins for predicated instructions.
David Green [Sun, 11 Jul 2021 13:45:54 +0000 (14:45 +0100)]
[IfCvt] Don't use pristine register for counting liveins for predicated instructions.

The test case here hits machine verifier problems. There are volatile
long loads that the results of do not get used, loading into two dead
registers. IfCvt will predicate them and as it does will add implicit
uses of the predicating registers due to thinking they are live in. As
nothing has used the register, the machine verifier disagrees that they
are really live and we end up with a failure.

The registers come from Pristine regs that LivePhysRegs counts as live.
This patch adds a addLiveInsNoPristines method to be used instead in
IfCvt, so that only really live in regs need to be added as implicit
operands.

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

3 years agosanitizer_common: unbreak ThreadRegistry tests
Dmitry Vyukov [Sun, 11 Jul 2021 10:55:04 +0000 (12:55 +0200)]
sanitizer_common: unbreak ThreadRegistry tests

https://reviews.llvm.org/D105713
forgot to update tests for the new ctor.

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

3 years ago[lldb] Fix compilation by adjusting to the new ASTContext signature.
Vassil Vassilev [Sun, 11 Jul 2021 10:52:52 +0000 (10:52 +0000)]
[lldb] Fix compilation by adjusting to the new ASTContext signature.

This change was introduced in https://reviews.llvm.org/D104918

3 years agosanitizer_common: add simpler ThreadRegistry ctor
Dmitry Vyukov [Fri, 9 Jul 2021 16:34:30 +0000 (18:34 +0200)]
sanitizer_common: add simpler ThreadRegistry ctor

Currently ThreadRegistry is overcomplicated because of tsan,
it needs tid quarantine and reuse counters. Other sanitizers
don't need that. It also seems that no other sanitizer now
needs max number of threads. Asan used to need 2^24 limit,
but it does not seem to be needed now. Other sanitizers blindly
copy-pasted that without reasons. Lsan also uses quarantine,
but I don't see why that may be potentially needed.

Add a ThreadRegistry ctor that does not require any sizes
and use it in all sanitizers except for tsan.
In preparation for new tsan runtime, which won't need
any of these parameters as well.

Reviewed By: vitalybuka

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

3 years ago[clang-repl] Implement partial translation units and error recovery.
Vassil Vassilev [Wed, 12 May 2021 16:19:40 +0000 (16:19 +0000)]
[clang-repl] Implement partial translation units and error recovery.

https://reviews.llvm.org/D96033 contained a discussion regarding efficient
modeling of error recovery. @rjmccall has outlined the key ideas:

Conceptually, we can split the translation unit into a sequence of partial
translation units (PTUs). Every declaration will be associated with a unique PTU
that owns it.

The first key insight here is that the owning PTU isn't always the "active"
(most recent) PTU, and it isn't always the PTU that the declaration
"comes from". A new declaration (that isn't a redeclaration or specialization of
anything) does belong to the active PTU. A template specialization, however,
belongs to the most recent PTU of all the declarations in its signature - mostly
that means that it can be pulled into a more recent PTU by its template
arguments.

The second key insight is that processing a PTU might extend an earlier PTU.
Rolling back the later PTU shouldn't throw that extension away. For example, if
the second PTU defines a template, and the third PTU requires that template to
be instantiated at float, that template specialization is still part of the
second PTU. Similarly, if the fifth PTU uses an inline function belonging to the
fourth, that definition still belongs to the fourth. When we go to emit code in
a new PTU, we map each declaration we have to emit back to its owning PTU and
emit it in a new module for just the extensions to that PTU. We keep track of
all the modules we've emitted for a PTU so that we can unload them all if we
decide to roll it back.

Most declarations/definitions will only refer to entities from the same or
earlier PTUs. However, it is possible (primarily by defining a
previously-declared entity, but also through templates or ADL) for an entity
that belongs to one PTU to refer to something from a later PTU. We will have to
keep track of this and prevent unwinding to later PTU when we recognize it.
Fortunately, this should be very rare; and crucially, we don't have to do the
bookkeeping for this if we've only got one PTU, e.g. in normal compilation.
Otherwise, PTUs after the first just need to record enough metadata to be able
to revert any changes they've made to declarations belonging to earlier PTUs,
e.g. to redeclaration chains or template specialization lists.

It should even eventually be possible for PTUs to provide their own slab
allocators which can be thrown away as part of rolling back the PTU. We can
maintain a notion of the active allocator and allocate things like Stmt/Expr
nodes in it, temporarily changing it to the appropriate PTU whenever we go to do
something like instantiate a function template. More care will be required when
allocating declarations and types, though.

We would want the PTU to be efficiently recoverable from a Decl; I'm not sure
how best to do that. An easy option that would cover most declarations would be
to make multiple TranslationUnitDecls and parent the declarations appropriately,
but I don't think that's good enough for things like member function templates,
since an instantiation of that would still be parented by its original class.
Maybe we can work this into the DC chain somehow, like how lexical DCs are.

We add a different kind of translation unit `TU_Incremental` which is a
complete translation unit that we might nonetheless incrementally extend later.
Because it is complete (and we might want to generate code for it), we do
perform template instantiation, but because it might be extended later, we don't
warn if it declares or uses undefined internal-linkage symbols.

This patch teaches clang-repl how to recover from errors by disconnecting the
most recent PTU and update the primary PTU lookup tables. For instance:

```./clang-repl
clang-repl> int i = 12; error;
In file included from <<< inputs >>>:1:
input_line_0:1:13: error: C++ requires a type specifier for all declarations
int i = 12; error;
            ^
error: Parsing failed.
clang-repl> int i = 13; extern "C" int printf(const char*,...);
clang-repl> auto r1 = printf("i=%d\n", i);
i=13
clang-repl> quit
```

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

3 years agosanitizer_common: sanitize time functions
Dmitry Vyukov [Fri, 9 Jul 2021 18:21:52 +0000 (20:21 +0200)]
sanitizer_common: sanitize time functions

We have SleepForSeconds, SleepForMillis and internal_sleep.
Some are implemented in terms of libc functions, some -- in terms
of syscalls. Some are implemented in per OS files,
some -- in libc/nolibc files. That's unnecessary complex
and libc functions cause crashes in some contexts because
we intercept them. There is no single reason to have calls to libc
when we have syscalls (and we have them anyway).

Add internal_usleep that is implemented in terms of syscalls per OS.
Make SleepForSeconds/SleepForMillis/internal_sleep a wrapper
around internal_usleep that is implemented in sanitizer_common.cpp once.

Also remove return values for internal_sleep, it's not used anywhere.

Eventually it would be nice to remove SleepForSeconds/SleepForMillis/internal_sleep.
There is no point in having that many different names for the same thing.

Reviewed By: vitalybuka

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

3 years agosanitizer_common: split LibIgnore into fast/slow paths
Dmitry Vyukov [Fri, 9 Jul 2021 18:33:24 +0000 (20:33 +0200)]
sanitizer_common: split LibIgnore into fast/slow paths

LibIgnore is checked in every interceptor.
Currently it has all logic in the single function
in the header, which makes it uninlinable.
Split it into fast path (no libraries ignored)
and slow path (have ignored libraries).
It makes the fast path inlinable (single load).

Reviewed By: vitalybuka

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

3 years ago[lld-macho][nfc] Expand the compact unwind symbol reloc test
Jez Ng [Sun, 11 Jul 2021 04:19:03 +0000 (00:19 -0400)]
[lld-macho][nfc] Expand the compact unwind symbol reloc test

Add a bit more detail to the comments, and check that the final binary
does indeed have a `__unwind_info` section (D105557 previosly regressed
this).

Also rename the test to emphasize that we are testing relocations
compact unwind, not relocations in general.

3 years ago[InstCombine] Add optimization to prevent poison from being propagated.
hyeongyu kim [Sun, 11 Jul 2021 02:45:32 +0000 (11:45 +0900)]
[InstCombine] Add optimization to prevent poison from being propagated.

In D104569, Freeze was inserted just before br to solve the `branching on undef` miscompilation problem.
But value analysis was being disturbed by added freeze.

```
v = load ptr
cond = freeze(icmp (and v, const), const')
br cond, ...
```
The case in which value analysis disturbed is as above.
By changing freeze to add immediately after load, value analysis will be successful again.

```
v = load ptr
freeze(icmp (and v, const), const')
=>
v = load ptr
v' = freeze v
icmp (and v', const), const'
```
In this patch, I propose the above optimization.
With this patch, the poison will not spread as the freeze is performed early.

Reviewed By: nikic, lebedev.ri

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

3 years agoFix windows directory separator some more for test from b447b9dce0d105e7f0b22db719fe8...
David Blaikie [Sun, 11 Jul 2021 02:07:41 +0000 (19:07 -0700)]
Fix windows directory separator some more for test from b447b9dce0d105e7f0b22db719fe8624108e99dc

3 years agoReapply "llvm-symbolizer: Fix "start file" to work with Split DWARF"
David Blaikie [Sun, 11 Jul 2021 01:46:43 +0000 (18:46 -0700)]
Reapply "llvm-symbolizer: Fix "start file" to work with Split DWARF"

Originally committed as 04c203e310bd3fb58e16c936c0200d680100526e
Reverted in 768510632c5ddbf9438693d9c7db1903e39295ad due to the test
failing when encountering windows directory separators.

Fix the path separator platform issue with a FileCheck pattern {{[/\\]}}

Original commit message:

A followup to the feature added in 69da27c7496ea373567ce5121e6fe8613846e7a5
that added the optional "start file name" to match "start line" - but this
didn't work with Split DWARF because of the need for the decl file number
resolution code to refer back to the skeleton unit to find its .debug_line
contribution. So this patch adds the necessary infrastructure to track the
skeleton unit corresponding to a split full unit for the purpose of this
lookup.

3 years ago[DivRemPairs] Add test cases for D87555. NFC
Craig Topper [Sun, 11 Jul 2021 01:34:59 +0000 (18:34 -0700)]
[DivRemPairs] Add test cases for D87555. NFC

3 years ago[RISCV] Restore non-constant srem test I accidentally deleted. NFC
Craig Topper [Sun, 11 Jul 2021 01:02:13 +0000 (18:02 -0700)]
[RISCV] Restore non-constant srem test I accidentally deleted. NFC

3 years ago[Analysis] Remove changeCondBranchToUnconditionalTo (NFC)
Kazu Hirata [Sun, 11 Jul 2021 00:21:32 +0000 (17:21 -0700)]
[Analysis] Remove changeCondBranchToUnconditionalTo (NFC)

The last use was removed on Jan 21, 2021 in commit
0895b836d74ed333468ddece2102140494eb33b6.

3 years ago[RISCV] Add test cases for div/rem with constant left hand side. NFC
Craig Topper [Sun, 11 Jul 2021 00:07:39 +0000 (17:07 -0700)]
[RISCV] Add test cases for div/rem with constant left hand side. NFC

Some of these would produce better code if we used W instructions,
but constant LHS currently prevents that.