platform/upstream/llvm.git
7 years agoUpdate google benchmark
Eric Fiselier [Tue, 18 Apr 2017 07:17:20 +0000 (07:17 +0000)]
Update google benchmark

llvm-svn: 300530

7 years agoAssert that a valid operator new/delete signature is always found by the coroutine...
Eric Fiselier [Tue, 18 Apr 2017 05:30:39 +0000 (05:30 +0000)]
Assert that a valid operator new/delete signature is always found by the coroutine body

llvm-svn: 300529

7 years agoSpeculatively attempt to fix bot failures caused by recent coroutine changes.
Eric Fiselier [Tue, 18 Apr 2017 05:08:08 +0000 (05:08 +0000)]
Speculatively attempt to fix bot failures caused by recent coroutine changes.

llvm-svn: 300528

7 years ago[APInt] Cleanup the reverseBits slow case a little.
Craig Topper [Tue, 18 Apr 2017 05:02:21 +0000 (05:02 +0000)]
[APInt] Cleanup the reverseBits slow case a little.

Use lshrInPlace. Use single bit extract and operator|=(uint64_t) to avoid a few temporary APInts.

llvm-svn: 300527

7 years ago[APInt] Make operator<<= shift in place. Improve the implementation of tcShiftLeft...
Craig Topper [Tue, 18 Apr 2017 04:39:48 +0000 (04:39 +0000)]
[APInt] Make operator<<= shift in place. Improve the implementation of tcShiftLeft and use it to implement operator<<=.

llvm-svn: 300526

7 years ago[XRay][compiler-rt] Use emulated TSC when CPU supports rdtscp, but cannot determine...
Douglas Yung [Tue, 18 Apr 2017 03:25:11 +0000 (03:25 +0000)]
[XRay][compiler-rt] Use emulated TSC when CPU supports rdtscp, but cannot determine the CPU frequency

A problem arises if a machine supports the rdtscp instruction, but the processor
frequency cannot be determined by the function getTSCFrequency(). In this case,
we want to use the emulated TSC instead. This patch implements that by adding a
call to getTSCFrequency() from probeRequiredCPUFeatures(), and the function only
returns true if both the processor supports rdtscp and the CPU frequency can be
determined.

This should fix PR32620.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 300525

7 years ago[coroutines] Fix building of new/delete expressions when get_return_object_on_allocat...
Eric Fiselier [Tue, 18 Apr 2017 03:12:48 +0000 (03:12 +0000)]
[coroutines] Fix building of new/delete expressions when get_return_object_on_allocation_failure() is present.

Summary:
This patch implements [dcl.fct.def.coroutine]p8:
> The unqualified-id get_return_object_on_allocation_failure is looked up in the scope of
> class P by class member access lookup (3.4.5). If a declaration is found, ..., and if a
> global allocation function is selected, the ::operator new(size_t, nothrow_t) form shall be used.
> [...]
> The allocation function used in this case must have a non-throwing noexcept-specification.

Reviewers: GorNishanov, rsmith, majnemer, aaron.ballman

Reviewed By: GorNishanov

Subscribers: cfe-commits

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

llvm-svn: 300524

7 years agoDebug Info: Remove special-casing of indirect function argument handling.
Adrian Prantl [Tue, 18 Apr 2017 01:22:01 +0000 (01:22 +0000)]
Debug Info: Remove special-casing of indirect function argument handling.

LLVM has changed the semantics of dbg.declare for describing function
arguments. After this patch a dbg.declare always takes the *address*
of a variable as the first argument, even if the argument is not an
alloca.

https://bugs.llvm.org/show_bug.cgi?id=32382
rdar://problem/31205000

llvm-svn: 300523

7 years agoPR32382: Fix emitting complex DWARF expressions.
Adrian Prantl [Tue, 18 Apr 2017 01:21:53 +0000 (01:21 +0000)]
PR32382: Fix emitting complex DWARF expressions.

The DWARF specification knows 3 kinds of non-empty simple location
descriptions:
1. Register location descriptions
  - describe a variable in a register
  - consist of only a DW_OP_reg
2. Memory location descriptions
  - describe the address of a variable
3. Implicit location descriptions
  - describe the value of a variable
  - end with DW_OP_stack_value & friends

The existing DwarfExpression code is pretty much ignorant of these
restrictions. This used to not matter because we only emitted very
short expressions that we happened to get right by accident.  This
patch makes DwarfExpression aware of the rules defined by the DWARF
standard and now chooses the right kind of location description for
each expression being emitted.

This would have been an NFC commit (for the existing testsuite) if not
for the way that clang describes captured block variables. Based on
how the previous code in LLVM emitted locations, DW_OP_deref
operations that should have come at the end of the expression are put
at its beginning. Fixing this means changing the semantics of
DIExpression, so this patch bumps the version number of DIExpression
and implements a bitcode upgrade.

There are two major changes in this patch:

I had to fix the semantics of dbg.declare for describing function
arguments. After this patch a dbg.declare always takes the *address*
of a variable as the first argument, even if the argument is not an
alloca.

When lowering a DBG_VALUE, the decision of whether to emit a register
location description or a memory location description depends on the
MachineLocation — register machine locations may get promoted to
memory locations based on their DIExpression. (Future) optimization
passes that want to salvage implicit debug location for variables may
do so by appending a DW_OP_stack_value. For example:
  DBG_VALUE, [RBP-8]                        --> DW_OP_fbreg -8
  DBG_VALUE, RAX                            --> DW_OP_reg0 +0
  DBG_VALUE, RAX, DIExpression(DW_OP_deref) --> DW_OP_reg0 +0

All testcases that were modified were regenerated from clang. I also
added source-based testcases for each of these to the debuginfo-tests
repository over the last week to make sure that no synchronized bugs
slip in. The debuginfo-tests compile from source and run the debugger.

https://bugs.llvm.org/show_bug.cgi?id=32382
<rdar://problem/31205000>

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

llvm-svn: 300522

