1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
Commit Graph

932 Commits

Author SHA1 Message Date
Craig Topper
0658ff9ba0 [APInt] Add getBitsSetFrom and setBitsFrom to set upper bits starting at a bit
We currently have methods to set a specified number of low bits, a specified number of high bits, or a range of bits. But looking at some existing code it seems sometimes we want to set the high bits starting from a certain bit. Currently we do this with something like getHighBits(BitWidth, BitWidth - StartBit). Or once we start switching to setHighBits, setHighBits(BitWidth - StartBit) or setHighBits(getBitWidth() - StartBit).

Particularly for the latter case it would be better to have a convenience method like setBitsFrom(StartBit) so we don't need to mention the bit width that's already known to the APInt object.

I considered just making setBits have a default value of UINT_MAX for the hiBit argument and we would internally MIN it with the bit width. So if it wasn't specified it would be treated as bit width. This would require removing the assertion we currently have on the value of hiBit and may not be as readable.

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

llvm-svn: 297114
2017-03-07 02:58:36 +00:00
Craig Topper
71df626b08 [APInt] Implement getLowBitsSet/getHighBitsSet/getBitsSet using setLowBits/setHighBits/setBits
This patch implements getLowBitsSet/getHighBitsSet/getBitsSet in terms of the new setLowBits/setHighBits/setBits methods by making an all 0s APInt and then calling the appropriate set method.

This also adds support to setBits to allow loBits/hiBits to be in the other order to match with getBitsSet behavior.

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

llvm-svn: 297112
2017-03-07 02:19:45 +00:00
Craig Topper
3a62ce44b4 [APInt] Add setLowBits/setHighBits methods to APInt.
Summary:
There are quite a few places in the code base that do something like the following to set the high or low bits in an APInt.

KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1);

For BitWidths larger than 64 this creates a short lived APInt with malloced storage. I think it might even call malloc twice. Its better to just provide methods that can set the necessary bits without the temporary APInt.

I'll update usages that benefit in a separate patch.

Reviewers: majnemer, MatzeB, davide, RKSimon, hans

Reviewed By: hans

Subscribers: llvm-commits

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

llvm-svn: 297111
2017-03-07 01:56:01 +00:00
Craig Topper
e2e31b6a01 [APInt] Move operator~ out of line to make it better able to reused memory allocation from temporary objects
Summary:
This makes operator~ take the APInt by value so if it came from a temporary APInt the move constructor will get invoked and it will be able to reuse the memory allocation from the temporary.

This is similar to what was already done for 2s complement negation.

Reviewers: hans, davide, RKSimon

Reviewed By: davide

Subscribers: llvm-commits

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

llvm-svn: 296997
2017-03-06 06:30:47 +00:00
Brad Smith
2d8b1cfabe Set default CPU for OpenBSD/arm to Cortex-A8
llvm-svn: 296493
2017-02-28 17:28:35 +00:00
Craig Topper
5fc36545f5 [APInt] Use UINT64_MAX instead of ~0ULL. NFC
llvm-svn: 296300
2017-02-26 19:28:48 +00:00
Craig Topper
0d258134e5 [APInt] Remove unnecessary early out from getLowBitsSet. The same case is handled equally well by the next check.
llvm-svn: 296299
2017-02-26 19:28:45 +00:00
Simon Pilgrim
879a5b0804 [APInt] Add APInt::extractBits() method to extract APInt subrange (reapplied)
The current pattern for extract bits in range is typically:

Mask.lshr(BitOffset).trunc(SubSizeInBits);

Which can be particularly slow for large APInts (MaskSizeInBits > 64) as they require the allocation of memory for the temporary variable.

This is another of the compile time issues identified in PR32037 (see also D30265).

This patch adds the APInt::extractBits() helper method which avoids the temporary memory allocation.

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

llvm-svn: 296272
2017-02-25 20:01:58 +00:00
Simon Pilgrim
643050a88e Revert: r296141 [APInt] Add APInt::extractBits() method to extract APInt subrange
The current pattern for extract bits in range is typically:

Mask.lshr(BitOffset).trunc(SubSizeInBits);

Which can be particularly slow for large APInts (MaskSizeInBits > 64) as they require the allocation of memory for the temporary variable.

This is another of the compile time issues identified in PR32037 (see also D30265).

This patch adds the APInt::extractBits() helper method which avoids the temporary memory allocation.

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

llvm-svn: 296147
2017-02-24 18:31:04 +00:00
Simon Pilgrim
a9d3aa72eb [APInt] Add APInt::extractBits() method to extract APInt subrange
The current pattern for extract bits in range is typically:

Mask.lshr(BitOffset).trunc(SubSizeInBits);

Which can be particularly slow for large APInts (MaskSizeInBits > 64) as they require the allocation of memory for the temporary variable.

This is another of the compile time issues identified in PR32037 (see also D30265).

This patch adds the APInt::extractBits() helper method which avoids the temporary memory allocation.

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

llvm-svn: 296141
2017-02-24 17:46:18 +00:00
Simon Pilgrim
b9a9904be5 Fix signed/unsigned comparison warnings
llvm-svn: 296109
2017-02-24 11:31:00 +00:00
Simon Pilgrim
af689eb896 [APInt] Add APInt::setBits() method to set all bits in range
The current pattern for setting bits in range is typically:

Mask |= APInt::getBitsSet(MaskSizeInBits, LoPos, HiPos);

Which can be particularly slow for large APInts (MaskSizeInBits > 64) as they require the allocation memory for the temporary variable.

This is one of the key compile time issues identified in PR32037.

This patch adds the APInt::setBits() helper method which avoids the temporary memory allocation completely, this first implementation uses setBit() internally instead but already significantly reduces the regression in PR32037 (~10% drop). Additional optimization may be possible.

I investigated whether there is need for APInt::clearBits() and APInt::flipBits() equivalents but haven't seen these patterns to be particularly common, but reusing the code would be trivial.

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

llvm-svn: 296102
2017-02-24 10:15:29 +00:00
Bryant Wong
e3c7364670 [ADT] Fix zip iterator interface.
This commit provides `zip_{first,shortest}` with the standard member types and
methods expected of iterators (e.g., `difference_type`), in order for zip to be
used with other adaptors, such as `make_filter_range`.

Support for reverse iteration has also been added.

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

llvm-svn: 296036
2017-02-23 23:00:46 +00:00
Marshall Clow
0eaf285460 Remove uses of deprecated std::random_shuffle in the LLVM code base. Reviewed as https://reviews.llvm.org/D29780.
llvm-svn: 295325
2017-02-16 14:37:03 +00:00
Zachary Turner
a94bd828dc [Support] Add StringRef::getAsDouble.
Differential Revision: https://reviews.llvm.org/D29918

llvm-svn: 295089
2017-02-14 19:06:37 +00:00
David Blaikie
57e529da18 Fix some missing negations in the traits checking from r294349
llvm-svn: 294357
2017-02-07 21:31:03 +00:00
Duncan P. N. Exon Smith
ef89dbf50d ADT: Add explicit conversions for reverse ilist iterators
Add explicit conversions between forward and reverse ilist iterators.
These follow the conversion conventions of std::reverse_iterator, which
are off-by-one: the newly-constructed "reverse" iterator dereferences to
the previous node of the one sent in.  This has the benefit of
converting reverse ranges in place:
  - If [I, E) is a valid range,
  - then [reverse(E), reverse(I)) gives the same range in reverse order.

ilist_iterator::getReverse() is unchanged: it returns a reverse iterator
to the *same* node.

llvm-svn: 294349
2017-02-07 21:03:50 +00:00
Joey Gouly
2aeb7aece2 [APInt] Fix rotl/rotr when the shift amount is greater than the total bit width.
Review: https://reviews.llvm.org/D27749
llvm-svn: 294295
2017-02-07 11:58:22 +00:00
Alex Denisov
346fae03fe TripleTest.FileFormat: check non-default value
Triple::objectFormat defaults to an Elf format.
Changing objectFormat to Elf doesn't make any difference.

llvm-svn: 294104
2017-02-04 22:49:22 +00:00
Alex Denisov
c9a09b97dd TripleTest.BitWidthArchVariants: add missing arch types (thumb, arm, le, ...)
llvm-svn: 294096
2017-02-04 18:20:20 +00:00
Alex Denisov
b09841f914 TripleTest.EndianArchVariants: add missing arch types (tce, le)
llvm-svn: 294095
2017-02-04 17:04:50 +00:00
Amaury Sechet
e7377daa9a [APInt] Add integer API bor bitwise operations.
Summary: As per title. I ran into that limitation of the API doing some other work, so I though that'd be a nice addition.

Reviewers: jroelofs, compnerd, majnemer

Subscribers: llvm-commits

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

llvm-svn: 294063
2017-02-03 22:54:41 +00:00
Matt Arsenault
b570b62964 DAGCombiner: Allow negating ConstantFP after legalize
llvm-svn: 293019
2017-01-25 04:54:34 +00:00
Dean Michael Berris
f38af1b633 Add test for default construction coverage of DenseSet iterators.
This is a follow-up to D28999.

llvm-svn: 292885
2017-01-24 05:29:40 +00:00
Dean Michael Berris
7317af58bd Allow DenseSet::iterators to be conveted to and compared with const_iterator
Summary:
This seemed to be an oversight seeing as DenseMap has these conversions.

This patch does the following:
- Adds a default constructor to the iterators.
- Allows DenseSet::ConstIterators to be copy constructed from DenseSet::Iterators
- Allows mutual comparison between Iterators and ConstIterators.

All of these are available in the DenseMap implementation, so the implementation here is trivial.

Reviewers: dblaikie, dberris

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 292879
2017-01-24 04:11:18 +00:00
Craig Topper
dc69bac218 [APInt] Remove calls to clearUnusedBits from XorSlowCase and operator^=
Summary:
There's a comment in XorSlowCase that says "0^0==1" which isn't true. 0 xored with 0 is still 0. So I don't think we need to clear any unused bits here.

Now there is no difference between XorSlowCase and AndSlowCase/OrSlowCase other than the operation being performed

Reviewers: majnemer, MatzeB, chandlerc, bkramer

Reviewed By: MatzeB

Subscribers: chfast, llvm-commits

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

llvm-svn: 292873
2017-01-24 02:10:15 +00:00
Tim Shen
28ce2d2c0f [APFloat] Add PPCDoubleDouble multiplication
Reviewers: echristo, hfinkel, kbarton, iteratee

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 292860
2017-01-24 00:19:45 +00:00
Tim Shen
4f93c19c2e [APFloat] Switch from (PPCDoubleDoubleImpl, IEEEdouble) layout to (IEEEdouble, IEEEdouble)
Summary:
This patch changes the layout of DoubleAPFloat, and adjust all
operations to do either:
1) (IEEEdouble, IEEEdouble) -> (uint64_t, uint64_t) -> PPCDoubleDoubleImpl,
   then run the old algorithm.
2) Do the right thing directly.

1) includes multiply, divide, remainder, mod, fusedMultiplyAdd, roundToIntegral,
   convertFromString, next, convertToInteger, convertFromAPInt,
   convertFromSignExtendedInteger, convertFromZeroExtendedInteger,
   convertToHexString, toString, getExactInverse.
2) includes makeZero, makeLargest, makeSmallest, makeSmallestNormalized,
   compare, bitwiseIsEqual, bitcastToAPInt, isDenormal, isSmallest,
   isLargest, isInteger, ilogb, scalbn, frexp, hash_value, Profile.

I could split this into two patches, e.g. use
1) for all operatoins first, then incrementally change some of them to
2). I didn't do that, because 1) involves code that converts data between
PPCDoubleDoubleImpl and (IEEEdouble, IEEEdouble) back and forth, and may
pessimize the compiler. Instead, I find easy functions and use
approach 2) for them directly.

Next step is to implement move multiply and divide from 1) to 2). I don't
have plans for other functions in 1).

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

llvm-svn: 292839
2017-01-23 22:39:35 +00:00
Matthias Braun
9e8eceea87 Add unittests for empty bitvectors.
Addendum to r292575

llvm-svn: 292817
2017-01-23 19:06:54 +00:00
Zachary Turner
0a3b8732fd [ADT] Add SparseBitVector::find_last().
Differential Revision: https://reviews.llvm.org/D28817

llvm-svn: 292288
2017-01-17 23:09:21 +00:00
Dan Gohman
355ce8f653 [WebAssembly] Add triple support for the new wasm object format
Differential Revision: https://reviews.llvm.org/D26701

llvm-svn: 292252
2017-01-17 20:34:09 +00:00
Tim Shen
ecff8bd65a [APFloatTest] Add tests for various operations
Differential Revision: https://reviews.llvm.org/D27833

llvm-svn: 291189
2017-01-05 22:57:54 +00:00
Justin Lebar
12b3022bd3 [ADT] Attempt to fix GCC warning in IntrusiveRefCntPtrTest.
Our copy constructor doesn't explicitly invoke the base class's
constructor, and GCC is (rightly) concerned.

llvm-svn: 291023
2017-01-04 22:49:55 +00:00
Chandler Carruth
d541339c25 [ADT] Speculative attempt to fix build bot issues with r290952.
This just removes the usage of llvm::reverse and llvm::seq. That makes
it harder to handle the empty case correctly and so I've also added
a test there.

This is just a shot in the dark at what might be behind the buildbot
failures. I can't reproduce any issues locally including with ASan...
I feel like I'm missing something...

llvm-svn: 290954
2017-01-04 11:40:18 +00:00
Chandler Carruth
5c979966df [ADT] Enhance the PriorityWorklist to support bulk insertion.
This is both convenient and more efficient as we can skip any
intermediate reallocation of the vector.

This usage pattern came up in a subsequent patch on the pass manager,
but it seems generically useful so I factored it out and added unittests
here.

llvm-svn: 290952
2017-01-04 11:13:11 +00:00
Abhilash Bhandari
b2431386bd [ADT] Fix for compilation error when operator++(int) (post-increment function) of SmallPtrSetIterator is used.
The bug was introduced in r289619.

Reviewers: Mehdi Amini

Subscribers: llvm-commits

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

llvm-svn: 290749
2016-12-30 12:34:36 +00:00
Justin Lebar
71e5133921 [ADT] Delete RefCountedBaseVPTR.
Summary:
This class is unnecessary.

Its comment indicated that it was a compile error to allocate an
instance of a class that inherits from RefCountedBaseVPTR on the stack.
This may have been true at one point, but it's not today.

Moreover you really do not want to allocate *any* refcounted object on
the stack, vptrs or not, so if we did have a way to prevent these
objects from being stack-allocated, we'd want to apply it to regular
RefCountedBase too, obviating the need for a separate RefCountedBaseVPTR
class.

