summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT
Commit message (Collapse)AuthorAgeFilesLines
...
* Resubmit "[BitVector] Add operator<<= and operator>>=."Zachary Turner2017-04-201-0/+122
| | | | | | | | | This was failing due to the use of assigning a Mask to an unsigned, rather than to a BitWord. But most systems do not have sizeof(unsigned) == sizeof(unsigned long), so the mask was getting truncated. llvm-svn: 300857
* Revert "[BitVector] Add operator<<= and operator>>=."Zachary Turner2017-04-201-122/+0
| | | | | | | This is causing test failures on Linux / BSD systems. Reverting while I investigate. llvm-svn: 300852
* [APInt] Add isSubsetOf method that can check if one APInt is a subset of ↵Craig Topper2017-04-201-0/+29
| | | | | | | | | | | | | | another without creating temporary APInts This question comes up in many places in SimplifyDemandedBits. This makes it easy to ask without allocating additional temporary APInts. The BitVector class provides a similar functionality through its (IMHO badly named) test(const BitVector&) method. Though its output polarity is reversed. I've provided one example use case in this patch. I plan to do more as a follow up. Differential Revision: https://reviews.llvm.org/D32258 llvm-svn: 300851
* [BitVector] Add operator<<= and operator>>=.Zachary Turner2017-04-201-0/+122
| | | | | | Differential Revision: https://reviews.llvm.org/D32244 llvm-svn: 300848
* Recommit "[APInt] Add back the asserts that check that the APInt shift ↵Craig Topper2017-04-201-2/+2
| | | | | | | | methods aren't called with values larger than BitWidth." This includes a fix to clamp a right shift of larger than BitWidth in DAG combining. llvm-svn: 300816
* Revert r300811 "[APInt] Add back the asserts that check that the APInt shift ↵Craig Topper2017-04-201-2/+2
| | | | | | | | methods aren't called with values larger than BitWidth." This is failing a self host debug build. llvm-svn: 300813
* [APInt] Add back the asserts that check that the APInt shift methods aren't ↵Craig Topper2017-04-201-2/+2
| | | | | | | | called with values larger than BitWidth. The underlying tcShiftRight/tcShiftLeft functions support the larger bit widths but the APInt interface shouldn't rely on that. llvm-svn: 300811
* [APInt] Make operator<<= shift in place. Improve the implementation of ↵Craig Topper2017-04-181-0/+33
| | | | | | tcShiftLeft and use it to implement operator<<=. llvm-svn: 300526
* [APInt] Merge the multiword code from lshrInPlace and tcShiftRight into a ↵Craig Topper2017-04-171-5/+33
| | | | | | | | | | | | single implementation This merges the two different multiword shift right implementations into a single version located in tcShiftRight. lshrInPlace now calls tcShiftRight for the multiword case. I retained the memmove fast path from lshrInPlace and used a memset for the zeroing. The for loop is basically tcShiftRight's implementation with the zeroing and the intra-shift of 0 removed. Differential Revision: https://reviews.llvm.org/D32114 llvm-svn: 300503
* [APInt] Remove self move check from move assignment operatorCraig Topper2017-04-171-30/+2
| | | | | | | | | | | | This was added to work around a bug in MSVC 2013's implementation of stable_sort. That bug has been fixed as of MSVC 2015 so we shouldn't need this anymore. Technically the current implementation has undefined behavior because we only protect the deleting of the pVal array with the self move check. There is still a memcpy of that.VAL to VAL that isn't protected. In the case of self move those are the same local and memcpy is undefined for src and dst overlapping. This reduces the size of the opt binary on my local x86-64 build by about 4k. Differential Revision: https://reviews.llvm.org/D32116 llvm-svn: 300477
* [APInt] Fix a bug in lshr by a value more than 64 bits above the bit width.Craig Topper2017-04-161-0/+5
| | | | | | This was throwing an assert because we determined the intra-word shift amount by subtracting the size of the full word shift from the total shift amount. But we failed to account for the fact that we clipped the full word shifts by total words first. To fix this just calculate the intra-word shift as the remainder of dividing by bits per word. llvm-svn: 300405
* Add more test cases for StringRef::edit_distanceAlex Denisov2017-04-141-2/+16
| | | | | | Example strings taken from here: http://www.let.rug.nl/~kleiweg/lev/ llvm-svn: 300312
* Remove all allocation and divisions from GreatestCommonDivisorRichard Smith2017-04-131-0/+43
| | | | | | | | | | | Switch from Euclid's algorithm to Stein's algorithm for computing GCD. This avoids the (expensive) APInt division operation in favour of bit operations. Remove all memory allocation from within the GCD loop by tweaking our `lshr` implementation so it can operate in-place. Differential Revision: https://reviews.llvm.org/D31968 llvm-svn: 300252
* Fix signed / unsigned comparison warnings.Zachary Turner2017-04-101-2/+2
| | | | llvm-svn: 299873
* [Support] Add support for finding unset bits in a BitVector.Zachary Turner2017-04-101-0/+39
| | | | | | | | | | | | BitVector had methods for searching for the first and next set bits, but it did not have analagous methods for finding the first and next unset bits. This is useful when your ones and zeros are grouped together and you want to iterate over ranges of ones and zeros. Differential Revision: https://reviews.llvm.org/D31802 llvm-svn: 299857
* [ADT] Add a generic breadth-first-search graph iterator.Davide Italiano2017-04-062-0/+75
| | | | | | | | This will be used in LCSSA to speed up the canonicalization. Differential Revision: https://reviews.llvm.org/D31694 llvm-svn: 299660
* [APInt] Move isMask and isShiftedMask out of APIntOps and into the APInt ↵Craig Topper2017-04-031-14/+15
| | | | | | | | | | class. Implement them without memory allocation for multiword This moves the isMask and isShiftedMask functions to be class methods. They now use the MathExtras.h function for single word size and leading/trailing zeros/ones or countPopulation for the multiword size. The previous implementation made multiple temorary memory allocations to do the bitwise arithmetic operations to match the MathExtras.h implementation. Differential Revision: https://reviews.llvm.org/D31565 llvm-svn: 299362
* [APInt] Add a public typedef for the internal type of APInt use it instead ↵Craig Topper2017-04-021-37/+37
| | | | | | | | | | | | | | | | of integerPart. Make APINT_BITS_PER_WORD and APINT_WORD_SIZE public. This patch is one step to attempt to unify the main APInt interface and the tc functions used by APFloat. This patch adds a WordType to APInt and uses that in all the tc functions. I've added temporary typedefs to APFloat to alias it to integerPart to keep the patch size down. I'll work on removing that in a future patch. In future patches I hope to reuse the tc functions to implement some of the main APInt functionality. I may remove APINT_ from BITS_PER_WORD and WORD_SIZE constants so that we don't have the repetitive APInt::APINT_ externally. Differential Revision: https://reviews.llvm.org/D31523 llvm-svn: 299341
* [APInt] Fix bugs in isShiftedMask to match behavior of the similar function ↵Craig Topper2017-03-311-8/+8
| | | | | | | | | | in MathExtras.h This removes a parameter from the routine that was responsible for a lot of the issue. It was a bit count that had to be set to the BitWidth of the APInt and would get passed to getLowBitsSet. This guaranteed the call to getLowBitsSet would create an all ones value. This was then compared to (V | (V-1)). So the only shifted masks we detected had to have the MSB set. The one in tree user is a transform in InstCombine that never fires due to earlier transforms covering the case better. I've submitted a patch to remove it completely, but for now I've just adapted it to the new interface for isShiftedMask. llvm-svn: 299273
* Fix 80-column violation in previous commit.Stephen Canon2017-03-311-1/+2
| | | | llvm-svn: 299257
* Fix APFloat mod (committing for simonbyrne)Stephen Canon2017-03-311-2/+65
| | | | | | | | The previous version was prone to intermediate rounding or overflow. Differential Revision: https://reviews.llvm.org/D29346 llvm-svn: 299256
* [APInt] Rewrite getLoBits in a way that will do one less memory allocation ↵Craig Topper2017-03-311-0/+18
| | | | | | in the multiword case. Rewrite getHiBits to use the class method version of lshr instead of the one in APIntOps. NFCI llvm-svn: 299243
* Spelling mistakes in comments. NFCI.Simon Pilgrim2017-03-311-1/+1
| | | | llvm-svn: 299197
* [APInt] Add unittests that demonstrate how very broken ↵Craig Topper2017-03-311-0/+25
| | | | | | | | | | APIntOps::isShiftedMask is. Did you know that 0 is a shifted mask? But 0x0000ff00 and 0x000000ff aren't? At least we get 0xff000000 right. I only see one usage of this function in the code base today and its in InstCombine. I think its protected against 0 being misreported as a mask. I guess we just don't have tests for the missed cases. llvm-svn: 299187
* [APInt] Use memset in setAllBits.Craig Topper2017-03-271-0/+38
| | | | llvm-svn: 298867
* ADT: Add range helpers for pointer_ and pointee_iteratorJustin Bogner2017-03-271-0/+16
| | | | llvm-svn: 298841
* Resubmit "Improve StringMap iterator support."Zachary Turner2017-03-211-0/+29
| | | | | | | The issue was trying to advance past the end of the iterator when computing the end() iterator. llvm-svn: 298461
* Revert "Improve StringMap iterator support."Zachary Turner2017-03-211-29/+0
| | | | | | | This is causing crashes in clang, so reverting until the problem is figured out. llvm-svn: 298440
* Improve StringMap iterator support.Zachary Turner2017-03-211-0/+29
| | | | | | | | | | | | | | | | | | StringMap's iterators did not support LLVM's iterator_facade_base, which made it unusable in various STL algorithms or with some of our range adapters. This patch makes both StringMapConstIterator as well as StringMapIterator support iterator_facade_base. With this in place, it is easy to make an iterator adapter that iterates over only keys, and whose value_type is StringRef. So I add StringMapKeyIterator as well, and provide the method StringMap::keys() that returns a range that can be iterated. Differential Revision: https://reviews.llvm.org/D31171 llvm-svn: 298436
* [ADT] Add a version of llvm::join() that takes a range.Zachary Turner2017-03-211-0/+2
| | | | llvm-svn: 298427
* Fix sign compare warning in unit test by using an explicit unsigned literal ↵David Blaikie2017-03-131-1/+1
| | | | | | suffix llvm-svn: 297674
* [ADT] Improve the genericity of llvm::enumerate().Zachary Turner2017-03-131-7/+17
| | | | | | | | | | | | | | There were some issues in the implementation of enumerate() preventing it from being used in various contexts. These were all related to the fact that it did not supporter llvm's iterator_facade_base class. So this patch adds support for that and additionally exposes a new helper method to_vector() that will evaluate an entire range and store the results in a vector. Differential Revision: https://reviews.llvm.org/D30853 llvm-svn: 297633
* Fix signed/unsigned comparison warningsSimon Pilgrim2017-03-101-11/+11
| | | | llvm-svn: 297460
* [APInt] Add APInt::insertBits() method to insert an APInt into a larger APIntSimon Pilgrim2017-03-101-0/+53
| | | | | | | | | | | | We currently have to insert bits via a temporary variable of the same size as the target with various shift/mask stages, resulting in further temporary variables, all of which require the allocation of memory for large APInts (MaskSizeInBits > 64). This is another of the compile time issues identified in PR32037 (see also D30265). This patch adds the APInt::insertBits() helper method which avoids the temporary memory allocation and masks/inserts the raw bits directly into the target. Differential Revision: https://reviews.llvm.org/D30780 llvm-svn: 297458
* Add support for DenseMap/DenseSet count and find using const pointersDaniel Berlin2017-03-102-0/+27
| | | | | | | | | | | | | | Summary: Similar to SmallPtrSet, this makes find and count work with both const referneces and const pointers. Reviewers: dblaikie Subscribers: llvm-commits, mzolotukhin Differential Revision: https://reviews.llvm.org/D30713 llvm-svn: 297424
* [Unittests] Fix a build failure with clang 3.8. NFCI.Davide Italiano2017-03-091-1/+1
| | | | llvm-svn: 297423
* ADT: Fix SmallPtrSet iterators in reverse modeDuncan P. N. Exon Smith2017-03-071-7/+25
| | | | | | | | | | | | | | | | | | | | | | | | Fix SmallPtrSet::iterator behaviour and creation ReverseIterate is true. - Any function that creates an iterator now uses SmallPtrSet::makeIterator, which creates an iterator that dereferences to the given pointer. - In reverse-iterate mode, initialze iterator::End with "CurArray" instead of EndPointer. - In reverse-iterate mode, the current node is iterator::Buffer[-1]. iterator::operator* and SmallPtrSet::makeIterator are the only ones that need to know. - Fix the assertions for reverse-iterate mode. This fixes the tests Danny B added in r297182, and adds a couple of others to confirm that dereferencing does the right thing, regardless of how the iterator was found, and that iteration works correctly from each return from find. llvm-svn: 297234
* Strip trailing whitespace.Simon Pilgrim2017-03-071-4/+1
| | | | llvm-svn: 297225
* Add unit tests for changes to SmallPtrSet and PointerLikeTypeTraitsDaniel Berlin2017-03-071-0/+33
| | | | llvm-svn: 297182
* [APInt] Add rvalue reference support to and, or, xor operations to allow ↵Craig Topper2017-03-071-0/+120
| | | | | | | | | | | | | | | | their memory allocation to be reused when possible This extends an earlier change that did similar for add and sub operations. With this first patch we lose the fastpath for the single word case as operator&= and friends don't support it. This can be added there if we think that's important. I had to change some functions in the APInt class since the operator overloads were moved out of the class and can't be used inside the class now. The getBitsSet change collides with another outstanding patch to implement it with setBits. But I didn't want to make this patch dependent on that series. I've also removed the Or, And, Xor functions which were rarely or never used. I already commited two changes to remove the only uses of Or that existed. Differential Revision: https://reviews.llvm.org/D30612 llvm-svn: 297121
* [APInt] Fix test names in unittest to match functions being tested. NFCCraig Topper2017-03-071-2/+2
| | | | llvm-svn: 297115
* [APInt] Add getBitsSetFrom and setBitsFrom to set upper bits starting at a bitCraig Topper2017-03-071-0/+21
| | | | | | | | | | | | 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
* [APInt] Implement getLowBitsSet/getHighBitsSet/getBitsSet using ↵Craig Topper2017-03-071-0/+18
| | | | | | | | | | | | 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
* [APInt] Add setLowBits/setHighBits methods to APInt.Craig Topper2017-03-071-0/+121
| | | | | | | | | | | | | | | | | | | | | 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
* [APInt] Move operator~ out of line to make it better able to reused memory ↵Craig Topper2017-03-061-0/+24
| | | | | | | | | | | | | | | | | | | 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
* Set default CPU for OpenBSD/arm to Cortex-A8Brad Smith2017-02-281-0/+4
| | | | llvm-svn: 296493
* [APInt] Use UINT64_MAX instead of ~0ULL. NFCCraig Topper2017-02-261-0/+10
| | | | llvm-svn: 296300
* [APInt] Remove unnecessary early out from getLowBitsSet. The same case is ↵Craig Topper2017-02-261-0/+10
| | | | | | handled equally well by the next check. llvm-svn: 296299
* [APInt] Add APInt::extractBits() method to extract APInt subrange (reapplied)Simon Pilgrim2017-02-251-0/+16
| | | | | | | | | | | | | | | | 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
* Revert: r296141 [APInt] Add APInt::extractBits() method to extract APInt ↵Simon Pilgrim2017-02-241-12/+0
| | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud