LLVM: include/llvm/ADT/ArrayRef.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_ADT_ARRAYREF_H

10#define LLVM_ADT_ARRAYREF_H

11

16#include

17#include

18#include

19#include

20#include <initializer_list>

21#include

22#include

23#include <type_traits>

24#include

25

26namespace llvm {

28

29

30

31

32

33

34

35

36

37

38

39

40 template

42 public:

54

55 private:

56

57 const T *Data = nullptr;

58

59

61

62 public:

63

64

65

66

68

69

70 ArrayRef(std::nullopt_t) {}

71

72

74 : Data(&OneElt), Length(1) {}

75

76

78 size_t length)

79 : Data(data), Length(length) {}

80

81

83 : Data(begin), Length(end - begin) {

85 }

86

87

88

89

90 template

92 : Data(Vec.data()), Length(Vec.size()) {

93 }

94

95

96 template

97 ArrayRef(const std::vector<T, A> &Vec)

98 : Data(Vec.data()), Length(Vec.size()) {}

99

100

101 template <size_t N>

102 constexpr ArrayRef(const std::array<T, N> &Arr)

103 : Data(Arr.data()), Length(N) {}

104

105

106 template <size_t N>

108 : Data(Arr), Length(N) {}

109

110

111#if LLVM_GNUC_PREREQ(9, 0, 0)

112

113

114

115#pragma GCC diagnostic push

116#pragma GCC diagnostic ignored "-Winit-list-lifetime"

117#endif

120 : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),

122#if LLVM_GNUC_PREREQ(9, 0, 0)

123#pragma GCC diagnostic pop

124#endif

125

126

127

128 template

130 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>

131 * = nullptr)

133

134

135

136

137 template <typename U, typename DummyT>

140 std::enable_if_t<std::is_convertible<U *const *, T const *>::value> * =

141 nullptr)

142 : Data(Vec.data()), Length(Vec.size()) {}

143

144

145

146 template <typename U, typename A>

148 std::enable_if_t<std::is_convertible<U *const *, T const *>::value>

149 * = nullptr)

150 : Data(Vec.data()), Length(Vec.size()) {}

151

152

153

154

155

158

161

162

164

165 const T *data() const { return Data; }

166

167

169

170

173 return Data[0];

174 }

175

176

179 return Data[Length-1];

180 }

181

182

184 T *Buff = A.template Allocate(Length);

185 std::uninitialized_copy(begin(), end(), Buff);

187 }

188

189

192 return false;

193 return std::equal(begin(), end(), RHS.begin());

194 }

195

196

197

199 assert(N+M <= size() && "Invalid specifier");

201 }

202

203

205

206

208 assert(size() >= N && "Dropping more elements than exist");

209 return slice(N, size() - N);

210 }

211

212

214 assert(size() >= N && "Dropping more elements than exist");

215 return slice(0, size() - N);

216 }

217

218

219

222 }

223

224

225

228 }

229

230

233 return *this;

234 return drop_back(size() - N);

235 }

236

237

240 return *this;

241 return drop_front(size() - N);

242 }

243

244

245

248 }

249

250

251

254 }

255

256

257

258

261 return Data[Index];

262 }

263

264

265

266

267

268 template

269 std::enable_if_t<std::is_same<U, T>::value, ArrayRef> &

271

272

273

274

275

276 template

277 std::enable_if_t<std::is_same<U, T>::value, ArrayRef> &

278 operator=(std::initializer_list) = delete;

279

280

281

282

283 std::vector vec() const {

284 return std::vector(Data, Data+Length);

285 }

286

287

288

289

290 operator std::vector() const {

291 return std::vector(Data, Data+Length);

292 }

293

294

295 };

296

297

298

299

300

301

302

303

304

305

306

307

308

309 template

311 public:

323

324

326

327

329

330

332

333

336

337

339

340

343

344

347

348

349 template <size_t N>

352

353

354 template <size_t N>

356

358

361

364

365

367 assert(!this->empty());

368 return data()[0];

369 }

370

371

373 assert(!this->empty());

374 return data()[this->size()-1];

375 }

376

377

378

380 assert(N + M <= this->size() && "Invalid specifier");

382 }

383

384

386 return slice(N, this->size() - N);

387 }

388

389

391 assert(this->size() >= N && "Dropping more elements than exist");

392 return slice(N, this->size() - N);

393 }

394

396 assert(this->size() >= N && "Dropping more elements than exist");

397 return slice(0, this->size() - N);

398 }

399

400

401

402 template

405 }

406

407

408

409 template

412 }

413

414

416 if (N >= this->size())

417 return *this;

