Skip to content

Commit 043cd20

Browse files
compnerdkubamracek
authored andcommitted
[LLVMSupport] Re-apply "pruning" on re-forked LLVMSupport from bb10270
This re-applies the "pruning" commit from bb10270, which did the following: - Remove many whole files, - Remove "epoch tracking" and "reverse iteration" support from ADT containers - Remove "ABI break checking" support from STLExtras - Remove float parsing functions from StringExtras.h - Remove APInt/APSInt dependencies from StringRef.h + StringRef.cpp (edit distance, int parsing) - Remove some variants of error handling and dependency of dbgs() from ErrorHandling.h and ErrorHandling.cpp We don't need to do the whole-file-removal step, because that's already done, but the rest is re-applied by doing: 1) git cherry-pick bb10270 2) manually resolving conflict in ADT/DenseMap.h by keeping HEAD's version of the chunk and removing epoch tracking from it 3) manually resolving conflict in ADT/STLExtras.h by keeping HEAD's version of the chunk and removing ABI check checking from it 4) manually resolving conflict in ADT/StringExtras.h by deleting the whole chunk (removing APInt/APSInt dependent functions) 5) manually resolving conflict in ErrorHandling.cpp by force-applying the cherry-pick's version (removing write() calls and OOM callback) 6) manually resolving the three conflicts in CMakeLists.txt files by keeping HEAD's version completely 7) git add stdlib/include/llvm/{ADT/StringSwitch.h,ADT/Twine.h,Support/raw_ostream.h} Original commit description: > Reduce LLVMSupport to the subset required for the runtime. This reduces > the TCB and the overheads of the runtime. The inline namespace's > preservation ensures that ODR violations do not occur.
1 parent 5ae5ce1 commit 043cd20

File tree

9 files changed

+46
-708
lines changed

9 files changed

+46
-708
lines changed

stdlib/include/llvm/ADT/DenseMap.h

Lines changed: 22 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
#define LLVM_ADT_DENSEMAP_H
1515

1616
#include "llvm/ADT/DenseMapInfo.h"
17-
#include "llvm/ADT/EpochTracker.h"
1817
#include "llvm/Support/AlignOf.h"
1918
#include "llvm/Support/Compiler.h"
2019
#include "llvm/Support/MathExtras.h"
2120
#include "llvm/Support/MemAlloc.h"
22-
#include "llvm/Support/ReverseIteration.h"
2321
#include "llvm/Support/type_traits.h"
2422
#include <algorithm>
2523
#include <cassert>
@@ -58,7 +56,7 @@ class DenseMapIterator;
5856

