@@ -200,6 +200,7 @@ class DINode : public MDNode {
200200 case DIEnumeratorKind:
201201 case DIBasicTypeKind:
202202 case DIStringTypeKind:
203+ case DISubrangeTypeKind:
203204 case DIDerivedTypeKind:
204205 case DICompositeTypeKind:
205206 case DISubroutineTypeKind:
@@ -342,9 +343,6 @@ class DIAssignID : public MDNode {
342343};
343344
344345// / Array subrange.
345- // /
346- // / TODO: Merge into node for DW_TAG_array_type, which should have a custom
347- // / type.
348346class DISubrange : public DINode {
349347 friend class LLVMContextImpl ;
350348 friend class MDNode ;
@@ -550,6 +548,7 @@ class DIScope : public DINode {
550548 return false ;
551549 case DIBasicTypeKind:
552550 case DIStringTypeKind:
551+ case DISubrangeTypeKind:
553552 case DIDerivedTypeKind:
554553 case DICompositeTypeKind:
555554 case DISubroutineTypeKind:
@@ -808,6 +807,7 @@ class DIType : public DIScope {
808807 return false ;
809808 case DIBasicTypeKind:
810809 case DIStringTypeKind:
810+ case DISubrangeTypeKind:
811811 case DIDerivedTypeKind:
812812 case DICompositeTypeKind:
813813 case DISubroutineTypeKind:
@@ -1167,6 +1167,97 @@ inline bool operator!=(DIDerivedType::PtrAuthData Lhs,
11671167 return !(Lhs == Rhs);
11681168}
11691169
1170+ // / Subrange type. This is somewhat similar to DISubrange, but it
1171+ // / is also a DIType.
1172+ class DISubrangeType : public DIType {
1173+ public:
1174+ typedef PointerUnion<ConstantInt *, DIVariable *, DIExpression *> BoundType;
1175+
1176+ private:
1177+ friend class LLVMContextImpl ;
1178+ friend class MDNode ;
1179+
1180+ DISubrangeType (LLVMContext &C, StorageType Storage, unsigned Line,
1181+ uint64_t SizeInBits, uint32_t AlignInBits, DIFlags Flags,
1182+ ArrayRef<Metadata *> Ops);
1183+
1184+ ~DISubrangeType () = default ;
1185+
1186+ static DISubrangeType *
1187+ getImpl (LLVMContext &Context, StringRef Name, DIFile *File, unsigned Line,
1188+ DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits,
1189+ DIFlags Flags, DIType *BaseType, Metadata *LowerBound,
1190+ Metadata *UpperBound, Metadata *Stride, Metadata *Bias,
1191+ StorageType Storage, bool ShouldCreate = true ) {
1192+ return getImpl (Context, getCanonicalMDString (Context, Name), File, Line,
1193+ Scope, SizeInBits, AlignInBits, Flags, BaseType, LowerBound,
1194+ UpperBound, Stride, Bias, Storage, ShouldCreate);
1195+ }
1196+
1197+ static DISubrangeType *getImpl (LLVMContext &Context, MDString *Name,
1198+ Metadata *File, unsigned Line, Metadata *Scope,
1199+ uint64_t SizeInBits, uint32_t AlignInBits,
1200+ DIFlags Flags, Metadata *BaseType,
1201+ Metadata *LowerBound, Metadata *UpperBound,
1202+ Metadata *Stride, Metadata *Bias,
1203+ StorageType Storage, bool ShouldCreate = true );
1204+
1205+ TempDISubrangeType cloneImpl () const {
1206+ return getTemporary (getContext (), getName (), getFile (), getLine (),
1207+ getScope (), getSizeInBits (), getAlignInBits (),
1208+ getFlags (), getBaseType (), getRawLowerBound (),
1209+ getRawUpperBound (), getRawStride (), getRawBias ());
1210+ }
1211+
1212+ BoundType convertRawToBound (Metadata *IN) const ;
1213+
1214+ public:
1215+ DEFINE_MDNODE_GET (DISubrangeType,
1216+ (MDString * Name, Metadata *File, unsigned Line,
1217+ Metadata *Scope, uint64_t SizeInBits, uint32_t AlignInBits,
1218+ DIFlags Flags, Metadata *BaseType, Metadata *LowerBound,
1219+ Metadata *UpperBound, Metadata *Stride, Metadata *Bias),
1220+ (Name, File, Line, Scope, SizeInBits, AlignInBits, Flags,
1221+ BaseType, LowerBound, UpperBound, Stride, Bias))
1222+ DEFINE_MDNODE_GET (DISubrangeType,
1223+ (StringRef Name, DIFile *File, unsigned Line,
1224+ DIScope *Scope, uint64_t SizeInBits, uint32_t AlignInBits,
1225+ DIFlags Flags, DIType *BaseType, Metadata *LowerBound,
1226+ Metadata *UpperBound, Metadata *Stride, Metadata *Bias),
1227+ (Name, File, Line, Scope, SizeInBits, AlignInBits, Flags,
1228+ BaseType, LowerBound, UpperBound, Stride, Bias))
1229+
1230+ TempDISubrangeType clone () const { return cloneImpl (); }
1231+
1232+ // / Get the base type this is derived from.
1233+ DIType *getBaseType () const { return cast_or_null<DIType>(getRawBaseType ()); }
1234+ Metadata *getRawBaseType () const { return getOperand (3 ); }
1235+
1236+ Metadata *getRawLowerBound () const { return getOperand (4 ).get (); }
1237+
1238+ Metadata *getRawUpperBound () const { return getOperand (5 ).get (); }
1239+
1240+ Metadata *getRawStride () const { return getOperand (6 ).get (); }
1241+
1242+ Metadata *getRawBias () const { return getOperand (7 ).get (); }
1243+
1244+ BoundType getLowerBound () const {
1245+ return convertRawToBound (getRawLowerBound ());
1246+ }
1247+
1248+ BoundType getUpperBound () const {
1249+ return convertRawToBound (getRawUpperBound ());
1250+ }
1251+
1252+ BoundType getStride () const { return convertRawToBound (getRawStride ()); }
1253+
1254+ BoundType getBias () const { return convertRawToBound (getRawBias ()); }
1255+
1256+ static bool classof (const Metadata *MD) {
1257+ return MD->getMetadataID () == DISubrangeTypeKind;
1258+ }
1259+ };
1260+
11701261// / Composite types.
11711262// /
11721263// / TODO: Detach from DerivedTypeBase (split out MDEnumType?).
0 commit comments