It seems that the main way RefCountedBaseVPTR provides safety is by
making its subclass's destructor virtual.  This may have been helpful at
one point, but these days clang will emit an error if you define a class
with virtual functions that inherits from RefCountedBase but doesn't
have a virtual destructor.

Reviewers: compnerd, dblaikie

Subscribers: cfe-commits, klimek, llvm-commits, mgorny

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

llvm-svn: 290717
2016-12-29 19:59:26 +00:00
Chandler Carruth
fa1ce92db5 [ADT] Add an llvm::erase_if utility to make the standard erase+remove_if
pattern easier to write.

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

llvm-svn: 290555
2016-12-26 23:30:44 +00:00
Chandler Carruth
6e1b70611d [ADT] Add a boring std::partition wrapper similar to our std::remove_if
wrapper.

llvm-svn: 290553
2016-12-26 23:10:40 +00:00
Chandler Carruth
238121e8d2 [ADT] Add a generic concatenating iterator and range (take 2).
This recommits r290512 that was reverted when MSVC failed to compile it. Since
then I've played with various approaches using rextester.com (where I was able
to reproduce the failure) and think that I have a solution thanks in part to
the help of Dave Blaikie! It seems MSVC just has a defective `decltype` in this
version. Manually writing out the type seems to do the trick, even though it is
.... quite complicated.

Original commit message:
This allows both defining convenience iterator/range accessors on types
which walk across N different independent ranges within the object, and
more direct and simple usages with range based for loops such as shown
in the unittest. The same facilities are used for both. They end up
quite small and simple as it happens.

I've also switched an iterator on `Module` to use this. I would like to
add another convenience iterator that includes even more sequences as
part of it and seeing this one already present motivated me to actually
abstract it away and introduce a general utility.

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

llvm-svn: 290528
2016-12-25 23:41:14 +00:00
Chandler Carruth
2badac86bf Revert r290512: [ADT] Add a generic concatenating iterator and range.
This code doesn't work on MSVC for reasons that elude me and I've not
yet covinced a workaround to compile cleanly so reverting for now while
I play with it.

llvm-svn: 290513
2016-12-25 09:36:24 +00:00
Chandler Carruth
da2be04107 [ADT] Add a generic concatenating iterator and range.
This allows both defining convenience iterator/range accessors on types
which walk across N different independent ranges within the object, and
more direct and simple usages with range based for loops such as shown
in the unittest. The same facilities are used for both. They end up
quite small and simple as it happens.

I've also switched an iterator on `Module` to use this. I would like to
add another convenience iterator that includes even more sequences as
part of it and seeing this one already present motivated me to actually
abstract it away and introduce a general utility.

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

llvm-svn: 290512
2016-12-25 08:22:50 +00:00
Evgeniy Stepanov
cbf1ce0628 Fix compilation.
unittests/ADT/TwineTest.cpp:106:38: error: field 'Count' will be initialized after base 'llvm::FormatAdapter<int>' [-Werror,-Wreorder]
    explicit formatter(int &Count) : Count(Count), FormatAdapter(0) {}

llvm-svn: 290029
2016-12-17 01:31:46 +00:00
Zachary Turner
7e117aec6b Add support for formatv to llvm::Twine.
Differential Revision: https://reviews.llvm.org/D27835

llvm-svn: 290020
2016-12-17 00:38:15 +00:00
Tim Shen
504763c5f0 [APFloatTest] Log when test fails. NFC
Reviewers: iteratee

Subscribers: llvm-commits

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

llvm-svn: 289904
2016-12-16 00:47:17 +00:00
Stephan Bergmann
760305752a Adapt to recent APFloat change
llvm-svn: 289649
2016-12-14 12:11:35 +00:00
Stephan Bergmann
aba15d97df Replace APFloatBase static fltSemantics data members with getter functions
At least the plugin used by the LibreOffice build
(<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly
uses those members (through inline functions in LLVM/Clang include files in turn
using them), but they are not exported by utils/extract_symbols.py on Windows,
and accessing data across DLL/EXE boundaries on Windows is generally
problematic.

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

llvm-svn: 289647
2016-12-14 11:57:17 +00:00
Mandeep Singh Grang
f3d88aa2be [llvm] Iterate SmallPtrSet in reverse order to uncover non-determinism in codegen
Summary:
Given a flag (-mllvm -reverse-iterate) this patch will enable iteration of SmallPtrSet in reverse order.
The idea is to compile the same source with and without this flag and expect the code to not change.
If there is a difference in codegen then it would mean that the codegen is sensitive to the iteration order of SmallPtrSet.
This is enabled only with LLVM_ENABLE_ABI_BREAKING_CHECKS.

Reviewers: chandlerc, dexonsmith, mehdi_amini

Subscribers: mgorny, emaste, llvm-commits

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

llvm-svn: 289619
2016-12-14 00:15:57 +00:00
Zachary Turner
d429264556 [ADT] Add llvm::StringLiteral.
StringLiteral is a wrapper around a string literal useful for
replacing global tables of char arrays with global tables of
StringRefs that can initialized in a constexpr context, avoiding
the invocation of a global constructor.

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

llvm-svn: 289551
2016-12-13 17:03:49 +00:00
Tim Shen
8d8bbb0918 [APFloatTest] Use std::make_tuple to make GCC 4.8 happy
Differential Revision: https://reviews.llvm.org/D26817

llvm-svn: 289474
2016-12-12 22:16:08 +00:00
Tim Shen
1af286f06d [APFloat] Implement PPCDoubleDouble add and subtract.
Summary:
I looked at libgcc's implementation (which is based on the paper,
Software for Doubled-Precision Floating-Point Computations", by Seppo Linnainmaa,
ACM TOMS vol 7 no 3, September 1981, pages 272-283.) and made it generic to
arbitrary IEEE floats.

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

llvm-svn: 289472
2016-12-12 21:59:30 +00:00
Michael Gottesman
0ded632cc4 [stl-extras] Provide an adaptor of std::count for ranges.
llvm-svn: 288619
2016-12-04 10:26:53 +00:00
Zachary Turner
f7b9285e0f Add some searching functions for ArrayRef<T>.
Differential Revision: https://reviews.llvm.org/D26999

llvm-svn: 287722
2016-11-22 23:22:19 +00:00
Chandler Carruth
d65f1f5cc9 [ADT] Add initializer list support to SmallPtrSet so that sets can be
easily initialized with some initial values.

llvm-svn: 287610
2016-11-22 03:27:43 +00:00
Zachary Turner
8a4b0ad535 [Support] Add StringRef::find_lower and contains_lower.
Differential Revision: https://reviews.llvm.org/D25299

llvm-svn: 286724
2016-11-12 17:17:12 +00:00
Jordan Rose
52592fc0c3 Add tests for r286139.
llvm-svn: 286141
2016-11-07 20:40:16 +00:00
Tim Shen
ea2942c690 [APFloat] Make functions that produce APFloaat objects use correct semantics.
Summary:
Fixes PR30869.

In D25977 I meant to change all functions that care about lifetime. I
changed constructors, factory functions, but I missed member/free
functions that return new instances. This patch changes them.

Reviewers: hfinkel, kbarton, echristo, joerg

Subscribers: llvm-commits, mehdi_amini

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

llvm-svn: 286060
2016-11-06 07:38:37 +00:00
Michael LeMay
5ef9bfec3f [ADT] IntervalMap: fix setStart and setStop
Summary:
These functions currently require that the new closed interval has a length of
at least 2.  They also currently permit empty half-open intervals.  This patch
defines nonEmpty in each traits structure and uses it to correct the
implementations of setStart and setStop.

Reviewers: stoklund, chandlerc

Subscribers: llvm-commits

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

llvm-svn: 285957
2016-11-03 19:14:46 +00:00
Michael Gottesman
faf00da81c [ilist_node] Add a getReverseIterator() method and a unittest for it.
This is the reverse_iterator analogue of getIterator().

llvm-svn: 285780
2016-11-02 00:59:58 +00:00
Alex Bradbury
4a18531531 [RISCV] Recognise riscv32 and riscv64 in triple parsing code
This is the first in a series of 10 initial patches that incrementally add an 
MC layer for RISC-V to LLVM. See 
<http://lists.llvm.org/pipermail/llvm-dev/2016-August/103748.html> for more 
discussion.

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

llvm-svn: 285707
2016-11-01 16:47:54 +00:00
Vedant Kumar
89649e6bdb [unittests] STLExtrasTest: Remove an MSVC 2013 workaround, NFCI.
Let's see what the bots have to say about this...

llvm-svn: 285091
2016-10-25 18:11:17 +00:00
Mehdi Amini
f7a229fb6c [ADT] Zip range adapter
This augments the STLExtras toolset with a zip iterator and range
adapter. Zip comes in two varieties: `zip`, which will zip to the
shortest of the input ranges, and `zip_first`, which limits its
`begin() == end()` checks to just the first range.

Recommit r284035 after MSVC2013 support has been dropped.

Patch by: Bryant Wong <github.com/bryant>

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

llvm-svn: 284623
2016-10-19 18:02:21 +00:00
Justin Lebar
99da2a4624 [ADT] Remove CachedHash<T>.
Nobody is using it.

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

llvm-svn: 284503
2016-10-18 17:50:39 +00:00
Justin Lebar
a5139fe1d8 [ADT] Add an initializer_list constructor to {Small,}DenseSet.
Reviewers: timshen

Subscribers: llvm-commits

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

llvm-svn: 284433
2016-10-17 22:24:32 +00:00
Justin Lebar
af9f288629 [ADT] Add SmallDenseSet.
Summary: This matches SmallDenseMap.

Reviewers: timshen

Subscribers: llvm-commits

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

llvm-svn: 284432
2016-10-17 22:24:28 +00:00
Richard Smith
9a14f428e4 PR30711: Fix incorrect profiling of 'long long' in FoldingSet, then use it to
fix TBAA violation in profiling of pointers.

llvm-svn: 284336
2016-10-16 17:49:09 +00:00
David L Kreitzer
96ecdb67e0 Define "contiki" OS specifier.
Patch by Michael LeMay

Differential revision: http://reviews.llvm.org/D24897

llvm-svn: 284240
2016-10-14 14:41:46 +00:00
Mehdi Amini
d0fe06cc25 Revert "[ADT] Zip range adapter"
This reverts commit r284035, which breaks with MSVC 2013.

llvm-svn: 284037
2016-10-12 19:54:08 +00:00
Mehdi Amini
679ff92d07 [ADT] Zip range adapter
This augments the STLExtras toolset with a zip iterator and range
adapter. Zip comes in two varieties: `zip`, which will zip to the
shortest of the input ranges, and `zip_first`, which limits its
`begin() == end()` checks to just the first krange.

Patch by: Bryant Wong <github.com/bryant>

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

llvm-svn: 284035
2016-10-12 19:43:02 +00:00
Jordan Rose
201cd0c255 Re-apply "Disallow ArrayRef assignment from temporaries."
This re-applies r283798, disabled in r283803, with the static_assert
tests disabled under MSVC. The deleted functions still seem to catch
mistakes in MSVC, so it's not a significant loss.

Part of rdar://problem/16375365

llvm-svn: 283935
2016-10-11 20:39:16 +00:00
Zachary Turner
14d2c535cb Revert "Disallow ArrayRef assignment from temporaries."
This reverts commit r283798, as it causes static asserts on
MSVC 2015 with the following errors:

ArrayRefTest.cpp(38): error C2338: Assigning from single prvalue element
ArrayRefTest.cpp(41): error C2338: Assigning from single xvalue element
ArrayRefTest.cpp(47): error C2338: Assigning from an initializer list

llvm-svn: 283803
2016-10-10 21:36:23 +00:00
Zachary Turner
80d8c682d7 Rename llvm::apply -> llvm::apply_tuple.
llvm::cl already has a function called llvm::apply() so this is
causing an ODR violation.  The STLExtras version should win the
vote on which one gets to be called apply() since it is named
after the equivalent STL function, but since renaiming the cl
version is more difficult, let's do this for now to get the
bots green.

llvm-svn: 283800
2016-10-10 21:24:34 +00:00
Jordan Rose
b52b42ffac Disallow ArrayRef assignment from temporaries.
Without this, the following statements will create ArrayRefs that
refer to temporary storage that goes out of scope by the end of the
line:

  someArrayRef = getSingleElement();
  someArrayRef = {elem1, elem2};

Note that the constructor still has this problem:

  ArrayRef<Element> someArrayRef = getSingleElement();
  ArrayRef<Element> someArrayRef = {elem1, elem2};

but that's a little harder to get rid of because we want to be able to
use this in calls:

  takesArrayRef(getSingleElement());
  takesArrayRef({elem1, elem2});

Part of rdar://problem/16375365. Reviewed by Duncan Exon Smith.

llvm-svn: 283798
2016-10-10 20:57:33 +00:00
Justin Lebar
96d7bc1342 [ADT] Don't use make_pointee_iterator in IteratorTest.
llvm-svn: 283794
2016-10-10 19:56:52 +00:00
Zachary Turner
4022c2b021 Add llvm::apply to STLExtras.
This is equivalent to the C++14 std::apply().  Since we are not
using C++14 yet, this allows us to still make use of apply anyway.

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

llvm-svn: 283779
2016-10-10 16:44:09 +00:00
Justin Lebar
02ac32407b [ADT] Add make_pointe{e,r}_iterator.
Reviewers: timshen

Subscribers: llvm-commits

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

llvm-svn: 283765
2016-10-10 16:26:03 +00:00
Justin Lebar
8960a1706e [ADT] Let MapVector handle non-copyable values.
Summary: The keys must still be copyable, because we store two copies of them.

Reviewers: timshen

Subscribers: llvm-commits

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

llvm-svn: 283764
2016-10-10 16:25:59 +00:00
Petr Hosek
994e0d12ef [Triple] Add triple for Fuchsia
Fuchsia is a new operating system.

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

llvm-svn: 283419
2016-10-06 05:17:26 +00:00
Reid Kleckner
96b15fe0ad Remove extra semicolon
llvm-svn: 283395
2016-10-05 21:46:56 +00:00
Reid Kleckner
4f9ae05be2 Fix the build with MSVC 2013, still cannot default move ctors yet
Ten days.

llvm-svn: 283394
2016-10-05 21:44:46 +00:00
David Callahan
8669fd34a9 Modify df_iterator to support post-order actions
Summary: This makes a change to the state used to maintain visited information for depth first iterator. We know assume a method "completed(...)" which is called after all children of a node have been visited. In all existing cases, this method does nothing so this patch has no functional changes.  It will however allow a client to distinguish back from cross edges in a DFS tree.

Reviewers: nadav, mehdi_amini, dberlin

