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

1

2

3

4

5

6

7

8

9#ifndef LLVM_ADT_TINYPTRVECTOR_H

10#define LLVM_ADT_TINYPTRVECTOR_H

11

15#include

16#include

17#include

18#include <type_traits>

19

20namespace llvm {

21

22

23

24

25

26

27

28template

30public:

33

34

35

36

38

39private:

41

42public:

44

46 if (VecTy *V = dyn_cast_if_present<VecTy *>(Val))

47 delete V;

48 }

49

51 if (VecTy *V = dyn_cast_if_present<VecTy *>(Val))

52 Val = new VecTy(*V);

53 }

54

56 if (this == &RHS)

57 return *this;

58 if (RHS.empty()) {

60 return *this;

61 }

62

63

64

65 if (isa(Val)) {

66 if (RHS.size() == 1)

67 Val = RHS.front();

68 else

69 Val = new VecTy(*cast<VecTy *>(RHS.Val));

70 return *this;

71 }

72

73

74 if (isa(RHS.Val)) {

75 cast<VecTy *>(Val)->clear();

76 cast<VecTy *>(Val)->push_back(RHS.front());

77 } else {

78 *cast<VecTy *>(Val) = *cast<VecTy *>(RHS.Val);

79 }

80 return *this;

81 }

82

84 RHS.Val = (EltTy)nullptr;

85 }

86

88 if (this == &RHS)

89 return *this;

90 if (RHS.empty()) {

92 return *this;

93 }

94

95

96

97

98 if (VecTy *V = dyn_cast_if_present<VecTy *>(Val)) {

99 if (isa(RHS.Val)) {

100 V->clear();

101 V->push_back(RHS.front());

102 RHS.Val = EltTy();

103 return *this;

104 }

105 delete V;

106 }

107

108 Val = RHS.Val;

109 RHS.Val = EltTy();

110 return *this;

111 }

112

114 : Val(IL.size() == 0

118

119

120

121

122

124 : Val(Elts.empty()

126 : Elts.size() == 1

129

131 : Val(Count == 0 ? PtrUnion()

134

135

138 return {};

139 if (isa(Val))

141 return *cast<VecTy *>(Val);

142 }

143

144

147 return {};

148 if (isa(Val))

150 return *cast<VecTy *>(Val);

151 }

152

153

154 template <

155 typename U,

156 std::enable_if_t<std::is_convertible<ArrayRef, ArrayRef>::value,

157 bool> = false>

160 }

161

163

164

165 if (Val.isNull()) return true;

166 if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val))

167 return Vec->empty();

168 return false;

169 }

170

173 return 0;

174 if (isa(Val))

175 return 1;

176 return cast<VecTy *>(Val)->size();

177 }

178

183

185 if (isa(Val))

187

188 return cast<VecTy *>(Val)->begin();

189 }

190

192 if (isa(Val))

194

195 return cast<VecTy *>(Val)->end();

196 }

197

200 }

201

204 }

205

208

211 }

212

215 }

216

218 assert(!Val.isNull() && "can't index into an empty vector");

219 if (isa(Val)) {

220 assert(i == 0 && "tinyvector index out of range");

221 return cast(Val);

222 }

223

224 assert(i < cast<VecTy *>(Val)->size() && "tinyvector index out of range");

225 return (*cast<VecTy *>(Val))[i];

226 }

227

230 if (isa(Val))

231 return cast(Val);

232 return cast<VecTy *>(Val)->front();

233 }

234

237 if (isa(Val))

238 return cast(Val);

239 return cast<VecTy *>(Val)->back();

240 }

241

243

245 Val = NewVal;

246 assert(!Val.isNull() && "Can't add a null value");

247 return;

248 }

249

250

251 if (isa(Val)) {

252 EltTy V = cast(Val);

253 Val = new VecTy();

254 cast<VecTy *>(Val)->push_back(V);

255 }

256

257

258 cast<VecTy *>(Val)->push_back(NewVal);

259 }

260

262

263 if (isa(Val))

264 Val = (EltTy)nullptr;

265 else if (VecTy *Vec = cast<VecTy *>(Val))

266 Vec->pop_back();

267 }

268

270

271 if (isa(Val)) {

272 Val = EltTy();

273 } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {

274

275 Vec->clear();

276 }

277

278 }

279

281 assert(I >= begin() && "Iterator to erase is out of bounds.");

282 assert(I < end() && "Erasing at past-the-end iterator.");

283

284

285 if (isa(Val)) {

287 Val = EltTy();

288 } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {

289

290

291 return Vec->erase(I);

292 }

293 return end();

294 }

295

297 assert(S >= begin() && "Range to erase is out of bounds.");

298 assert(S <= E && "Trying to erase invalid range.");

299 assert(E <= end() && "Trying to erase past the end.");

300

301 if (isa(Val)) {

302 if (S == begin() && S != E)

303 Val = EltTy();

304 } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {

305 return Vec->erase(S, E);

306 }

307 return end();

308 }

309

311 assert(I >= this->begin() && "Insertion iterator is out of bounds.");

312 assert(I <= this->end() && "Inserting past the end of the vector.");

313 if (I == end()) {

315 return std::prev(end());

316 }

317 assert(!Val.isNull() && "Null value with non-end insert iterator.");

318 if (isa(Val)) {

319 EltTy V = cast(Val);

321 Val = Elt;

324 }

325

326 return cast<VecTy *>(Val)->insert(I, Elt);

327 }

328

329 template

331 assert(I >= this->begin() && "Insertion iterator is out of bounds.");

332 assert(I <= this->end() && "Inserting past the end of the vector.");

333 if (From == To)

334 return I;

335

336

339 if (std::next(From) == To) {

342 }

343

344 Val = new VecTy();

345 } else if (isa(Val)) {

346 EltTy V = cast(Val);

347 Val = new VecTy();

348 cast<VecTy *>(Val)->push_back(V);

349 }

350 return cast<VecTy *>(Val)->insert(begin() + Offset, From, To);

351 }

352};

353

354}

355

356#endif

BlockVerifier::State From

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

Given that RA is a live value

This file defines the PointerUnion class, which is a discriminated union of pointer types.

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),...

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

bool isNull() const

Test if the pointer held in the union is null, regardless of which type it is.

First const * getAddrOfPtr1() const

If the union is set to the first pointer type get an address pointing to it.

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

TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...

reverse_iterator rbegin()

const EltTy * const_iterator

TinyPtrVector(std::initializer_list< EltTy > IL)

void push_back(EltTy NewVal)

TinyPtrVector & operator=(TinyPtrVector &&RHS)

std::reverse_iterator< const_iterator > const_reverse_iterator

const_reverse_iterator rbegin() const

TinyPtrVector(ArrayRef< EltTy > Elts)

Constructor from an ArrayRef.

std::reverse_iterator< iterator > reverse_iterator

const_iterator begin() const

iterator erase(iterator I)

TinyPtrVector & operator=(const TinyPtrVector &RHS)

TinyPtrVector(const TinyPtrVector &RHS)

const_reverse_iterator rend() const

const_iterator end() const

iterator insert(iterator I, const EltTy &Elt)

iterator erase(iterator S, iterator E)

SmallVector< EltTy, 4 > VecTy

typename VecTy::value_type value_type

TinyPtrVector(TinyPtrVector &&RHS)

iterator insert(iterator I, ItTy From, ItTy To)

EltTy operator[](unsigned i) const

TinyPtrVector(size_t Count, EltTy Value)

LLVM Value Representation.

This is an optimization pass for GlobalISel generic memory operations.