[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.
This revision was automatically updated to reflect the committed changes. Closed by commit rL337036: PR15730/PR16986 Allow dependently typed vector_size types. (authored by erichkeane, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D49045?vs=155419=155462#toc Repository: rL LLVM https://reviews.llvm.org/D49045 Files: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/include/clang/AST/RecursiveASTVisitor.h cfe/trunk/include/clang/AST/Type.h cfe/trunk/include/clang/AST/TypeLoc.h cfe/trunk/include/clang/AST/TypeNodes.def cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/include/clang/Serialization/ASTBitCodes.h cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/AST/ASTStructuralEquivalence.cpp cfe/trunk/lib/AST/ItaniumMangle.cpp cfe/trunk/lib/AST/MicrosoftMangle.cpp cfe/trunk/lib/AST/Type.cpp cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/lib/Lex/LiteralSupport.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/test/SemaCXX/vector.cpp cfe/trunk/tools/libclang/CIndex.cpp Index: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h === --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h @@ -993,6 +993,12 @@ TRY_TO(TraverseType(T->getPointeeType())); }) +DEF_TRAVERSE_TYPE(DependentVectorType, { + if (T->getSizeExpr()) +TRY_TO(TraverseStmt(T->getSizeExpr())); + TRY_TO(TraverseType(T->getElementType())); +}) + DEF_TRAVERSE_TYPE(DependentSizedExtVectorType, { if (T->getSizeExpr()) TRY_TO(TraverseStmt(T->getSizeExpr())); @@ -1221,6 +1227,12 @@ TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); }) +DEF_TRAVERSE_TYPELOC(DependentVectorType, { + if (TL.getTypePtr()->getSizeExpr()) +TRY_TO(TraverseStmt(TL.getTypePtr()->getSizeExpr())); + TRY_TO(TraverseType(TL.getTypePtr()->getElementType())); +}) + // FIXME: size and attributes // FIXME: base VectorTypeLoc is unfinished DEF_TRAVERSE_TYPELOC(ExtVectorType, { Index: cfe/trunk/include/clang/AST/ASTContext.h === --- cfe/trunk/include/clang/AST/ASTContext.h +++ cfe/trunk/include/clang/AST/ASTContext.h @@ -168,6 +168,7 @@ mutable llvm::FoldingSet DependentAddressSpaceTypes; mutable llvm::FoldingSet VectorTypes; + mutable llvm::FoldingSet DependentVectorTypes; mutable llvm::FoldingSet FunctionNoProtoTypes; mutable llvm::ContextualFoldingSet FunctionProtoTypes; @@ -1321,6 +1322,11 @@ /// \pre \p VectorType must be a built-in type. QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const; + /// Return the unique reference to the type for a dependently sized vector of + /// the specified element type. + QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr, + SourceLocation AttrLoc, + VectorType::VectorKind VecKind) const; /// Return the unique reference to an extended vector type /// of the specified element type and size. Index: cfe/trunk/include/clang/AST/TypeNodes.def === --- cfe/trunk/include/clang/AST/TypeNodes.def +++ cfe/trunk/include/clang/AST/TypeNodes.def @@ -75,6 +75,7 @@ DEPENDENT_TYPE(DependentSizedExtVector, Type) DEPENDENT_TYPE(DependentAddressSpace, Type) TYPE(Vector, Type) +DEPENDENT_TYPE(DependentVector, Type) TYPE(ExtVector, VectorType) ABSTRACT_TYPE(Function, Type) TYPE(FunctionProto, FunctionType) Index: cfe/trunk/include/clang/AST/Type.h === --- cfe/trunk/include/clang/AST/Type.h +++ cfe/trunk/include/clang/AST/Type.h @@ -1590,6 +1590,7 @@ class VectorTypeBitfields { friend class VectorType; +friend class DependentVectorType; unsigned : NumTypeBits; @@ -3079,6 +3080,51 @@ } }; +/// Represents a vector type where either the type or size is dependent. + +/// For example: +/// \code +/// template +/// class vector { +/// typedef T __attribute__((vector_size(Size))) type; +/// } +/// \endcode +class DependentVectorType : public Type, public llvm::FoldingSetNode { + friend class ASTContext; + + const ASTContext + QualType ElementType; + Expr *SizeExpr; + SourceLocation Loc; + + DependentVectorType(const ASTContext , QualType ElementType, + QualType CanonType, Expr *SizeExpr, + SourceLocation Loc, VectorType::VectorKind vecKind); + +public: + Expr *getSizeExpr() const { return SizeExpr; } + QualType getElementType() const { return
[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM, though it's your call on the const_cast stuff whether you want to revert or keep it. Comment at: include/clang/AST/Type.h:3105 +public: + Expr *getSizeExpr() const { return SizeExpr; } + QualType getElementType() const { return ElementType; } erichkeane wrote: > aaron.ballman wrote: > > Can this return `const Expr *` and have a non-const overload to return the > > non-const `Expr *`? > Done, but unfortunately, TypeLoc visitation (RecursiveASTVisitor) lacks const > correctness in a bunch of places so a cast was required there :/ > Additionally, TreeTransform has similar issues, so a const-cast was required > as well. Both end up being a bit of a cleanup, perhaps more than I can > tackle at the moment. Oye, now that I see how many const_cast's get added, I'm starting to regret asking for this. :-P Your call as to whether you want to leave it in this state or revert back the const-correctness attempt. https://reviews.llvm.org/D49045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.
erichkeane added inline comments. Comment at: include/clang/AST/ASTContext.h:1327-1329 + QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr, + SourceLocation AttrLoc, + VectorType::VectorKind VecKind) const; aaron.ballman wrote: > The formatting looks off here. Did clang-format do this? It DID, then I renamed it and forgot to rerun :/ Comment at: include/clang/AST/Type.h:3105 +public: + Expr *getSizeExpr() const { return SizeExpr; } + QualType getElementType() const { return ElementType; } aaron.ballman wrote: > Can this return `const Expr *` and have a non-const overload to return the > non-const `Expr *`? Done, but unfortunately, TypeLoc visitation (RecursiveASTVisitor) lacks const correctness in a bunch of places so a cast was required there :/ Additionally, TreeTransform has similar issues, so a const-cast was required as well. Both end up being a bit of a cleanup, perhaps more than I can tackle at the moment. Comment at: lib/AST/ItaniumMangle.cpp:3007-3008 +void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) { + llvm_unreachable( + "Mangling for Dependent Sized Neon Vector not yet implemented"); +} aaron.ballman wrote: > This seems reachable. I don't think it IS actually (since we never create one of these), but point made :) https://reviews.llvm.org/D49045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.
erichkeane updated this revision to Diff 155419. erichkeane marked 12 inline comments as done. https://reviews.llvm.org/D49045 Files: include/clang/AST/ASTContext.h include/clang/AST/RecursiveASTVisitor.h include/clang/AST/Type.h include/clang/AST/TypeLoc.h include/clang/AST/TypeNodes.def include/clang/Sema/Sema.h include/clang/Serialization/ASTBitCodes.h lib/AST/ASTContext.cpp lib/AST/ASTStructuralEquivalence.cpp lib/AST/ItaniumMangle.cpp lib/AST/MicrosoftMangle.cpp lib/AST/Type.cpp lib/AST/TypePrinter.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaType.cpp lib/Sema/TreeTransform.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp test/SemaCXX/vector.cpp tools/libclang/CIndex.cpp Index: lib/Serialization/ASTWriter.cpp === --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -455,6 +455,14 @@ Code = TYPE_DEPENDENT_SIZED_EXT_VECTOR; } +void ASTTypeWriter::VisitDependentVectorType(const DependentVectorType *T) { + Record.AddTypeRef(T->getElementType()); + Record.AddStmt(const_cast(T->getSizeExpr())); + Record.AddSourceLocation(T->getAttributeLoc()); + Record.push_back(T->getVectorKind()); + Code = TYPE_DEPENDENT_SIZED_VECTOR; +} + void ASTTypeWriter::VisitDependentAddressSpaceType( const DependentAddressSpaceType *T) { @@ -676,6 +684,11 @@ Record.AddSourceLocation(TL.getNameLoc()); } +void TypeLocWriter::VisitDependentVectorTypeLoc( +DependentVectorTypeLoc TL) { + Record.AddSourceLocation(TL.getNameLoc()); +} + void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } Index: lib/Serialization/ASTReader.cpp === --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -6369,6 +6369,17 @@ return Context.getPipeType(ElementType, ReadOnly); } + case TYPE_DEPENDENT_SIZED_VECTOR: { +unsigned Idx = 0; +QualType ElementType = readType(*Loc.F, Record, Idx); +Expr *SizeExpr = ReadExpr(*Loc.F); +SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); +unsigned VecKind = Record[Idx]; + +return Context.getDependentVectorType(ElementType, SizeExpr, AttrLoc, + (VectorType::VectorKind)VecKind); + } + case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { unsigned Idx = 0; @@ -6549,6 +6560,11 @@ TL.setNameLoc(ReadSourceLocation()); } +void TypeLocReader::VisitDependentVectorTypeLoc( +DependentVectorTypeLoc TL) { + TL.setNameLoc(ReadSourceLocation()); +} + void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation()); } Index: lib/AST/ASTStructuralEquivalence.cpp === --- lib/AST/ASTStructuralEquivalence.cpp +++ lib/AST/ASTStructuralEquivalence.cpp @@ -51,7 +51,7 @@ /// Determine structural equivalence of two expressions. static bool IsStructurallyEquivalent(StructuralEquivalenceContext , - Expr *E1, Expr *E2) { + const Expr *E1, const Expr *E2) { if (!E1 || !E2) return E1 == E2; @@ -408,6 +408,20 @@ break; } + case Type::DependentVector: { +const auto *Vec1 = cast(T1); +const auto *Vec2 = cast(T2); +if (Vec1->getVectorKind() != Vec2->getVectorKind()) + return false; +if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(), + Vec2->getSizeExpr())) + return false; +if (!IsStructurallyEquivalent(Context, Vec1->getElementType(), + Vec2->getElementType())) + return false; +break; + } + case Type::Vector: case Type::ExtVector: { const auto *Vec1 = cast(T1); Index: lib/AST/ItaniumMangle.cpp === --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -539,7 +539,9 @@ void mangleBareFunctionType(const FunctionProtoType *T, bool MangleReturnType, const FunctionDecl *FD = nullptr); void mangleNeonVectorType(const VectorType *T); + void mangleNeonVectorType(const DependentVectorType *T); void mangleAArch64NeonVectorType(const VectorType *T); + void mangleAArch64NeonVectorType(const DependentVectorType *T); void mangleIntegerLiteral(QualType T, const llvm::APSInt ); void mangleMemberExprBase(const Expr *base, bool isArrow); @@ -1930,6 +1932,7 @@ case Type::VariableArray: case Type::DependentSizedArray: case Type::DependentAddressSpace: + case Type::DependentVector: case Type::DependentSizedExtVector: case Type::Vector: case Type::ExtVector: @@ -3000,6 +3003,14 @@ Out << BaseName << EltName; } +void CXXNameMangler::mangleNeonVectorType(const
[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.
aaron.ballman added inline comments. Comment at: include/clang/AST/ASTContext.h:1327-1329 + QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr, + SourceLocation AttrLoc, + VectorType::VectorKind VecKind) const; The formatting looks off here. Did clang-format do this? Comment at: include/clang/AST/Type.h:3083 +/// Represents a vector type where either the type or sizeis dependent. + sizeis -> size is Comment at: include/clang/AST/Type.h:3105 +public: + Expr *getSizeExpr() const { return SizeExpr; } + QualType getElementType() const { return ElementType; } Can this return `const Expr *` and have a non-const overload to return the non-const `Expr *`? Comment at: lib/AST/ASTContext.cpp:3316 } +QualType +ASTContext::getDependentVectorType(QualType VecType, Expr *SizeExpr, Insert a newline above, and reformat. Comment at: lib/AST/ItaniumMangle.cpp:3007-3008 +void CXXNameMangler::mangleNeonVectorType(const DependentVectorType *T) { + llvm_unreachable( + "Mangling for Dependent Sized Neon Vector not yet implemented"); +} This seems reachable. Comment at: lib/AST/ItaniumMangle.cpp:3080 +const DependentVectorType *T) { + llvm_unreachable( + "Mangling for Dependent Sized AArch64 Neon Vector not yet implemented"); As does this. Comment at: lib/AST/Type.cpp:192 + +void DependentVectorType::Profile(llvm::FoldingSetNodeID , + const ASTContext , Formatting? Also, does this need to take the `VecKind`? Comment at: lib/Sema/SemaTemplateDeduction.cpp:1841 +case Type::DependentVector: { + const DependentVectorType *VectorParam = + cast(Param); Can use `const auto *` here. Comment at: lib/Sema/SemaTemplateDeduction.cpp:1844 + + if (const VectorType *VectorArg = dyn_cast(Arg)) { +// Perform deduction on the element types. Here too. Comment at: lib/Sema/SemaTemplateDeduction.cpp:1864 +return DeduceNonTypeTemplateArgument(S, TemplateParams, NTTP, ArgSize, + S.Context.IntTy, true, Info, + Deduced); Can the size ever be negative? Perhaps an unsigned type would be better than a signed type? Comment at: lib/Sema/SemaTemplateDeduction.cpp:1868 + + if (const DependentVectorType *VectorArg = + dyn_cast(Arg)) { `const auto *` Comment at: lib/Sema/SemaTemplateDeduction.cpp:5281 + case Type::DependentVector: { +const DependentVectorType *VecType = cast(T); +MarkUsedTemplateParameters(Ctx, VecType->getElementType(), OnlyDeduced, `const auto *` https://reviews.llvm.org/D49045 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D49045: PR15730/PR16986 Allow dependently typed vector_size types.
erichkeane created this revision. erichkeane added reviewers: rsmith, aaron.ballman, mibintc, mikerice, Manna. As listed in the above PRs, vector_size doesn't allow dependent types/values. This patch introduces a new DependentVectorType to handle a VectorType that has a dependent size or type. In the future, ALL the vector-types should be able to create one of these to handle dependent types/sizes as well. For example, DependentSizedExtVectorType could likely be switched to just use this instead, though that is left as an exercise for the future. https://reviews.llvm.org/D49045 Files: include/clang/AST/ASTContext.h include/clang/AST/RecursiveASTVisitor.h include/clang/AST/Type.h include/clang/AST/TypeLoc.h include/clang/AST/TypeNodes.def include/clang/Sema/Sema.h include/clang/Serialization/ASTBitCodes.h lib/AST/ASTContext.cpp lib/AST/ASTStructuralEquivalence.cpp lib/AST/ItaniumMangle.cpp lib/AST/MicrosoftMangle.cpp lib/AST/Type.cpp lib/AST/TypePrinter.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaType.cpp lib/Sema/TreeTransform.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp test/SemaCXX/vector.cpp tools/libclang/CIndex.cpp Index: lib/Serialization/ASTWriter.cpp === --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -454,6 +454,15 @@ Code = TYPE_DEPENDENT_SIZED_EXT_VECTOR; } +void ASTTypeWriter::VisitDependentVectorType( +const DependentVectorType *T) { + Record.AddTypeRef(T->getElementType()); + Record.AddStmt(T->getSizeExpr()); + Record.AddSourceLocation(T->getAttributeLoc()); + Record.push_back(T->getVectorKind()); + Code = TYPE_DEPENDENT_SIZED_VECTOR; +} + void ASTTypeWriter::VisitDependentAddressSpaceType( const DependentAddressSpaceType *T) { @@ -675,6 +684,11 @@ Record.AddSourceLocation(TL.getNameLoc()); } +void TypeLocWriter::VisitDependentVectorTypeLoc( +DependentVectorTypeLoc TL) { + Record.AddSourceLocation(TL.getNameLoc()); +} + void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { Record.AddSourceLocation(TL.getNameLoc()); } Index: lib/Serialization/ASTReader.cpp === --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -6369,6 +6369,17 @@ return Context.getPipeType(ElementType, ReadOnly); } + case TYPE_DEPENDENT_SIZED_VECTOR: { +unsigned Idx = 0; +QualType ElementType = readType(*Loc.F, Record, Idx); +Expr *SizeExpr = ReadExpr(*Loc.F); +SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); +unsigned VecKind = Record[Idx]; + +return Context.getDependentVectorType(ElementType, SizeExpr, AttrLoc, + (VectorType::VectorKind)VecKind); + } + case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { unsigned Idx = 0; @@ -6549,6 +6560,11 @@ TL.setNameLoc(ReadSourceLocation()); } +void TypeLocReader::VisitDependentVectorTypeLoc( +DependentVectorTypeLoc TL) { + TL.setNameLoc(ReadSourceLocation()); +} + void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { TL.setNameLoc(ReadSourceLocation()); } Index: lib/AST/ASTStructuralEquivalence.cpp === --- lib/AST/ASTStructuralEquivalence.cpp +++ lib/AST/ASTStructuralEquivalence.cpp @@ -405,6 +405,20 @@ break; } + case Type::DependentVector: { +const auto *Vec1 = cast(T1); +const auto *Vec2 = cast(T2); +if (Vec1->getVectorKind() != Vec2->getVectorKind()) + return false; +if (!IsStructurallyEquivalent(Context, Vec1->getSizeExpr(), + Vec2->getSizeExpr())) + return false; +if (!IsStructurallyEquivalent(Context, Vec1->getElementType(), + Vec2->getElementType())) + return false; +break; + } + case Type::Vector: case Type::ExtVector: { const auto *Vec1 = cast(T1); Index: lib/AST/ItaniumMangle.cpp === --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -539,7 +539,9 @@ void mangleBareFunctionType(const FunctionProtoType *T, bool MangleReturnType, const FunctionDecl *FD = nullptr); void mangleNeonVectorType(const VectorType *T); + void mangleNeonVectorType(const DependentVectorType *T); void mangleAArch64NeonVectorType(const VectorType *T); + void mangleAArch64NeonVectorType(const DependentVectorType *T); void mangleIntegerLiteral(QualType T, const llvm::APSInt ); void mangleMemberExprBase(const Expr *base, bool isArrow); @@ -1930,6 +1932,7 @@ case Type::VariableArray: case Type::DependentSizedArray: case Type::DependentAddressSpace: + case Type::DependentVector: case Type::DependentSizedExtVector: case