Subscribers: MatzeB, mzolotukhin, twoh, freik, llvm-commits

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

llvm-svn: 283391
2016-10-05 21:36:16 +00:00
Vitaly Buka
ef86d65751 [ADT] Add missing const_iterator DenseSet::find() const
Summary: Probably overlooked.

Reviewers: eugenis, dblaikie

Subscribers: llvm-commits

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

llvm-svn: 283377
2016-10-05 20:36:39 +00:00
Zachary Turner
c9a75c816c Fix build due to comparison of std::pairs.
llvm-svn: 283342
2016-10-05 17:04:36 +00:00
Zachary Turner
10f9def152 Add llvm::enumerate() range adapter.
This allows you to enumerate over a range using a range-based
for while the return type contains the index of the enumeration.

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

llvm-svn: 283337
2016-10-05 16:54:09 +00:00
Zachary Turner
cc36037bff [Support] Add case-insensitive versions of StringSwitch members.
This adds support for CaseLower, CasesLower, StartsWithLower, and
EndsWithLower.

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

llvm-svn: 283244
2016-10-04 19:33:13 +00:00
Zachary Turner
9dbed92a4a Add unit tests for StringSwitch.
Differential revision: https://reviews.llvm.org/D25205

llvm-svn: 283138
2016-10-03 19:56:50 +00:00
Joerg Sonnenberger
100750a643 Turn LLVM_ENABLE_ABI_BREAKING_CHECKS into a 0/1 definition like
LLVM_ENABLE_THREADS. Include llvm-config.h explicitly in headers to make
sure that the definition is available.

llvm-svn: 282907
2016-09-30 19:52:27 +00:00
Zachary Turner
afdf5e3940 Resubmit "Add llvm::enumerate() to STLExtras."
The CL was originally failing due to the use of some C++14
specific features, so I've removed those.  Hopefully this will
satisfy the bots.

llvm-svn: 282867
2016-09-30 15:43:59 +00:00
Zachary Turner
d200751f68 Revert "Add llvm::enumerate() to STLExtras."
This reverts commit r282804 as it seems to use some C++ features
that not all compilers support.

llvm-svn: 282809
2016-09-29 23:05:41 +00:00
Zachary Turner
b83b38ce16 Add llvm::enumerate() to STLExtras.
enumerate allows you to iterate over a range by pairing the
iterator's value with its index in the enumeration.  This gives
you most of the benefits of using a for loop while still allowing
the range syntax.

llvm-svn: 282804
2016-09-29 22:59:30 +00:00
Zachary Turner
a5137ef9a9 Add llvm::join_items to StringExtras.
llvm::join_items is similar to llvm::join, which produces a string
by concatenating a sequence of values together separated by a
given separator.  But it differs in that the arguments to
llvm::join() are same-type members of a container, whereas the
arguments to llvm::join_items are arbitrary types passed into
a variadic template.  The only requirement on parameters to
llvm::join_items (including for the separator themselves) is
that they be implicitly convertible to std::string or have
an overload of std::string::operator+

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

llvm-svn: 282502
2016-09-27 16:37:30 +00:00
Zachary Turner
e1a79703aa Fix signed / unsigned comparison.
llvm-svn: 282348
2016-09-25 03:57:34 +00:00
Zachary Turner
3c222df487 Add some predicated searching functions to StringRef.
This adds 4 new functions to StringRef, which can be used to
take or drop characters while a certain condition is met, or
until a certain condition is met.  They are:

take_while - Return characters until a condition is not met.
take_until - Return characters until a condition is met.
drop_while - Remove characters until a condition is not met.
drop_until - Remove characters until a condition is met.

Internally, all of these functions delegate to two additional
helper functions which can be used to search for the position
of a character meeting or not meeting a condition, which are:

find_if - Find the first character matching a predicate.
find_if_not - Find the first character not matching a predicate.

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

llvm-svn: 282346
2016-09-25 03:27:29 +00:00
Tom Stellard
a0456d6c9f Triple: Add opencl environment type
Summary:
For AMDGPU, we have been using the operating system component of the triple
for specifying the low-level runtime that is being used.  The rationale for
this is that the host operating system (e.g. Linux) is irrelevant for GPU code,
since its execution enviroment will be mostly controled by the low-level runtime
being used to execute the code.

In most cases, higher level languages have their own runtime which is
implemented on top of the low-level runtime.  The kernel ABIs of each
language mostly depend on the low-level runtime, but there may be some
slight differences between languages.  OpenCL for example, may append
additional arguments to the kernel in order to pass values like global
offsets or buffers for printf.  OpenMP, HCC, or other languages may want
to add their own values which differ from OpenCL.

The reason for adding a new opencl environment type is to make it possible for the backend
to distinguish between the ABIs of the higher-level languages and handle them correctly.
It seems cleaner to use the enviroment component for this rather than creating a new
OS type for every combination of low-level runtime / high-level language.

Reviewers: Anastasia, chandlerc

Subscribers: whchung, pekka.jaaskelainen, wdng, yaxunl, llvm-commits

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

llvm-svn: 282218
2016-09-23 00:42:56 +00:00
Zachary Turner
ba26d470c1 Fix build breakage due to typo in cast.
llvm-svn: 282183
2016-09-22 19:21:32 +00:00
Zachary Turner
986cc88263 Speculative fix for build failures due to consumeInteger.
A recent patch added support for consumeInteger() and made
getAsInteger delegate to this function.  A few buildbots are
failing as a result with an assertion failure.  On a hunch,
I tested what happens if I call getAsInteger() on an empty
string, and sure enough it crashes the same way that the
buildbots are crashing.

I confirmed that getAsInteger() on an empty string did not
crash before my patch, so I suspect this to be the cause.

I also added a unit test for the empty string.

llvm-svn: 282170
2016-09-22 15:55:05 +00:00
Zachary Turner
3d1c3fcd78 [Support] Add StringRef::consumeInteger.
StringRef::getInteger() exists and treats the entire string as
an integer of the specified radix, failing if any invalid characters
are encountered or the number overflows.

Sometimes you might have something like "123456foo" and you want
to get the number 123456 and leave the string "foo" remaining.
This is similar to what would be possible by using the standard
runtime library functions strtoul et al and specifying an end
pointer.

This patch adds consumeInteger(), which does exactly that.  It
consumes as much as possible until an invalid character is found,
and modifies the StringRef in place so that upon return only
the portion of the StringRef after the number remains.

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

llvm-svn: 282164
2016-09-22 15:05:19 +00:00
Duncan P. N. Exon Smith
0410d4f82c ADT: Never allocate nodes in iplist<> and ilist<>
Remove createNode() and any API that depending on it, and add
HasCreateNode to the list of checks for HasObsoleteCustomizations.  Now
an ilist *never* allocates (this was already true for iplist).

This factors out all the differences between iplist and ilist.  I'll aim
to rename both to "owning_ilist" eventually, to call out the interesting
(not exactly intrusive) ownership semantics.  In the meantime, I've left
both names around to reduce code churn.

One of the deleted APIs is the ilist copy constructor.  I've lifted up
and tested iplist::cloneFrom (ala simple_ilist::cloneFrom) as a
replacement.

Users of ilist<> and iplist<> that want the list to allocate nodes have
a few options:
- use std::list;
- use AllocatorList or BumpPtrList (or build a similarly trivial list);
- use cloneFrom (which is explicit at the call site); or
- allocate at the call site.

See r280573, r281177, r281181, and r281182 for examples of what to do if
you're updating out-of-tree code.

llvm-svn: 281184
2016-09-11 23:43:43 +00:00
Duncan P. N. Exon Smith
1af3e8d9df ADT: Add AllocatorList, and use it for yaml::Token
- Add AllocatorList, a non-intrusive list that owns an LLVM-style
  allocator and provides a std::list-like interface (trivially built on
  top of simple_ilist),
- add a typedef (and unit tests) for BumpPtrList, and
- use BumpPtrList for the list of llvm::yaml::Token (i.e., TokenQueueT).

TokenQueueT has no need for the complexity of an intrusive list.  The
only reason to inherit from ilist was to customize the allocator.
TokenQueueT was the only example in-tree of using ilist<> in a truly
non-intrusive way.

Moreover, this removes the final use of the non-intrusive
ilist_traits<>::createNode (after r280573, r281177, and r281181).  I
have a WIP patch that removes this customization point (and the API that
relies on it) that I plan to commit soon.

Note: AllocatorList owns the allocator, which limits the viable API
(e.g., splicing must be on the same list).  For now I've left out
any problematic API.  It wouldn't be hard to split AllocatorList into
two layers: an Impl class that calls DerivedT::getAlloc (via CRTP), and
derived classes that handle Allocator ownership/reference/etc semantics;
and then implement splice with appropriate assertions; but TBH we should
probably just customize the std::list allocators at that point.

llvm-svn: 281182
2016-09-11 22:40:40 +00:00
Duncan P. N. Exon Smith
2a55cf5af8 ADT: Add sentinel tracking and custom tags to ilists
This adds two declarative configuration options for intrusive lists
(available for simple_ilist, iplist, and ilist).  Both of these options
affect ilist_node interoperability and need to be passed both to the
node and the list.  Instead of adding a new traits class, they're
specified as optional template parameters (in any order).

The two options:

 1. Pass ilist_sentinel_tracking<true> or ilist_sentinel_tracking<false>
    to control whether there's a bit on ilist_node "prev" pointer
    indicating whether it's the sentinel.  The default behaviour is to
    use a bit if and only if LLVM_ENABLE_ABI_BREAKING_CHECKS.

 2. Pass ilist_tag<TagA> and ilist_tag<TagB> to allow insertion of a
    single node into two different lists (simultaneously).

I have an immediate use-case for (1) ilist_sentinel_tracking: fixing the
validation semantics of MachineBasicBlock::reverse_iterator to match
ilist::reverse_iterator (ala r280032: see the comments at the end of the
commit message there).  I'm adding (2) ilist_tag in the same commit to
validate that the options framework supports expansion.  Justin Bogner
mentioned this might enable a possible cleanup in SelectionDAG, but I'll
leave this to others to explore.  In the meantime, the unit tests and
the comments for simple_ilist and ilist_node have usage examples.

Note that there's a layer of indirection to support optional,
out-of-order, template paramaters.  Internal classes are templated on an
instantiation of the non-variadic ilist_detail::node_options.
User-facing classes use ilist_detail::compute_node_options to compute
the correct instantiation of ilist_detail::node_options.

The comments for ilist_detail::is_valid_option describe how to add new
options (e.g., ilist_packed_int<int NumBits>).

llvm-svn: 281167
2016-09-11 16:20:53 +00:00
Duncan P. N. Exon Smith
997810cad7 ADT: Move ilist_node_access to ilist_detail::NodeAccess...
... and make a few ilist-internal API changes, in preparation for
changing how ilist_node is templated.  The only effect for ilist users
should be changing the friend target from llvm::ilist_node_access to
llvm::ilist_detail::NodeAccess (which is only necessary when they
inherit privately from ilist_node).
- Split out SpecificNodeAccess, which has overloads of getNodePtr and
  getValuePtr that are untemplated.
- Use more typedefs to prevent more changes later.
- Force inheritance to use *NodeAccess (to emphasize that ilist *users*
  shouldn't be doing this).

There should be no functionality change here.

llvm-svn: 281142
2016-09-10 16:55:06 +00:00
Duncan P. N. Exon Smith
8080a7d548 ADT: Use typedefs for ilist_base and ilist_node_base, NFC
This is a prep commit to minimize changes in a follow-up that is adding
a template parameter to ilist_node_base and ilist_base.

llvm-svn: 281141
2016-09-10 16:28:52 +00:00
Duncan P. N. Exon Smith
ce15235f06 ADT: Fix up IListTest.privateNode and get it passing
This test was using the wrong type, and so not actually testing much.
ilist_iterator constructors weren't going through ilist_node_access, so
they didn't actually work with private inheritance.

llvm-svn: 280564
2016-09-03 01:06:08 +00:00
Tim Shen
830cc5f6f2 s/static inline/static/ for headers I have changed in r279475. NFC.
llvm-svn: 280257
2016-08-31 16:48:13 +00:00
Zachary Turner
175eaf044f Fix unit test after function name change.
llvm-svn: 280129
2016-08-30 18:45:32 +00:00
Duncan P. N. Exon Smith
9df0e64f25 ADT: Split ilist_node_traits into alloc and callback, NFC
Many lists want to override only allocation semantics, or callbacks for
iplist.  Split these up to prevent code duplication.
- Specialize ilist_alloc_traits to change the implementations of
  deleteNode() and createNode().
- One common desire is to do nothing deleteNode() and disable
  createNode().  Specialize ilist_alloc_traits to inherit from
  ilist_noalloc_traits for that behaviour.
- Specialize ilist_callback_traits to use the addNodeToList(),
  removeNodeFromList(), and transferNodesFromList() callbacks.

As a drive-by, add some coverage to the callback-related unit tests.

llvm-svn: 280128
2016-08-30 18:40:47 +00:00
Zachary Turner
184ba7aaa0 Add StringRef::take_front and StringRef::take_back
Reviewed By: majnemer, rnk
Differential Revision: https://reviews.llvm.org/D23965

llvm-svn: 280114
2016-08-30 17:29:59 +00:00
Duncan P. N. Exon Smith
9200890ea3 ADT: Split out simple_ilist, a simple intrusive list
Split out a new, low-level intrusive list type with clear semantics.
Unlike iplist (and ilist), all operations on simple_ilist are intrusive,
and simple_ilist never takes ownership of its nodes.  This enables an
intuitive API that has the right defaults for intrusive lists.
- insert() takes references (not pointers!) to nodes (in iplist/ilist,
  passing a reference will cause the node to be copied).
- erase() takes only iterators (like std::list), and does not destroy
  the nodes.
- remove() takes only references and has the same behaviour as erase().
- clear() does not destroy the nodes.
- The destructor does not destroy the nodes.
- New API {erase,remove,clear}AndDispose() take an extra Disposer
  functor for callsites that want to call some disposal routine (e.g.,
  std::default_delete).

This list is not currently configurable, and has no callbacks.

The initial motivation was to fix iplist<>::sort to work correctly (even
with callbacks in ilist_traits<>).  iplist<> uses simple_ilist<>::sort
directly.  The new test in unittests/IR/ModuleTest.cpp crashes without
this commit.

Fixing sort() via a low-level layer provided a good opportunity to:
- Unit test the low-level functionality thoroughly.
- Modernize the API, largely inspired by other intrusive list
  implementations.

Here's a sketch of a longer-term plan:
- Create BumpPtrList<>, a non-intrusive list implemented using
  simple_ilist<>, and use it for the Token list in
  lib/Support/YAMLParser.cpp.  This will factor out the only real use of
  createNode().
- Evolve the iplist<> and ilist<> APIs in the direction of
  simple_ilist<>, making allocation/deallocation explicit at call sites
  (similar to simple_ilist<>::eraseAndDispose()).
- Factor out remaining calls to createNode() and deleteNode() and remove
  the customization from ilist_traits<>.
- Transition uses of iplist<>/ilist<> that don't need callbacks over to
  simple_ilist<>.

llvm-svn: 280107
2016-08-30 16:23:55 +00:00
Duncan P. N. Exon Smith
a7bb9b755d ADT: Explode include/llvm/ADT/{ilist,ilist_node}.h, NFC
I'm working on a lower-level intrusive list that can be used
stand-alone, and splitting the files up a bit will make the code easier
to organize.  Explode the ilist headers in advance to improve blame
lists in the future.
- Move ilist_node_base from ilist_node.h to ilist_node_base.h.
- Move ilist_base from ilist.h to ilist_base.h.
- Move ilist_iterator from ilist.h to ilist_iterator.h.
- Move ilist_node_access from ilist.h to ilist_node.h to support
  ilist_iterator.
- Update unit tests to #include smaller headers.
- Clang-format the moved things.

I noticed in transit that there is a simplify_type specialization for
ilist_iterator.  Since there is no longer an implicit conversion from
ilist<T>::iterator to T*, this doesn't make sense (effectively it's a
form of implicit conversion).  For now I've added a FIXME.