7 years ago[asan] Fixup for r300483 (which is a fixup for r300473).
Evgeniy Stepanov [Tue, 18 Apr 2017 01:08:00 +0000 (01:08 +0000)]
[asan] Fixup for r300483 (which is a fixup for r300473).

Sanitizer Printf() does not know about %lu.

llvm-svn: 300521

7 years agoAdd const to a const method. NFC
George Burgess IV [Tue, 18 Apr 2017 01:04:05 +0000 (01:04 +0000)]
Add const to a const method. NFC

llvm-svn: 300520

7 years agoTestStaticVariables still fails on Linux.
Jim Ingham [Tue, 18 Apr 2017 00:44:14 +0000 (00:44 +0000)]
TestStaticVariables still fails on Linux.

llvm-svn: 300519

7 years ago[Target] Use hasOneUse() instead of getNumUses().
Davide Italiano [Tue, 18 Apr 2017 00:29:54 +0000 (00:29 +0000)]
[Target] Use hasOneUse() instead of getNumUses().

The latter does a liner scan over a linked list, therefore is
much more expensive.

llvm-svn: 300518

7 years agoThis test is succeeding on macOS with clang.
Jim Ingham [Tue, 18 Apr 2017 00:20:59 +0000 (00:20 +0000)]
This test is succeeding on macOS with clang.

llvm-svn: 300517

7 years agoAllow a standard library to implement conditional noexcept for optional and unique_pt...
Billy Robert O'Neal III [Tue, 18 Apr 2017 00:19:50 +0000 (00:19 +0000)]
Allow a standard library to implement conditional noexcept for optional and unique_ptr hash functions.

These tests were unconditionally asserting that optional and unique_ptr declare throwing hashes, but MSVC++ implements conditional noexcept forwarding that of the underlying hash function. As a result we were failing these tests but there's nothing forbidding strengthening noexcept in that way.

Changed the ASSERT_NOT_NOEXCEPT asserts to use types which themselves have non-noexcept hash functions.

llvm-svn: 300516

7 years agoFix mishandling of escaped newlines followed by newlines or nuls.
Richard Smith [Mon, 17 Apr 2017 23:44:51 +0000 (23:44 +0000)]
Fix mishandling of escaped newlines followed by newlines or nuls.

Previously, if an escaped newline was followed by a newline or a nul, we'd lex
the escaped newline as a bogus space character. This led to a bunch of
different broken corner cases:

For the pattern "\\\n\0#", we would then have a (horizontal) space whose
spelling ends in a newline, and would decide that the '#' is at the start of a
line, and incorrectly start preprocessing a directive in the middle of a
logical source line. If we were already in the middle of a directive, this
would result in our attempting to process multiple directives at the same time!
This resulted in crashes, asserts, and hangs on invalid input, as discovered by
fuzz-testing.

For the pattern "\\\n" at EOF (with an implicit following nul byte), we would
produce a bogus trailing space character with spelling "\\\n". This was mostly
harmless, but would lead to clang-format getting confused and misformatting in
rare cases. We now produce a trailing EOF token with spelling "\\\n",
consistent with our handling for other similar cases -- an escaped newline is
always part of the token containing the next character, if any.

For the pattern "\\\n\n", this was somewhat more benign, but would produce an
extraneous whitespace token to clients who care about preserving whitespace.
However, it turns out that our lexing for line comments was relying on this bug
due to an off-by-one error in its computation of the end of the comment, on the
slow path where the comment might contain escaped newlines.

llvm-svn: 300515

7 years agoObject: Shrink the size of irsymtab::Symbol by a word. NFCI.
Peter Collingbourne [Mon, 17 Apr 2017 23:43:49 +0000 (23:43 +0000)]
Object: Shrink the size of irsymtab::Symbol by a word. NFCI.

Instead of storing an UncommonIndex on the Symbol, use a flag bit to store
whether the Symbol has an Uncommon. This shrinks Chromium's .bc files (after
D32061) by about 1%.

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

llvm-svn: 300514

7 years agoRename coroutine warning when unhandled_exception() is missing
Eric Fiselier [Mon, 17 Apr 2017 23:28:02 +0000 (23:28 +0000)]
Rename coroutine warning when unhandled_exception() is missing

llvm-svn: 300513

7 years agoUnify the common code in the ios, tvos, watchos platforms into a single
Jason Molenda [Mon, 17 Apr 2017 22:52:20 +0000 (22:52 +0000)]
Unify the common code in the ios, tvos, watchos platforms into a single
PlatformRemoveDarwinDevice class, subclassed to those three so they can
provide their specific information.

<rdar://problem/30159764>

llvm-svn: 300512

7 years agoRevert r300504 - [coroutines] Fix rebuilding of implicit and dependent coroutine...
Eric Fiselier [Mon, 17 Apr 2017 22:40:44 +0000 (22:40 +0000)]
Revert r300504 - [coroutines] Fix rebuilding of implicit and dependent coroutine statements.

I have no idea what's happening here. The tests that fail on all of the bots
pass on my machine. Further investigation needed.

llvm-svn: 300511

7 years agoWork around GCC 4.9 bug regarding default initialization of const variables
Eric Fiselier [Mon, 17 Apr 2017 22:32:02 +0000 (22:32 +0000)]
Work around GCC 4.9 bug regarding default initialization of const variables

llvm-svn: 300510

7 years ago[ubsan] Skip null checks if they are constant-folded away
Vedant Kumar [Mon, 17 Apr 2017 22:26:10 +0000 (22:26 +0000)]
[ubsan] Skip null checks if they are constant-folded away

The IR builder can constant-fold null checks if the pointer operand
points to a constant. If the "is-non-null" check is folded away to
"true", don't emit the null check + branch.

Testing: check-clang, check-ubsan.

This slightly reduces the amount of null checks we emit when compiling
X86ISelLowering.cpp. Here are the numbers from patched/unpatched clangs
based on r300371.

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            25251 |
  | patched, -O0   |            23925 | (-5.3%)
  -------------------------------------

