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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80#ifndef LLVM_ADT_SEQUENCE_H

81#define LLVM_ADT_SEQUENCE_H

82

83#include

84#include

85#include

86#include <type_traits>

87

88

91

92namespace llvm {

93

94

95

96

97

98

99

103

107

110

112

113

115 const intmax_t BotT = intmax_t(std::numeric_limits::min());

116 const intmax_t BotU = intmax_t(std::numeric_limits::min());

117 const uintmax_t TopT = uintmax_t(std::numeric_limits::max());

118 const uintmax_t TopU = uintmax_t(std::numeric_limits::max());

120 (TopT < TopU && Value > static_cast<U>(TopT)));

121}

122

123

124

125

126

128

129 template <typename Integral,

130 std::enable_if_t<std::is_integral::value, bool> = 0>

133 assertOutOfBounds();

135 Result.Value = static_cast<intmax_t>(FromValue);

136 return Result;

137 }

138

139

140 template <typename Enum,

141 std::enable_if_t<std::is_enum::value, bool> = 0>

145

146

149

153 assertOutOfBounds();

154 return Result;

155 }

156

158 intmax_t Result;

160 assertOutOfBounds();

161 return Result;

162 }

163

164

165 template <typename Integral,

166 std::enable_if_t<std::is_integral::value, bool> = 0>

167 Integral to() const {

169 assertOutOfBounds();

170 return static_cast<Integral>(Value);

171 }

172

173

174

175 template <typename Enum,

176 std::enable_if_t<std::is_enum::value, bool> = 0>

177 Enum to() const {

178 using type = std::underlying_type_t;

180 }

181

182private:

183 static void assertOutOfBounds() { assert(false && "Out of bounds"); }

184

186};

187

194

195

197

199

200

202

204

205

208

213

214

217

218

220 const auto Copy = *this;

221 ++*this;

222 return Copy;

223 }

225 const auto Copy = *this;

226 --*this;

227 return Copy;

228 }

229

230

233

234

237

238

240 return IsReverse ? O.SI - SI : SI - O.SI;

241 }

242

243private:

245

248 }

249

251

252 void offset(intmax_t Offset) { SI = SI + getOffset(Offset); }

253

254 CheckedInt SI;

255

256

258};

259

260}

261

272

274 : BeginValue(Begin), PastEndValue(End) {

275 assert(Begin <= End && "Begin must be less or equal to End.");

276 if (Inclusive)

277 ++PastEndValue;

278 }

279

280 size_t size() const { return PastEndValue - BeginValue; }

281 bool empty() const { return BeginValue == PastEndValue; }

282

285

288

289private:

290 static_assert(std::is_integral::value || std::is_enum::value,

291 "T must be an integral or enum type");

292 static_assert(std::is_same<T, std::remove_cv_t>::value,

293 "T must not be const nor volatile");

294

297};

298

299

300

301

302

303template <typename T, typename = std::enable_if_t<std::is_integral::value &&

304 !std::is_enum::value>>

308

309

310

311

312

313template <typename T, typename = std::enable_if_t<std::is_integral::value &&

314 !std::is_enum::value>>

318

319

320

321

322

323template <typename T, typename = std::enable_if_t<std::is_integral::value &&

324 !std::is_enum::value>>

328

329

330

331

332

333

334

335template <typename EnumT,

336 typename = std::enable_if_t<std::is_enum::value>>

339 "Enum type is not marked as iterable.");

341}

342

343

344

345

346

347

348

349

350template <typename EnumT,

351 typename = std::enable_if_t<std::is_enum::value>>

355

356

357

358

359

360

361

362template <typename EnumT,

363 typename = std::enable_if_t<std::is_enum::value>>

366 "Enum type is not marked as iterable.");

368}

369

370

371

372

373

374

375

376

377template <typename EnumT,

378 typename = std::enable_if_t<std::is_enum::value>>

383

384}

385

386#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)

static std::optional< int32_t > getOffset(ArrayRef< int32_t > Offsets, size_t Idx)

This file contains library features backported from future STL versions.

LLVM Value Representation.

bool canTypeFitValue(const U Value)

Definition Sequence.h:114

This is an optimization pass for GlobalISel generic memory operations.

FunctionAddr VTableAddr Value

auto seq_inclusive(T Begin, T End)

Iterate over an integral type from Begin to End inclusive.

Definition Sequence.h:325

auto enum_seq_inclusive(EnumT Begin, EnumT End)