llvm-svn: 280047
2016-08-30 01:37:58 +00:00
Duncan P. N. Exon Smith
0f5a6f8621 Rename unittests/ADT/ilistTestTemp.cpp => IListTest.cpp
And rename the tests inside from ilistTest to IListTest.  This makes the
file sort properly in the CMakeLists.txt (previously, sorting would
throw it down to the end of the list) and is consistent with the tests
I've added more recently.

Why use IListNodeBaseTest.cpp (and a test name of IListNodeBaseTest)?
- ilist_node_base_test is the obvious thing, since this is testing
  ilist_node_base.  However, gtest disallows underscores in test names.
- ilist_node_baseTest fails for the same reason.
- ilistNodeBaseTest is weird, because it isn't in our usual
  TitleCaseTest form that we use for tests, and it also doesn't have the
  name of the tested class in it.
- IlistNodeBaseTest matches TitleCaseTest, but "Ilist" is hard to read,
  and really "ilist" is an abbreviation for "IntrusiveList" so the
  lowercase "list" is strange.
- That left IListNodeBaseTest.

Note: I made this move in two stages, with a temporary filename of
ilistTestTemp in between in r279524.  This was in the hopes of avoiding
problems on Git and SVN clients on case-insensitive filesystems,
particularly on buildbots with incremental checkouts.

llvm-svn: 280033
2016-08-30 00:18:43 +00:00
Duncan P. N. Exon Smith
4e09f9bf86 ADT: Give ilist<T>::reverse_iterator a handle to the current node
Reverse iterators to doubly-linked lists can be simpler (and cheaper)
than std::reverse_iterator.  Make it so.

In particular, change ilist<T>::reverse_iterator so that it is *never*
invalidated unless the node it references is deleted.  This matches the
guarantees of ilist<T>::iterator.

(Note: MachineBasicBlock::iterator is *not* an ilist iterator, but a
MachineInstrBundleIterator<MachineInstr>.  This commit does not change
MachineBasicBlock::reverse_iterator, but it does update
MachineBasicBlock::reverse_instr_iterator.  See note at end of commit
message for details on bundle iterators.)

Given the list (with the Sentinel showing twice for simplicity):

     [Sentinel] <-> A <-> B <-> [Sentinel]

the following is now true:
 1. begin() represents A.
 2. begin() holds the pointer for A.
 3. end() represents [Sentinel].
 4. end() holds the poitner for [Sentinel].
 5. rbegin() represents B.
 6. rbegin() holds the pointer for B.
 7. rend() represents [Sentinel].
 8. rend() holds the pointer for [Sentinel].

The changes are #6 and #8.  Here are some properties from the old
scheme (which used std::reverse_iterator):
- rbegin() held the pointer for [Sentinel] and rend() held the pointer
  for A;
- operator*() cost two dereferences instead of one;
- converting from a valid iterator to its valid reverse_iterator
  involved a confusing increment; and
- "RI++->erase()" left RI invalid.  The unintuitive replacement was
  "RI->erase(), RE = end()".

With vector-like data structures these properties are hard to avoid
(since past-the-beginning is not a valid pointer), and don't impose a
real cost (since there's still only one dereference, and all iterators
are invalidated on erase).  But with lists, this was a poor design.

Specifically, the following code (which obviously works with normal
iterators) now works with ilist::reverse_iterator as well:

    for (auto RI = L.rbegin(), RE = L.rend(); RI != RE;)
      fooThatMightRemoveArgFromList(*RI++);

Converting between iterator and reverse_iterator for the same node uses
the getReverse() function.

    reverse_iterator iterator::getReverse();
    iterator reverse_iterator::getReverse();

Why doesn't iterator <=> reverse_iterator conversion use constructors?

In order to catch and update old code, reverse_iterator does not even
have an explicit conversion from iterator.  It wouldn't be safe because
there would be no reasonable way to catch all the bugs from the changed
semantic (see the changes at call sites that are part of this patch).

Old code used this API:

    std::reverse_iterator::reverse_iterator(iterator);
    iterator std::reverse_iterator::base();

Here's how to update from old code to new (that incorporates the
semantic change), assuming I is an ilist<>::iterator and RI is an
ilist<>::reverse_iterator:

            [Old]         ==>          [New]
    reverse_iterator(I)       (--I).getReverse()
    reverse_iterator(I)         ++I.getReverse()
  --reverse_iterator(I)           I.getReverse()
    reverse_iterator(++I)         I.getReverse()
          RI.base()          (--RI).getReverse()
          RI.base()            ++RI.getReverse()
        --RI.base()              RI.getReverse()
      (++RI).base()              RI.getReverse()
  delete &*RI, RE = end()         delete &*RI++
  RI->erase(), RE = end()         RI++->erase()

=======================================
Note: bundle iterators are out of scope
=======================================

MachineBasicBlock::iterator, also known as
MachineInstrBundleIterator<MachineInstr>, is a wrapper to represent
MachineInstr bundles.  The idea is that each operator++ takes you to the
beginning of the next bundle.  Implementing a sane reverse iterator for
this is harder than ilist.  Here are the options:
- Use std::reverse_iterator<MBB::i>.  Store a handle to the beginning of
  the next bundle.  A call to operator*() runs a loop (usually
  operator--() will be called 1 time, for unbundled instructions).
  Increment/decrement just works.  This is the status quo.
- Store a handle to the final node in the bundle.  A call to operator*()
  still runs a loop, but it iterates one time fewer (usually
  operator--() will be called 0 times, for unbundled instructions).
  Increment/decrement just works.
- Make the ilist_sentinel<MachineInstr> *always* store that it's the
  sentinel (instead of just in asserts mode).  Then the bundle iterator
  can sniff the sentinel bit in operator++().

I initially tried implementing the end() option as part of this commit,
but updating iterator/reverse_iterator conversion call sites was
error-prone.  I have a WIP series of patches that implements the final
option.

llvm-svn: 280032
2016-08-30 00:13:12 +00:00
David Blaikie
db16cc2b96 Fix ArrayRef initializer_list Ctor Test
The InitializerList test had undefined behavior by creating a dangling pointer to the temporary initializer list.  This patch removes the undefined behavior in the test by creating the initializer list directly.

Reviewers: mehdi_amini, dblaikie

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

llvm-svn: 279783
2016-08-25 22:09:13 +00:00
Duncan P. N. Exon Smith
4e1990f5f1 Rename unittests/ADT/ilistTest.cpp to ilistTestTemp.cpp (temporarily)
I'll rename this to IListTest.cpp after a waiting period (tonight?
tomorrow?), with a full explanation in that commit.

First, I'm moving it aside because Git doesn't play well with case-only
filename changes on case-insensitive file systems (and I suspect the
same is true of SVN).  This two-stage change should help to avoid
spurious failures on bots that don't do clean checkouts.

llvm-svn: 279524
2016-08-23 15:56:50 +00:00
Duncan P. N. Exon Smith
38ac81f154 ADT: Separate some list manipulation API into ilist_base, NFC
Separate algorithms in iplist<T> that don't depend on T into ilist_base,
and unit test them.

While I was adding unit tests for these algorithms anyway, I also added
unit tests for ilist_node_base and ilist_sentinel<T>.

To make the algorithms and unit tests easier to write, I also did the
following minor changes as a drive-by:
- encapsulate Prev/Next in ilist_node_base to so that algorithms are
  easier to read, and
- update ilist_node_access API to take nodes by reference.

There should be no real functionality change here.

llvm-svn: 279484
2016-08-22 22:21:07 +00:00
Duncan P. N. Exon Smith
dbdc604bd8 Fix header comment for unittests/ADT/ilistTest.cpp
llvm-svn: 279483
2016-08-22 22:04:16 +00:00
Tim Shen
9f534cfb0c [ADT] Actually mutate the iterator VisitStack.back().second, not its copy.
Summary: Before the change, *Opt never actually gets updated by the end
of toNext(), so for every next time the loop has to start over from
child_begin(). This bug doesn't affect the correctness, since Visited prevents
it from re-entering the same node again; but it's slow.

Reviewers: dberris, dblaikie, dannyb

Subscribers: llvm-commits

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

llvm-svn: 279482
2016-08-22 21:59:26 +00:00
Tim Shen
33e4d80307 [GraphTraits] Replace all NodeType usage with NodeRef
This should finish the GraphTraits migration.

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

llvm-svn: 279475
2016-08-22 21:09:30 +00:00
Duncan P. N. Exon Smith
913b8f020e Move unittests/Support/IteratorTest.cpp to unittests/ADT/
This testing stuff from ADT, not Support.  Fix the file location.

llvm-svn: 279372
2016-08-20 14:58:31 +00:00
Duncan P. N. Exon Smith
a35145a428 Reapply "ADT: Remove UB in ilist (and use a circular linked list)"
This reverts commit r279053, reapplying r278974 after fixing PR29035
with r279104.

Note that r279312 has been committed in the meantime, and this has been
rebased on top of that.  Otherwise it's identical to r278974.

Note for maintainers of out-of-tree code (that I missed in the original
message): if the new isKnownSentinel() assertion is firing from
ilist_iterator<>::operator*(), this patch has identified a bug in your
code.  There are a few common patterns:
- Some IR-related APIs htake an IRUnit* that might be nullptr, and pass
  in an incremented iterator as an insertion point.  Some old code was
  using "&*++I", which in the case of end() only worked by fluke.  If
  the IRUnit in question inherits from ilist_node_with_parent<>, you can
  use "I->getNextNode()".  Otherwise, use "List.getNextNode(*I)".
- In most other cases, crashes on &*I just need to check for I==end()
  before dereferencing.
- There's also occasional code that sends iterators into a function, and
  then starts calling I->getOperand() (or other API).  Either check for
  end() before the entering the function, or early exit.

Note for if the static_assert with HasObsoleteCustomization is firing
for you:
- r278513 has examples of how to stop using custom sentinel traits.
- r278532 removed ilist_nextprev_traits since no one was using it.  See
  lld's r278469 for the only migration I needed to do.

Original commit message follows.

----

This removes the undefined behaviour (UB) in ilist/ilist_node/etc.,
mainly by removing (gutting) the ilist_sentinel_traits customization
point and canonicalizing on a single, efficient memory layout.  This
fixes PR26753.

The new ilist is a doubly-linked circular list.
- ilist_node_base has two ilist_node_base*: Next and Prev.  Size-of: two
  pointers.
- ilist_node<T> (size-of: two pointers) is a type-safe wrapper around
  ilist_node_base.
- ilist_iterator<T> (size-of: two pointers) operates on an
  ilist_node<T>*, and downcasts to T* on dereference.
- ilist_sentinel<T> (size-of: two pointers) is a wrapper around
  ilist_node<T> that has some extra API for list management.
- ilist<T> (size-of: two pointers) has an ilist_sentinel<T>, whose
  address is returned for end().

The new memory layout matches ilist_half_embedded_sentinel_traits<T>
exactly.  The Head pointer that previously lived in ilist<T> is
effectively glued to the ilist_half_node<T> that lived in
ilist_half_embedded_sentinel_traits<T>, becoming the Next and Prev in
the ilist_sentinel_node<T>, respectively.  sizeof(ilist<T>) is now the
size of two pointers, and there is never any additional storage for a
sentinel.

This is a much simpler design for a doubly-linked list, removing most of
the corner cases of list manipulation (add, remove, etc.).  In follow-up
commits, I intend to move as many algorithms as possible into a
non-templated base class (ilist_base) to reduce code size.

Moreover, this fixes the UB in ilist_iterator/getNext/getPrev
operations.  Previously, ilist_iterator<T> operated on a T*, even when
the sentinel was not of type T (i.e., ilist_embedded_sentinel_traits and
ilist_half_embedded_sentinel_traits).  This added UB to all operations
involving end().   Now, ilist_iterator<T> operates on an ilist_node<T>*,
and only downcasts when the full type is guaranteed to be T*.

What did we lose?  There used to be a crash (in some configurations) on
++end().  Curiously (via UB), ++end() would return begin() for users of
ilist_half_embedded_sentinel_traits<T>, but otherwise ++end() would
cause a nice dependable nullptr dereference, crashing instead of a
possible infinite loop.  Options:
 1. Lose that behaviour.
 2. Keep it, by stealing a bit from Prev in asserts builds.
 3. Crash on dereference instead, using the same technique.

Hans convinced me (because of the number of problems this and r278532
exposed on Windows) that we really need some assertion here, at least in
the short term.  I've opted for #3 since I think it catches more bugs.

I added only a couple of unit tests to root out specific bugs I hit
during bring-up, but otherwise this is tested implicitly via the
extensive usage throughout LLVM.

Planned follow-ups:
- Remove ilist_*sentinel_traits<T>.  Here I've just gutted them to
  prevent build failures in sub-projects.  Once I stop referring to them
  in sub-projects, I'll come back and delete them.
- Add ilist_base and move algorithms there.
- Check and fix move construction and assignment.

Eventually, there are other interesting directions:
- Rewrite reverse iterators, so that rbegin().getNodePtr()==&*rbegin().
  This allows much simpler logic when erasing elements during a reverse
  traversal.
- Remove ilist_traits::createNode, by deleting the remaining API that
  creates nodes.  Intrusive lists shouldn't be creating nodes
  themselves.