llvm-svn: 300509

7 years ago[ubsan] Skip null checks on pointers to the start of an alloca
Vedant Kumar [Mon, 17 Apr 2017 22:26:07 +0000 (22:26 +0000)]
[ubsan] Skip null checks on pointers to the start of an alloca

Pointers to the start of an alloca are non-null, so we don't need to
emit runtime null checks for them.

Testing: check-clang, check-ubsan.

This significantly reduces the amount of null checks we emit when
compiling X86ISelLowering.cpp. Here are the numbers from patched /
unpatched clangs based on r300371.

  -------------------------------------
  | Setup          | # of null checks |
  -------------------------------------
  | unpatched, -O0 |            45439 |
  | patched, -O0   |            25251 | (-44.4%)
  -------------------------------------

llvm-svn: 300508

7 years agoBuild SymbolMap in SampleProfileLoader to help matchin function names with suffix.
Dehao Chen [Mon, 17 Apr 2017 22:23:05 +0000 (22:23 +0000)]
Build SymbolMap in SampleProfileLoader to help matchin function names with suffix.

Summary: If there is suffix added in the function name (e.g. module hash added by thinLTO), we will not be able to find a match in profile as the suffix does not exist in profile. This patch build a map from function name to Function *. The map includes the entry for the stripped function name so that inlineHotFunctions can find the corresponding function to promote/inline.

Reviewers: davidxl, dnovillo, tejohnson

Reviewed By: davidxl

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 300507

7 years agoChange the testcase tail-merge-after-mbp.ll to tail-merge-after-mbp.mir
Haicheng Wu [Mon, 17 Apr 2017 22:22:38 +0000 (22:22 +0000)]
Change the testcase tail-merge-after-mbp.ll to tail-merge-after-mbp.mir

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

llvm-svn: 300506

7 years ago[SimplifyCFG] Use hasNUses instead of comparing getNumUses to a constant."
Craig Topper [Mon, 17 Apr 2017 22:13:00 +0000 (22:13 +0000)]
[SimplifyCFG] Use hasNUses instead of comparing getNumUses to a constant."

The use list is a linked list so getNumUses requires a linear scan through the whole list. hasNUses will stop scanning at N and see if that is the end.

llvm-svn: 300505

7 years ago[coroutines] Fix rebuilding of implicit and dependent coroutine statements.
Eric Fiselier [Mon, 17 Apr 2017 22:06:13 +0000 (22:06 +0000)]
[coroutines] Fix rebuilding of implicit and dependent coroutine statements.

Summary:
Certain implicitly generated coroutine statements, such as the calls to 'return_value()' or `return_void()` or `get_return_object_on_allocation_failure()`, cannot be built until the promise type is no longer dependent. This means they are not built until after the coroutine body statement has been transformed.

This patch fixes an issue where these statements would never be built for coroutine templates.

It also fixes a small issue where diagnostics about `get_return_object_on_allocation_failure()` were incorrectly suppressed.

Reviewers: rsmith, majnemer, GorNishanov, aaron.ballman

Reviewed By: GorNishanov

Subscribers: cfe-commits

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

llvm-svn: 300504

7 years ago[APInt] Merge the multiword code from lshrInPlace and tcShiftRight into a single...
Craig Topper [Mon, 17 Apr 2017 21:43:43 +0000 (21:43 +0000)]
[APInt] Merge the multiword code from lshrInPlace and tcShiftRight into a single implementation

This merges the two different multiword shift right implementations into a single version located in tcShiftRight. lshrInPlace now calls tcShiftRight for the multiword case.

I retained the memmove fast path from lshrInPlace and used a memset for the zeroing. The for loop is basically tcShiftRight's implementation with the zeroing and the intra-shift of 0 removed.

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

llvm-svn: 300503

7 years ago[WebAssembly] Fix WebAssemblyOptimizeReturned after r300367
Jacob Gravelle [Mon, 17 Apr 2017 21:40:28 +0000 (21:40 +0000)]
[WebAssembly] Fix WebAssemblyOptimizeReturned after r300367

Summary:
Refactoring changed paramHasAttr(1 + i) to paramHasAttr(0), fix that to
paramHasAttr(i).
Add more tests to WebAssemblyOptimizeReturned that catch that
regression.

Reviewers: dschuff

Subscribers: jfb, sbc100, llvm-commits

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

llvm-svn: 300502

7 years agoclang-cl: Support the /Zc:twoPhase[-] command-line option (PR32680)
Hans Wennborg [Mon, 17 Apr 2017 21:28:36 +0000 (21:28 +0000)]
clang-cl: Support the /Zc:twoPhase[-] command-line option (PR32680)

It sounds like MSVC is adding support for two-phase name lookup in a
future version, enabled by this flag (see bug).

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

llvm-svn: 300501

7 years ago[SCEV] Fix another unused variable warning in release builds.
Benjamin Kramer [Mon, 17 Apr 2017 21:07:26 +0000 (21:07 +0000)]
[SCEV] Fix another unused variable warning in release builds.

llvm-svn: 300500

7 years agoFix an unused variable error in rL300494.
Wei Mi [Mon, 17 Apr 2017 21:00:45 +0000 (21:00 +0000)]
Fix an unused variable error in rL300494.

llvm-svn: 300499

7 years ago[libFuzzer] experimental option -cleanse_crash: tries to replace all bytes in a crash...
Kostya Serebryany [Mon, 17 Apr 2017 20:58:21 +0000 (20:58 +0000)]
[libFuzzer] experimental option -cleanse_crash: tries to replace all bytes in a crash reproducer with garbage, while still preserving the crash

llvm-svn: 300498

7 years agoRevert "Address http://bugs.llvm.org/pr30994 so that a non-friend can properly replac...
Benjamin Kramer [Mon, 17 Apr 2017 20:57:40 +0000 (20:57 +0000)]
Revert "Address bugs.llvm.org/pr30994 so that a non-friend can properly replace a friend, and a visible friend can properly replace an invisible friend but not vice verse, and definitions are not replaced. This fixes the two FIXME in SemaTemplate/friend-template.cpp."