418 return drop_back(this->size() - N);

419 }

420

421

423 if (N >= this->size())

424 return *this;

425 return drop_front(this->size() - N);

426 }

427

428

429

430 template

433 }

434

435

436

437 template

440 }

441

442

443

444

446 assert(Index < this->size() && "Invalid index!");

447 return data()[Index];

448 }

449 };

450

451

453 public:

456

459 std::copy(Data.begin(), Data.end(), this->begin());

460 }

461

463

465 delete[] this->data();

468 return *this;

469 }

470

472 };

473

474

475

476

478

479

481

482

484

485

487

488

489 template <typename T, unsigned N>

491

492

494

495

496 template <typename T, std::size_t N>

498

499

501

502

504

505

507

508

509

510

511

512

514

515

516

517 template

519

520

521 template

523

524 template <class T, unsigned N>

526

527

529

530

531 template <class T, std::size_t N>

533

534

535 template <typename T, size_t N>

537

538

539

540

541

542 template

544 return LHS.equals(RHS);

545 }

546

547 template

550 }

551

552 template

554 return !(LHS == RHS);

555 }

556

557 template

559 return !(LHS == RHS);

560 }

561

562

563

566 }

567

568

572 reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)), size_t(0));

573 }

574

577 reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)), size_t(0));

578 }

579

581 assert(Val.data() != getEmptyKey().data() &&

582 "Cannot hash the empty key!");

583 assert(Val.data() != getTombstoneKey().data() &&

584 "Cannot hash the tombstone key!");

586 }

587

589 if (RHS.data() == getEmptyKey().data())

590 return LHS.data() == getEmptyKey().data();

591 if (RHS.data() == getTombstoneKey().data())

592 return LHS.data() == getTombstoneKey().data();

594 }

595 };

596

597}

598

599#endif

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

#define LLVM_LIFETIME_BOUND

#define LLVM_GSL_POINTER

LLVM_GSL_POINTER - Apply this to non-owning classes like StringRef to enable lifetime warnings.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the SmallVector class.

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

std::enable_if_t< std::is_same< U, T >::value, ArrayRef< T > > & operator=(std::initializer_list< U >)=delete

Disallow accidental assignment from a temporary.

std::vector< T > vec() const

bool equals(ArrayRef RHS) const

equals - Check for element-wise equality.

ArrayRef< T > drop_while(PredicateT Pred) const

Return a copy of *this with the first N elements satisfying the given predicate removed.

const T & back() const

back - Get the last element.

ArrayRef(const std::vector< U *, A > &Vec, std::enable_if_t< std::is_convertible< U *const *, T const * >::value > *=nullptr)

Construct an ArrayRef<const T*> from std::vector<T*>.

ArrayRef< T > take_front(size_t N=1) const

Return a copy of *this with only the first N elements.

constexpr ArrayRef(std::initializer_list< T > Vec LLVM_LIFETIME_BOUND)

Construct an ArrayRef from a std::initializer_list.

MutableArrayRef< T > copy(Allocator &A)

ArrayRef< T > drop_front(size_t N=1) const

Drop the first N elements of the array.

ArrayRef< T > slice(size_t N) const

slice(n) - Chop off the first N elements of the array.

reverse_iterator rend() const

const T & front() const

front - Get the first element.

ArrayRef< T > take_while(PredicateT Pred) const

Return the first N elements of this Array that satisfy the given predicate.

ArrayRef(const T &OneElt LLVM_LIFETIME_BOUND)

Construct an ArrayRef from a single element.

constexpr ArrayRef(const T *begin LLVM_LIFETIME_BOUND, const T *end)

Construct an ArrayRef from a range.

std::reverse_iterator< const_iterator > const_reverse_iterator

ArrayRef< T > take_until(PredicateT Pred) const

Return the first N elements of this Array that don't satisfy the given predicate.

ArrayRef< T > drop_until(PredicateT Pred) const

Return a copy of *this with the first N elements not satisfying the given predicate removed.

size_t size() const

size - Get the array size.

ArrayRef()=default

Construct an empty ArrayRef.

ArrayRef(std::nullopt_t)

Construct an empty ArrayRef from std::nullopt.

ArrayRef(const ArrayRef< U * > &A, std::enable_if_t< std::is_convertible< U *const *, T const * >::value > *=nullptr)

Construct an ArrayRef<const T*> from ArrayRef<T*>.

std::reverse_iterator< iterator > reverse_iterator

ArrayRef< T > drop_back(size_t N=1) const

Drop the last N elements of the array.

constexpr ArrayRef(const std::array< T, N > &Arr)

Construct an ArrayRef from a std::array.