- Remove ilist_traits::deleteNode, by (1) asserting that lists are empty
  on destruction and (2) changing API that calls it to take a Deleter
  functor (intrusive lists shouldn't be in the memory management
  business).
- Reconfigure the remaining callback traits (addNodeToList, etc.) to be
  higher-level, pulling out a simple_ilist<T> that is much easier to
  read and understand.
- Allow tags (e.g., ilist_node<T,tag1> and ilist_node<T,tag2>) so that T
  can be a member of multiple intrusive lists.

llvm-svn: 279314
2016-08-19 20:40:12 +00:00
Duncan P. N. Exon Smith
2afcedbd91 Reapply "ADT: Tidy up ilist_traits static asserts, NFC"
This spiritually reapplies r279012 (reverted in r279052) without the
r278974 parts.  The differences:

  - Only the HasGetNext trait exists here, so I've only cleaned up (and
    tested) it.  I still added HasObsoleteCustomization since I know
    this will be expanding when r278974 is reapplied.

  - I changed the unit tests to use static_assert to catch problems
    earlier in the build.

  - I added negative tests for the type traits.

Original commit message follows.

----

Change the ilist traits to use decltype instead of sizeof, and add
HasObsoleteCustomization so that additions to this list don't
need to be added in two places.

I suspect this will now work with MSVC, since the trait tested in
r278991 seems to work.  If for some reason it continues to fail on
Windows I'll follow up by adding back the #ifndef _MSC_VER.

llvm-svn: 279312
2016-08-19 20:17:23 +00:00
Chandler Carruth
da38ee93c5 [ADT] Add the worlds simplest STL extra. Or at least close to it.
This is a little class template that just builds an inheritance chain of
empty classes. Despite how simple this is, it can be used to really
nicely create ranked overload sets. I've added a unittest as much to
document this as test it. You can pass an object of this type as an
argument to a function overload set an it will call the first viable and
enabled candidate at or below the rank of the object.

I'm planning to use this in a subsequent commit to more clearly rank
overload candidates used for SFINAE. All credit for this technique and
both lines of code here to Richard Smith who was helping me rewrite the
SFINAE check in question to much more effectively capture the intended
set of checks.

llvm-svn: 279197
2016-08-19 02:07:51 +00:00
Duncan P. N. Exon Smith
3136a3223e Reapply "ADT: Remove references in has_rbegin for reverse()"
This reverts commit r279086, reapplying r279084.  I'm not sure what I
ran before, because the compile failure for ADTTests reproduced locally.

The problem is that TestRev is calling BidirectionalVector::rbegin()
when the BidirectionalVector is const, but rbegin() is always non-const.
I've updated BidirectionalVector::rbegin() to be callable from const.

Original commit message follows.

--

As a follow-up to r278991, add some tests that check that
decltype(reverse(R).begin()) == decltype(R.rbegin()), and get them
passing by adding std::remove_reference to has_rbegin.

I'm using static_assert instead of EXPECT_TRUE (and updated the other
has_rbegin check from r278991 in the same way) since I figure that's
more helpful.

llvm-svn: 279091
2016-08-18 17:15:25 +00:00
Duncan P. N. Exon Smith
36ad6d58c6 Revert "ADT: Remove references in has_rbegin for reverse()"
This reverts commit r279084, since it failed on a bot:
  http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/41733

llvm-svn: 279086
2016-08-18 16:27:41 +00:00
Duncan P. N. Exon Smith
4c0d22d452 ADT: Remove references in has_rbegin for reverse()
As a follow-up to r278991, add some tests that check that
decltype(reverse(R).begin()) == decltype(R.rbegin()), and get them
passing by adding std::remove_reference to has_rbegin.

I'm using static_assert instead of EXPECT_TRUE (and updated the other
has_rbegin check from r278991 in the same way) since I figure that's
more helpful.

llvm-svn: 279084
2016-08-18 16:22:54 +00:00
Diana Picus
2662ef05f1 Revert "ADT: Remove UB in ilist (and use a circular linked list)"
This reverts commit r278974 which broke some of our bots (e.g.
clang-cmake-aarch64-42vma, clang-cmake-aarch64-full).

llvm-svn: 279053
2016-08-18 11:17:53 +00:00
Diana Picus
746d46ed86 Revert "ADT: Tidy up ilist_traits static asserts, NFC"
This reverts commit r279012.
r278974 broke some bots, I have to revert this to get to it.

llvm-svn: 279052
2016-08-18 11:17:47 +00:00
Duncan P. N. Exon Smith
762c7604e5 ADT: Tidy up ilist_traits static asserts, NFC
Change the ilist traits to use decltype instead of sizeof, and add
HasObsoleteCustomization so that additions to this list don't need to be
added in two places.

I suspect this will now work with MSVC, since the trait tested in
r278991 seems to work.  If for some reason it continues to fail on
Windows I'll follow up by adding back the #ifndef _MSC_VER.

llvm-svn: 279012
2016-08-17 23:47:56 +00:00
Pete Cooper
0149be7d58 Actually enable new test for const RangeAdapter. Missing from r278991
llvm-svn: 279000
2016-08-17 22:52:39 +00:00
Pete Cooper
c1662528d1 Fix reverse to work on const rbegin()/rend().
Duncan found that reverse worked on mutable rbegin(), but the has_rbegin
trait didn't work with a const method.  See http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160815/382890.html
for more details.

Turns out this was already solved in clang with has_getDecl.  Copied that and made it work for rbegin.

This includes the tests Duncan attached to that thread, including the traits test.

llvm-svn: 278991
2016-08-17 22:06:59 +00:00
Duncan P. N. Exon Smith
9ac8992a85 ADT: Remove UB in ilist (and use a circular linked list)
This removes the undefined behaviour (UB) in ilist/ilist_node/etc.,
mainly by removing (gutting) the ilist_sentinel_traits customization
point and canonicalizing on a single, efficient memory layout.  This
fixes PR26753.

The new ilist is a doubly-linked circular list.
- ilist_node_base has two ilist_node_base*: Next and Prev.  Size-of: two
  pointers.
- ilist_node<T> (size-of: two pointers) is a type-safe wrapper around
  ilist_node_base.
- ilist_iterator<T> (size-of: two pointers) operates on an
  ilist_node<T>*, and downcasts to T* on dereference.
- ilist_sentinel<T> (size-of: two pointers) is a wrapper around
  ilist_node<T> that has some extra API for list management.
- ilist<T> (size-of: two pointers) has an ilist_sentinel<T>, whose
  address is returned for end().

The new memory layout matches ilist_half_embedded_sentinel_traits<T>
exactly.  The Head pointer that previously lived in ilist<T> is
effectively glued to the ilist_half_node<T> that lived in
ilist_half_embedded_sentinel_traits<T>, becoming the Next and Prev in
the ilist_sentinel_node<T>, respectively.  sizeof(ilist<T>) is now the
size of two pointers, and there is never any additional storage for a
sentinel.

This is a much simpler design for a doubly-linked list, removing most of
the corner cases of list manipulation (add, remove, etc.).  In follow-up
commits, I intend to move as many algorithms as possible into a
non-templated base class (ilist_base) to reduce code size.

Moreover, this fixes the UB in ilist_iterator/getNext/getPrev
operations.  Previously, ilist_iterator<T> operated on a T*, even when
the sentinel was not of type T (i.e., ilist_embedded_sentinel_traits and
ilist_half_embedded_sentinel_traits).  This added UB to all operations
involving end().   Now, ilist_iterator<T> operates on an ilist_node<T>*,
and only downcasts when the full type is guaranteed to be T*.

What did we lose?  There used to be a crash (in some configurations) on
++end().  Curiously (via UB), ++end() would return begin() for users of
ilist_half_embedded_sentinel_traits<T>, but otherwise ++end() would
cause a nice dependable nullptr dereference, crashing instead of a
possible infinite loop.  Options:
 1. Lose that behaviour.
 2. Keep it, by stealing a bit from Prev in asserts builds.
 3. Crash on dereference instead, using the same technique.

Hans convinced me (because of the number of problems this and r278532
exposed on Windows) that we really need some assertion here, at least in
the short term.  I've opted for #3 since I think it catches more bugs.

I added only a couple of unit tests to root out specific bugs I hit
during bring-up, but otherwise this is tested implicitly via the
extensive usage throughout LLVM.

Planned follow-ups:
- Remove ilist_*sentinel_traits<T>.  Here I've just gutted them to
  prevent build failures in sub-projects.  Once I stop referring to them
  in sub-projects, I'll come back and delete them.
- Add ilist_base and move algorithms there.
- Check and fix move construction and assignment.

Eventually, there are other interesting directions:
- Rewrite reverse iterators, so that rbegin().getNodePtr()==&*rbegin().
  This allows much simpler logic when erasing elements during a reverse
  traversal.
- Remove ilist_traits::createNode, by deleting the remaining API that
  creates nodes.  Intrusive lists shouldn't be creating nodes
  themselves.
- Remove ilist_traits::deleteNode, by (1) asserting that lists are empty
  on destruction and (2) changing API that calls it to take a Deleter
  functor (intrusive lists shouldn't be in the memory management
  business).
- Reconfigure the remaining callback traits (addNodeToList, etc.) to be
  higher-level, pulling out a simple_ilist<T> that is much easier to
  read and understand.
- Allow tags (e.g., ilist_node<T,tag1> and ilist_node<T,tag2>) so that T
  can be a member of multiple intrusive lists.

llvm-svn: 278974
2016-08-17 20:44:33 +00:00
Zijiao Ma
d505e4743a Remove the Triple tests that stressing the TargetParser's behaviour.
Now the tests of TargetParser is in place:
unittests/Support/TargetParserTest.cpp.
So the tests in TripleTest.cpp which actually stressing TargetParser's behavior could be removed.

llvm-svn: 278899
2016-08-17 03:17:07 +00:00
Duncan P. N. Exon Smith
941fc6d2e7 ADT: Add some missing coverage for iplist::splice
These splices are interesting because they involve swapping two nodes in
the same list.  There are two ways to do this.  Assuming:

    A -> B -> [Sentinel]

You can either:
- splice B before A, with:        L.splice(A,       L, B) or
- splice A before Sentinel, with: L.splice(L.end(), L, A) to create:

    B -> A -> [Sentinel]

These two swapping-splices are somewhat interesting corner cases for
maintaining the list invariants.  The tests pass even with my new ilist
implementation, but I had some doubts about the latter when I was
looking at weird UB effects.  Since I can't find equivalent explicit
test coverage elsewhere it seems prudent to commit.

llvm-svn: 278887
2016-08-17 02:08:08 +00:00
Tim Shen
e69d467a94 [ADT] Change PostOrderIterator to use NodeRef. NFC.
Reviewers: dblaikie

Subscribers: mzolotukhin, llvm-commits

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

llvm-svn: 278752
2016-08-15 21:52:54 +00:00
Mehdi Amini
784f5239a9 [ADT] Add a reserve() method to DenseSet as well as an insert() for R-value
Recommit 278600 with some fixes to make the test more robust.

llvm-svn: 278604
2016-08-13 20:42:19 +00:00
Mehdi Amini
19082f556e Revert "[ADT] Add a reserve method to DenseSet as well as an insert() for R-value"
This reverts commit r278600. The unittest does not pass on MSVC, there is
an extra move. Investigating how to make it more robust.

llvm-svn: 278603
2016-08-13 20:14:39 +00:00
Mehdi Amini
fc467f872b [ADT] Add a reserve method to DenseSet as well as an insert() for R-value
llvm-svn: 278600
2016-08-13 19:40:13 +00:00
Tim Shen
5026b80249 [ADT] Add relation operators for Optional
Summary: Make Optional's behavior the same as the coming std::optional.

Reviewers: dblaikie

Subscribers: llvm-commits

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

llvm-svn: 278397
2016-08-11 20:10:15 +00:00
Jonathan Roelofs
661ec64587 Fix UB in APInt::ashr
i64 -1, whose sign bit is the 0th one, can't be left shifted without invoking UB.

https://reviews.llvm.org/D23362

llvm-svn: 278280
2016-08-10 19:50:14 +00:00
Tim Shen
8573eb4217 [ADT] Add make_scope_exit().
Summary: make_scope_exit() is described in C++ proposal p0052r2, which uses RAII to do cleanup works at scope exit.

Reviewers: chandlerc

Subscribers: llvm-commits

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

llvm-svn: 278251
2016-08-10 17:52:09 +00:00
Chandler Carruth
a0e0d32a56 [ADT] Make the triple test 1000x faster through more focused test cases.
The current approach isn't a long-term viable pattern. Given the set of
architectures A, vendors V, operating systems O, and environments E, it
does |A| * |V| * |O| * |E| * 4! tests. As LLVM grows, this test keeps
getting slower, despite my working very hard to make it get some
"optimizations" even in -O0 builds in order to lower the constant
factors. Fundamentally, we're doing an unreasonable amount of work.i

Looking at the specific thing being tested -- the goal seems very
clearly to be testing the *permutations*, not the *combinations*. The
combinations are driving up the complexity much more than anything else.

Instead, test every possible value for a given triple entry in every
permutation of *some* triple. This really seems to cover the core goal
of the test. Every single possible triple component is tested in every
position. But because we keep the rest of the triple constant, it does
so in a dramatically more scalable amount of time. With this model we do
(|A| + |V| + |O| + |E|) * 4! tests.

For me on a debug build, this goes from running for 19 seconds to 19
milliseconds, or a 1000x improvement. This makes a world of difference
for the critical path of 'ninja check-llvm' and other extremely common
workflows.

Thanks to Renato, Dean, and David for the helpful review comments and
helping me refine the explanation of the change.

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

llvm-svn: 277912
2016-08-06 06:00:50 +00:00
Tim Shen
4df0ad8244 [ADT] NFC: Generalize GraphTraits requirement of "NodeType *" in interfaces to "NodeRef", and migrate SCCIterator.h to use NodeRef
Summary: By generalize the interface, users are able to inject more flexible Node token into the algorithm, for example, a pair of vector<Node>* and index integer. Currently I only migrated SCCIterator to use NodeRef, but more is coming. It's a NFC.

Reviewers: dblaikie, chandlerc

Subscribers: llvm-commits

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

llvm-svn: 277399
2016-08-01 22:32:20 +00:00
Chandler Carruth
cd6624d554 [ADT] Add 'consume_front' and 'consume_back' methods to StringRef which
are very handy when parsing text.

They are essentially a combination of startswith and a self-modifying
drop_front, or endswith and drop_back respectively.

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