This reverts commit r300443. Breaks compiling libc++ with modules in
some configurations.

llvm-svn: 300497

7 years agoAdd a linker script to version LLVM symbols
Sylvestre Ledru [Mon, 17 Apr 2017 20:51:50 +0000 (20:51 +0000)]
Add a linker script to version LLVM symbols

Summary:
This patch adds a very simple linker script to version the lib's symbols
and thus trying to avoid crashes if an application loads two different
LLVM versions (as long as they do not share data between them).

Note that we deliberately *don't* make LLVM_5.0 depend on LLVM_4.0:
they're incompatible and the whole point of this patch is
to tell the linker that.

Avoid unexpected crashes when two LLVM versions are used in the same process.

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>
Author: Lisandro Damían Nicanor Pérez Meyer <lisandro@debian.org>
Author: Sylvestre Ledru <sylvestre@debian.org>
Bug-Debian:  https://bugs.debian.org/848368

Reviewers: beanz, rnk

Reviewed By: rnk

Subscribers: mgorny, llvm-commits

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

llvm-svn: 300496

7 years ago[InstCombine] Matchers work with both ConstExpr and Instructions.
Davide Italiano [Mon, 17 Apr 2017 20:49:50 +0000 (20:49 +0000)]
[InstCombine] Matchers work with both ConstExpr and Instructions.

So, `cast<Instruction>` is not guaranteed to succeed. Change the
code so that we create a new constant and use it in the newly
created instruction, as it's done in other places in InstCombine.

OK'ed by Sanjay/Craig. Fixes PR32686.

llvm-svn: 300495

7 years ago[SCEV] Add a local cache for getZeroExtendExpr and getSignExtendExpr to prevent
Wei Mi [Mon, 17 Apr 2017 20:40:05 +0000 (20:40 +0000)]
[SCEV] Add a local cache for getZeroExtendExpr and getSignExtendExpr to prevent
the exponential behavior.

The patch is to fix PR32043. Functions getZeroExtendExpr and getSignExtendExpr
may call themselves recursively more than once. This is potentially a 2^N
complexity behavior. The exponential behavior was not commonly exposed before
because of existing global cache mechnism like UniqueSCEVs or some early return
mechanism when flags FlagNSW or FlagNUW are seen. However, we still have case
which can expose the exponential behavior, like the case in PR32043, so we add
a local cache in getZeroExtendExpr and getSignExtendExpr. If the input of the
functions -- SCEV and type pair have been seen before, we can find the extended
expression directly in the local cache.

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

llvm-svn: 300494

7 years ago[InstSimplify] add/move tests for (icmp X, C1 & icmp X, C2); NFC
Sanjay Patel [Mon, 17 Apr 2017 20:38:33 +0000 (20:38 +0000)]
[InstSimplify] add/move tests for (icmp X, C1 & icmp X, C2); NFC

We simplify based on range intersection, but we're missing folds.

llvm-svn: 300493

7 years agoUpdate the test to fix the buildbot failure introduced by r300486 (NFC)
Dehao Chen [Mon, 17 Apr 2017 20:35:32 +0000 (20:35 +0000)]
Update the test to fix the buildbot failure introduced by r300486 (NFC)

llvm-svn: 300492

7 years agoUpdate suspended threads info to be compatible with darwin
Francis Ricci [Mon, 17 Apr 2017 20:29:38 +0000 (20:29 +0000)]
Update suspended threads info to be compatible with darwin

Summary:
On Darwin, we need to track thread and tid as separate values.
This patch splits out the implementation of the suspended threads list
to be OS-specific.

Reviewers: glider, kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 300491

7 years ago[WebAssembly] Encode block signatures as SLEB instead of ULEB
Derek Schuff [Mon, 17 Apr 2017 20:28:28 +0000 (20:28 +0000)]
[WebAssembly] Encode block signatures as SLEB instead of ULEB

Use SLEB (varint) for block_type immediates in accordance with the spec.

Patch by Yury Delendik

llvm-svn: 300490

7 years agoFix passing incorrectly value-category when constructing unique_ptr's deleter
Eric Fiselier [Mon, 17 Apr 2017 20:20:27 +0000 (20:20 +0000)]
Fix passing incorrectly value-category when constructing unique_ptr's deleter

llvm-svn: 300489

7 years ago[optional] Update synopsis for LWG2934
Casey Carter [Mon, 17 Apr 2017 20:15:16 +0000 (20:15 +0000)]
[optional] Update synopsis for LWG2934

(comment-only change)

llvm-svn: 300488

7 years agoCodeGen: Let byval parameter use alloca address space
Yaxun Liu [Mon, 17 Apr 2017 20:10:44 +0000 (20:10 +0000)]
CodeGen: Let byval parameter use alloca address space

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

llvm-svn: 300487

7 years agoAdd GNU_discriminator support for inline callsites in llvm-symbolizer.
Dehao Chen [Mon, 17 Apr 2017 20:10:39 +0000 (20:10 +0000)]
Add GNU_discriminator support for inline callsites in llvm-symbolizer.

Summary: LLVM symbolize cannot recognize GNU_discriminator for inline callsites. This patch adds support for it.

Reviewers: dblaikie

Reviewed By: dblaikie

Subscribers: llvm-commits

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

llvm-svn: 300486

7 years agoCodeGen: Let lifetime intrinsic use alloca address space
Yaxun Liu [Mon, 17 Apr 2017 20:03:11 +0000 (20:03 +0000)]
CodeGen: Let lifetime intrinsic use alloca address space

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

llvm-svn: 300485

7 years ago[tsan] Add missing include for uint64_t in test.
Benjamin Kramer [Mon, 17 Apr 2017 19:55:12 +0000 (19:55 +0000)]
[tsan] Add missing include for uint64_t in test.

llvm-svn: 300484

