Skip to content

Commit 7021182

Browse files
committed
[nfc][llvm] Replace pointer cast functions in PointerUnion by llvm casting functions.
This patch replaces the uses of PointerUnion.is function by llvm::isa, PointerUnion.get function by llvm::cast, and PointerUnion.dyn_cast by llvm::dyn_cast_if_present. This is according to the FIXME in the definition of the class PointerUnion. This patch does not remove them as they are being used in other subprojects. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D148449
1 parent 63395cb commit 7021182

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+361
-357
lines changed

llvm/include/llvm/ADT/FunctionExtras.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,15 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
172172
bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
173173

174174
bool isTrivialCallback() const {
175-
return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
175+
return isa<TrivialCallback *>(CallbackAndInlineFlag.getPointer());
176176
}
177177

178178
CallPtrT getTrivialCallback() const {
179-
return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
179+
return cast<TrivialCallback *>(CallbackAndInlineFlag.getPointer())->CallPtr;
180180
}
181181

182182
NonTrivialCallbacks *getNonTrivialCallbacks() const {
183-
return CallbackAndInlineFlag.getPointer()
184-
.template get<NonTrivialCallbacks *>();
183+
return cast<NonTrivialCallbacks *>(CallbackAndInlineFlag.getPointer());
185184
}
186185