llvm-svn: 277288
2016-07-31 02:19:13 +00:00
Dimitry Andric
a30a510ed0 Remove obsolete XFAIL for a test that used to sometimes miscompile under
FreeBSD with gcc 4.2.1, a long time ago (see r113824).  Noticed by Pete
Cooper.

llvm-svn: 276730
2016-07-26 06:49:14 +00:00
Pete Cooper
a18d1734a0 Use RValue refs in APInt add/sub methods.
This adds versions of operator + and - which are optimized for the LHS/RHS of the
operator being RValue's.  When an RValue is available, we can use its storage space
instead of allocating new space.

On code such as ConstantRange which makes heavy use of APInt's over 64-bits in size,
this results in significant numbers of saved allocations.

Thanks to David Blaikie for all the review and most of the code here.

llvm-svn: 276470
2016-07-22 20:55:46 +00:00
Benjamin Kramer
38c61d7923 [DenseMap] Add a C++17-style try_emplace method.
This provides an elegant pattern to solve the "construct if not in map
already" problem we have many times in LLVM. Without try_emplace we
either have to rely on a sentinel value (nullptr) or do two lookups.

llvm-svn: 276277
2016-07-21 13:37:53 +00:00
Benjamin Kramer
750272d02a Rename StringMap::emplace_second to try_emplace.
Coincidentally this function maps to the C++17 try_emplace. Rename it
for consistentcy with C++17 std::map. NFC.

llvm-svn: 276276
2016-07-21 13:37:48 +00:00
Justin Lebar
bade3bc474 Fix warnings in ImmutableSetTest and SequenceTest.
Doing "I++" inside of an EXPECT_* triggers

  warning: expression with side effects has no effect in an unevaluated context

because EXPECT_* partially expands to

  EqHelper<(sizeof(::testing::internal::IsNullLiteralHelper(i++)) == 1)>

which is an unevaluated context.

llvm-svn: 275717
2016-07-17 18:10:30 +00:00
Justin Lebar
98656f3236 [ADT] Add LLVM_MARK_AS_BITMASK_ENUM, used to enable bitwise operations on enums without static_cast.
Summary: Normally when you do a bitwise operation on an enum value, you
get back an instance of the underlying type (e.g. int).  But using this
macro, bitwise ops on your enum will return you back instances of the
enum.  This is particularly useful for enums which represent a
combination of flags.

Suppose you have a function which takes an int and a set of flags.  One
way to do this would be to take two numeric params:

  enum SomeFlags { F1 = 1, F2 = 2, F3 = 4, ... };
  void Fn(int Num, int Flags);

  void foo() {
    Fn(42, F2 | F3);
  }

But now if you get the order of arguments wrong, you won't get an error.

You might try to fix this by changing the signature of Fn so it accepts
a SomeFlags arg:

  enum SomeFlags { F1 = 1, F2 = 2, F3 = 4, ... };
  void Fn(int Num, SomeFlags Flags);

  void foo() {
    Fn(42, static_cast<SomeFlags>(F2 | F3));
  }

But now we need a static cast after doing "F2 | F3" because the result
of that computation is the enum's underlying type.

This patch adds a mechanism which gives us the safety of the second
approach with the brevity of the first.

  enum SomeFlags {
    F1 = 1, F2 = 2, F3 = 4, ..., F_MAX = 128,
    LLVM_MARK_AS_BITMASK_ENUM(F_MAX)
  };

  void Fn(int Num, SomeFlags Flags);

  void foo() {
    Fn(42, F2 | F3);  // No static_cast.
  }

The LLVM_MARK_AS_BITMASK_ENUM macro enables overloads for bitwise
operators on SomeFlags.  Critically, these operators return the enum
type, not its underlying type, so you don't need any static_casts.

An advantage of this solution over the previously-proposed BitMask class
[0, 1] is that we don't need any wrapper classes -- we can operate
directly on the enum itself.

The approach here is somewhat similar to OpenOffice's typed_flags_set
[2].  But we skirt the need for a wrapper class (and a good deal of
complexity) by judicious use of enable_if.  We SFINAE on the presence of
a particular enumerator (added by the LLVM_MARK_AS_BITMASK_ENUM macro)
instead of using a traits class so that it's impossible to use the enum
before the overloads are present.  The solution here also seamlessly
works across multiple namespaces.

[0] http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150622/283369.html
[1] http://lists.llvm.org/pipermail/llvm-commits/attachments/20150623/073434b6/attachment.obj
[2] https://cgit.freedesktop.org/libreoffice/core/tree/include/o3tl/typed_flags_set.hxx

Reviewers: chandlerc, rsmith

Subscribers: llvm-commits

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

llvm-svn: 275292
2016-07-13 18:23:16 +00:00
Chandler Carruth
69a27222d9 [ADT] Add a new data structure for managing a priority worklist where
re-insertion of entries into the worklist moves them to the end.

This is fairly similar to a SetVector, but helps in the case where in
addition to not inserting duplicates you want to adjust the sequence of
a pop-off-the-back worklist.

I'm not at all attached to the name of this data structure if others
have better suggestions, but this is one that David Majnemer brought up
in IRC discussions that seems plausible.

I've trimmed the interface down somewhat from SetVector's interface
because several things make less sense here IMO: iteration primarily.
I'd prefer to add these back as we have users that need them. My use
case doesn't even need all of what is provided here. =]

I've also included a basic unittest to make sure this functions
reasonably.

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

llvm-svn: 274198
2016-06-30 02:32:20 +00:00
Davide Italiano
387ce51c92 [Triple] Reimplement isLittleEndian(). Now it works for arm too.
Differential Revision:   http://reviews.llvm.org/D21846

llvm-svn: 274154
2016-06-29 20:01:39 +00:00
Rafael Espindola
915dc69c99 Add support for musl-libc on ARM Linux.
Patch by Lei Zhang!

llvm-svn: 273726
2016-06-24 21:14:33 +00:00
Evgeniy Stepanov
0e1477e15b Fix BitVector move ctor/assignment.
Current implementation leaves the object in an invalid state.

This reverts commit bf0c389ac683cd6c0e5959b16537e59e5f4589e3.

llvm-svn: 272965
2016-06-16 21:45:13 +00:00
Rafael Espindola
417a1022df Add a Musl environment to the triple.
It will be used in clang.

Patch by Lei Zhang.

llvm-svn: 272660
2016-06-14 12:45:33 +00:00
Ben Craig
d37457ba08 Adding reserve and capacity methods to FoldingSet
http://reviews.llvm.org/D20930

llvm-svn: 271669
2016-06-03 13:54:48 +00:00
Ahmed Bougacha
64f0370857 [ADT] Pass ArrayRef::slice size_t instead of unsigned.
Also fix slice wrappers drop_front and drop_back.
The unittests are pretty awkward, but do the job; alternatives
welcome!

..and yes, I do have ArrayRefs with more than 4 billion elements.

llvm-svn: 271546
2016-06-02 17:26:03 +00:00
Pete Cooper
a4a912aae4 Don't allocate in APInt::slt. NFC.
APInt::slt was copying the LHS and RHS in to temporaries then making
them unsigned so that it could use an unsigned comparision.  It did
this even on the paths which were trivial to give results for, such
as the sign bit of the LHS being set while RHS was not set.

This changes the logic to return out immediately in the trivial cases,
and use an unsigned comparison in the remaining cases.  But this time,
just use the unsigned comparison directly without creating any temporaries.

This works because, for example:
  true = (-2 slt -1) = (0xFE ult 0xFF)

Also added some tests explicitly for slt with APInt's larger than 64-bits
so that this new code is tested.

Using the memory for 'opt -O2 verify-uselistorder.lto.opt.bc -o opt.bc'
(see r236629 for details), this reduces the number of allocations from
26.8M to 23.9M.

llvm-svn: 270881
2016-05-26 17:40:07 +00:00
Chandler Carruth
6004493dd0 [ADT] Add an 'llvm::seq' function which produces an iterator range over
a sequence of values.

It increments through the values in the half-open range: [Begin, End),
producing those values when indirecting the iterator. It should support
integers, iterators, and any other type providing these basic arithmetic
operations.

This came up in the C++ standards committee meeting, and it seemed like
a useful construct that LLVM might want as well, and I wanted to
understand how easily we could solve it. I suspect this can be used to
write simpler counting loops even in LLVM along the lines of:

  for (int i : seq(0, v.size())) {
    ...
  };

As part of this, I had to fix the lack of a proxy object returned from
the operator[] in our iterator facade.

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

llvm-svn: 269390
2016-05-13 03:57:50 +00:00
Reid Kleckner
9a635e6090 [ADT] Add drop_front method to ArrayRef
We have it for StringRef but not ArrayRef, and ArrayRef has drop_back,
so I see no reason it shouldn't have drop_front. Splitting this out of a
change that I have that will use this funcitonality.

llvm-svn: 268434
2016-05-03 20:53:20 +00:00
Rafael Espindola
becf204913 Add a CachedHash structure.
A DenseMap doesn't store the hashes, so it needs to recompute them when
the table is resized.

In some applications the hashing cost is noticeable. That is the case
for example in lld for symbol names (StringRef).

This patch adds a templated structure that can wraps any value that can
go in a DenseMap and caches the hash.

llvm-svn: 266981
2016-04-21 12:16:21 +00:00
Mehdi Amini
9ff867f98c [NFC] Header cleanup
Removed some unused headers, replaced some headers with forward class declarations.

Found using simple scripts like this one:
clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap'

Patch by Eugene Kosov <claprix@yandex.ru>

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

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266595
2016-04-18 09:17:29 +00:00
Mehdi Amini
70b295014e Remove some unneeded headers and replace some headers with forward class declarations (NFC)
Differential Revision: http://reviews.llvm.org/D19154

Patch by Eugene Kosov <claprix@yandex.ru>

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266524
2016-04-16 07:51:28 +00:00
Matt Arsenault
795072118d APInt: Add overload of isMask
This mimics the version in MathExtras.h which isn't testing for a
specific mask size.

llvm-svn: 266101
2016-04-12 18:17:23 +00:00
Duncan P. N. Exon Smith
5f366e4aa0 Revert "Fix Clang-tidy modernize-deprecated-headers warnings in remaining files; other minor fixes."
This reverts commit r265454 since it broke the build.  E.g.:

  http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_build/22413/

llvm-svn: 265459
2016-04-05 20:45:04 +00:00
Eugene Zelenko
a612bac11f Fix Clang-tidy modernize-deprecated-headers warnings in remaining files; other minor fixes.
Some Include What You Use suggestions were used too.

Use anonymous namespaces in source files.

Differential revision: http://reviews.llvm.org/D18778

llvm-svn: 265454
2016-04-05 20:19:49 +00:00
Hal Finkel
66a0968e06 Add a copy constructor to StringMap
There is code under review that requires StringMap to have a copy constructor,
and this makes StringMap more consistent with our other containers (like
DenseMap) that have copy constructors.

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

llvm-svn: 264906
2016-03-30 19:54:56 +00:00
Mehdi Amini
3aa467efee StringMap/DenseMap unittests: use piecewise_construct and ensure no copy occurs.
This makes us no longer relying on move-construction elision by the compiler.
Suggested by D. Blaikie.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264475
2016-03-25 23:25:06 +00:00
Jun Bum Lim
0857fa46b4 [SetVector] Add erase() method
This is a recommit of r264414 after fixing the buildbot failure caused by
incompatible use of std::vector.erase().

The original message:

Add erase() which returns an iterator pointing to the next element after the
erased one. This makes it possible to erase selected elements while iterating
over the SetVector :
  while (I != E)
    if (test(*I))
      I = SetVector.erase(I);
    else
      ++I;

Reviewers: qcolombet, mcrosier, MatzeB, dblaikie

Subscribers: dberlin, dblaikie, mcrosier, llvm-commits

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

llvm-svn: 264450
2016-03-25 19:28:08 +00:00
Jun Bum Lim
cd509e296e Revert "[SetVector] Add erase() method"
This reverts commit r264414.

llvm-svn: 264420
2016-03-25 16:49:16 +00:00
Mehdi Amini
5a67abb5fc Improve StringMap unittests: reintroduce move count, but shield against std::pair internals
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264418
2016-03-25 16:36:00 +00:00
Mehdi Amini
5143e0f517 Ensure that the StringMap does not grow during the test for pre-allocation/reserve
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264416
2016-03-25 16:09:34 +00:00
Jun Bum Lim
305aa24843 [SetVector] Add erase() method
Summary:
Add erase() which returns an iterator pointing to the next element after the
erased one. This makes it possible to erase selected elements while iterating
over the SetVector :
  while (I != E)
    if (test(*I))
      I = SetVector.erase(I);
    else
      ++I;

Reviewers: qcolombet, mcrosier, MatzeB, dblaikie

Subscribers: dberlin, dblaikie, mcrosier, llvm-commits

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

llvm-svn: 264414
2016-03-25 16:04:43 +00:00
Mehdi Amini
90f0c30a7d Disable counting the number of move in the unittest, it seems to rely on move-construction elision
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264412
2016-03-25 15:46:14 +00:00
Mehdi Amini
7f6c7f0a20 Query the StringMap only once when creating MDString (NFC)
Summary:
Loading IR with debug info improves MDString::get() from 19ms to 10ms.
This is a rework of D16597 with adding an "emplace" method on the StringMap
to avoid requiring the MDString move ctor to be public.

Reviewers: dexonsmith

Subscribers: llvm-commits

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

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264386
2016-03-25 05:58:04 +00:00
Mehdi Amini
aad049fea9 Adjust initial size in StringMap constructor to guarantee no grow()
Summary:
StringMap ctor accepts an initialize size, but expect it to be
rounded to the next power of 2. The ctor can handle that directly
instead of expecting clients to round it. Also, since the map will
resize itself when 75% full, take this into account an initialize
a larger initial size to avoid any growth.

Reviewers: dblaikie

Subscribers: llvm-commits

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

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264385
2016-03-25 05:57:57 +00:00
Mehdi Amini
bbd89f73ab Fix DenseMap::reserve(): the formula was wrong
Summary:
Just running the loop in the unittests for a few more iterations
(till 48) exhibit that the condition on the limit was not handled
properly in r263522.
Rewrite the test to use a class to count move/copies that happens
when inserting into the map.
Also take the opportunity to refactor the logic to compute the
number of buckets required for a given number of entries in the map.
Use this when constructing a DenseMap with a desired size given to
the constructor (and add a tests for this).

Reviewers: dblaikie