7 years agoFixup for r300473: Use %lu on Linux for tid_t in format strings.
Kuba Mracek [Mon, 17 Apr 2017 19:51:58 +0000 (19:51 +0000)]
Fixup for r300473: Use %lu on Linux for tid_t in format strings.

llvm-svn: 300483

7 years agoAMDGPU: Use MachineRegisterInfo to find max used register
Matt Arsenault [Mon, 17 Apr 2017 19:48:30 +0000 (19:48 +0000)]
AMDGPU: Use MachineRegisterInfo to find max used register

Avoid looping through program to determine register counts.
This avoids needing to look at regmask operands.

Also fixes some counting errors with flat_scr when there
are no stack objects.

llvm-svn: 300482

7 years agoAMDGPU: Change stack alignment
Matt Arsenault [Mon, 17 Apr 2017 19:48:24 +0000 (19:48 +0000)]
AMDGPU: Change stack alignment

While the incoming stack for a kernel is 256-byte aligned,
this refers to the base address of the entire wave. This isn't
useful information for most of codegen. Fixes unnecessarily
aligning stack objects in callees.

llvm-svn: 300481

7 years ago[CodeGenPrepare] Fix crash due to an invalid CFG
Brendon Cahoon [Mon, 17 Apr 2017 19:11:04 +0000 (19:11 +0000)]
[CodeGenPrepare] Fix crash due to an invalid CFG

The splitIndirectCriticalEdges function generates and invalid CFG when the
'Target' basic block is a loop to itself. When this occurs, the code that
updates the predecessor terminator needs to update the terminator in the split
basic block.

This occurs when there is an edge from block D back to D. Since D is split in
to D0 and D1, the code needs to update the terminator in D1. But D1 is not in
the OtherPreds vector, so it was not getting updated.

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

llvm-svn: 300480

7 years agoUnbreak build of the wasm backend after r300463.
Benjamin Kramer [Mon, 17 Apr 2017 19:08:41 +0000 (19:08 +0000)]
Unbreak build of the wasm backend after r300463.

llvm-svn: 300479

7 years agoBitcode: Add missing build dep to fix shlib build.
Peter Collingbourne [Mon, 17 Apr 2017 18:53:27 +0000 (18:53 +0000)]
Bitcode: Add missing build dep to fix shlib build.

llvm-svn: 300478

7 years ago[APInt] Remove self move check from move assignment operator
Craig Topper [Mon, 17 Apr 2017 18:44:27 +0000 (18:44 +0000)]
[APInt] Remove self move check from move assignment operator

This was added to work around a bug in MSVC 2013's implementation of stable_sort. That bug has been fixed as of MSVC 2015 so we shouldn't need this anymore.

Technically the current implementation has undefined behavior because we only protect the deleting of the pVal array with the self move check. There is still a memcpy of that.VAL to VAL that isn't protected. In the case of self move those are the same local and memcpy is undefined for src and dst overlapping.

This reduces the size of the opt binary on my local x86-64 build by about 4k.

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

llvm-svn: 300477

7 years ago[ClangASTContext] Placate `casts away qualifiers` warnings from GCC.
Davide Italiano [Mon, 17 Apr 2017 18:24:18 +0000 (18:24 +0000)]
[ClangASTContext] Placate `casts away qualifiers` warnings from GCC.

llvm-svn: 300476

7 years ago[IR] Implement DataLayout::getPointerTypeSizeInBits using getPointerSizeInBits directly
Craig Topper [Mon, 17 Apr 2017 18:22:36 +0000 (18:22 +0000)]
[IR] Implement DataLayout::getPointerTypeSizeInBits using getPointerSizeInBits directly

Currently we use getTypeSizeInBits which contains a switch statement to dispatch based on what the Type is. We know we always have a pointer type here, but the compiler isn't able to figure out that out to remove the switch.

This patch changes it to just call handle the pointer type directly by calling getPointerSizeInBits without going through a switch.

getPointerTypeSizeInBits is called pretty often, particularly by getOrEnforceKnownAlignment which is used by InstCombine. This should speed that up a little bit.

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

llvm-svn: 300475

7 years agoAArch64: put nonlazybind special handling behind a flag for now.
Tim Northover [Mon, 17 Apr 2017 18:18:47 +0000 (18:18 +0000)]
AArch64: put nonlazybind special handling behind a flag for now.

It's basically a terrible idea anyway but objc_msgSend gets emitted like that.
We can decide on a better way to deal with it in the unlikely event that anyone
actually uses it.

llvm-svn: 300474