Iterate over an enum type from Begin to End inclusive.

Definition Sequence.h:364

auto enum_seq(EnumT Begin, EnumT End)

Iterate over an enum type from Begin up to - but not including - End.

Definition Sequence.h:337

constexpr force_iteration_on_noniterable_enum_t force_iteration_on_noniterable_enum

Definition Sequence.h:109

static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)

constexpr std::underlying_type_t< Enum > to_underlying(Enum E)

Returns underlying integer value of an enum.

std::enable_if_t< std::is_signed_v< T >, T > AddOverflow(T X, T Y, T &Result)

Add two signed integers, computing the two's complement truncated result, returning true if overflow ...

auto seq(T Begin, T End)

Iterate over an integral type from Begin up to - but not including - End.

Definition Sequence.h:305

std::enable_if_t< std::is_signed_v< T >, T > SubOverflow(T X, T Y, T &Result)

Subtract two signed integers, computing the two's complement truncated result, returning true if an o...

Definition Sequence.h:127

static CheckedInt from(Integral FromValue)

Definition Sequence.h:131

static CheckedInt from(Enum FromValue)

Definition Sequence.h:142

Integral to() const

Definition Sequence.h:167

bool operator!=(const CheckedInt &O) const

Definition Sequence.h:148

CheckedInt operator+(intmax_t Offset) const

Definition Sequence.h:150

bool operator==(const CheckedInt &O) const

Definition Sequence.h:147

Enum to() const

Definition Sequence.h:177

intmax_t operator-(CheckedInt Other) const

Definition Sequence.h:157

Definition Sequence.h:188

void operator-=(intmax_t Offset)

Definition Sequence.h:232

bool operator==(const SafeIntIterator &O) const

Definition Sequence.h:206

SafeIntIterator(T Value)

Definition Sequence.h:196

bool operator<=(const SafeIntIterator &O) const

Definition Sequence.h:211

SafeIntIterator operator+(intmax_t Offset) const

Definition Sequence.h:235

SafeIntIterator operator--(int)

Definition Sequence.h:224

reference operator*() const

Definition Sequence.h:201

SafeIntIterator(const SafeIntIterator< T, !IsReverse > &O)

Definition Sequence.h:198

SafeIntIterator operator-(intmax_t Offset) const

Definition Sequence.h:236

void operator+=(intmax_t Offset)

Definition Sequence.h:231

T * pointer

Definition Sequence.h:192

value_type reference

Definition Sequence.h:193

intmax_t difference_type

Definition Sequence.h:191

bool operator>=(const SafeIntIterator &O) const

Definition Sequence.h:212

bool operator>(const SafeIntIterator &O) const

Definition Sequence.h:210

T value_type

Definition Sequence.h:190

bool operator!=(const SafeIntIterator &O) const

Definition Sequence.h:207

reference operator[](intmax_t Offset) const

Definition Sequence.h:203

intmax_t operator-(const SafeIntIterator &O) const

Definition Sequence.h:239

void operator--()

Definition Sequence.h:216

SafeIntIterator operator++(int)

Definition Sequence.h:219

friend struct SafeIntIterator

Definition Sequence.h:257

bool operator<(const SafeIntIterator &O) const

Definition Sequence.h:209

void operator++()

Definition Sequence.h:215

std::random_access_iterator_tag iterator_category

Definition Sequence.h:189

Definition Sequence.h:100

static constexpr bool is_iterable

Definition Sequence.h:101

Definition Sequence.h:104

force_iteration_on_noniterable_enum_t()=default

Definition Sequence.h:262

auto rend() const

Definition Sequence.h:287

iota_range(T Begin, T End, bool Inclusive)

Definition Sequence.h:273

iterator const_iterator

Definition Sequence.h:267

auto rbegin() const

Definition Sequence.h:286

T value_type

Definition Sequence.h:263

auto begin() const

Definition Sequence.h:283

reverse_iterator const_reverse_iterator

Definition Sequence.h:269

detail::SafeIntIterator< value_type, false > iterator

Definition Sequence.h:266

std::size_t size_type

Definition Sequence.h:271

size_t size() const

Definition Sequence.h:280

detail::SafeIntIterator< value_type, true > reverse_iterator

Definition Sequence.h:268

bool empty() const

Definition Sequence.h:281

T & reference

Definition Sequence.h:264

intmax_t difference_type

Definition Sequence.h:270

auto end() const

Definition Sequence.h:284

const T & const_reference

Definition Sequence.h:265