Skip to content

Commit c4ffee4

Browse files
committed
Allow passing Visited set into Type::isScalableTy
1 parent a4a26a1 commit c4ffee4

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

llvm/include/llvm/IR/DerivedTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ class StructType : public Type {
290290
bool isSized(SmallPtrSetImpl<Type *> *Visited = nullptr) const;
291291

292292
/// Returns true if this struct contains a scalable vector.
293-
bool isScalableTy(SmallPtrSetImpl<Type *> *Visited = nullptr) const;
293+
bool isScalableTy(SmallPtrSetImpl<Type *> &Visited) const;
294+
using Type::isScalableTy;
294295

295296
/// Returns true if this struct contains homogeneous scalable vector types.
296297
/// Note that the definition of homogeneous scalable vector type is not

llvm/include/llvm/IR/Type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class Type {
206206
bool isScalableTargetExtTy() const;
207207

208208
/// Return true if this is a type whose size is a known multiple of vscale.
209+
bool isScalableTy(SmallPtrSetImpl<Type *> &Visited) const;
209210
bool isScalableTy() const;
210211

211212
/// Return true if this is a FP type or a vector of FP.

llvm/lib/IR/Type.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ bool Type::isIntegerTy(unsigned Bitwidth) const {
5858
return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
5959
}
6060

61-
bool Type::isScalableTy() const {
61+
bool Type::isScalableTy(SmallPtrSetImpl<Type *> &Visited) const {
6262
if (const auto *ATy = dyn_cast<ArrayType>(this))
63-
return ATy->getElementType()->isScalableTy();
64-
if (const auto *STy = dyn_cast<StructType>(this)) {
65-
SmallPtrSet<Type *, 4> Visited;
66-
return STy->isScalableTy(&Visited);
67-
}
63+
return ATy->getElementType()->isScalableTy(Visited);
64+
if (const auto *STy = dyn_cast<StructType>(this))
65+
return STy->isScalableTy(Visited);
6866
return getTypeID() == ScalableVectorTyID || isScalableTargetExtTy();
6967
}
7068

69+
bool Type::isScalableTy() const {
70+
SmallPtrSet<Type *, 4> Visited;
71+
return isScalableTy(Visited);
72+
}
73+
7174
const fltSemantics &Type::getFltSemantics() const {
7275
switch (getTypeID()) {
7376
case HalfTyID: return APFloat::IEEEhalf();
@@ -394,14 +397,14 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef<Type*> ETypes,
394397
return ST;
395398
}
396399

397-
bool StructType::isScalableTy(SmallPtrSetImpl<Type *> *Visited) const {
400+
bool StructType::isScalableTy(SmallPtrSetImpl<Type *> &Visited) const {
398401
if ((getSubclassData() & SCDB_ContainsScalableVector) != 0)
399402
return true;
400403

401404
if ((getSubclassData() & SCDB_NotContainsScalableVector) != 0)
402405
return false;
403406

404-
if (Visited && !Visited->insert(const_cast<StructType *>(this)).second)
407+
if (!Visited.insert(const_cast<StructType *>(this)).second)
405408
return false;
406409

407410
for (Type *Ty : elements()) {

0 commit comments

Comments
 (0)