187186
CallPtrT getCallPtr() const {

llvm/include/llvm/ADT/PointerUnion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ class PointerUnion
172172
/// If the union is set to the first pointer type get an address pointing to
173173
/// it.
174174
First *getAddrOfPtr1() {
175-
assert(is<First>() && "Val is not the first pointer");
175+
assert(isa<First>(*this) && "Val is not the first pointer");
176176
assert(
177-
PointerLikeTypeTraits<First>::getAsVoidPointer(get<First>()) ==
177+
PointerLikeTypeTraits<First>::getAsVoidPointer(cast<First>(*this)) ==
178178
this->Val.getPointer() &&
179179
"Can't get the address because PointerLikeTypeTraits changes the ptr");
180180
return const_cast<First *>(

llvm/include/llvm/ADT/TinyPtrVector.h

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class TinyPtrVector {
4343
TinyPtrVector() = default;
4444

4545
~TinyPtrVector() {
46-
if (VecTy *V = Val.template dyn_cast<VecTy*>())
46+
if (VecTy *V = dyn_cast_if_present<VecTy *>(Val))
4747
delete V;
4848
}
4949

5050
TinyPtrVector(const TinyPtrVector &RHS) : Val(RHS.Val) {
51-
if (VecTy *V = Val.template dyn_cast<VecTy*>())
51+
if (VecTy *V = dyn_cast_if_present<VecTy *>(Val))
5252
Val = new VecTy(*V);
5353
}
5454

@@ -62,20 +62,20 @@ class TinyPtrVector {
6262

6363
// Try to squeeze into the single slot. If it won't fit, allocate a copied
6464
// vector.
65-
if (Val.template is<EltTy>()) {
65+
if (isa<EltTy>(Val)) {
6666
if (RHS.size() == 1)
6767
Val = RHS.front();
6868
else
69-
Val = new VecTy(*RHS.Val.template get<VecTy*>());
69+
Val = new VecTy(*cast<VecTy *>(RHS.Val));
7070
return *this;
7171
}
7272

7373
// If we have a full vector allocated, try to re-use it.
74-
if (RHS.Val.template is<EltTy>()) {
75-
Val.template get<VecTy*>()->clear();
76-
Val.template get<VecTy*>()->push_back(RHS.front());
74+
if (isa<EltTy>(RHS.Val)) {
75+
cast<VecTy *>(Val)->clear();
76+
cast<VecTy *>(Val)->push_back(RHS.front());
7777
} else {
78-
*Val.template get<VecTy*>() = *RHS.Val.template get<VecTy*>();
78+
*cast<VecTy *>(Val) = *cast<VecTy *>(RHS.Val);
7979
}
8080
return *this;
8181
}
@@ -95,8 +95,8 @@ class TinyPtrVector {
9595
// If this vector has been allocated on the heap, re-use it if cheap. If it
9696
// would require more copying, just delete it and we'll steal the other
9797
// side.
98-
if (VecTy *V = Val.template dyn_cast<VecTy*>()) {
99-
if (RHS.Val.template is<EltTy>()) {
98+
if (VecTy *V = dyn_cast_if_present<VecTy *>(Val)) {
99+
if (isa<EltTy>(RHS.Val)) {
100100
V->clear();
101101
V->push_back(RHS.front());
102102
RHS.Val = EltTy();
@@ -136,18 +136,18 @@ class TinyPtrVector {
136136
operator ArrayRef<EltTy>() const {
137137
if (Val.isNull())
138138
return std::nullopt;
139-
if (Val.template is<EltTy>())
139+
if (isa<EltTy>(Val))
140140
return *Val.getAddrOfPtr1();
141-
return *Val.template get<VecTy*>();
141+
return *cast<VecTy *>(Val);
142142
}
143143

144144
// implicit conversion operator to MutableArrayRef.
145145
operator MutableArrayRef<EltTy>() {
146146
if (Val.isNull())
147147
return std::nullopt;
148-
if (Val.template is<EltTy>())
148+
if (isa<EltTy>(Val))
149149
return *Val.getAddrOfPtr1();
150-
return *Val.template get<VecTy*>();
150+
return *cast<VecTy *>(Val);
151151
}
152152

153153
// Implicit conversion to ArrayRef<U> if EltTy* implicitly converts to U*.
@@ -163,17 +163,17 @@ class TinyPtrVector {
163163
// This vector can be empty if it contains no element, or if it
164164
// contains a pointer to an empty vector.
165165
if (Val.isNull()) return true;
166-
if (VecTy *Vec = Val.template dyn_cast<VecTy*>())
166+
if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val))
167167
return Vec->empty();
168168
return false;
169169
}
170170

171171
unsigned size() const {
172172
if (empty())
173173
return 0;
174-
if (Val.template is<EltTy>())
174+
if (isa<EltTy>(Val))
175175
return 1;
176-
return Val.template get<VecTy*>()->size();
176+
return cast<VecTy *>(Val)->size();
177177
}
178178

179179
using iterator = EltTy *;
@@ -182,17 +182,17 @@ class TinyPtrVector {
182182
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
183183

184184
iterator begin() {
185-
if (Val.template is<EltTy>())
185+
if (isa<EltTy>(Val))
186186
return Val.getAddrOfPtr1();
187187

188-
return Val.template get<VecTy *>()->begin();
188+
return cast<VecTy *>(Val)->begin();
189189
}
190190

191191
iterator end() {
192-
if (Val.template is<EltTy>())
192+
if (isa<EltTy>(Val))
193193
return begin() + (Val.isNull() ? 0 : 1);
194194

195-
return Val.template get<VecTy *>()->end();
195+
return cast<VecTy *>(Val)->end();
196196
}
197197

198198
const_iterator begin() const {
@@ -216,28 +216,27 @@ class TinyPtrVector {
216216

217217
EltTy operator[](unsigned i) const {
218218
assert(!Val.isNull() && "can't index into an empty vector");
219-
if (Val.template is<EltTy>()) {
219+
if (isa<EltTy>(Val)) {
220220
assert(i == 0 && "tinyvector index out of range");
221-
return Val.template get<EltTy>();
221+
return cast<EltTy>(Val);
222222
}
223223

224-
assert(i < Val.template get<VecTy*>()->size() &&
225-
"tinyvector index out of range");
226-
return (*Val.template get<VecTy*>())[i];
224+
assert(i < cast<VecTy *>(Val)->size() && "tinyvector index out of range");
225+
return (*cast<VecTy *>(Val))[i];
227226
}
228227

229228
EltTy front() const {
230229
assert(!empty() && "vector empty");
231-
if (Val.template is<EltTy>())
232-
return Val.template get<EltTy>();
233-
return Val.template get<VecTy*>()->front();
230+
if (isa<EltTy>(Val))
231+
return cast<EltTy>(Val);
232+
return cast<VecTy *>(Val)->front();
234233
}
235234

236235
EltTy back() const {
237236
assert(!empty() && "vector empty");
238-
if (Val.template is<EltTy>())
239-
return Val.template get<EltTy>();
240-
return Val.template get<VecTy*>()->back();
237+
if (isa<EltTy>(Val))
238+
return cast<EltTy>(Val);
239+
return cast<VecTy *>(Val)->back();
241240
}
242241

243242
void push_back(EltTy NewVal) {
@@ -249,29 +248,29 @@ class TinyPtrVector {
249248
}
250249

251250
// If we have a single value, convert to a vector.
252-
if (Val.template is<EltTy>()) {
253-
EltTy V = Val.template get<EltTy>();
251+
if (isa<EltTy>(Val)) {
252+
EltTy V = cast<EltTy>(Val);
254253
Val = new VecTy();
255-
Val.template get<VecTy*>()->push_back(V);
254+
cast<VecTy *>(Val)->push_back(V);
256255
}
257256

258257
// Add the new value, we know we have a vector.
259-
Val.template get<VecTy*>()->push_back(NewVal);
258+
cast<VecTy *>(Val)->push_back(NewVal);
260259
}
261260

262261
void pop_back() {
263262
// If we have a single value, convert to empty.
264-
if (Val.template is<EltTy>())
263+
if (isa<EltTy>(Val))
265264
Val = (EltTy)nullptr;
266-
else if (VecTy *Vec = Val.template get<VecTy*>())
265+
else if (VecTy *Vec = cast<VecTy *>(Val))
267266
Vec->pop_back();
268267
}
269268

270269
void clear() {
271270
// If we have a single value, convert to empty.
272-
if (Val.template is<EltTy>()) {
271+
if (isa<EltTy>(Val)) {
273272
Val = EltTy();
274-
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
273+
} else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
275274
// If we have a vector form, just clear it.
276275
Vec->clear();
277276
}
@@ -283,10 +282,10 @@ class TinyPtrVector {
283282
assert(I < end() && "Erasing at past-the-end iterator.");
284283

285284
// If we have a single value, convert to empty.
286-
if (Val.template is<EltTy>()) {
285+
if (isa<EltTy>(Val)) {
287286
if (I == begin())
288287
Val = EltTy();
289-
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
288+
} else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
290289
// multiple items in a vector; just do the erase, there is no
291290
// benefit to collapsing back to a pointer
292291
return Vec->erase(I);
@@ -299,10 +298,10 @@ class TinyPtrVector {
299298
assert(S <= E && "Trying to erase invalid range.");
300299
assert(E <= end() && "Trying to erase past the end.");
301300

302-
if (Val.template is<EltTy>()) {
301+
if (isa<EltTy>(Val)) {
303302
if (S == begin() && S != E)
304303
Val = EltTy();
305-
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
304+
} else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
306305
return Vec->erase(S, E);
307306
}
308307
return end();
@@ -316,15 +315,15 @@ class TinyPtrVector {
316315
return std::prev(end());
317316
}
318317
assert(!Val.isNull() && "Null value with non-end insert iterator.");
319-
if (Val.template is<EltTy>()) {
320-
EltTy V = Val.template get<EltTy>();
318+
if (isa<EltTy>(Val)) {
319+
EltTy V = cast<EltTy>(Val);
321320
assert(I == begin());
322321
Val = Elt;
323322
push_back(V);
324323
return begin();
325324
}
326325

327-
return Val.template get<VecTy*>()->insert(I, Elt);
326+
return cast<VecTy *>(Val)->insert(I, Elt);
328327
}
329328

330329
template<typename ItTy>
@@ -343,12 +342,12 @@ class TinyPtrVector {
343342
}
344343

345344
Val = new VecTy();
346-
} else if (Val.template is<EltTy>()) {
347-
EltTy V = Val.template get<EltTy>();
345+
} else if (isa<EltTy>(Val)) {
346+
EltTy V = cast<EltTy>(Val);
348347
Val = new VecTy();
349-
Val.template get<VecTy*>()->push_back(V);
348+
cast<VecTy *>(Val)->push_back(V);
350349
}
351-
return Val.template get<VecTy*>()->insert(begin() + Offset, From, To);
350+
return cast<VecTy *>(Val)->insert(begin() + Offset, From, To);
352351
}
353352
};
354353

llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DwarfStringPoolEntryRef {
6363
/// thus specified entry mustn`t be reallocated.
6464
DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry *> &Entry)
6565
: MapEntry(&Entry) {
66-
assert(MapEntry.get<ByPtrStringEntryPtr>()->second != nullptr);
66+
assert(cast<ByPtrStringEntryPtr>(MapEntry)->second != nullptr);
6767
}
6868

6969
explicit operator bool() const { return !MapEntry.isNull(); }
@@ -85,18 +85,18 @@ class DwarfStringPoolEntryRef {
8585

8686
/// \returns string.
8787
StringRef getString() const {
88-
if (MapEntry.is<ByValStringEntryPtr>())
89-
return MapEntry.get<ByValStringEntryPtr>()->first();
88+
if (isa<ByValStringEntryPtr>(MapEntry))
89+
return cast<ByValStringEntryPtr>(MapEntry)->first();
9090

91-
return MapEntry.get<ByPtrStringEntryPtr>()->first();
91+
return cast<ByPtrStringEntryPtr>(MapEntry)->first();
9292
}
9393

9494
/// \returns the entire string pool entry for convenience.
9595
const DwarfStringPoolEntry &getEntry() const {
96-
if (MapEntry.is<ByValStringEntryPtr>())
97-
return MapEntry.get<ByValStringEntryPtr>()->second;
96+
if (isa<ByValStringEntryPtr>(MapEntry))
97+
return cast<ByValStringEntryPtr>(MapEntry)->second;
9898

99-
return *MapEntry.get<ByPtrStringEntryPtr>()->second;
99+
return *cast<ByPtrStringEntryPtr>(MapEntry)->second;
100100
}
101101

102102
bool operator==(const DwarfStringPoolEntryRef &X) const {

llvm/include/llvm/CodeGen/MachineMemOperand.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ struct MachinePointerInfo {
6969
uint8_t ID = 0)
7070
: V(v), Offset(offset), StackID(ID) {
7171
if (V) {
72-
if (const auto *ValPtr = V.dyn_cast<const Value*>())
72+
if (const auto *ValPtr = dyn_cast_if_present<const Value *>(V))
7373
AddrSpace = ValPtr->getType()->getPointerAddressSpace();
7474
else
75-
AddrSpace = V.get<const PseudoSourceValue*>()->getAddressSpace();
75+
AddrSpace = cast<const PseudoSourceValue *>(V)->getAddressSpace();
7676
}
7777
}
7878

7979
MachinePointerInfo getWithOffset(int64_t O) const {
8080
if (V.isNull())
8181
return MachinePointerInfo(AddrSpace, Offset + O);
82-
if (V.is<const Value*>())
83-
return MachinePointerInfo(V.get<const Value*>(), Offset + O, StackID);
84-
return MachinePointerInfo(V.get<const PseudoSourceValue*>(), Offset + O,
82+
if (isa<const Value *>(V))
83+
return MachinePointerInfo(cast<const Value *>(V), Offset + O, StackID);
84+
return MachinePointerInfo(cast<const PseudoSourceValue *>(V), Offset + O,
8585
StackID);
8686
}
8787

@@ -207,10 +207,12 @@ class MachineMemOperand {
207207
/// other PseudoSourceValue member functions which return objects which stand
208208
/// for frame/stack pointer relative references and other special references
209209
/// which are not representable in the high-level IR.
210-
const Value *getValue() const { return PtrInfo.V.dyn_cast<const Value*>(); }
210+
const Value *getValue() const {
211+
return dyn_cast_if_present<const Value *>(PtrInfo.V);
212+
}
211213

212214
const PseudoSourceValue *getPseudoValue() const {
213-
return PtrInfo.V.dyn_cast<const PseudoSourceValue*>();
215+
return dyn_cast_if_present<const PseudoSourceValue *>(PtrInfo.V);
214216
}
215217

216218
const void *getOpaqueValue() const { return PtrInfo.V.getOpaqueValue(); }

llvm/include/llvm/CodeGen/MachineRegisterInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ class MachineRegisterInfo {
660660
/// This shouldn't be used directly unless \p Reg has a register class.
661661
/// \see getRegClassOrNull when this might happen.
662662
const TargetRegisterClass *getRegClass(Register Reg) const {
663-
assert(VRegInfo[Reg.id()].first.is<const TargetRegisterClass *>() &&
663+
assert(isa<const TargetRegisterClass *>(VRegInfo[Reg.id()].first) &&
664664
"Register class not set, wrong accessor");
665-
return VRegInfo[Reg.id()].first.get<const TargetRegisterClass *>();
665+
return cast<const TargetRegisterClass *>(VRegInfo[Reg.id()].first);
666666
}
667667

668668
/// Return the register class of \p Reg, or null if Reg has not been assigned
@@ -678,7 +678,7 @@ class MachineRegisterInfo {
678678
/// the select pass, using getRegClass is safe.
679679
const TargetRegisterClass *getRegClassOrNull(Register Reg) const {
680680
const RegClassOrRegBank &Val = VRegInfo[Reg].first;
681-
return Val.dyn_cast<const TargetRegisterClass *>();
681+
return dyn_cast_if_present<const TargetRegisterClass *>(Val);
682682
}
683683

684684
/// Return the register bank of \p Reg, or null if Reg has not been assigned
@@ -687,7 +687,7 @@ class MachineRegisterInfo {
687687
/// RegisterBankInfo::getRegBankFromRegClass.
688688
const RegisterBank *getRegBankOrNull(Register Reg) const {
689689
const RegClassOrRegBank &Val = VRegInfo[Reg].first;
690-
return Val.dyn_cast<const RegisterBank *>();
690+
return dyn_cast_if_present<const RegisterBank *>(Val);
691691
}
692692

693693
/// Return the register bank or register class of \p Reg.

0 commit comments

Comments
 (0)