oota-llvm.git
10 years agoGraphWriter: try gv before xdg-open
Alp Toker [Wed, 4 Jun 2014 04:11:12 +0000 (04:11 +0000)]
GraphWriter: try gv before xdg-open

Avoid changing behaviour for everyone who's used to the traditional ghostview
UI, especially since it knows how to stay in the foreground unlike xdg-open.

Amendment to r210147.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210148 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoGraphWriter: support the XDG open utility
Alp Toker [Wed, 4 Jun 2014 03:57:44 +0000 (03:57 +0000)]
GraphWriter: support the XDG open utility

This runs a suitable viewer on Unix desktop environments specified by
Freedesktop.org (GNOME, KDE, Linux distributions etc.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210147 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoconfig.h: fix layering and don't duplicate definitions
Alp Toker [Wed, 4 Jun 2014 03:21:38 +0000 (03:21 +0000)]
config.h: fix layering and don't duplicate definitions

Also correct the llvm-config.h header guard so it doesn't depend on 'CONFIG_H'
which is commonly defined in external projects and caused trouble for
embedders.

In future llvm/Config/llvm-config.h will be installed, but not
the private llvm/Config/config.h header.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210144 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoDebugInfo: Partial revert r209984 due to more cases where abstract DbgVariables do...
David Blaikie [Wed, 4 Jun 2014 01:30:59 +0000 (01:30 +0000)]
DebugInfo: Partial revert r209984 due to more cases where abstract DbgVariables do not have associated DIEs.

Along with a test case to demonstrate that due to inlining order there
are cases where abstract variable DIEs are not constructed since the
abstract subprogram was built due to a previous inlining that optimized
away those variables. This produces incorrect debug info (the 'missing'
abstract variable causes the inlined instance of that variable to be
emitted with a full description (name, line, file) rather than
referencing the abstract origin), but this commit at least ensures that
it doesn't crash...

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210143 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix typos
Matt Arsenault [Tue, 3 Jun 2014 23:06:13 +0000 (23:06 +0000)]
Fix typos

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210135 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoCalculate dead instructions when a live interval is created.
Pete Cooper [Tue, 3 Jun 2014 22:42:10 +0000 (22:42 +0000)]
Calculate dead instructions when a live interval is created.

This gets us closer to being able to remove LiveVariables entirely which is where dead instructions are currently tagged as such.

Reviewed by Jakob Olesen

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210132 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRevert r209381 as it isn't a local variable. Add a testcase so that
Eric Christopher [Tue, 3 Jun 2014 21:01:39 +0000 (21:01 +0000)]
Revert r209381 as it isn't a local variable. Add a testcase so that
we know next time this happens.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210127 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFixup formatting in the pass.
Eric Christopher [Tue, 3 Jun 2014 21:01:35 +0000 (21:01 +0000)]
Fixup formatting in the pass.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210126 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUpdate comments to match reality.
Rafael Espindola [Tue, 3 Jun 2014 20:25:26 +0000 (20:25 +0000)]
Update comments to match reality.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210125 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix a small bug in the parsing of anonymous globals.
Rafael Espindola [Tue, 3 Jun 2014 20:07:32 +0000 (20:07 +0000)]
Fix a small bug in the parsing of anonymous globals.

It was able to parse

hidden dllexport global i32 42

but not

dllexport global i32 42

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210121 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoSimplify the parsing of unnamed globals. No functionality changed.
Rafael Espindola [Tue, 3 Jun 2014 20:00:20 +0000 (20:00 +0000)]
Simplify the parsing of unnamed globals. No functionality changed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210120 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUpdate comment. This should have been part of r210062.
Rafael Espindola [Tue, 3 Jun 2014 19:38:37 +0000 (19:38 +0000)]
Update comment. This should have been part of r210062.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210119 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRemove some redundant doc comments
Alp Toker [Tue, 3 Jun 2014 19:06:49 +0000 (19:06 +0000)]
Remove some redundant doc comments

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210118 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[AArch64] Fix typo in load/store optimizer.
Tilmann Scheller [Tue, 3 Jun 2014 16:33:13 +0000 (16:33 +0000)]
[AArch64] Fix typo in load/store optimizer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210114 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[AArch64] Add regression tests for the load/store optimizer which cover post-index...
Tilmann Scheller [Tue, 3 Jun 2014 16:03:00 +0000 (16:03 +0000)]
[AArch64] Add regression tests for the load/store optimizer which cover post-index update folding with sub rather than add.

The tests check that the following transform happens:

  (ldr|str) X, [x20]
   ...
  sub x20, x20, #16
   ->
  (ldr|str) X, [x20], #-16

with X being either w0, x0, s0, d0 or q0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210113 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoImplement one operator== with another.
Rafael Espindola [Tue, 3 Jun 2014 15:06:22 +0000 (15:06 +0000)]
Implement one operator== with another.

Thanks for David Blaikie for the suggestion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210107 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[asan] Fix coverage instrumentation with -asan-globals=0.
Evgeniy Stepanov [Tue, 3 Jun 2014 14:16:00 +0000 (14:16 +0000)]
[asan] Fix coverage instrumentation with -asan-globals=0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210103 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAArch64: mark small types (i1, i8, i16) as promoted
Tim Northover [Tue, 3 Jun 2014 13:54:53 +0000 (13:54 +0000)]
AArch64: mark small types (i1, i8, i16) as promoted

This means the output of LowerFormalArguments returns a lowered
SDValue with the correct type (expected in SelectionDAGBuilder).
Without this, an assertion under a DEBUG macro triggers when those
types are passed on the stack.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210102 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdd operator== and operator!= to compare with nullptr.
Rafael Espindola [Tue, 3 Jun 2014 13:26:18 +0000 (13:26 +0000)]
Add operator== and operator!= to compare with nullptr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210100 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUse an enum class.
Rafael Espindola [Tue, 3 Jun 2014 05:26:12 +0000 (05:26 +0000)]
Use an enum class.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210078 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUse an enum class.
Rafael Espindola [Tue, 3 Jun 2014 05:12:33 +0000 (05:12 +0000)]
Use an enum class.

Might also fix the windows build.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210077 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRemove the last unspecified_bool_type from llvm.
Rafael Espindola [Tue, 3 Jun 2014 05:05:15 +0000 (05:05 +0000)]
Remove the last unspecified_bool_type from llvm.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210076 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoMake this operator bool() explicit to match the standard library.
Rafael Espindola [Tue, 3 Jun 2014 04:54:15 +0000 (04:54 +0000)]
Make this operator bool() explicit to match the standard library.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210073 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoMake this operator bool() explicit to match the standard library.
Rafael Espindola [Tue, 3 Jun 2014 04:42:24 +0000 (04:42 +0000)]
Make this operator bool() explicit to match the standard library.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210072 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoIgnore line numbers on debug intrinsics. Add an assert to ensure that we aren't emitt...
Nick Lewycky [Tue, 3 Jun 2014 04:25:36 +0000 (04:25 +0000)]
Ignore line numbers on debug intrinsics. Add an assert to ensure that we aren't emitting line number zero, the .gcno format uses this to indicate that the next field is a filename.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210068 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[AArch64] Correctly deal with VPR stack parameter passing.
Jiangning Liu [Tue, 3 Jun 2014 03:25:09 +0000 (03:25 +0000)]
[AArch64] Correctly deal with VPR stack parameter passing.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210067 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoProcess::GetRandomNumber(): fix insecure RNG
Alp Toker [Tue, 3 Jun 2014 03:01:03 +0000 (03:01 +0000)]
Process::GetRandomNumber(): fix insecure RNG

This could have generated non-random output under error conditions in release
builds.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210065 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAllow alias to point to an arbitrary ConstantExpr.
Rafael Espindola [Tue, 3 Jun 2014 02:41:57 +0000 (02:41 +0000)]
Allow alias to point to an arbitrary ConstantExpr.

This  patch changes GlobalAlias to point to an arbitrary ConstantExpr and it is
up to MC (or the system assembler) to decide if that expression is valid or not.

This reduces our ability to diagnose invalid uses and how early we can spot
them, but it also lets us do things like

@test5 = alias inttoptr(i32 sub (i32 ptrtoint (i32* @test2 to i32),
                                 i32 ptrtoint (i32* @bar to i32)) to i32*)

An important implication of this patch is that the notion of aliased global
doesn't exist any more. The alias has to encode the information needed to
access it in its metadata (linkage, visibility, type, etc).

Another consequence to notice is that getSection has to return a "const char *".
It could return a NullTerminatedStringRef if there was such a thing, but when
that was proposed the decision was to just uses "const char*" for that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210062 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdd back commit r210029.
Rafael Espindola [Mon, 2 Jun 2014 22:01:04 +0000 (22:01 +0000)]
Add back commit r210029.

The code was actually correct. Sorry for the confusion. I have expanded the
comment saying why the analysis is valid to avoid me misunderstaning it
again in the future.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210052 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoConvert test to FileCheck.
Rafael Espindola [Mon, 2 Jun 2014 21:23:54 +0000 (21:23 +0000)]
Convert test to FileCheck.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210049 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRevert "Add the nsw flag when we detect that an add will not signed overflow."
Rafael Espindola [Mon, 2 Jun 2014 21:12:19 +0000 (21:12 +0000)]
Revert "Add the nsw flag when we detect that an add will not signed overflow."

This reverts commit r210029.

It was not correctly handling cases where LHS and RHS had multiple but different
sign bits.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210048 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoInitLibcallNames can take a Triple instead of a TargetMachine.
Eric Christopher [Mon, 2 Jun 2014 20:51:49 +0000 (20:51 +0000)]
InitLibcallNames can take a Triple instead of a TargetMachine.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210045 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdded support to optimize comparisons with "lshr exact" of a constant.
Rafael Espindola [Mon, 2 Jun 2014 19:19:04 +0000 (19:19 +0000)]
Added support to optimize comparisons with "lshr exact" of a constant.

Patch by Rahul Jain.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210040 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRemove sanitizer blacklist from ASan/TSan/MSan function passes.
Alexey Samsonov [Mon, 2 Jun 2014 18:08:27 +0000 (18:08 +0000)]
Remove sanitizer blacklist from ASan/TSan/MSan function passes.

Instrumentation passes now use attributes
address_safety/thread_safety/memory_safety which are added by Clang frontend.
Clang parses the blacklist file and adds the attributes accordingly.

Currently blacklist is still used in ASan module pass to disable instrumentation
for certain global variables. We should fix this as well by collecting the
set of globals we're going to instrument in Clang and passing it to ASan
in metadata (as we already do for dynamically-initialized globals and init-order
checking).

This change also removes -tsan-blacklist and -msan-blacklist LLVM commandline
flags in favor of -fsanitize-blacklist= Clang flag.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210038 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoOmit else branch after return.
Eric Christopher [Mon, 2 Jun 2014 17:29:07 +0000 (17:29 +0000)]
Omit else branch after return.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210034 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[X86] Fix checked arithmetic for i8 on X86.
Andrea Di Biagio [Mon, 2 Jun 2014 16:00:27 +0000 (16:00 +0000)]
[X86] Fix checked arithmetic for i8 on X86.

When lowering a ISD::BRCOND into a test+branch, make sure that we
always use the correct condition code to emit the test operation.

This fixes PR19858: "i8 checked mul is wrong on x86".

Patch by Keno Fisher!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210032 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdd the nsw flag when we detect that an add will not signed overflow.
Rafael Espindola [Mon, 2 Jun 2014 14:32:58 +0000 (14:32 +0000)]
Add the nsw flag when we detect that an add will not signed overflow.

We already had a function for checking this, we were just using it only in
specialized cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210029 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[msan] Remove an out-of-date comment.
Evgeniy Stepanov [Mon, 2 Jun 2014 12:58:08 +0000 (12:58 +0000)]
[msan] Remove an out-of-date comment.

MSan is no longer an "early prototype".

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210023 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRemove path_tclsh.m4.
Rafael Espindola [Mon, 2 Jun 2014 12:54:32 +0000 (12:54 +0000)]
Remove path_tclsh.m4.

Looks like it was only used by dejagnu and is now dead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210022 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[AArch64] Add some more regression tests for store pre-index update folding in the...
Tilmann Scheller [Mon, 2 Jun 2014 12:33:33 +0000 (12:33 +0000)]
[AArch64] Add some more regression tests for store pre-index update folding in the load/store optimizer.

Add tests for the following transform:

 add x8, x8, #16
  ...
 str X, [x8]
  ->
 str X, [x8, #16]!

with X being either w0, x0, s0, d0 or q0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210021 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[msan] Handle x86 vector pack intrinsics.
Evgeniy Stepanov [Mon, 2 Jun 2014 12:31:44 +0000 (12:31 +0000)]
[msan] Handle x86 vector pack intrinsics.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210020 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[AArch64] Add some more regression tests for load pre-index update folding in the...
Tilmann Scheller [Mon, 2 Jun 2014 11:57:09 +0000 (11:57 +0000)]
[AArch64] Add some more regression tests for load pre-index update folding in the load/store optimizer.

Add tests for the following transform:

 add x8, x8, #16
  ...
 ldr X, [x8]
  ->
 ldr X, [x8, #16]!

with X being either w0, x0, s0, d0 or q0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210018 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdded inst combine tarnsform for (1 << X) & C pattrens where C is (some PowerOf2...
Dinesh Dwivedi [Mon, 2 Jun 2014 07:57:24 +0000 (07:57 +0000)]
Added inst combine tarnsform for (1 << X) & C pattrens where C is (some PowerOf2 - 1)

This patch can handles following cases from http://nondot.org/sabre/LLVMNotes/InstCombine.txt
  "((1 << X) & 7) == 0" ==> "X > 2"
  "((1 << X) & 7) != 0" ==> "X < 3".

Differential Revision: http://reviews.llvm.org/D3678

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210007 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdded inst combine transforms for single bit tests from Chris's note
Dinesh Dwivedi [Mon, 2 Jun 2014 07:24:36 +0000 (07:24 +0000)]
Added inst combine transforms for single bit tests from Chris's note

if ((x & C) == 0) x |= C becomes x |= C
if ((x & C) != 0) x ^= C becomes x &= ~C
if ((x & C) == 0) x ^= C becomes x |= C
if ((x & C) != 0) x &= ~C becomes x &= ~C
if ((x & C) == 0) x &= ~C becomes nothing

Differential Revision: http://reviews.llvm.org/D3777

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210006 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoSilence -Wreturn-type warning
Alp Toker [Mon, 2 Jun 2014 04:34:10 +0000 (04:34 +0000)]
Silence -Wreturn-type warning

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210005 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoGraphWriter: tweak the program fallback order
Alp Toker [Mon, 2 Jun 2014 04:14:23 +0000 (04:14 +0000)]
GraphWriter: tweak the program fallback order

Amend r210001 to use the classic fallback order behaviour if the requested
graphing program isn't found.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210003 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoGraphWriter: detect graph viewer programs at runtime
Alp Toker [Mon, 2 Jun 2014 01:40:04 +0000 (01:40 +0000)]
GraphWriter: detect graph viewer programs at runtime

Replace the crufty build-time configure checks for program paths with
equivalent runtime logic.

This lets users install graphing tools as needed without having to reconfigure
and rebuild LLVM, while eliminating a long chain of inappropriate compile
dependencies that included GUI programs and the windowing system.

Additional features:

 * Support the OS X 'open' command to view graphs generated by any of the
   Graphviz utilities. This is an alternative to the Graphviz OS X UI which is
   no longer available on Mountain Lion.

 * Produce informative log output upon failure to indicate which programs can
   be installed to view graphs.

Ping me if this doesn't work for your particular environment.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210001 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoInstruction::isIdenticalToWhenDefined(): Check getNumOperands() in advance of std...
NAKAMURA Takumi [Mon, 2 Jun 2014 01:35:34 +0000 (01:35 +0000)]
Instruction::isIdenticalToWhenDefined(): Check getNumOperands() in advance of std::equal(op) to appease MSVC Debug build.

MSVC Debug build is confused with (possibly invalid) op_begin(), if op_begin() == op_end().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210000 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoSupport: add 6-parameter format
Saleem Abdulrasool [Mon, 2 Jun 2014 01:17:54 +0000 (01:17 +0000)]
Support: add 6-parameter format

Since we cannot yet use variadic templates, add a specialisation for
6-parameters to format.  This is motivated by a need for the additional
parameter for formatting information for an unwind decoder for Windows on ARM.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209999 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoSupport: add Windows ARM EH data structures
Saleem Abdulrasool [Mon, 2 Jun 2014 01:17:49 +0000 (01:17 +0000)]
Support: add Windows ARM EH data structures

Introduce the support structures necessary to deal with the Windows ARM EH data.
These definitions are extremely aggressive about assertions to aid future use
for generation of the entries and subsequent decoding.

The names for the various fields are meant to reflect the names used by the
Visual Studio toolchain to aid communication.

Due to the complexity in reading a few of the values, there are a couple of
additional utility functions to decode the information.

In general, there are two ways to encode the unwinding information:
- packed, which places the data inline into the
  _IMAGE_ARM_RUNTIME_FUNCTION_ENTRY structure.
- unpacked, which places the data into auxiliary structures placed into the
  .xdata section.

The set of structures allow reading of data in either encoding, with the minor
caveat that epilogue scopes need to be decoded manually by constructing the
structure from the data returned by the RuntimeFunction structure.

These definitions are meant for read-only access at the current point as the
first use of them will be to decode the exception information.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209998 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoARMEB: Fix function return type f64
Christian Pirker [Sun, 1 Jun 2014 09:30:52 +0000 (09:30 +0000)]
ARMEB: Fix function return type f64

Reviewed at http://reviews.llvm.org/D3968

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209990 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUpdates in IntelJITEventListener.cpp - by Arch Robison.
Elena Demikhovsky [Sun, 1 Jun 2014 08:45:11 +0000 (08:45 +0000)]
Updates in IntelJITEventListener.cpp - by Arch Robison.

This patch updates IntelJITEventListener.cpp to account for revision 206654, which removed some methods from DILineInfo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209989 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoR600: Set all float vector expands in the same place
Matt Arsenault [Sun, 1 Jun 2014 07:38:21 +0000 (07:38 +0000)]
R600: Set all float vector expands in the same place

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209988 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoDebugInfo: Assert that DbgVariables have associated DIEs
David Blaikie [Sun, 1 Jun 2014 03:38:13 +0000 (03:38 +0000)]
DebugInfo: Assert that DbgVariables have associated DIEs

This was previously committed in r209680 and reverted in r209683 after
it caused sanitizer builds to crash.

The issue seems to be that the DebugLoc associated with dbg.value IR
intrinsics isn't necessarily accurate. Instead, we duplicate the
DIVariables and add an InlinedAt field to them to record their
location.

We were using this InlinedAt field to compute the LexicalScope for the
variable, but not using it in the abstract DbgVariable construction and
mapping. This resulted in a formal parameter to the current concrete
function, correctly having no InlinedAt information, but incorrectly
having a DebugLoc that described an inlined location within the
function... thus an abstract DbgVariable was created for the variable,
but its DIE was never constructed (since the LexicalScope had no such
variable). This DbgVariable was silently ignored (by testing for a
non-null DIE on the abstract DbgVariable).

So, fix this by using the right scoping information when constructing
abstract DbgVariables.

In the long run, I suspect we want to undo the work that added this
second kind of location tracking and fix the places where the DebugLoc
propagation on the dbg.value intrinsic fails. This will shrink debug
info (by not duplicating DIVariables), make it more efficient (by not
having to construct new DIVariable metadata nodes to try to map back to
a single variable), and benefit all instructions.

But perhaps there are insurmountable issues with DebugLoc quality that
I'm unaware of... I just don't know how we can't /just keep the DebugLoc
from the dbg.declare to the dbg.values and never get this wrong/.

Some history context:

http://llvm.org/viewvc/llvm-project?view=revision&revision=135629
http://llvm.org/viewvc/llvm-project?view=revision&revision=137253

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209984 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix typos
Alp Toker [Sat, 31 May 2014 21:26:28 +0000 (21:26 +0000)]
Fix typos

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209982 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoExecutionEngine: avoid NDEBUG in headers
Alp Toker [Sat, 31 May 2014 21:26:17 +0000 (21:26 +0000)]
ExecutionEngine: avoid NDEBUG in headers

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209981 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUpdate a couple of header inclusion guards
Alp Toker [Sat, 31 May 2014 21:26:09 +0000 (21:26 +0000)]
Update a couple of header inclusion guards

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209980 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoR600/SI: Remove redundant patterns
Matt Arsenault [Sat, 31 May 2014 19:25:17 +0000 (19:25 +0000)]
R600/SI: Remove redundant patterns

These patterns are already handled in the instruction definition.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209979 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[SelectionDAG] Force cycle detection in AssignTopologicalOrder before aborting
Adam Nemet [Sat, 31 May 2014 16:23:20 +0000 (16:23 +0000)]
[SelectionDAG] Force cycle detection in AssignTopologicalOrder before aborting

DAG cycle detection is only enabled with ENABLE_EXPENSIVE_CHECKS.  However we
can run it just before we would crash in order to provide more informative
diagnostics.

Now in addition to the "Overran sorted position" message we also get the Node
printed if a cycle was detected.

Tested by building several configs: Debug+Assert, Debug+Assert+Check (this is
ENABLE_EXPENSIVE_CHECKS), Release+Assert and Release.  Also tried that the
AssignTopologicalOrder assert produces the expected results.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209977 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[SelectionDAG] Pass DAG to checkForCycles
Adam Nemet [Sat, 31 May 2014 16:23:17 +0000 (16:23 +0000)]
[SelectionDAG] Pass DAG to checkForCycles

Pass the DAG down to checkForCycles from all callers where we have it.  This
allows target-specific nodes to be printed properly.

Also print some missing newlines.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209976 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[SelectionDAG] Remove duplicate declaration
Adam Nemet [Sat, 31 May 2014 16:23:13 +0000 (16:23 +0000)]
[SelectionDAG] Remove duplicate declaration

Prefer the decl in SelectionDAGNodes.h because it's used there and
SelectionDAG.h includes SelectionDAGNodes.h.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209975 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[Reassociate] Similar to "X + -X" -> "0", added code to handle "X + ~X" -> "-1".
Benjamin Kramer [Sat, 31 May 2014 15:01:54 +0000 (15:01 +0000)]
[Reassociate] Similar to "X + -X" -> "0", added code to handle "X + ~X" -> "-1".

Handle "X + ~X" -> "-1" in the function Value *Reassociate::OptimizeAdd(Instruction *I, SmallVectorImpl<ValueEntry> &Ops);
This patch implements:
TODO: We could handle "X + ~X" -> "-1" if we wanted, since "-X = ~X+1".

Patch by Rahul Jain!

Differential Revision: http://reviews.llvm.org/D3835

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209973 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoR600/SI: Fix [s|u]int_to_fp for i1
Matt Arsenault [Sat, 31 May 2014 06:47:42 +0000 (06:47 +0000)]
R600/SI: Fix [s|u]int_to_fp for i1

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209971 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix typos in tablegen error messages
Matt Arsenault [Sat, 31 May 2014 05:18:52 +0000 (05:18 +0000)]
Fix typos in tablegen error messages

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209968 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[yaml2obj] Add new command line option `-docnum`.
Simon Atanasyan [Sat, 31 May 2014 04:51:07 +0000 (04:51 +0000)]
[yaml2obj] Add new command line option `-docnum`.

Input YAML file might contain multiple object file definitions.
New option `-docnum` allows to specify an ordinal number (starting from 1)
of definition used for an object file generation.

Patch reviewed by Sean Silva.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209967 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoreally fix the windows build.
Rafael Espindola [Sat, 31 May 2014 03:40:00 +0000 (03:40 +0000)]
really fix the windows build.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209964 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix windows build.
Rafael Espindola [Sat, 31 May 2014 03:26:57 +0000 (03:26 +0000)]
Fix windows build.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209961 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoThere is no std::errc::success, remove the llvm one.
Rafael Espindola [Sat, 31 May 2014 03:21:04 +0000 (03:21 +0000)]
There is no std::errc::success, remove the llvm one.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209960 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoTurn errc and windows_error into enum classes.
Rafael Espindola [Sat, 31 May 2014 02:29:28 +0000 (02:29 +0000)]
Turn errc and windows_error into enum classes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209957 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoUse error_code() instead of error_code::succes()
Rafael Espindola [Sat, 31 May 2014 01:37:45 +0000 (01:37 +0000)]
Use error_code() instead of error_code::succes()

There is no std::error_code::success, so this removes much of the noise
in transitioning to std::error_code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209952 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix the behavior of ExecuteAndWait with a non-zero timeout.
Peter Collingbourne [Sat, 31 May 2014 01:36:02 +0000 (01:36 +0000)]
Fix the behavior of ExecuteAndWait with a non-zero timeout.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209951 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoMake blend tests more specific
Filipe Cabecinhas [Sat, 31 May 2014 00:52:23 +0000 (00:52 +0000)]
Make blend tests more specific

Following the lead set by r209324, I'm making these tests match the whole
instruction, so we can be sure we're lowering them correctly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209947 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[ASan] Behave the same for functions w/o sanitize_address attribute and blacklisted...
Alexey Samsonov [Sat, 31 May 2014 00:33:05 +0000 (00:33 +0000)]
[ASan] Behave the same for functions w/o sanitize_address attribute and blacklisted functions

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209946 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[TSan] Fixup a test case after r209939
Alexey Samsonov [Sat, 31 May 2014 00:26:03 +0000 (00:26 +0000)]
[TSan] Fixup a test case after r209939

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209945 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[TSan] Behave the same for functions w/o sanitize_thread attribute and blacklisted...
Alexey Samsonov [Sat, 31 May 2014 00:11:37 +0000 (00:11 +0000)]
[TSan] Behave the same for functions w/o sanitize_thread attribute and blacklisted functions

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209939 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agodelete dead code.
Rafael Espindola [Sat, 31 May 2014 00:10:47 +0000 (00:10 +0000)]
delete dead code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209938 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoHave the TLOF creation take a Triple rather than needing a subtarget.
Eric Christopher [Sat, 31 May 2014 00:07:32 +0000 (00:07 +0000)]
Have the TLOF creation take a Triple rather than needing a subtarget.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209937 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[X86] Add two combine rules to simplify dag nodes introduced during type legalization...
Andrea Di Biagio [Fri, 30 May 2014 23:17:53 +0000 (23:17 +0000)]
[X86] Add two combine rules to simplify dag nodes introduced during type legalization when promoting nodes with illegal vector type.

This patch teaches the backend how to simplify/canonicalize dag node
sequences normally introduced by the backend when promoting certain dag nodes
with illegal vector type.

This patch adds two new combine rules:
1) fold (shuffle (bitcast (BINOP A, B)), Undef, <Mask>) ->
        (shuffle (BINOP (bitcast A), (bitcast B)), Undef, <Mask>)

2) fold (BINOP (shuffle (A, Undef, <Mask>)), (shuffle (B, Undef, <Mask>))) ->
        (shuffle (BINOP A, B), Undef, <Mask>).

Both rules are only triggered on the type-legalized DAG.
In particular, rule 1. is a target specific combine rule that attempts
to sink a bitconvert into the operands of a binary operation.
Rule 2. is a target independet rule that attempts to move a shuffle
immediately after a binary operation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209930 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoConvert a vselect into a concat_vector if possible
Filipe Cabecinhas [Fri, 30 May 2014 23:03:11 +0000 (23:03 +0000)]
Convert a vselect into a concat_vector if possible

Summary:
If both vector args to vselect are concat_vectors and the condition is
constant and picks half a vector from each argument, convert the vselect
into a concat_vectors.

Added a test.

The ConvertSelectToConcatVector is assuming it doesn't get vselects with
arguments of, for example, <undef, undef, true, true>. Those get taken
care of in the checks above its call.

Reviewers: nadav, delena, grosbach, hfinkel

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D3916

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209929 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoisSVR4ABI() returned !isDarwin() so just move that to the else
Eric Christopher [Fri, 30 May 2014 22:47:53 +0000 (22:47 +0000)]
isSVR4ABI() returned !isDarwin() so just move that to the else
block and remove the unreachable code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209927 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRename CreateTLOF->createTLOF to match the rest of the file and the
Eric Christopher [Fri, 30 May 2014 22:47:48 +0000 (22:47 +0000)]
Rename CreateTLOF->createTLOF to match the rest of the file and the
rest of the targets with a similar function name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209926 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoSeparate the check for blend shuffle_vector masks
Filipe Cabecinhas [Fri, 30 May 2014 21:31:21 +0000 (21:31 +0000)]
Separate the check for blend shuffle_vector masks

Summary:
Separate the check for blend shuffle_vector masks into isBlendMask.
This function will also be used to check if a vector shuffle is legal. No
change in functionality was intended, but we ended up improving codegen on
two tests, which were being (more) optimized only if the resulting shuffle
was legal.

Reviewers: nadav, delena, andreadb

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D3964

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209923 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agofixed more typos
Sanjay Patel [Fri, 30 May 2014 21:18:13 +0000 (21:18 +0000)]
fixed more typos

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209921 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoRoll DbgVariable::setMInsn into the constructor. No functional changes.
Adrian Prantl [Fri, 30 May 2014 21:10:13 +0000 (21:10 +0000)]
Roll DbgVariable::setMInsn into the constructor. No functional changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209920 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoadded link to CMake page
Sanjay Patel [Fri, 30 May 2014 21:07:25 +0000 (21:07 +0000)]
added link to CMake page

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209918 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agofixed typo
Sanjay Patel [Fri, 30 May 2014 20:55:55 +0000 (20:55 +0000)]
fixed typo

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209916 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoMake bitcast, extractelement, and insertelement considered cheap for speculation.
Matt Arsenault [Fri, 30 May 2014 18:34:43 +0000 (18:34 +0000)]
Make bitcast, extractelement, and insertelement considered cheap for speculation.

This helps more branches into selects. On R600,
vectors are cheap and anything that helps
remove branches is very good.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209914 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoFix MIPS exception personality encoding.
Logan Chien [Fri, 30 May 2014 16:48:56 +0000 (16:48 +0000)]
Fix MIPS exception personality encoding.

For MIPS, we have to encode the personality routine with
an indirect pointer to absptr; otherwise, some link warning
warning will be raised, and the program might crash in some
early MIPS Android device.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209907 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoMachO: move test to ARM directory.
Tim Northover [Fri, 30 May 2014 16:01:29 +0000 (16:01 +0000)]
MachO: move test to ARM directory.

This test specifies an ARM triple, so it needs ARM as a registered
target.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209905 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoPR19753: Optimize comparisons with "ashr exact" of a constanst.
Rafael Espindola [Fri, 30 May 2014 15:54:32 +0000 (15:54 +0000)]
PR19753: Optimize comparisons with "ashr exact" of a constanst.

Patch by suyog sarda.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209903 91177308-0d34-0410-b5e6-96231b3b80d8

10 years ago[pr19636] Fix known bit computation in urem instruction with power of two.
Rafael Espindola [Fri, 30 May 2014 15:00:45 +0000 (15:00 +0000)]
[pr19636]  Fix known bit computation in urem instruction with power of two.
Patch by Andrey Kuharev.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209902 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoSelectionDAG: skip barriers for unordered atomic operations
Tim Northover [Fri, 30 May 2014 14:41:51 +0000 (14:41 +0000)]
SelectionDAG: skip barriers for unordered atomic operations

Unordered is strictly weaker than monotonic, so if the latter doesn't have any
barriers then the former certainly shouldn't.

rdar://problem/16548260

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209901 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoARM: use AAPCS-style prologues for embedded MachO.
Tim Northover [Fri, 30 May 2014 13:23:06 +0000 (13:23 +0000)]
ARM: use AAPCS-style prologues for embedded MachO.

Darwin prologues save their GPRs in two stages: a narrow push of r0-r7 & lr,
followed by a wide push of the remaining registers if there are any. AAPCS uses
a single push.w instruction.

It turns out that, on average, enough registers get pushed that code is smaller
in the AAPCS prologue, which is a nice property for M-class programmers. They
also have other options available for back-traces, so can hopefully deal with
the fact that FP & LR aren't adjacent in memory.

rdar://problem/15909583

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209895 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoMachO: support N_INDR aliases in assembly files.
Tim Northover [Fri, 30 May 2014 13:22:59 +0000 (13:22 +0000)]
MachO: support N_INDR aliases in assembly files.

This makes LLVM create N_INDR aliases (to be resolved by the linker) when
appropriate.

rdar://problem/15125513

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209894 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAArch64 & ARM: disable generic test that relies on no CFG changes.
Tim Northover [Fri, 30 May 2014 10:56:12 +0000 (10:56 +0000)]
AArch64 & ARM: disable generic test that relies on no CFG changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209885 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoARM & AArch64: make use of common cmpxchg idioms after expansion
Tim Northover [Fri, 30 May 2014 10:09:59 +0000 (10:09 +0000)]
ARM & AArch64: make use of common cmpxchg idioms after expansion

The C and C++ semantics for compare_exchange require it to return a bool
indicating success. This gets mapped to LLVM IR which follows each cmpxchg with
an icmp of the value loaded against the desired value.

When lowered to ldxr/stxr loops, this extra comparison is redundant: its
results are implicit in the control-flow of the function.

This commit makes two changes: it replaces that icmp with appropriate PHI
nodes, and then makes sure earlyCSE is called after expansion to actually make
use of the opportunities revealed.

I've also added -{arm,aarch64}-enable-atomic-tidy options, so that
existing fragile tests aren't perturbed too much by the change. Many
of them either rely on undef/unreachable too pervasively to be
restored to something well-defined (particularly while making sure
they test the same obscure assert from many years ago), or depend on a
particular CFG shape, which is disrupted by SimplifyCFG.

rdar://problem/16227836

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209883 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAArch64 & ARM: remove undefined behaviour from some tests.
Tim Northover [Fri, 30 May 2014 08:59:55 +0000 (08:59 +0000)]
AArch64 & ARM: remove undefined behaviour from some tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209880 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoTest cases named with dates is a legacy rule not used now. Rename several test cases.
Hao Liu [Fri, 30 May 2014 05:58:19 +0000 (05:58 +0000)]
Test cases named with dates is a legacy rule not used now. Rename several test cases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209877 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAllow vectorization of intrinsics such as powi,cttz and ctlz in Loop and SLP Vectorizer.
Karthik Bhat [Fri, 30 May 2014 04:31:24 +0000 (04:31 +0000)]
Allow vectorization of intrinsics such as powi,cttz and ctlz in Loop and SLP Vectorizer.

This patch adds support to vectorize intrinsics such as powi, cttz and ctlz in Vectorizer. These intrinsics are different from other
intrinsics as second argument to these function must be same in order to vectorize them and it should be represented as a scalar.
Review: http://reviews.llvm.org/D3851#inline-32769 and http://reviews.llvm.org/D3937#inline-32857

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209873 91177308-0d34-0410-b5e6-96231b3b80d8

10 years agoAdd a trivial ArrayRef helper overload to the SelectionDAG interface.
Chandler Carruth [Fri, 30 May 2014 03:50:06 +0000 (03:50 +0000)]
Add a trivial ArrayRef helper overload to the SelectionDAG interface.
I'm using this pretty frequently in a patch I'm working on and it seems
generally useful.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209872 91177308-0d34-0410-b5e6-96231b3b80d8