5957
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
6058
typename BucketT>
61-
class DenseMapBase : public DebugEpochBase {
59+
class DenseMapBase {
6260
template <typename T>
6361
using const_arg_type_t = typename const_pointer_or_const_ref<T>::type;
6462

@@ -77,22 +75,18 @@ class DenseMapBase : public DebugEpochBase {
7775
// empty buckets.
7876
if (empty())
7977
return end();
80-
if (shouldReverseIterate<KeyT>())
81-
return makeIterator(getBucketsEnd() - 1, getBuckets(), *this);
82-
return makeIterator(getBuckets(), getBucketsEnd(), *this);
78+
return makeIterator(getBuckets(), getBucketsEnd());
8379
}
8480
inline iterator end() {
85-
return makeIterator(getBucketsEnd(), getBucketsEnd(), *this, true);
81+
return makeIterator(getBucketsEnd(), getBucketsEnd(), true);
8682
}
8783
inline const_iterator begin() const {
8884
if (empty())
8985
return end();
90-
if (shouldReverseIterate<KeyT>())
91-
return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *this);
92-
return makeConstIterator(getBuckets(), getBucketsEnd(), *this);
86+
return makeConstIterator(getBuckets(), getBucketsEnd());
9387
}
9488
inline const_iterator end() const {
95-
return makeConstIterator(getBucketsEnd(), getBucketsEnd(), *this, true);
89+
return makeConstIterator(getBucketsEnd(), getBucketsEnd(), true);
9690
}
9791

9892
LLVM_NODISCARD bool empty() const {
@@ -104,13 +98,11 @@ class DenseMapBase : public DebugEpochBase {
10498
/// before resizing again.
10599
void reserve(size_type NumEntries) {
106100
auto NumBuckets = getMinBucketToReserveForEntries(NumEntries);
107-
incrementEpoch();
108101
if (NumBuckets > getNumBuckets())
109102
grow(NumBuckets);
110103
}
111104

112105
void clear() {
113-
incrementEpoch();
114106
if (getNumEntries() == 0 && getNumTombstones() == 0) return;
115107

116108
// If the capacity of the array is huge, and the # elements used is small,
@@ -151,19 +143,13 @@ class DenseMapBase : public DebugEpochBase {
151143
iterator find(const_arg_type_t<KeyT> Val) {
152144
BucketT *TheBucket;
153145
if (LookupBucketFor(Val, TheBucket))
154-
return makeIterator(TheBucket,
155-
shouldReverseIterate<KeyT>() ? getBuckets()
156-
: getBucketsEnd(),
157-
*this, true);
146+
return makeIterator(TheBucket, getBucketsEnd(), true);
158147
return end();
159148
}
160149
const_iterator find(const_arg_type_t<KeyT> Val) const {
161150
const BucketT *TheBucket;
162151
if (LookupBucketFor(Val, TheBucket))
163-
return makeConstIterator(TheBucket,
164-
shouldReverseIterate<KeyT>() ? getBuckets()
165-
: getBucketsEnd(),
166-
*this, true);
152+
return makeConstIterator(TheBucket, getBucketsEnd(), true);
167153
return end();
168154
}
169155

@@ -176,20 +162,14 @@ class DenseMapBase : public DebugEpochBase {
176162
iterator find_as(const LookupKeyT &Val) {
177163
BucketT *TheBucket;
178164
if (LookupBucketFor(Val, TheBucket))
179-
return makeIterator(TheBucket,
180-
shouldReverseIterate<KeyT>() ? getBuckets()
181-
: getBucketsEnd(),
182-
*this, true);
165+
return makeIterator(TheBucket, getBucketsEnd(), true);
183166
return end();
184167
}
185168
template<class LookupKeyT>
186169
const_iterator find_as(const LookupKeyT &Val) const {
187170
const BucketT *TheBucket;
188171
if (LookupBucketFor(Val, TheBucket))
189-
return makeConstIterator(TheBucket,
190-
shouldReverseIterate<KeyT>() ? getBuckets()
191-
: getBucketsEnd(),
192-
*this, true);
172+
return makeConstIterator(TheBucket, getBucketsEnd(), true);
193173
return end();
194174
}
195175

@@ -223,22 +203,13 @@ class DenseMapBase : public DebugEpochBase {
223203
std::pair<iterator, bool> try_emplace(KeyT &&Key, Ts &&... Args) {
224204
BucketT *TheBucket;
225205
if (LookupBucketFor(Key, TheBucket))
226-
return std::make_pair(makeIterator(TheBucket,
227-
shouldReverseIterate<KeyT>()
228-
? getBuckets()
229-
: getBucketsEnd(),
230-
*this, true),
206+
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(), true),
231207
false); // Already in map.
232208

233209
// Otherwise, insert the new element.
234210
TheBucket =
235211
InsertIntoBucket(TheBucket, std::move(Key), std::forward<Ts>(Args)...);
236-
return std::make_pair(makeIterator(TheBucket,
237-
shouldReverseIterate<KeyT>()
238-
? getBuckets()
239-
: getBucketsEnd(),
240-
*this, true),
241-
true);
212+
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(), true), true);
242213
}
243214

244215
// Inserts key,value pair into the map if the key isn't already in the map.
@@ -248,21 +219,12 @@ class DenseMapBase : public DebugEpochBase {
248219
std::pair<iterator, bool> try_emplace(const KeyT &Key, Ts &&... Args) {
249220
BucketT *TheBucket;
250221
if (LookupBucketFor(Key, TheBucket))
251-
return std::make_pair(makeIterator(TheBucket,
252-
shouldReverseIterate<KeyT>()
253-
? getBuckets()
254-
: getBucketsEnd(),
255-
*this, true),
222+
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(), true),
256223
false); // Already in map.
257224

258225
// Otherwise, insert the new element.
259226
TheBucket = InsertIntoBucket(TheBucket, Key, std::forward<Ts>(Args)...);
260-
return std::make_pair(makeIterator(TheBucket,
261-
shouldReverseIterate<KeyT>()
262-
? getBuckets()
263-
: getBucketsEnd(),
264-
*this, true),
265-
true);
227+
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(), true), true);
266228
}
267229

268230
/// Alternate version of insert() which allows a different, and possibly
@@ -275,21 +237,13 @@ class DenseMapBase : public DebugEpochBase {
275237
const LookupKeyT &Val) {
276238
BucketT *TheBucket;
277239
if (LookupBucketFor(Val, TheBucket))
278-
return std::make_pair(makeIterator(TheBucket,
279-
shouldReverseIterate<KeyT>()
280-
? getBuckets()
281-
: getBucketsEnd(),
282-
*this, true),
240+
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(), *this, true),
283241
false); // Already in map.
284242

285243
// Otherwise, insert the new element.
286244
TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first),
287245
std::move(KV.second), Val);
288-
return std::make_pair(makeIterator(TheBucket,
289-
shouldReverseIterate<KeyT>()
290-
? getBuckets()
291-
: getBucketsEnd(),
292-
*this, true),
246+
return std::make_pair(makeIterator(TheBucket, getBucketsEnd(), *this, true),
293247
true);
294248
}
295249