7 years ago[sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs
Kuba Mracek [Mon, 17 Apr 2017 18:17:38 +0000 (18:17 +0000)]
[sanitizer] Introduce tid_t as a typedef for OS-provided thread IDs

We seem to assume that OS-provided thread IDs are either uptr or int, neither of which is true on Darwin. This introduces a tid_t type, which holds a OS-provided thread ID (gettid on Linux, pthread_threadid_np on Darwin, pthread_self on FreeBSD).

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

llvm-svn: 300473

7 years agoAMDGPU: Test handling of R_AMDGPU_ABS64 in RelocVisitor
Konstantin Zhuravlyov [Mon, 17 Apr 2017 18:12:45 +0000 (18:12 +0000)]
AMDGPU: Test handling of R_AMDGPU_ABS64 in RelocVisitor

llvm-svn: 300472

7 years ago[IR] Put the Use list waymarking bits in the bit positions documentation says they...
Craig Topper [Mon, 17 Apr 2017 18:12:30 +0000 (18:12 +0000)]
[IR] Put the Use list waymarking bits in the bit positions documentation says they are using

The documentation for the waymarking algorithm says that we use the lower 2 bits of Use::Prev to store the way marking bits. But because we use a PointerIntPair with the default PointerLikeTypeTraits, we're using bits 2:1 on 64-bit targets.

There's also a trick employed for distinguishing Users that have Uses stored with them and Users that have Uses stored in a separate array. The documentation says we use the LSB of the first byte of the real User object or the User* that occurs at the end of the Use array. But again due to the PointerLikeTypeTraits we're really using bit 2(64-bit) or bit 1(32-bit) and not the LSB. This is a little worrying because the first byte of the User object is the vtable ptr so we're assuming the vtable has 8 byte or 4 byte alignment where what is documented would only require 2 byte alignment.

This patch provides a custom traits override for these two cases to put the bits where the documentation says they are. It also has the side effect of removing some shifts from the waymarking traversal implementation.

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

llvm-svn: 300471

7 years agoAMDGPU: Set CodePointerSize to 8 for amdgcn
Konstantin Zhuravlyov [Mon, 17 Apr 2017 18:02:09 +0000 (18:02 +0000)]
AMDGPU: Set CodePointerSize to 8 for amdgcn

llvm-svn: 300470

7 years agoAdd additional CHECKs to safestack.c.
Adrian Prantl [Mon, 17 Apr 2017 17:57:05 +0000 (17:57 +0000)]
Add additional CHECKs to safestack.c.

llvm-svn: 300469

7 years agoRevert "Revert "Add a test for debug info with the safestack sanitizer enabled.""
Adrian Prantl [Mon, 17 Apr 2017 17:57:03 +0000 (17:57 +0000)]
Revert "Revert "Add a test for debug info with the safestack sanitizer enabled.""

This reapplies commit r299730 with an additional REQUIRES line.

llvm-svn: 300468

7 years agoRevert "Revert "Add a test for __block variables + asan.""
Adrian Prantl [Mon, 17 Apr 2017 17:57:01 +0000 (17:57 +0000)]
Revert "Revert "Add a test for __block variables + asan.""

This reapplies commit r300228.

llvm-svn: 300467

7 years agoRevert "Revert "Add an end-to-end testcase for address sanitizer.""
Adrian Prantl [Mon, 17 Apr 2017 17:56:59 +0000 (17:56 +0000)]
Revert "Revert "Add an end-to-end testcase for address sanitizer.""
This reapplies r299731 and adds an appropriate REQUIRES line.

llvm-svn: 300466

7 years agoObject: Use offset+size as the irsymtab string representation.
Peter Collingbourne [Mon, 17 Apr 2017 17:55:24 +0000 (17:55 +0000)]
Object: Use offset+size as the irsymtab string representation.

This is consistent with the bitcode string table.

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

llvm-svn: 300465

7 years agoBitcode: Add a string table to the bitcode format.
Peter Collingbourne [Mon, 17 Apr 2017 17:51:36 +0000 (17:51 +0000)]
Bitcode: Add a string table to the bitcode format.

Add a top-level STRTAB block containing a string table blob, and start storing
strings for module codes FUNCTION, GLOBALVAR, ALIAS, IFUNC and COMDAT in
the string table.

This change allows us to share names between globals and comdats as well
as between modules, and improves the efficiency of loading bitcode files by
no longer using a bit encoding for symbol names. Once we start writing the
irsymtab to the bitcode file we will also be able to share strings between
it and the module.

On my machine, link time for Chromium for Linux with ThinLTO decreases by
about 7% for no-op incremental builds or about 1% for full builds. Total
bitcode file size decreases by about 3%.

As discussed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2017-April/111732.html

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

llvm-svn: 300464

7 years agoDistinguish between code pointer size and DataLayout::getPointerSize() in DWARF info...
Konstantin Zhuravlyov [Mon, 17 Apr 2017 17:41:25 +0000 (17:41 +0000)]
Distinguish between code pointer size and DataLayout::getPointerSize() in DWARF info generation

llvm-svn: 300463

7 years agoAArch64: support nonlazybind
Tim Northover [Mon, 17 Apr 2017 17:27:56 +0000 (17:27 +0000)]
AArch64: support nonlazybind

It's almost certainly not a good idea to actually use it in most cases (there's
a pretty large code size overhead on AArch64), but we can't do those
experiments until it's supported.

llvm-svn: 300462

7 years agoUse default ref capture to simplify local lambdas, use a template to avoid std::funct...
David Blaikie [Mon, 17 Apr 2017 17:16:19 +0000 (17:16 +0000)]
Use default ref capture to simplify local lambdas, use a template to avoid std::function overhead, other cleanup

llvm-svn: 300461

7 years agoRevert "Add a test for debug info with the safestack sanitizer enabled."
Ahmed Bougacha [Mon, 17 Apr 2017 16:59:29 +0000 (16:59 +0000)]
Revert "Add a test for debug info with the safestack sanitizer enabled."

This reverts commit r299730.

It's causing failures on a bot because of missing compiler-rt:
http://green.lab.llvm.org/green/job/clang-stage2-cmake-RgSan_check

llvm-svn: 300460

7 years agoRevert "Add an end-to-end testcase for address sanitizer."
Ahmed Bougacha [Mon, 17 Apr 2017 16:59:27 +0000 (16:59 +0000)]
Revert "Add an end-to-end testcase for address sanitizer."

This reverts commit r299731.

It's causing failures on a bot because of missing compiler-rt:
http://green.lab.llvm.org/green/job/clang-stage2-cmake-RgSan_check

llvm-svn: 300459

7 years agoRevert "Add a test for __block variables + asan."
Ahmed Bougacha [Mon, 17 Apr 2017 16:59:25 +0000 (16:59 +0000)]
Revert "Add a test for __block variables + asan."

This reverts commit r300228.

It's causing failures on a bot because of missing compiler-rt:
http://green.lab.llvm.org/green/job/clang-stage2-cmake-RgSan_check

llvm-svn: 300458

7 years agoIntroduce APInt::isSignBitSet/isSignBitClear. Use in place isSignBitSet in place...
Craig Topper [Mon, 17 Apr 2017 16:38:20 +0000 (16:38 +0000)]
Introduce APInt::isSignBitSet/isSignBitClear. Use in place isSignBitSet in place of isNegative in known bits tracking.