ArrayRef< T > take_back(size_t N=1) const

Return a copy of *this with only the last N elements.

bool empty() const

empty - Check if the array is empty.

constexpr ArrayRef(const T(&Arr LLVM_LIFETIME_BOUND)[N])

Construct an ArrayRef from a C array.

ArrayRef(const SmallVectorTemplateCommon< U *, DummyT > &Vec, std::enable_if_t< std::is_convertible< U *const *, T const * >::value > *=nullptr)

Construct an ArrayRef<const T*> from a SmallVector<T*>.

constexpr ArrayRef(const T *data LLVM_LIFETIME_BOUND, size_t length)

Construct an ArrayRef from a pointer and length.

const T & operator[](size_t Index) const

ArrayRef(const std::vector< T, A > &Vec)

Construct an ArrayRef from a std::vector.

std::enable_if_t< std::is_same< U, T >::value, ArrayRef< T > > & operator=(U &&Temporary)=delete

Disallow accidental assignment from a temporary.

reverse_iterator rbegin() const

ArrayRef< T > slice(size_t N, size_t M) const

slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.

ArrayRef(const SmallVectorTemplateCommon< T, U > &Vec)

Construct an ArrayRef from a SmallVector.

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

MutableArrayRef< T > take_until(PredicateT Pred) const

Return the first N elements of this Array that don't satisfy the given predicate.

MutableArrayRef(T &OneElt)

Construct a MutableArrayRef from a single element.

MutableArrayRef< T > drop_front(size_t N=1) const

Drop the first N elements of the array.

MutableArrayRef< T > take_back(size_t N=1) const

Return a copy of *this with only the last N elements.

reverse_iterator rbegin() const

MutableArrayRef(T *begin, T *end)

Construct a MutableArrayRef from a range.

MutableArrayRef< T > slice(size_t N) const

slice(n) - Chop off the first N elements of the array.

MutableArrayRef(T *data, size_t length)

Construct a MutableArrayRef from a pointer and length.

MutableArrayRef()=default

Construct an empty MutableArrayRef.

constexpr MutableArrayRef(std::array< T, N > &Arr)

Construct a MutableArrayRef from a std::array.

T & front() const

front - Get the first element.

std::reverse_iterator< const_iterator > const_reverse_iterator

T & operator[](size_t Index) const

T & back() const

back - Get the last element.

MutableArrayRef(std::vector< T > &Vec)

Construct a MutableArrayRef from a std::vector.

constexpr MutableArrayRef(T(&Arr)[N])

Construct a MutableArrayRef from a C array.

MutableArrayRef(SmallVectorImpl< T > &Vec)

Construct a MutableArrayRef from a SmallVector.

MutableArrayRef< T > drop_back(size_t N=1) const

MutableArrayRef< T > take_while(PredicateT Pred) const

Return the first N elements of this Array that satisfy the given predicate.

MutableArrayRef< T > slice(size_t N, size_t M) const

slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.

MutableArrayRef< T > drop_while(PredicateT Pred) const

Return a copy of *this with the first N elements satisfying the given predicate removed.

reverse_iterator rend() const

MutableArrayRef< T > drop_until(PredicateT Pred) const

Return a copy of *this with the first N elements not satisfying the given predicate removed.

MutableArrayRef< T > take_front(size_t N=1) const

Return a copy of *this with only the first N elements.

MutableArrayRef(std::nullopt_t)

Construct an empty MutableArrayRef from std::nullopt.

std::reverse_iterator< iterator > reverse_iterator

This is a MutableArrayRef that owns its array.

OwningArrayRef & operator=(OwningArrayRef &&Other)

OwningArrayRef(OwningArrayRef &&Other)

OwningArrayRef(ArrayRef< T > Data)

OwningArrayRef(size_t Size)

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

An opaque object representing a hash code.

This is an optimization pass for GlobalISel generic memory operations.

hash_code hash_value(const FixedPointSemantics &Val)

auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)

Get the size of a range.

bool operator!=(uint64_t V1, const APInt &V2)

bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)

auto find_if_not(R &&Range, UnaryPredicate P)

MutableArrayRef(T &OneElt) -> MutableArrayRef< T >

auto find_if(R &&Range, UnaryPredicate P)

Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.

hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)

Compute a hash_code for a sequence of values.

static bool isEqual(ArrayRef< T > LHS, ArrayRef< T > RHS)

static ArrayRef< T > getTombstoneKey()

static unsigned getHashValue(ArrayRef< T > Val)

static ArrayRef< T > getEmptyKey()

An information struct used to provide DenseMap with the various necessary components for a given valu...