[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
frasercrmck added a comment. LGTM too. Though the commit title and message has hyphens in places I wouldn't expect them. `macros` and `builtins` is fine. Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:797 // Init RISC-V extensions for (const auto &T : OutInTypes) { nit: This still says "extensions" Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
craig.topper accepted this revision. craig.topper added a comment. This revision is now accepted and ready to land. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
eopXD updated this revision to Diff 402036. eopXD marked an inline comment as done. eopXD added a comment. Cleanup unused enum. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 Files: clang/utils/TableGen/RISCVVEmitter.cpp Index: clang/utils/TableGen/RISCVVEmitter.cpp === --- clang/utils/TableGen/RISCVVEmitter.cpp +++ clang/utils/TableGen/RISCVVEmitter.cpp @@ -100,6 +100,9 @@ bool isValid() const { return Valid; } bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; } bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; } + bool isVector(unsigned Width) const { +return isVector() && ElementBitwidth == Width; + } bool isFloat() const { return ScalarType == ScalarTypeKind::Float; } bool isSignedInteger() const { return ScalarType == ScalarTypeKind::SignedInteger; @@ -134,13 +137,15 @@ using RVVTypePtr = RVVType *; using RVVTypes = std::vector; +using RISCVPredefinedMacroT = uint8_t; -enum RISCVExtension : uint8_t { +enum RISCVPredefinedMacro : RISCVPredefinedMacroT { Basic = 0, - F = 1 << 1, - D = 1 << 2, - Zfh = 1 << 3, - RV64 = 1 << 4, + Zfh = 1 << 1, + RV64 = 1 << 2, + VectorMaxELen64 = 1 << 3, + VectorMaxELenFp32 = 1 << 4, + VectorMaxELenFp64 = 1 << 5, }; // TODO refactor RVVIntrinsic class design after support all intrinsic @@ -164,7 +169,7 @@ // The types we use to obtain the specific LLVM intrinsic. They are index of // InputTypes. -1 means the return type. std::vector IntrinsicTypes; - uint8_t RISCVExtensions = 0; + RISCVPredefinedMacroT RISCVPredefinedMacros = 0; unsigned NF = 1; public: @@ -188,7 +193,9 @@ bool isMask() const { return IsMask; } StringRef getIRName() const { return IRName; } StringRef getManualCodegen() const { return ManualCodegen; } - uint8_t getRISCVExtensions() const { return RISCVExtensions; } + RISCVPredefinedMacroT getRISCVPredefinedMacros() const { +return RISCVPredefinedMacros; + } unsigned getNF() const { return NF; } const std::vector &getIntrinsicTypes() const { return IntrinsicTypes; @@ -251,7 +258,8 @@ // Emit the architecture preprocessor definitions. Return true when emits // non-empty string. - bool emitExtDefStr(uint8_t Extensions, raw_ostream &o); + bool emitMacroRestrictionStr(RISCVPredefinedMacroT PredefinedMacros, + raw_ostream &o); // Slice Prototypes string into sub prototype string and process each sub // prototype string individually in the Handler. void parsePrototypes(StringRef Prototypes, @@ -789,15 +797,17 @@ // Init RISC-V extensions for (const auto &T : OutInTypes) { if (T->isFloatVector(16) || T->isFloat(16)) - RISCVExtensions |= RISCVExtension::Zfh; -else if (T->isFloatVector(32) || T->isFloat(32)) - RISCVExtensions |= RISCVExtension::F; -else if (T->isFloatVector(64) || T->isFloat(64)) - RISCVExtensions |= RISCVExtension::D; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; +if (T->isFloatVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp32; +if (T->isFloatVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp64; +if (T->isVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen64; } for (auto Extension : RequiredExtensions) { if (Extension == "RV64") - RISCVExtensions |= RISCVExtension::RV64; + RISCVPredefinedMacros |= RISCVPredefinedMacro::RV64; } // Init OutputType and InputTypes @@ -981,7 +991,7 @@ // The same extension include in the same arch guard marco. llvm::stable_sort(Defs, [](const std::unique_ptr &A, const std::unique_ptr &B) { -return A->getRISCVExtensions() < B->getRISCVExtensions(); +return A->getRISCVPredefinedMacros() < B->getRISCVPredefinedMacros(); }); OS << "#define __rvv_ai static __inline__\n"; @@ -1280,15 +1290,16 @@ void RVVEmitter::emitArchMacroAndBody( std::vector> &Defs, raw_ostream &OS, std::function PrintBody) { - uint8_t PrevExt = (*Defs.begin())->getRISCVExtensions(); - bool NeedEndif = emitExtDefStr(PrevExt, OS); + RISCVPredefinedMacroT PrevMacros = + (*Defs.begin())->getRISCVPredefinedMacros(); + bool NeedEndif = emitMacroRestrictionStr(PrevMacros, OS); for (auto &Def : Defs) { -uint8_t CurExt = Def->getRISCVExtensions(); -if (CurExt != PrevExt) { +RISCVPredefinedMacroT CurMacros = Def->getRISCVPredefinedMacros(); +if (CurMacros != PrevMacros) { if (NeedEndif) OS << "#endif\n\n"; - NeedEndif = emitExtDefStr(CurExt, OS); - PrevExt = CurExt; + NeedEndif = emitMacroRestrictionStr(CurMacros, OS); + PrevMacros = CurMacros; } if (Def->hasAutoDef()) PrintBody(OS, *Def); @@ -1297,19
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
craig.topper added inline comments. Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:144 Basic = 0, F = 1 << 1, D = 1 << 2, Drop F and D here? Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:1319 ListSeparator LS(" && "); - if (Extents & RISCVExtension::F) + if (PredefinedMacros & RISCVPredefinedMacro::F) OS << LS << "defined(__riscv_f)"; Drop F and D here Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
eopXD updated this revision to Diff 401870. eopXD added a comment. Follow clang-format. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 Files: clang/utils/TableGen/RISCVVEmitter.cpp Index: clang/utils/TableGen/RISCVVEmitter.cpp === --- clang/utils/TableGen/RISCVVEmitter.cpp +++ clang/utils/TableGen/RISCVVEmitter.cpp @@ -100,6 +100,9 @@ bool isValid() const { return Valid; } bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; } bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; } + bool isVector(unsigned Width) const { +return isVector() && ElementBitwidth == Width; + } bool isFloat() const { return ScalarType == ScalarTypeKind::Float; } bool isSignedInteger() const { return ScalarType == ScalarTypeKind::SignedInteger; @@ -134,13 +137,17 @@ using RVVTypePtr = RVVType *; using RVVTypes = std::vector; +using RISCVPredefinedMacroT = uint8_t; -enum RISCVExtension : uint8_t { +enum RISCVPredefinedMacro : RISCVPredefinedMacroT { Basic = 0, F = 1 << 1, D = 1 << 2, Zfh = 1 << 3, RV64 = 1 << 4, + VectorMaxELen64 = 1 << 5, + VectorMaxELenFp32 = 1 << 6, + VectorMaxELenFp64 = 1 << 7, }; // TODO refactor RVVIntrinsic class design after support all intrinsic @@ -164,7 +171,7 @@ // The types we use to obtain the specific LLVM intrinsic. They are index of // InputTypes. -1 means the return type. std::vector IntrinsicTypes; - uint8_t RISCVExtensions = 0; + RISCVPredefinedMacroT RISCVPredefinedMacros = 0; unsigned NF = 1; public: @@ -188,7 +195,9 @@ bool isMask() const { return IsMask; } StringRef getIRName() const { return IRName; } StringRef getManualCodegen() const { return ManualCodegen; } - uint8_t getRISCVExtensions() const { return RISCVExtensions; } + RISCVPredefinedMacroT getRISCVPredefinedMacros() const { +return RISCVPredefinedMacros; + } unsigned getNF() const { return NF; } const std::vector &getIntrinsicTypes() const { return IntrinsicTypes; @@ -251,7 +260,8 @@ // Emit the architecture preprocessor definitions. Return true when emits // non-empty string. - bool emitExtDefStr(uint8_t Extensions, raw_ostream &o); + bool emitMacroRestrictionStr(RISCVPredefinedMacroT PredefinedMacros, + raw_ostream &o); // Slice Prototypes string into sub prototype string and process each sub // prototype string individually in the Handler. void parsePrototypes(StringRef Prototypes, @@ -789,15 +799,17 @@ // Init RISC-V extensions for (const auto &T : OutInTypes) { if (T->isFloatVector(16) || T->isFloat(16)) - RISCVExtensions |= RISCVExtension::Zfh; -else if (T->isFloatVector(32) || T->isFloat(32)) - RISCVExtensions |= RISCVExtension::F; -else if (T->isFloatVector(64) || T->isFloat(64)) - RISCVExtensions |= RISCVExtension::D; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; +if (T->isFloatVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp32; +if (T->isFloatVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp64; +if (T->isVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen64; } for (auto Extension : RequiredExtensions) { if (Extension == "RV64") - RISCVExtensions |= RISCVExtension::RV64; + RISCVPredefinedMacros |= RISCVPredefinedMacro::RV64; } // Init OutputType and InputTypes @@ -981,7 +993,7 @@ // The same extension include in the same arch guard marco. llvm::stable_sort(Defs, [](const std::unique_ptr &A, const std::unique_ptr &B) { -return A->getRISCVExtensions() < B->getRISCVExtensions(); +return A->getRISCVPredefinedMacros() < B->getRISCVPredefinedMacros(); }); OS << "#define __rvv_ai static __inline__\n"; @@ -1280,15 +1292,16 @@ void RVVEmitter::emitArchMacroAndBody( std::vector> &Defs, raw_ostream &OS, std::function PrintBody) { - uint8_t PrevExt = (*Defs.begin())->getRISCVExtensions(); - bool NeedEndif = emitExtDefStr(PrevExt, OS); + RISCVPredefinedMacroT PrevMacros = + (*Defs.begin())->getRISCVPredefinedMacros(); + bool NeedEndif = emitMacroRestrictionStr(PrevMacros, OS); for (auto &Def : Defs) { -uint8_t CurExt = Def->getRISCVExtensions(); -if (CurExt != PrevExt) { +RISCVPredefinedMacroT CurMacros = Def->getRISCVPredefinedMacros(); +if (CurMacros != PrevMacros) { if (NeedEndif) OS << "#endif\n\n"; - NeedEndif = emitExtDefStr(CurExt, OS); - PrevExt = CurExt; + NeedEndif = emitMacroRestrictionStr(CurMacros, OS); + PrevMacros = CurMacros; } if (Def->hasAutoDef()) PrintBody(OS, *Def); @@ -1297,19 +1310,26 @@ OS << "#endif\n\n"; } -bool RVVEmitter::emitExtDefStr(
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
eopXD added inline comments. Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:149 RV64 = 1 << 5, + VectorMaxELen32 = 1 << 6, + VectorMaxELen64 = 1 << 7, craig.topper wrote: > Do we need VectorMaxELen32 isn't that the minimum? Yes you are correct. We don't need it. Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:804 + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; else if (T->isFloatVector(32) || T->isFloat(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::F; craig.topper wrote: > Can D and F go away? Done. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
eopXD updated this revision to Diff 401862. eopXD marked 2 inline comments as done. eopXD added a comment. Rebase and addres comments. Resolve conflcits due to zvlsseg removal. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 Files: clang/utils/TableGen/RISCVVEmitter.cpp Index: clang/utils/TableGen/RISCVVEmitter.cpp === --- clang/utils/TableGen/RISCVVEmitter.cpp +++ clang/utils/TableGen/RISCVVEmitter.cpp @@ -100,6 +100,9 @@ bool isValid() const { return Valid; } bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; } bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; } + bool isVector(unsigned Width) const { +return isVector() && ElementBitwidth == Width; + } bool isFloat() const { return ScalarType == ScalarTypeKind::Float; } bool isSignedInteger() const { return ScalarType == ScalarTypeKind::SignedInteger; @@ -134,13 +137,17 @@ using RVVTypePtr = RVVType *; using RVVTypes = std::vector; +using RISCVPredefinedMacroT = uint8_t; -enum RISCVExtension : uint8_t { +enum RISCVPredefinedMacro : RISCVPredefinedMacroT { Basic = 0, F = 1 << 1, D = 1 << 2, Zfh = 1 << 3, RV64 = 1 << 4, + VectorMaxELen64 = 1 << 5, + VectorMaxELenFp32 = 1 << 6, + VectorMaxELenFp64 = 1 << 7, }; // TODO refactor RVVIntrinsic class design after support all intrinsic @@ -164,7 +171,7 @@ // The types we use to obtain the specific LLVM intrinsic. They are index of // InputTypes. -1 means the return type. std::vector IntrinsicTypes; - uint8_t RISCVExtensions = 0; + RISCVPredefinedMacroT RISCVPredefinedMacros = 0; unsigned NF = 1; public: @@ -188,7 +195,9 @@ bool isMask() const { return IsMask; } StringRef getIRName() const { return IRName; } StringRef getManualCodegen() const { return ManualCodegen; } - uint8_t getRISCVExtensions() const { return RISCVExtensions; } + RISCVPredefinedMacroT getRISCVPredefinedMacros() const { +return RISCVPredefinedMacros; + } unsigned getNF() const { return NF; } const std::vector &getIntrinsicTypes() const { return IntrinsicTypes; @@ -251,7 +260,7 @@ // Emit the architecture preprocessor definitions. Return true when emits // non-empty string. - bool emitExtDefStr(uint8_t Extensions, raw_ostream &o); + bool emitMacroRestrictionStr(RISCVPredefinedMacroT PredefinedMacros, raw_ostream &o); // Slice Prototypes string into sub prototype string and process each sub // prototype string individually in the Handler. void parsePrototypes(StringRef Prototypes, @@ -789,15 +798,17 @@ // Init RISC-V extensions for (const auto &T : OutInTypes) { if (T->isFloatVector(16) || T->isFloat(16)) - RISCVExtensions |= RISCVExtension::Zfh; -else if (T->isFloatVector(32) || T->isFloat(32)) - RISCVExtensions |= RISCVExtension::F; -else if (T->isFloatVector(64) || T->isFloat(64)) - RISCVExtensions |= RISCVExtension::D; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; +if (T->isFloatVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp32; +if (T->isFloatVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp64; +if (T->isVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen64; } for (auto Extension : RequiredExtensions) { if (Extension == "RV64") - RISCVExtensions |= RISCVExtension::RV64; + RISCVPredefinedMacros |= RISCVPredefinedMacro::RV64; } // Init OutputType and InputTypes @@ -981,7 +992,7 @@ // The same extension include in the same arch guard marco. llvm::stable_sort(Defs, [](const std::unique_ptr &A, const std::unique_ptr &B) { -return A->getRISCVExtensions() < B->getRISCVExtensions(); +return A->getRISCVPredefinedMacros() < B->getRISCVPredefinedMacros(); }); OS << "#define __rvv_ai static __inline__\n"; @@ -1280,15 +1291,15 @@ void RVVEmitter::emitArchMacroAndBody( std::vector> &Defs, raw_ostream &OS, std::function PrintBody) { - uint8_t PrevExt = (*Defs.begin())->getRISCVExtensions(); - bool NeedEndif = emitExtDefStr(PrevExt, OS); + RISCVPredefinedMacroT PrevMacros = (*Defs.begin())->getRISCVPredefinedMacros(); + bool NeedEndif = emitMacroRestrictionStr(PrevMacros, OS); for (auto &Def : Defs) { -uint8_t CurExt = Def->getRISCVExtensions(); -if (CurExt != PrevExt) { +RISCVPredefinedMacroT CurMacros = Def->getRISCVPredefinedMacros(); +if (CurMacros != PrevMacros) { if (NeedEndif) OS << "#endif\n\n"; - NeedEndif = emitExtDefStr(CurExt, OS); - PrevExt = CurExt; + NeedEndif = emitMacroRestrictionStr(CurMacros, OS); + PrevMacros = CurMacros; } if (Def->hasAutoDef()) PrintBody(OS, *Def); @@ -1297,19 +1308,26 @@ OS << "
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
craig.topper added inline comments. Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:149 RV64 = 1 << 5, + VectorMaxELen32 = 1 << 6, + VectorMaxELen64 = 1 << 7, Do we need VectorMaxELen32 isn't that the minimum? Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:804 + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; else if (T->isFloatVector(32) || T->isFloat(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::F; Can D and F go away? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
eopXD updated this revision to Diff 401687. eopXD added a comment. Update code. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 Files: clang/utils/TableGen/RISCVVEmitter.cpp Index: clang/utils/TableGen/RISCVVEmitter.cpp === --- clang/utils/TableGen/RISCVVEmitter.cpp +++ clang/utils/TableGen/RISCVVEmitter.cpp @@ -100,6 +100,9 @@ bool isValid() const { return Valid; } bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; } bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; } + bool isVector(unsigned Width) const { +return isVector() && ElementBitwidth == Width; + } bool isFloat() const { return ScalarType == ScalarTypeKind::Float; } bool isSignedInteger() const { return ScalarType == ScalarTypeKind::SignedInteger; @@ -134,14 +137,19 @@ using RVVTypePtr = RVVType *; using RVVTypes = std::vector; +using RISCVPredefinedMacroT = uint16_t; -enum RISCVExtension : uint8_t { +enum RISCVPredefinedMacro : uint16_t { Basic = 0, F = 1 << 1, D = 1 << 2, Zfh = 1 << 3, Zvlsseg = 1 << 4, RV64 = 1 << 5, + VectorMaxELen32 = 1 << 6, + VectorMaxELen64 = 1 << 7, + VectorMaxELenFp32 = 1 << 8, + VectorMaxELenFp64 = 1 << 9, }; // TODO refactor RVVIntrinsic class design after support all intrinsic @@ -165,7 +173,7 @@ // The types we use to obtain the specific LLVM intrinsic. They are index of // InputTypes. -1 means the return type. std::vector IntrinsicTypes; - uint8_t RISCVExtensions = 0; + RISCVPredefinedMacroT RISCVPredefinedMacros = 0; unsigned NF = 1; public: @@ -189,7 +197,9 @@ bool isMask() const { return IsMask; } StringRef getIRName() const { return IRName; } StringRef getManualCodegen() const { return ManualCodegen; } - uint8_t getRISCVExtensions() const { return RISCVExtensions; } + RISCVPredefinedMacroT getRISCVPredefinedMacros() const { +return RISCVPredefinedMacros; + } unsigned getNF() const { return NF; } const std::vector &getIntrinsicTypes() const { return IntrinsicTypes; @@ -252,7 +262,7 @@ // Emit the architecture preprocessor definitions. Return true when emits // non-empty string. - bool emitExtDefStr(uint8_t Extensions, raw_ostream &o); + bool emitMacroRestrictionStr(RISCVPredefinedMacroT PredefinedMacros, raw_ostream &o); // Slice Prototypes string into sub prototype string and process each sub // prototype string individually in the Handler. void parsePrototypes(StringRef Prototypes, @@ -790,17 +800,26 @@ // Init RISC-V extensions for (const auto &T : OutInTypes) { if (T->isFloatVector(16) || T->isFloat(16)) - RISCVExtensions |= RISCVExtension::Zfh; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; else if (T->isFloatVector(32) || T->isFloat(32)) - RISCVExtensions |= RISCVExtension::F; + RISCVPredefinedMacros |= RISCVPredefinedMacro::F; else if (T->isFloatVector(64) || T->isFloat(64)) - RISCVExtensions |= RISCVExtension::D; + RISCVPredefinedMacros |= RISCVPredefinedMacro::D; + +if (T->isVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen32; +else if (T->isVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen64; +if (T->isFloatVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp32; +else if (T->isFloatVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp64; } for (auto Extension : RequiredExtensions) { if (Extension == "Zvlsseg") - RISCVExtensions |= RISCVExtension::Zvlsseg; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zvlsseg; if (Extension == "RV64") - RISCVExtensions |= RISCVExtension::RV64; + RISCVPredefinedMacros |= RISCVPredefinedMacro::RV64; } // Init OutputType and InputTypes @@ -984,7 +1003,7 @@ // The same extension include in the same arch guard marco. llvm::stable_sort(Defs, [](const std::unique_ptr &A, const std::unique_ptr &B) { -return A->getRISCVExtensions() < B->getRISCVExtensions(); +return A->getRISCVPredefinedMacros() < B->getRISCVPredefinedMacros(); }); OS << "#define __rvv_ai static __inline__\n"; @@ -1283,15 +1302,15 @@ void RVVEmitter::emitArchMacroAndBody( std::vector> &Defs, raw_ostream &OS, std::function PrintBody) { - uint8_t PrevExt = (*Defs.begin())->getRISCVExtensions(); - bool NeedEndif = emitExtDefStr(PrevExt, OS); + RISCVPredefinedMacroT PrevMacros = (*Defs.begin())->getRISCVPredefinedMacros(); + bool NeedEndif = emitMacroRestrictionStr(PrevMacros, OS); for (auto &Def : Defs) { -uint8_t CurExt = Def->getRISCVExtensions(); -if (CurExt != PrevExt) { +RISCVPredefinedMacroT CurMacros = Def->getRISCVPredefinedMacros(); +if (CurMacros != PrevMacros) {
[PATCH] D112986: [Clang][RISCV] Restrict rvv builtin-s with zve macro-s
eopXD updated this revision to Diff 401684. eopXD added a comment. Update code. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112986/new/ https://reviews.llvm.org/D112986 Files: clang/utils/TableGen/RISCVVEmitter.cpp Index: clang/utils/TableGen/RISCVVEmitter.cpp === --- clang/utils/TableGen/RISCVVEmitter.cpp +++ clang/utils/TableGen/RISCVVEmitter.cpp @@ -100,6 +100,9 @@ bool isValid() const { return Valid; } bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; } bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; } + bool isVector(unsigned Width) const { +return isVector() && ElementBitwidth == Width; + } bool isFloat() const { return ScalarType == ScalarTypeKind::Float; } bool isSignedInteger() const { return ScalarType == ScalarTypeKind::SignedInteger; @@ -134,14 +137,19 @@ using RVVTypePtr = RVVType *; using RVVTypes = std::vector; +using RISCVPredefinedMacroT = uint16_t; -enum RISCVExtension : uint8_t { +enum RISCVPredefinedMacro : uint16_t { Basic = 0, F = 1 << 1, D = 1 << 2, Zfh = 1 << 3, Zvlsseg = 1 << 4, RV64 = 1 << 5, + VectorMaxELen32 = 1 << 6, + VectorMaxELen64 = 1 << 7, + VectorMaxELenFp32 = 1 << 8, + VectorMaxELenFp64 = 1 << 9, }; // TODO refactor RVVIntrinsic class design after support all intrinsic @@ -165,7 +173,7 @@ // The types we use to obtain the specific LLVM intrinsic. They are index of // InputTypes. -1 means the return type. std::vector IntrinsicTypes; - uint8_t RISCVExtensions = 0; + RISCVPredefinedMacroT RISCVPredefinedMacros = 0; unsigned NF = 1; public: @@ -189,7 +197,9 @@ bool isMask() const { return IsMask; } StringRef getIRName() const { return IRName; } StringRef getManualCodegen() const { return ManualCodegen; } - uint8_t getRISCVExtensions() const { return RISCVExtensions; } + RISCVPredefinedMacroT getRISCVPredefinedMacros() const { +return RISCVPredefinedMacros; + } unsigned getNF() const { return NF; } const std::vector &getIntrinsicTypes() const { return IntrinsicTypes; @@ -252,7 +262,7 @@ // Emit the architecture preprocessor definitions. Return true when emits // non-empty string. - bool emitExtDefStr(uint8_t Extensions, raw_ostream &o); + bool emitMacroRestrictionStr(RISCVPredefinedMacroT PredefinedMacros, raw_ostream &o); // Slice Prototypes string into sub prototype string and process each sub // prototype string individually in the Handler. void parsePrototypes(StringRef Prototypes, @@ -790,17 +800,26 @@ // Init RISC-V extensions for (const auto &T : OutInTypes) { if (T->isFloatVector(16) || T->isFloat(16)) - RISCVExtensions |= RISCVExtension::Zfh; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zfh; else if (T->isFloatVector(32) || T->isFloat(32)) - RISCVExtensions |= RISCVExtension::F; + RISCVPredefinedMacros |= RISCVPredefinedMacro::F; else if (T->isFloatVector(64) || T->isFloat(64)) - RISCVExtensions |= RISCVExtension::D; + RISCVPredefinedMacros |= RISCVPredefinedMacro::D; + +if (T->isVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen32; +else if (T->isVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELen64; +if (T->isFloatVector(32)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp32; +else if (T->isFloatVector(64)) + RISCVPredefinedMacros |= RISCVPredefinedMacro::VectorMaxELenFp64; } for (auto Extension : RequiredExtensions) { if (Extension == "Zvlsseg") - RISCVExtensions |= RISCVExtension::Zvlsseg; + RISCVPredefinedMacros |= RISCVPredefinedMacro::Zvlsseg; if (Extension == "RV64") - RISCVExtensions |= RISCVExtension::RV64; + RISCVPredefinedMacros |= RISCVPredefinedMacro::RV64; } // Init OutputType and InputTypes @@ -984,7 +1003,7 @@ // The same extension include in the same arch guard marco. llvm::stable_sort(Defs, [](const std::unique_ptr &A, const std::unique_ptr &B) { -return A->getRISCVExtensions() < B->getRISCVExtensions(); +return A->getRISCVPredefinedMacros() < B->getRISCVPredefinedMacros(); }); OS << "#define __rvv_ai static __inline__\n"; @@ -1283,15 +1302,15 @@ void RVVEmitter::emitArchMacroAndBody( std::vector> &Defs, raw_ostream &OS, std::function PrintBody) { - uint8_t PrevExt = (*Defs.begin())->getRISCVExtensions(); - bool NeedEndif = emitExtDefStr(PrevExt, OS); + RISCVPredefinedMacroT PrevMacros = (*Defs.begin())->getRISCVPredefinedMacros(); + bool NeedEndif = emitMacroRestrictionStr(PrevMacros, OS); for (auto &Def : Defs) { -uint8_t CurExt = Def->getRISCVExtensions(); -if (CurExt != PrevExt) { +RISCVPredefinedMacroT CurMacros = Def->getRISCVPredefinedMacros(); +if (CurMacros != PrevMacros) {