@@ -462,24 +416,13 @@ class DenseMapBase : public DebugEpochBase {
462416
}
463417

464418
private:
465-
iterator makeIterator(BucketT *P, BucketT *E,
466-
DebugEpochBase &Epoch,
467-
bool NoAdvance=false) {
468-
if (shouldReverseIterate<KeyT>()) {
469-
BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
470-
return iterator(B, E, Epoch, NoAdvance);
471-
}
472-
return iterator(P, E, Epoch, NoAdvance);
419+
iterator makeIterator(BucketT *P, BucketT *E, bool NoAdvance=false) {
420+
return iterator(P, E, NoAdvance);
473421
}
474422

475423
const_iterator makeConstIterator(const BucketT *P, const BucketT *E,
476-
const DebugEpochBase &Epoch,
477424
const bool NoAdvance=false) const {
478-
if (shouldReverseIterate<KeyT>()) {
479-
const BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
480-
return const_iterator(B, E, Epoch, NoAdvance);
481-
}
482-
return const_iterator(P, E, Epoch, NoAdvance);
425+
return const_iterator(P, E, NoAdvance);
483426
}
484427

485428
unsigned getNumEntries() const {
@@ -565,8 +508,6 @@ class DenseMapBase : public DebugEpochBase {
565508
template <typename LookupKeyT>
566509
BucketT *InsertIntoBucketImpl(const KeyT &Key, const LookupKeyT &Lookup,
567510
BucketT *TheBucket) {
568-
incrementEpoch();
569-
570511
// If the load of the hash table is more than 3/4, or if fewer than 1/8 of
571512
// the buckets are empty (meaning that many are filled with tombstones),
572513
// grow the table.
@@ -757,8 +698,6 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
757698
}
758699

759700
void swap(DenseMap& RHS) {
760-
this->incrementEpoch();
761-
RHS.incrementEpoch();
762701
std::swap(Buckets, RHS.Buckets);
763702
std::swap(NumEntries, RHS.NumEntries);
764703
std::swap(NumTombstones, RHS.NumTombstones);
@@ -1190,7 +1129,7 @@ class SmallDenseMap
11901129

11911130
template <typename KeyT, typename ValueT, typename KeyInfoT, typename Bucket,
11921131
bool IsConst>
1193-
class DenseMapIterator : DebugEpochBase::HandleBase {
1132+
class DenseMapIterator {
11941133
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;
11951134
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, false>;
11961135

@@ -1209,16 +1148,9 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
12091148
public:
12101149
DenseMapIterator() = default;
12111150

1212-
DenseMapIterator(pointer Pos, pointer E, const DebugEpochBase &Epoch,
1213-
bool NoAdvance = false)
1214-
: DebugEpochBase::HandleBase(&Epoch), Ptr(Pos), End(E) {
1215-
assert(isHandleInSync() && "invalid construction!");
1216-
1151+
DenseMapIterator(pointer Pos, pointer E, bool NoAdvance = false)
1152+
: Ptr(Pos), End(E) {
12171153
if (NoAdvance) return;
1218-
if (shouldReverseIterate<KeyT>()) {
1219-
RetreatPastEmptyBuckets();
1220-
return;
1221-
}
12221154
AdvancePastEmptyBuckets();
12231155
}
12241156

@@ -1229,29 +1161,19 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
12291161
typename = std::enable_if_t<!IsConstSrc && IsConst>>
12301162
DenseMapIterator(
12311163
const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &I)
1232-
: DebugEpochBase::HandleBase(I), Ptr(I.Ptr), End(I.End) {}
1164+
: Ptr(I.Ptr), End(I.End) {}
12331165

12341166
reference operator*() const {
1235-
assert(isHandleInSync() && "invalid iterator access!");
12361167
assert(Ptr != End && "dereferencing end() iterator");
1237-
if (shouldReverseIterate<KeyT>())
1238-
return Ptr[-1];
12391168
return *Ptr;
12401169
}
12411170
pointer operator->() const {
1242-
assert(isHandleInSync() && "invalid iterator access!");
12431171
assert(Ptr != End && "dereferencing end() iterator");
1244-
if (shouldReverseIterate<KeyT>())
1245-
return &(Ptr[-1]);
12461172
return Ptr;
12471173
}
12481174

12491175
friend bool operator==(const DenseMapIterator &LHS,
12501176
const DenseMapIterator &RHS) {
1251-
assert((!LHS.Ptr || LHS.isHandleInSync()) && "handle not in sync!");
1252-
assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!");
1253-
assert(LHS.getEpochAddress() == RHS.getEpochAddress() &&
1254-
"comparing incomparable iterators!");
12551177
return LHS.Ptr == RHS.Ptr;
12561178
}
12571179

@@ -1261,19 +1183,12 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
12611183
}
12621184

12631185
inline DenseMapIterator& operator++() { // Preincrement
1264-
assert(isHandleInSync() && "invalid iterator access!");
12651186
assert(Ptr != End && "incrementing end() iterator");
1266-
if (shouldReverseIterate<KeyT>()) {
1267-
--Ptr;
1268-
RetreatPastEmptyBuckets();
1269-
return *this;
1270-
}
12711187
++Ptr;
12721188
AdvancePastEmptyBuckets();
12731189
return *this;
12741190
}
12751191
DenseMapIterator operator++(int) { // Postincrement
1276-
assert(isHandleInSync() && "invalid iterator access!");
12771192
DenseMapIterator tmp = *this; ++*this; return tmp;
12781193
}
12791194

stdlib/include/llvm/ADT/STLExtras.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/ADT/STLForwardCompat.h"
2121
#include "llvm/ADT/iterator.h"
2222
#include "llvm/ADT/iterator_range.h"
23-
#include "llvm/Config/abi-breaking.h"
2423
#include "llvm/Support/ErrorHandling.h"
2524
#include <algorithm>
2625
#include <cassert>
@@ -521,37 +520,21 @@ class early_inc_iterator_impl
521520

522521
using PointerT = typename std::iterator_traits<WrappedIteratorT>::pointer;
523522

524-
protected:
525-
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
526-
bool IsEarlyIncremented = false;
527-
#endif
528-
529523
public:
530524
early_inc_iterator_impl(WrappedIteratorT I) : BaseT(I) {}
531525

532526
using BaseT::operator*;
533527
decltype(*std::declval<WrappedIteratorT>()) operator*() {
534-
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
535-
assert(!IsEarlyIncremented && "Cannot dereference twice!");
536-
IsEarlyIncremented = true;
537-
#endif
538528
return *(this->I)++;
539529
}
540530

541531
using BaseT::operator++;
542532
early_inc_iterator_impl &operator++() {
543-
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
544-
assert(IsEarlyIncremented && "Cannot increment before dereferencing!");
545-
IsEarlyIncremented = false;
546-
#endif
547533
return *this;
548534
}
549535

550536
friend bool operator==(const early_inc_iterator_impl &LHS,
551537
const early_inc_iterator_impl &RHS) {
552-
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
553-
assert(!LHS.IsEarlyIncremented && "Cannot compare after dereferencing!");
554-
#endif
555538
return (const BaseT &)LHS == (const BaseT &)RHS;
556539
}
557540
};

0 commit comments

Comments
 (0)