[clang] [Clang][AArch64]Refactor typespec handling in SveEmitter.cpp (PR #117717)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 10:25:03 PST 2024
================
@@ -423,131 +434,143 @@ const std::array<SVEEmitter::ReinterpretTypeInfo, 12> SVEEmitter::Reinterprets =
// Type implementation
//===----------------------------------------------------------------------===//
-std::string SVEType::builtin_str() const {
- std::string S;
- if (isVoid())
+std::string SVEType::builtinBaseType() const {
+ switch (Kind) {
+ case TypeKind::Void:
return "v";
-
- if (isScalarPredicate())
- return "b";
-
- if (isSvcount())
+ case TypeKind::Svcount:
return "Qa";
-
- if (isVoidPointer())
- S += "v";
- else if (!isFloatingPoint())
+ case TypeKind::BFloat16:
+ assert(ElementBitwidth == 16 && "Invalid BFloat16!");
+ return "y";
+ case TypeKind::MFloat8:
+ assert(ElementBitwidth == 8 && "Invalid MFloat8!");
+ return "c";
+ case TypeKind::Float:
switch (ElementBitwidth) {
- case 1: S += "b"; break;
- case 8: S += "c"; break;
- case 16: S += "s"; break;
- case 32: S += "i"; break;
- case 64: S += "Wi"; break;
- case 128: S += "LLLi"; break;
- default: llvm_unreachable("Unhandled case!");
+ case 16:
+ return "h";
+ case 32:
+ return "f";
+ case 64:
+ return "d";
+ default:
+ llvm_unreachable("Unhandled float width!");
}
- else if (isFloat())
+ case TypeKind::Predicate:
+ if (isScalar())
+ return "b";
+ [[fallthrough]];
+ // SInt/UInt, PredicatePattern, PrefetchOp.
+ default:
switch (ElementBitwidth) {
- case 16: S += "h"; break;
- case 32: S += "f"; break;
- case 64: S += "d"; break;
- default: llvm_unreachable("Unhandled case!");
+ case 1:
+ return "b";
+ case 8:
+ return "c";
+ case 16:
+ return "s";
+ case 32:
+ return "i";
+ case 64:
+ return "Wi";
+ case 128:
+ return "LLLi";
+ default:
+ llvm_unreachable("Unhandled bitwidth!");
}
- else if (isBFloat()) {
- assert(ElementBitwidth == 16 && "Not a valid BFloat.");
- S += "y";
- } else if (isMFloat()) {
- assert(ElementBitwidth == 8 && "Not a valid MFloat.");
- S += "m";
}
+}
- if (!isFloatingPoint()) {
- if ((isChar() || isPointer()) && !isVoidPointer()) {
- // Make chars and typed pointers explicitly signed.
- if (Signed)
- S = "S" + S;
- else if (!Signed)
- S = "U" + S;
- } else if (!isVoidPointer() && !Signed) {
- S = "U" + S;
- }
- }
+std::string SVEType::builtin_str() const {
- // Constant indices are "int", but have the "constant expression" modifier.
- if (isImmediate()) {
- assert(!isFloat() && "fp immediates are not supported");
- S = "I" + S;
- }
+ std::string Prefix;
- if (isScalar()) {
- if (Constant) S += "C";
- if (Pointer) S += "*";
- return S;
+ if (isScalableVector())
+ Prefix = "q" + llvm::utostr(getNumElements() * NumVectors);
+ else if (isFixedLengthVector())
+ Prefix = "V" + llvm::utostr(getNumElements() * NumVectors);
+ else if (isImmediate()) {
+ assert(!isFloatingPoint() && "fp immediates are not supported");
+ Prefix = "I";
}
- if (isFixedLengthVector())
- return "V" + utostr(getNumElements() * NumVectors) + S;
- return "q" + utostr(getNumElements() * NumVectors) + S;
+ // Make chars and integer pointers explicitly signed.
+ if ((ElementBitwidth == 8 || isPointer()) && isSignedInteger())
----------------
SpencerAbson wrote:
For the most part it is, but in many cases it is not and I assumed there was a reason for it. For example: `__builtin_sve_svget4_b`, `__builtin_sve_svwhilegt_b8_s64_x2` - perhaps there is a bug I can fix here?
https://github.com/llvm/llvm-project/pull/117717
More information about the cfe-commits
mailing list