Subscribers: llvm-commits

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

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264384
2016-03-25 05:57:52 +00:00
David Blaikie
4824d34fa2 [ADT] C++11ify SmallVector::erase's arguments from iterator to const_iterator
llvm-svn: 264330
2016-03-24 20:25:51 +00:00
Matt Arsenault
8eb0f64d4c APFloat: Fix signalling nans for scalbn
llvm-svn: 264219
2016-03-23 23:51:45 +00:00
Pete Cooper
0059979e14 StringRef::copy shouldn't allocate anything for length 0 strings.
The BumpPtrAllocator currently doesn't handle zero length allocations well.
The discussion for how to fix that is ongoing.  However, there's no need
for StringRef::copy to actually allocate anything here anyway, so just
return StringRef() when we get a zero length copy.

Reviewed by David Blaikie

llvm-svn: 264201
2016-03-23 21:49:31 +00:00
Mehdi Amini
160ac40f92 Fix unittests: resize() -> reserve()
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 264029
2016-03-22 07:35:51 +00:00
Matt Arsenault
5d7eb096ca APFloat: Add frexp
llvm-svn: 263950
2016-03-21 16:49:16 +00:00
Matt Arsenault
f2fb55d608 Implement constant folding for bitreverse
llvm-svn: 263945
2016-03-21 15:00:35 +00:00
Mike Aizatsky
8b73d34d94 Revert "allow lambdas in mapped_iterator"
MSVC as usual:

C:\Buildbot\Slave\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\include\llvm/ADT/STLExtras.h(120):
error C2100: illegal indirection
C:\Buildbot\Slave\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm.src\include\llvm/IR/Instructions.h(3966):
note: see reference to class template instantiation
'llvm::mapped_iterator<llvm::User::op_iterator,llvm::CatchSwitchInst::DerefFnTy>'
being compiled

This reverts commit e091dd63f1f34e043748e28ad160d3bc17731168.

llvm-svn: 263760
2016-03-17 23:32:20 +00:00
Mike Aizatsky
f856af3360 allow lambdas in mapped_iterator
Differential Revision: http://reviews.llvm.org/D17311

llvm-svn: 263759
2016-03-17 23:22:22 +00:00
Fiona Glaser
750f1d0625 DenseMap: make .resize() do the intuitive thing
In some places, like InstCombine, we resize a DenseMap to fit the elements
we intend to put in it, then insert those elements (to avoid continual
reallocations as it grows). But .resize(foo) doesn't actually do what
people think; it resizes to foo buckets (which is really an
implementation detail the user of DenseMap probably shouldn't care about),
not the space required to fit foo elements. DenseMap grows if 3/4 of its
buckets are full, so this actually causes one forced reallocation every
time instead of avoiding a reallocation.

This patch makes .resize(foo) do the intuitive thing: it grows to the size
necessary to fit foo elements without new allocations.

Also include a test to verify that .resize() actually does what we think it
does.

llvm-svn: 263522
2016-03-15 01:50:46 +00:00
Quentin Colombet
573b41c165 [ADT] Add a pop_back_val method to the SparseSet container.
The next commit will use it.

llvm-svn: 263455
2016-03-14 18:10:41 +00:00
Matt Arsenault
26aa8f6035 APFloat: Fix ilogb for denormals
llvm-svn: 263370
2016-03-13 05:12:32 +00:00
Matt Arsenault
b9effef6fc APFloat: Fix scalbn handling of denormals
This was incorrect for denormals, and also failed
on longer exponent ranges.

llvm-svn: 263369
2016-03-13 05:11:51 +00:00
Jordan Rose
8c6650f01b [ADT] Fix PointerEmbeddedInt when the underlying type is uintptr_t.
...and when you try to store negative values in it.

llvm-svn: 261259
2016-02-18 21:00:08 +00:00
Vedant Kumar
edda1d67ad [ADT] Add StringRef::{l,r}trim(char) overloads (NFC)
Add support for trimming a single kind of character from a StringRef.
This makes the common case of trimming null bytes much neater. It's also
probably a bit speedier too, since it avoids creating a std::bitset in
find_{first,last}_not_of.

llvm-svn: 260925
2016-02-16 01:48:39 +00:00
Matt Arsenault
b576160845 Add AMDGPU related triple vendors/OSes
As support expands to more runtimes, we'll need to
distinguish between more than just HSA and unknown.
This also lets us stop using unknown everywhere.

llvm-svn: 260790
2016-02-13 01:56:21 +00:00
Argyrios Kyrtzidis
94fe44f7a0 [ADT] Revert the llvm/ADT/OptionSet.h header and unit test.
llvm-svn: 260714
2016-02-12 19:47:35 +00:00
Argyrios Kyrtzidis
314b947efa [unittests/ADT] OptionSetTest: ifdef out for now a specific test that fails on MSVC.
llvm-svn: 260663
2016-02-12 07:50:01 +00:00
Argyrios Kyrtzidis
05cc472794 [unittests/ADT] OptionSetTest: ifdef out a part that fails to compile on MSVC.
llvm-svn: 260655
2016-02-12 05:52:37 +00:00
Argyrios Kyrtzidis
eaf4355f60 [ADT] Introduce ‘OptionSet’ in llvm/ADT headers, which is a utility class that makes it convenient to work with enumerators representing bit options.
llvm-svn: 260652
2016-02-12 02:48:26 +00:00
Tim Northover
49f7c6fb6b ARMv7k: use Cortex-A7 by default even for tvOS
Also actually test the default CPU from those triples.

llvm-svn: 260621
2016-02-11 23:49:08 +00:00
Jacques Pienaar
837592b498 [lanai] Add Lanai triple.
Add triple for the Lanai backend.

General Lanai backend discussion on llvm-dev thread "[RFC] Lanai backend".

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

llvm-svn: 260545
2016-02-11 17:16:20 +00:00
Matthias Braun
6b6916f5aa SmallPtrSetTest: More checks for the swap() testing
llvm-svn: 259152
2016-01-29 03:34:36 +00:00
Matthias Braun
a51e4b9705 SmallPtrSetTest: Check that iterators are still valid after erase()
llvm-svn: 259151
2016-01-29 03:34:34 +00:00
Chris Bieneman
1b8d4f74aa Remove autoconf support
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

"I felt a great disturbance in the [build system], as if millions of [makefiles] suddenly cried out in terror and were suddenly silenced. I fear something [amazing] has happened."
- Obi Wan Kenobi

Reviewers: chandlerc, grosbach, bob.wilson, tstellarAMD, echristo, whitequark

Subscribers: chfast, simoncook, emaste, jholewinski, tberghammer, jfb, danalbert, srhines, arsenm, dschuff, jyknight, dsanders, joker.eph, llvm-commits

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

llvm-svn: 258861
2016-01-26 21:29:08 +00:00
Michael Gottesman
b04f462e22 Fix PointerIntPair so that it can use an enum class as its integer template argument.
Summary:
The problem here is that an enum class can not be implicitly converted to an
integer. That assumption snuck back into PointerIntPair. This commit fixes the
issue and more importantly adds some unittests to make sure that we do not break
this again.

rdar://23594806

Reviewers: gribozavr

Subscribers: llvm-commits

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

llvm-svn: 257574
2016-01-13 05:59:13 +00:00
Chandler Carruth
8bbd7bacc1 [ADT] Add an abstraction for embedding an integer within a pointer-like
type.

This makes it easy and safe to use a set of flags as one elmenet of
a tagged union with pointers. There is quite a bit of code that has
historically done this by casting arbitrary integers to "pointers" and
assuming that this was safe and reliable. It is neither, and has started
to rear its head by triggering safety asserts in various abstractions
like PointerLikeTypeTraits when the integers chosen are invariably poor
choices for *some* platform and *some* situation. Not to mention the
(hopefully unlikely) prospect of one of these integers actually getting
allocated!

With this, it will be straightforward to build type safe abstractions
like this without being error prone. The abstraction itself is also
remarkably simple thanks to the implicit conversion.

This use case and pattern was also independently created by the folks
working on Swift, and they're going to incrementally add any missing
functionality they find.

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

llvm-svn: 257284
2016-01-10 09:40:13 +00:00
Chandler Carruth
2cfc282af1 [ADT] Add a sum type abstraction for pointer-like types.
This is a much more general and powerful form of PointerUnion. It
provides a reasonably complete sum type (from type theory) for
pointer-like types. It has several significant advantages over the
existing PointerUnion infrastructure:

1) It allows more than two pointer types to participate without awkward
   nesting structures.
2) It directly exposes the tag so that it is convenient to write
   switches over the possible members.
3) It can re-use the same type for multiple tag values, something that
   has been worked around by either abusing PointerIntPair or defining
   nonce types and doing unsafe pointer casting.
4) It supports customization of the PointerLikeTypeTraits used for
   specific member types. This means it could (in theory) be used even
   with types that are over-aligned on allocation to expose larger
   numbers of bits to the tag.

All in all, I think it is at least complimentary to the existing
infrastructure, and a strict improvement for some use cases.

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

llvm-svn: 257282
2016-01-10 08:48:23 +00:00
Chandler Carruth
60283c96ef [ADT] Use a nonce type with at least 4 byte alignment.
We didn't actually statically check this, and so it worked 25% of the
time for me. =/ Really sorry it took so long to fix, I shouldn't leave
the commit log editor window open without saving and landing the commit.
=[

llvm-svn: 256528
2015-12-29 00:03:24 +00:00
Chandler Carruth
37e9125e68 [ADT] Don't use a fixture just to get a nonce type for this unittest.
Instead, actually produce a nonce type in the test and use that. This
makes the test, IMO, both simpler and more clear.

llvm-svn: 256518
2015-12-28 20:03:16 +00:00
Artyom Skrobov
433c2c5f72 Handle ARMv6-J as an alias, instead of fake architecture
Summary:
This follows D14577 to treat ARMv6-J as an alias for ARMv6,
instead of an architecture in its own right.

The functional change is that the default CPU when targeting ARMv6-J
changes from arm1136j-s to arm1136jf-s, which is currently used as
the default CPU for ARMv6; both are, in fact, ARMv6-J CPUs.

The J-bit (Jazelle support) is irrelevant to LLVM, and it doesn't
affect code generation, attributes, optimizations, or anything else,
apart from selecting the default CPU.

Reviewers: rengolin, logan, compnerd

Subscribers: aemerson, llvm-commits, rengolin

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

llvm-svn: 253675
2015-11-20 16:46:09 +00:00
Stephen Canon
517872001b Add isInteger() to APFloat.
Useful utility function; this wasn't too hard to do before, but also wasn't
obviously discoverable.  Make it explicit.  Reviewed offline by Michael
Gottesman.

llvm-svn: 253254
2015-11-16 21:52:48 +00:00
Artyom Skrobov
add8d5cbfa Handle ARMv6KZ naming
Summary:
* ARMv6KZ is the "canonical" name, given in the ARMARM
* ARMv6Z is an "official abbreviation" for it, mentioned in the ARMARM
* ARMv6ZK is a popular misspelling, which we should support as an alias.

The patch corrects the handling of the names.

Functional changes:
* ARMv6Z no longer treated as an architecture in its own right
* ARMv6ZK renamed to ARMv6KZ, accepting ARMv6ZK as an alias
* arm1176jz-s and arm1176jzf-s recognized as ARMv6ZK, instead of ARMv6K
* default ARMv6K CPU changed to arm1176j-s

Reviewers: rengolin, logan, compnerd

Subscribers: aemerson, llvm-commits, rengolin

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

llvm-svn: 253206
2015-11-16 14:05:32 +00:00
Duncan P. N. Exon Smith
bc2ac24566 ADT: Avoid relying on UB in ilist_node::getNextNode()
Re-implement `ilist_node::getNextNode()` and `getPrevNode()` without
relying on the sentinel having a "next" pointer.  Instead, get access to
the owning list and compare against the `begin()` and `end()` iterators.

This only works when the node *can* get access to the owning list.  The
new support is in `ilist_node_with_parent<>`, and any class `Ty`
inheriting from `ilist_node<NodeTy>` that wants `getNextNode()` and/or
`getPrevNode()` should inherit from
`ilist_node_with_parent<NodeTy, ParentTy>` instead.  The requirements:

  - `NodeTy` must have a `getParent()` function that returns the parent.
  - `ParentTy` must have a `getSublistAccess()` static that, given a(n
    ignored) `NodeTy*` (to determine which list), returns a member field
    pointer to the appropriate `ilist<>`.

This isn't the cleanest way to get access to the owning list, but it
leverages the API already used in the IR hierarchy (see, e.g.,
`Instruction::getSublistAccess()`).

If anyone feels like ripping out the calls to `getNextNode()` and
`getPrevNode()` and replacing with direct iterator logic, they can also
remove the access function, etc., but as an incremental step, I'm
maintaining the API where it's currently used in tree.

If these requirements are *not* met, call sites with access to the ilist
can call `iplist<NodeTy>::getNextNode(NodeTy*)` directly, as in
ilistTest.cpp.

Why rewrite this?

The old code was broken, calling `getNext()` on a sentinel that possibly
didn't have a "next" pointer at all!  The new code avoids that
particular flavour of UB (see the commit message for r252538 for more
details about the "lucky" memory layout that made this function so
interesting).

There's still some UB here: the end iterator gets downcast to `NodeTy*`,
even when it's a sentinel (which is typically
`ilist_half_node<NodeTy*>`).  I'll tackle that in follow-up commits.
See this llvm-dev thread for more details:
http://lists.llvm.org/pipermail/llvm-dev/2015-October/091115.html

What's the danger?

There might be some code that relies on `getNextNode()` or
`getPrevNode()` *never* returning `nullptr` -- i.e., that relies on them
being broken when the sentinel is an `ilist_half_node<NodeTy>`.  I tried
to root out those cases with the audits I did leading up to r252380, but
it's possible I missed one or two.  I hope not.

(If (1) you have out-of-tree code, (2) you've reverted r252380
temporarily, and (3) you get some weird crashes with this commit, then I
recommend un-reverting r252380 and auditing the compile errors looking
for "strange" implicit conversions.)

llvm-svn: 252694
2015-11-11 02:26:42 +00:00
Michael Gottesman
951417fd40 Add a unittest for SmallDenseMap that tests assigning a SmallDenseMap when it is not small.
This complements CopyConstructorNotSmallTest. If we are testing the copy
constructor in such a way, we should also probably test assignment in the same
way.

llvm-svn: 251736
2015-10-31 05:23:53 +00:00
Michael Kuperstein
6d9717c9b3 [X86] Make elfiamcu an OS, not an environment.
GNU tools require elfiamcu to take up the entire OS field, so, e.g.
i?86-*-linux-elfiamcu is not considered a legal triple.
Make us compatible.

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

llvm-svn: 251390
2015-10-27 07:23:59 +00:00
Michael Kuperstein
f5ce8355a3 [X86] Add support for elfiamcu triple
This adds support for the i?86-*-elfiamcu triple, which indicates the IAMCU psABI is used.

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

