Skip to content

Commit 0feb8f3

Browse files
chrysnkkysen
andcommitted
ast-exporter: Refactor recognition of vector types
Co-authored-by: Khyber Sen <[email protected]>
1 parent e6377b2 commit 0feb8f3

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

c2rust-ast-exporter/src/AstExporter.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,21 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
322322
auto kind = T->getKind();
323323

324324
#if CLANG_VERSION_MAJOR >= 10
325-
// Handle built-in vector types as if they're normal vector types
326-
if (kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool
325+
// Recognize ARM vector types
326+
const bool is_sve = kind >= BuiltinType::SveInt8 && kind <= BuiltinType::SveBool;
327+
#else
328+
const bool is_sve = false;
329+
#endif // CLANG_VERSION_MAJOR >= 10
330+
327331
#if CLANG_VERSION_MAJOR >= 13
328-
/* RISC-V vector types */
329-
|| kind >= BuiltinType::RvvInt8mf8 && kind <= BuiltinType::RvvBool64
332+
// Recognize RISC-V vector types
333+
const bool is_rvv = kind >= BuiltinType::RvvInt8mf8 && kind <= BuiltinType::RvvBool64;
334+
#else
335+
const bool is_rvv = false;
330336
#endif // CLANG_VERSION_MAJOR >= 13
331-
) {
337+
338+
// Handle built-in vector types as if they're normal vector types
339+
if (is_sve || is_rvv) {
332340
// Declare ElemType and ElemCount as needed by various Clang versions
333341
#if CLANG_VERSION_MAJOR >= 11
334342
auto Info = Context->getBuiltinVectorTypeInfo(T);
@@ -348,6 +356,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
348356
auto ElemType = [&] {
349357
switch (kind) {
350358
default: llvm_unreachable("Unknown builtin SVE type!");
359+
#if CLANG_VERSION_MAJOR >= 10
351360
case BuiltinType::SveInt8: return Ctx.SignedCharTy;
352361
case BuiltinType::SveUint8: return Ctx.UnsignedCharTy;
353362
case BuiltinType::SveBool: return Ctx.UnsignedCharTy;
@@ -360,6 +369,7 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
360369
case BuiltinType::SveFloat16: return Ctx.Float16Ty;
361370
case BuiltinType::SveFloat32: return Ctx.FloatTy;
362371
case BuiltinType::SveFloat64: return Ctx.DoubleTy;
372+
#endif // CLANG_VERSION_MAJOR >= 10
363373
}
364374
}();
365375
// All the SVE types present in Clang 10 are 128-bit vectors
@@ -377,7 +387,6 @@ class TypeEncoder final : public TypeVisitor<TypeEncoder> {
377387
VisitQualType(ElemType);
378388
return;
379389
}
380-
#endif // CLANG_VERSION_MAJOR >= 10
381390

382391
const TypeTag tag = [&] {
383392
switch (kind) {

0 commit comments

Comments
 (0)