This makes statements like KnownZero.isNegative() (which means the value we're tracking is positive) less confusing.

llvm-svn: 300457

7 years agoDon't read non-readable address ranges during lsan pointer scanning
Francis Ricci [Mon, 17 Apr 2017 16:34:38 +0000 (16:34 +0000)]
Don't read non-readable address ranges during lsan pointer scanning

Summary: This specifically addresses the Mach-O zero page, which we cannot read from.

Reviewers: kubamracek, samsonov, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300456

7 years agoDon't ever reduce the timeout of a packet, only increase it.
Greg Clayton [Mon, 17 Apr 2017 16:20:22 +0000 (16:20 +0000)]
Don't ever reduce the timeout of a packet, only increase it.

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

llvm-svn: 300455

7 years ago[ObjC] Mark loads from __NSArray0 and __NSDictionary0 as invariant.load.
Akira Hatanaka [Mon, 17 Apr 2017 15:21:55 +0000 (15:21 +0000)]
[ObjC] Mark loads from __NSArray0 and __NSDictionary0 as invariant.load.

Also, simplify code by calling MakeNaturalAlignAddrLValue.

This is a follow-up to r300396.

llvm-svn: 300454

7 years agoAMDGPU: SimplifyDemandedElts for image intrinsics
Matt Arsenault [Mon, 17 Apr 2017 15:12:44 +0000 (15:12 +0000)]
AMDGPU: SimplifyDemandedElts for image intrinsics

Causes some VGPR usage improvements in shaderdb, but
introduces some SGPR spilling regressions due to random
scheduling changes later.

llvm-svn: 300453

7 years ago[LCSSA] Don't insert tokens into the worklist at all.
Davide Italiano [Mon, 17 Apr 2017 14:32:05 +0000 (14:32 +0000)]
[LCSSA] Don't insert tokens into the worklist at all.

We're gonna skip them anyway, so there's no point in inserting them
in the first place.

llvm-svn: 300452

7 years agoSigh. Once again forgot about the 'no exceptions' bots.
Marshall Clow [Mon, 17 Apr 2017 14:18:44 +0000 (14:18 +0000)]
Sigh. Once again forgot about the 'no exceptions' bots.

llvm-svn: 300451

7 years agoScan Kernel Alloc Once page for global pointers
Francis Ricci [Mon, 17 Apr 2017 14:07:06 +0000 (14:07 +0000)]
Scan Kernel Alloc Once page for global pointers

Summary: libxpc stashes some pointers here.

Reviewers: kubamracek, alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 300450

7 years agoMark LWG#2853 as complete. No code changes required, but added a couple of extra...
Marshall Clow [Mon, 17 Apr 2017 13:19:14 +0000 (13:19 +0000)]
Mark LWG#2853 as complete. No code changes required, but added a couple of extra tests

llvm-svn: 300449

7 years agoFix crash in invoking microtask on ios arm64.
Andrey Churbanov [Mon, 17 Apr 2017 11:58:20 +0000 (11:58 +0000)]
Fix crash in invoking microtask on ios arm64.

Patch by Ni Hui.

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

llvm-svn: 300448

7 years agoIntroducing LLVMMetadataRef
Amaury Sechet [Mon, 17 Apr 2017 11:52:54 +0000 (11:52 +0000)]
Introducing LLVMMetadataRef

Summary:
This seems like an uncontroversial first step toward providing access to the metadata hierarchy that now exists in LLVM. This should allow for good debug info support from C.

Future plans are to deprecate API that take mixed bags of values and metadata (mainly the LLVMMDNode family of functions) and migrate the rest toward the use of LLVMMetadataRef.

Once this is in place, mapping of DIBuilder will be able to start.

Reviewers: mehdi_amini, echristo, whitequark, jketema, Wallbraker

Reviewed By: Wallbraker

Subscribers: Eugene.Zelenko, axw, mehdi_amini, llvm-commits

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

llvm-svn: 300447

7 years ago[LoopPeeling] Get rid of Phis that become invariant after N steps
Max Kazantsev [Mon, 17 Apr 2017 09:52:02 +0000 (09:52 +0000)]
[LoopPeeling] Get rid of Phis that become invariant after N steps

This patch is a generalization of the improvement introduced in rL296898.
Previously, we were able to peel one iteration of a loop to get rid of a Phi that becomes
an invariant on the 2nd iteration. In more general case, if a Phi becomes invariant after
N iterations, we can peel N times and turn it into invariant.
In order to do this, we for every Phi in loop's header we define the Invariant Depth value
which is calculated as follows:

Given %x = phi <Inputs from above the loop>, ..., [%y, %back.edge].

If %y is a loop invariant, then Depth(%x) = 1.
If %y is a Phi from the loop header, Depth(%x) = Depth(%y) + 1.
Otherwise, Depth(%x) is infinite.
Notice that if we peel a loop, all Phis with Depth = 1 become invariants,
and all other Phis with finite depth decrease the depth by 1.
Thus, peeling N first iterations allows us to turn all Phis with Depth <= N
into invariants.

Reviewers: reames, apilipenko, mkuper, skatkov, anna, sanjoy

Reviewed By: sanjoy

Subscribers: llvm-commits

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

llvm-svn: 300446

7 years ago[ELF] - Add compress-debug-output-i386.s testcase.
George Rimar [Mon, 17 Apr 2017 09:04:07 +0000 (09:04 +0000)]
[ELF] - Add compress-debug-output-i386.s testcase.

This is for --compress-debug-sections (r300444), we have
x64 testcase, but did not have i386 one.

llvm-svn: 300445

7 years ago[ELF] - Implemented --compress-debug-sections option.
George Rimar [Mon, 17 Apr 2017 08:58:12 +0000 (08:58 +0000)]
[ELF] - Implemented --compress-debug-sections option.

Patch implements --compress-debug-sections=zlib.

In compare with D20211 (a year old patch, abandoned), it implementation
uses streaming and fully reimplemented, does not support zlib-gnu for
simplification.

This is PR32308.

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

llvm-svn: 300444

7 years agoAddress http://bugs.llvm.org/pr30994 so that a non-friend can properly replace a...
Yaron Keren [Mon, 17 Apr 2017 08:51:20 +0000 (08:51 +0000)]
Address bugs.llvm.org/pr30994 so that a non-friend can properly replace a friend, and a visible friend can properly replace an invisible friend but not vice verse, and definitions are not replaced. This fixes the two FIXME in SemaTemplate/friend-template.cpp.

The code implements Richard Smith suggestion in comment 3 of the PR.

reviewer: Vassil Vassilev

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

llvm-svn: 300443

7 years ago[BPI] NFC: reorder ifs to bail out earlier
Serguei Katkov [Mon, 17 Apr 2017 06:39:47 +0000 (06:39 +0000)]
[BPI] NFC: reorder ifs to bail out earlier

This is non-functional change to re-order if statements to bail out earlier
from unreachable and ColdCall heuristics.

Reviewers: sanjoy, reames, junbuml, vsk, chandlerc

Reviewed By: chandlerc

Subscribers: llvm-commits

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

llvm-svn: 300442

7 years ago[LoopPeeling] Fix condition for phi-eliminating peeling
Max Kazantsev [Mon, 17 Apr 2017 05:38:28 +0000 (05:38 +0000)]
[LoopPeeling] Fix condition for phi-eliminating peeling

When peeling loops basing on phis becoming invariants, we make a wrong loop size check.
UP.Threshold should be compared against the total numbers of instructions after the transformation,
which is equal to 2 * LoopSize in case of peeling one iteration.
We should also check that the maximum allowed number of peeled iterations is not zero.

Reviewers: sanjoy, anna, reames, mkuper

Reviewed By: mkuper

Subscribers: llvm-commits

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

llvm-svn: 300441

7 years ago[BPI] Use metadata info before any other heuristics
Serguei Katkov [Mon, 17 Apr 2017 04:33:04 +0000 (04:33 +0000)]
[BPI] Use metadata info before any other heuristics

Metadata potentially is more precise than any heuristics we use, so
it makes sense to use first metadata info if it is available. However it makes
sense to examine it against other strong heuristics like unreachable one.
If edge coming to unreachable block has higher probability then it is expected
by unreachable heuristic then we use heuristic and remaining probability is
distributed among other reachable blocks equally.

An example where metadata might be more strong then unreachable heuristic is
as follows: it is possible that there are two branches and for the branch A
metadata says that its probability is (0, 2^25). For the branch B
the probability is (1, 2^25).
So the expectation is that first edge of B is hotter than first edge of A
because first edge of A did not executed at least once.
If first edge of A points to the unreachable block then using the unreachable
heuristics we'll set the probability for A to (1, 2^20) and now edge of A
becomes hotter than edge of B.
This is unexpected behavior.

This fixed the biggest part of https://bugs.llvm.org/show_bug.cgi?id=32214

Reviewers: sanjoy, junbuml, vsk, chandlerc

Reviewed By: chandlerc

Subscribers: llvm-commits, reames, davidxl

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

llvm-svn: 300440

7 years ago[InstCombine] Simplify 1/X for vectors.
Craig Topper [Mon, 17 Apr 2017 03:41:47 +0000 (03:41 +0000)]
[InstCombine] Simplify 1/X for vectors.

llvm-svn: 300439

7 years ago[InstCombine] Add test cases for missing support for simplifying 1/X for vectors...
Craig Topper [Mon, 17 Apr 2017 03:41:44 +0000 (03:41 +0000)]
[InstCombine] Add test cases for missing support for simplifying 1/X for vectors. NFC

llvm-svn: 300438

7 years ago[InstCombine] Add support for vector srem->urem.
Craig Topper [Mon, 17 Apr 2017 01:51:24 +0000 (01:51 +0000)]
[InstCombine] Add support for vector srem->urem.

llvm-svn: 300437

7 years ago[InstCombine] Add missing testcases for srem->urem conversion. The vector version...
Craig Topper [Mon, 17 Apr 2017 01:51:21 +0000 (01:51 +0000)]
[InstCombine] Add missing testcases for srem->urem conversion. The vector version isn't currently supported. NFC

llvm-svn: 300436

7 years ago[InstCombine] Add support for turning vector sdiv into udiv.
Craig Topper [Mon, 17 Apr 2017 01:51:19 +0000 (01:51 +0000)]
[InstCombine] Add support for turning vector sdiv into udiv.

llvm-svn: 300435

7 years ago[InstCombine] Add test cases for missing support for turning vector sdiv into udiv...
Craig Topper [Mon, 17 Apr 2017 01:51:16 +0000 (01:51 +0000)]
[InstCombine] Add test cases for missing support for turning vector sdiv into udiv. NFC

llvm-svn: 300434

7 years ago[LCSSA] Simplify a loop. NFCI.
Davide Italiano [Mon, 17 Apr 2017 00:02:45 +0000 (00:02 +0000)]
[LCSSA] Simplify a loop. NFCI.

llvm-svn: 300433

7 years ago[InstCombine][ValueTracking] When computing known bits for Srem make sure we don...
Craig Topper [Sun, 16 Apr 2017 21:46:12 +0000 (21:46 +0000)]
[InstCombine][ValueTracking] When computing known bits for Srem make sure we don't compute known bits for the LHS twice.

If we already called computeKnownBits for the RHS being a constant power of 2, we've already computed everything we can and should just stop. I think previously we would still recurse if we had determined the result was negative or had not determined the sign bit at all.

llvm-svn: 300432

7 years ago[LCSSA] Fix non-determinism due to iterating over a SmallPtrSet.
Davide Italiano [Sun, 16 Apr 2017 21:07:04 +0000 (21:07 +0000)]
[LCSSA] Fix non-determinism due to iterating over a SmallPtrSet.

Use a SmallSetVector instead.

llvm-svn: 300431