llvm-svn: 251222
2015-10-25 08:07:37 +00:00
Duncan P. N. Exon Smith
43390ff2fc unittests: Remove implicit ilist iterator conversions, NFC
llvm-svn: 250843
2015-10-20 18:30:20 +00:00
Dylan McKay
683884b796 Initial migration of AVR backend
This patch adds the underlying infrastructure for an AVR backend to be included into LLVM. It is the first of a series of patches aimed at moving the out-of-tree AVR backend into the tree.

It consists of adding a new`Triple` target 'avr'.

llvm-svn: 250492
2015-10-16 03:10:30 +00:00
Yaron Keren
ec99ed2cc1 Simplify SmallBitVector::applyMask by consolidating common code for 32- and 64-bit builds
and assert when mask is too large to apply in the small case,
previously the extra words were silently ignored.
clang-format the entire function to match current code standards.

This is a rewrite of r247972 which was reverted in r247983 due to
warning and possible UB on 32-bits hosts.

llvm-svn: 247993
2015-09-18 15:08:24 +00:00
Aaron Ballman
def3e26caa Reverting r247972 (and subordinate commit r247972) as the 32-bit left-shift is undefined behavior on implementations where uinptr_t is 32-bits. One such platform is Windows, MSVC, x86.
llvm-svn: 247983
2015-09-18 12:18:41 +00:00
Yaron Keren
4c0fa3700e Fix BitVectorTest on 32-bit hosts after r247972.
We can't apply two words of 32-bit mask in the small case
where the internal storage is just one 32-bit word.

llvm-svn: 247974
2015-09-18 07:24:35 +00:00
Yaron Keren
c155166785 Simplify SmallBitVector::applyMask by consolidating common code for 32-bit and 64-bit builds.
Extend mask value to 64 bits before taking its complement and assert when mask is
too large to apply in the small case (previously the extra words were silently ignored).

http://reviews.llvm.org/D11890

Patch by James Touton!

llvm-svn: 247972
2015-09-18 06:35:12 +00:00
Chandler Carruth
e9c3d2d316 [ADT] Fix a confusing interface spec and some annoying peculiarities
with the StringRef::split method when used with a MaxSplit argument
other than '-1' (which nobody really does today, but which should
actually work).

The spec claimed both to split up to MaxSplit times, but also to append
<= MaxSplit strings to the vector. One of these doesn't make sense.
Given the name "MaxSplit", let's go with it being a max over how many
*splits* occur, which means the max on how many strings get appended is
MaxSplit+1. I'm not actually sure the implementation correctly provided
this logic either, as it used a really opaque loop structure.

The implementation was also playing weird games with nullptr in the data
field to try to rely on a totally opaque hidden property of the split
method that returns a pair. Nasty IMO.

Replace all of this with what is (IMO) simpler code that doesn't use the
pair returning split method, and instead just finds each separator and
appends directly. I think this is a lot easier to read, and it most
definitely matches the spec. Added some tests that exercise the corner
cases around StringRef() and StringRef("") that all now pass.

I'll start using this in code in the next commit.

llvm-svn: 247249
2015-09-10 07:51:37 +00:00
Chandler Carruth
5e0afb35b0 [ADT] Add a single-character version of the small vector split routine
on StringRef. Finding and splitting on a single character is
substantially faster than doing it on even a single character StringRef
-- we immediately get to a *very* tuned memchr call this way.

Even nicer, we get to this even in a debug build, shaving 18% off the
runtime of TripleTest.Normalization, helping PR23676 some more.

llvm-svn: 247244
2015-09-10 06:07:03 +00:00
Mehdi Amini
f9dd260ee5 Add makeArrayRef() overload for ArrayRef input (no-op/identity) NFC
The purpose is to allow templated wrapper to work with either
ArrayRef or any convertible operation:

template<typename Container>
void wrapper(const Container &Arr) {
  impl(makeArrayRef(Arr));
}

with Container being a std::vector, a SmallVector, or an ArrayRef.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 247214
2015-09-10 00:05:04 +00:00
Ben Craig
108dbc7c6d Adding full stops to comments
Also, test commit

llvm-svn: 246855
2015-09-04 15:28:13 +00:00
Richard Smith
e8f2654b47 Fix APInt value initialization to give a zero value as any sane integer type
should, rather than giving a broken value that doesn't even zero/sign-extend
properly.

llvm-svn: 246836
2015-09-04 04:08:36 +00:00
Chandler Carruth
f0232a2a7f Teach the target parsing framework to directly compute the length of all
of its strings when expanding the string literals from the macros, and
push all of the APIs to be StringRef instead of C-string APIs.

This (remarkably) removes a very non-trivial number of strlen calls. It
even deletes code and complexity from one of the primary users -- Clang.

llvm-svn: 246374
2015-08-30 07:51:04 +00:00
David Blaikie
bdabca9432 Allow Optionals to be compared to None
This is something like nullopt in std::experimental::optional. Optional
could already be constructed from None, so this seems like an obvious
extension from there.

I have a use in a future patch for Clang, though it may not go that
way/end up used - so this seemed worth committing now regardless.

llvm-svn: 245518
2015-08-19 23:07:27 +00:00
David Blaikie
2063494b0a Simplify PackedVector by removing user-defined special members that aren't any different than the defaults
This causes the other special members (like move and copy construction,
and move assignment) to come through for free. Some code in clang was
depending on the (deprecated, in the original code) copy ctor. Now that
there's no user-defined special members, they're all available without
any deprecation concerns.

llvm-svn: 244835
2015-08-12 23:26:12 +00:00
Yaron Keren
89e34e6618 Add SmallString test trying to exercise the realloc() code path
by allocating a small size (will go through malloc) and then large size.

llvm-svn: 244637
2015-08-11 17:35:49 +00:00
Benjamin Kramer
214753cf47 [ArrayRefTest] Work around a GCC 4.8 internal compiler error.
llvm-svn: 244023
2015-08-05 09:39:41 +00:00
NAKAMURA Takumi
84cfaa9d50 unittests/ADT/ArrayRefTest.cpp: Suppress r243995 on g++-4.8 for now to unbreak bots.
For example of mingw-w64-g++-4.8.1,

  llvm/unittests/ADT/ArrayRefTest.cpp: In member function 'virtual void {anonymous}::ArrayRefTest_AllocatorCopy_Test::TestBody()':
  llvm/unittests/ADT/ArrayRefTest.cpp:56:40: internal compiler error: in count_type_elements, at expr.c:5523
     } Array3Src[] = {{"hello"}, {"world"}};
                                          ^
  Please submit a full bug report,
  with preprocessed source if appropriate.

llvm-svn: 244017
2015-08-05 06:11:23 +00:00
Benjamin Kramer
73b65dd362 [ArrayRef] Make copy use std::uninitialized_copy.
std::copy does not work for non-trivially copyable classes when we're
copying into uninitialized memory.

llvm-svn: 243995
2015-08-04 15:52:56 +00:00
Matt Arsenault
591931d078 Add amdopencl environment to triple
This is used by the AMD x86 OpenCL implementation
to change some ABI details on Windows and Linux.

llvm-svn: 243627
2015-07-30 08:16:51 +00:00
Pete Cooper
37a409c394 Reapply "Add reverse(ContainerTy) range adapter."
This reverts commit r243567, which ultimately reapplies r243563.

The fix here was to use std::enable_if for overload resolution.  Thanks to David
Blaikie for lots of help on this, and for the extra tests!

Original commit message follows:

For cases where we needed a foreach loop in reverse over a container,
we had to do something like

 for (const GlobalValue *GV : make_range(TypeInfos.rbegin(),
                                         TypeInfos.rend())) {

This provides a convenience method which shortens this to

 for (const GlobalValue *GV : reverse(TypeInfos)) {

There are 2 versions of this, with a preference to the rbegin() version.

The first uses rbegin() and rend() to construct an iterator_range.

The second constructs an iterator_range from the begin() and end() methods
wrapped in std::reverse_iterator's.

Reviewed by David Blaikie.

llvm-svn: 243581
2015-07-29 22:19:09 +00:00
Pete Cooper
a0dfca2294 Revert "Add reverse(ContainerTy) range adapter."
This reverts commit r243563.

The GCC buildbots were extremely unhappy about this.  Reverting while
we discuss a better way of doing overload resolution.

llvm-svn: 243567
2015-07-29 20:29:10 +00:00
Pete Cooper
c43d5555e2 Add reverse(ContainerTy) range adapter.
For cases where we needed a foreach loop in reverse over a container,
we had to do something like

  for (const GlobalValue *GV : make_range(TypeInfos.rbegin(),
                                          TypeInfos.rend())) {

This provides a convenience method which shortens this to

  for (const GlobalValue *GV : reverse(TypeInfos)) {

There are 2 versions of this, with a preference to the rbegin() version.

The first uses rbegin() and rend() to construct an iterator_range.

The second constructs an iterator_range from the begin() and end() methods
wrapped in std::reverse_iterator's.

Reviewed by David Blaikie.

llvm-svn: 243563
2015-07-29 20:00:39 +00:00
Daniel Berlin
e3f88c58ad Miscellaneous Fixes for SparseBitVector
Summary:

1. Fix return value in `SparseBitVector::operator&=`.
2. Add checks if SBV is being assigned is invoking SBV.

Reviewers: dberlin

Subscribers: llvm-commits

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

Committed on behalf of sl@

llvm-svn: 242693
2015-07-20 18:26:23 +00:00
Benjamin Kramer
4475ed2091 [Triple] Add a helper to switch between big/little endian variants
This will be used from clang's driver.

llvm-svn: 241527
2015-07-06 23:58:14 +00:00
Pawel Bylica
87cf433a3d Change APInt comparison with uint64_t.
Summary:
This patch changes the way APInt is compared with a value of type uint64_t.
Before the uint64_t value was truncated to the size of APInt before comparison.
Now the comparison takes into account full 64-bit precision.

Test Plan: Unit tests added. No regressions. Self-hosted check-all done as well.

Reviewers: chandlerc, dexonsmith

Subscribers: llvm-commits

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

llvm-svn: 241204
2015-07-01 22:56:43 +00:00
Dan Gohman
dfd1e4003d Drop the OS from the WebAssembly target triple for now.
This unbreaks TripleTest.Normalization. We'll have to come up with a new
plan for the OS component of the target triple for WebAssembly.

llvm-svn: 241041
2015-06-30 03:52:25 +00:00
Dan Gohman
e04339a4ce [WebAssembly] Initial WebAssembly backend
This WebAssembly backend is just a skeleton at this time and is not yet
functional.

llvm-svn: 241022
2015-06-29 23:51:55 +00:00
Pawel Bylica
8b05f5ba5d Add missing <array> include.
llvm-svn: 240629
2015-06-25 10:47:08 +00:00
Pawel Bylica
91ca53a942 Express APInt::{s,u}{l,g}e(uint64_t) in terms of APInt::{s,u}{l,g}t(uint64_t). NFC.
This is preparation for http://reviews.llvm.org/D10655: Change APInt comparison with uint64_t.
Some unit tests added also.

llvm-svn: 240626
2015-06-25 10:23:52 +00:00
Alex Lorenz
1b3d959d3c ADTTests: merge #ifdef checks from r240436.
This commit merges the #ifdef and #ifndef checks into one #if, as
suggested by Duncan P. N. Exon Smith.

llvm-svn: 240553
2015-06-24 17:05:04 +00:00
Chandler Carruth
f46ea62013 [ADT] Teach DenseMap to support StringRef keys.
While often you want to use something specialized like StringMap, when
the strings already have persistent storage a normal densemap over them
can be more efficient.

This can't go into StringRef.h because of really obnoxious header chains
from the hashing code to the endian detection code to CPU feature
detection code to StringMap.

llvm-svn: 240528
2015-06-24 10:06:29 +00:00
Alex Lorenz
80dea2fad8 ADT: Add a string APSInt constructor.
This commit moves the APSInt initialization code that's used by
the LLLexer class into a new APSInt constructor that constructs
APSInts from strings.

This change is useful for MIR Serialization, as it would allow
the MILexer class to use the same APSInt initialization as 
LLexer when parsing immediate machine operands.

llvm-svn: 240436
2015-06-23 18:22:10 +00:00
Duncan P. N. Exon Smith
28058eb1bf modules: Add explicit dependency on intrinsics_gen
`LLVM_ENABLE_MODULES` builds sometimes fail because `Intrinsics.td`
needs to regenerate `Instrinsics.h` before anyone can include anything
from the LLVM_IR module.  Represent the dependency explicitly to prevent
that.

llvm-svn: 239796
2015-06-16 00:44:12 +00:00
Aaron Ballman
0856283b6f Removing spurious semi colons; NFC.
llvm-svn: 239399
2015-06-09 12:03:46 +00:00
Benjamin Kramer
cc65db81cb [APInt] Remove special case for i1.
Add a unit test.

llvm-svn: 239062
2015-06-04 18:19:13 +00:00
Renato Golin
ea3094b9b8 ARMTargetParser: Make BSD Thumb/BE armv6 work
Simple change to make arch like "thumbv6" and "armbev6" to return the
correct CPU for FreeBSD and NetBSD.

llvm-svn: 238353
2015-05-27 19:49:53 +00:00
Renato Golin
b66fc6adbd Adding profile and version parsers to ARMTargetParser
This allows us to match armv6m to default to thumb, but will also be used by
Clang's driver and remove the current incomplete copy in it.

llvm-svn: 238036
2015-05-22 18:17:55 +00:00
Renato Golin
f02533865a Make Triple::parseARMArch use ARMTargetParser
Simplifying Triple::parseARMArch, leaving all the parsing to ARMTargetParser.

This commit also adds AArch64 detection to ARMTargetParser canonicalization,
and a two RedHat arch names (v{6,7}hl, meaning hard-float / little-endian).

Adding enough unit tests to cover the basics. Clang checks fine.

llvm-svn: 237902
2015-05-21 13:52:20 +00:00
Renato Golin
af6572aa97 Get Triple::getARMCPUForArch() to use TargetParser
First ARMTargetParser FIXME, conservatively changing the way we parse CPUs
in the back-end. Still not perfect, with a lot of special cases, but moving
towards a more generic solution.

Moving all logic to the target parser made some unwritten assumptions
about architectures in Clang to break. I've added a lot of architectures
required by Clang, and default to CPUs that Clang believes it should
(and I agree).

I've also added a lot of unit tests, with the correct CPU for each
architecture, and Clang seems to be working correctly, too.

It also became clear that using "unsigned ID" as the argument for the get
methods makes it hard to know what ID, so I also changed the argument names
to match the enum type names.

llvm-svn: 237797
2015-05-20 15:05:07 +00:00