@@ -88,6 +88,22 @@ bool Type::containsNonGlobalTargetExtType() const {
8888 return containsNonGlobalTargetExtType (Visited);
8989}
9090
91+ bool Type::containsNonLocalTargetExtType (
92+ SmallPtrSetImpl<const Type *> &Visited) const {
93+ if (const auto *ATy = dyn_cast<ArrayType>(this ))
94+ return ATy->getElementType ()->containsNonLocalTargetExtType (Visited);
95+ if (const auto *STy = dyn_cast<StructType>(this ))
96+ return STy->containsNonLocalTargetExtType (Visited);
97+ if (auto *TT = dyn_cast<TargetExtType>(this ))
98+ return !TT->hasProperty (TargetExtType::CanBeLocal);
99+ return false ;
100+ }
101+
102+ bool Type::containsNonLocalTargetExtType () const {
103+ SmallPtrSet<const Type *, 4 > Visited;
104+ return containsNonLocalTargetExtType (Visited);
105+ }
106+
91107const fltSemantics &Type::getFltSemantics () const {
92108 switch (getTypeID ()) {
93109 case HalfTyID: return APFloat::IEEEhalf ();
@@ -469,6 +485,34 @@ bool StructType::containsNonGlobalTargetExtType(
469485 return false ;
470486}
471487
488+ bool StructType::containsNonLocalTargetExtType (
489+ SmallPtrSetImpl<const Type *> &Visited) const {
490+ if ((getSubclassData () & SCDB_ContainsNonLocalTargetExtType) != 0 )
491+ return true ;
492+
493+ if ((getSubclassData () & SCDB_NotContainsNonLocalTargetExtType) != 0 )
494+ return false ;
495+
496+ if (!Visited.insert (this ).second )
497+ return false ;
498+
499+ for (Type *Ty : elements ()) {
500+ if (Ty->containsNonLocalTargetExtType (Visited)) {
501+ const_cast <StructType *>(this )->setSubclassData (
502+ getSubclassData () | SCDB_ContainsNonLocalTargetExtType);
503+ return true ;
504+ }
505+ }
506+
507+ // For structures that are opaque, return false but do not set the
508+ // SCDB_NotContainsNonLocalTargetExtType flag since it may gain non-local
509+ // target extension types when it becomes non-opaque.
510+ if (!isOpaque ())
511+ const_cast <StructType *>(this )->setSubclassData (
512+ getSubclassData () | SCDB_NotContainsNonLocalTargetExtType);
513+ return false ;
514+ }
515+
472516bool StructType::containsHomogeneousScalableVectorTypes () const {
473517 if (getNumElements () <= 0 || !isa<ScalableVectorType>(elements ().front ()))
474518 return false ;
@@ -922,15 +966,18 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
922966 LLVMContext &C = Ty->getContext ();
923967 StringRef Name = Ty->getName ();
924968 if (Name == " spirv.Image" )
925- return TargetTypeInfo (PointerType::get (C, 0 ), TargetExtType::CanBeGlobal);
969+ return TargetTypeInfo (PointerType::get (C, 0 ), TargetExtType::CanBeGlobal,
970+ TargetExtType::CanBeLocal);
926971 if (Name.starts_with (" spirv." ))
927972 return TargetTypeInfo (PointerType::get (C, 0 ), TargetExtType::HasZeroInit,
928- TargetExtType::CanBeGlobal);
973+ TargetExtType::CanBeGlobal,
974+ TargetExtType::CanBeLocal);
929975
930976 // Opaque types in the AArch64 name space.
931977 if (Name == " aarch64.svcount" )
932978 return TargetTypeInfo (ScalableVectorType::get (Type::getInt1Ty (C), 16 ),
933- TargetExtType::HasZeroInit);
979+ TargetExtType::HasZeroInit,
980+ TargetExtType::CanBeLocal);
934981
935982 // RISC-V vector tuple type. The layout is represented as the type that needs
936983 // the same number of vector registers(VREGS) as this tuple type, represented
@@ -942,12 +989,14 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
942989 RISCV::RVVBitsPerBlock / 8 ) *
943990 Ty->getIntParameter (0 );
944991 return TargetTypeInfo (
945- ScalableVectorType::get (Type::getInt8Ty (C), TotalNumElts));
992+ ScalableVectorType::get (Type::getInt8Ty (C), TotalNumElts),
993+ TargetExtType::CanBeLocal);
946994 }
947995
948996 // DirectX resources
949997 if (Name.starts_with (" dx." ))
950- return TargetTypeInfo (PointerType::get (C, 0 ), TargetExtType::CanBeGlobal);
998+ return TargetTypeInfo (PointerType::get (C, 0 ), TargetExtType::CanBeGlobal,
999+ TargetExtType::CanBeLocal);
9511000
9521001 // Opaque types in the AMDGPU name space.
9531002 if (Name == " amdgcn.named.barrier" ) {
0 commit comments