@@ -730,6 +730,82 @@ unsigned Type::getPointerAddressSpace() const {
730730 return cast<PointerType>(getScalarType ())->getAddressSpace ();
731731}
732732
733+ // / Class to represent target extensions types, which are generally
734+ // / unintrospectable from target-independent optimizations.
735+ // /
736+ // / Target extension types have a string name, and optionally have type and/or
737+ // / integer parameters. The exact meaning of any parameters is dependent on the
738+ // / target.
739+ class TargetExtType : public Type {
740+ TargetExtType (LLVMContext &C, StringRef Name, ArrayRef<Type *> Types,
741+ ArrayRef<unsigned > Ints);
742+
743+ std::string Name;
744+ unsigned *IntParams;
745+
746+ public:
747+ TargetExtType (const TargetExtType &) = delete ;
748+ TargetExtType &operator =(const TargetExtType &) = delete ;
749+
750+ // / Return a target extension type having the specified name and optional
751+ // / type and integer parameters.
752+ static TargetExtType *get (LLVMContext &Context, StringRef Name,
753+ ArrayRef<Type *> Types = std::nullopt ,
754+ ArrayRef<unsigned > Ints = std::nullopt );
755+
756+ // / Return the name for this target extension type. Two distinct target
757+ // / extension types may have the same name if their type or integer parameters
758+ // / differ.
759+ StringRef getName () const { return Name; }
760+
761+ // / Return the type parameters for this particular target extension type. If
762+ // / there are no parameters, an empty array is returned.
763+ ArrayRef<Type *> type_params () const {
764+ return makeArrayRef (type_param_begin (), type_param_end ());
765+ }
766+
767+ using type_param_iterator = Type::subtype_iterator;
768+ type_param_iterator type_param_begin () const { return ContainedTys; }
769+ type_param_iterator type_param_end () const {
770+ return &ContainedTys[NumContainedTys];
771+ }
772+
773+ Type *getTypeParameter (unsigned i) const { return getContainedType (i); }
774+ unsigned getNumTypeParameters () const { return getNumContainedTypes (); }
775+
776+ // / Return the integer parameters for this particular target extension type.
777+ // / If there are no parameters, an empty array is returned.
778+ ArrayRef<unsigned > int_params () const {
779+ return makeArrayRef (IntParams, getNumIntParameters ());
780+ }
781+
782+ unsigned getIntParameter (unsigned i) const { return IntParams[i]; }
783+ unsigned getNumIntParameters () const { return getSubclassData (); }
784+
785+ enum Property {
786+ // / zeroinitializer is valid for this target extension type.
787+ HasZeroInit = 1U << 0 ,
788+ // / This type may be used as the value type of a global variable.
789+ CanBeGlobal = 1U << 1 ,
790+ };
791+
792+ // / Returns true if the target extension type contains the given property.
793+ bool hasProperty (Property Prop) const ;
794+
795+ // / Returns an underlying layout type for the target extension type. This
796+ // / type can be used to query size and alignment information, if it is
797+ // / appropriate (although note that the layout type may also be void). It is
798+ // / not legal to bitcast between this type and the layout type, however.
799+ Type *getLayoutType () const ;
800+
801+ // / Methods for support type inquiry through isa, cast, and dyn_cast.
802+ static bool classof (const Type *T) { return T->getTypeID () == TargetExtTyID; }
803+ };
804+
805+ StringRef Type::getTargetExtName () const {
806+ return cast<TargetExtType>(this )->getName ();
807+ }
808+
733809} // end namespace llvm
734810
735811#endif // LLVM_IR_DERIVEDTYPES_H
0 commit comments