[clang] [clang][Builtins] Parse clang extended vectors types. (PR #83584)

Francesco Petrogalli via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 1 07:34:28 PST 2024


https://github.com/fpetrogalli created https://github.com/llvm/llvm-project/pull/83584

Clang extended vector types are mangled as follows:

   ext_vector_type_<lanes>_<scalar type>

This is used to defetmine the builtins signature for builtins that use parmeters defined as

    typedef <scalar type> ext_vector_type_<lanes>_<scalar type> __attribute__((ext_vector_type(<lanes>)))

For example:

    typedef double ext_vector_type_4_double __attribute__((ext_vector_type(4)))

>From 38ac0be1b5a8c11fff8717042e3619f0f59b2cbf Mon Sep 17 00:00:00 2001
From: Francesco Petrogalli <francesco.petrogalli at apple.com>
Date: Fri, 1 Mar 2024 16:23:57 +0100
Subject: [PATCH] [clang][Builtins] Parse clang extended vectors types.

Clang extended vector types are mangled as follows:

   ext_vector_type_<lanes>_<scalar type>

This is used to defetmine the builtins signature for builtins that
use parmeters defined as

    typedef <scalar type> ext_vector_type_<lanes>_<scalar type> __attribute__((ext_vector_type(<lanes>)))

For example:

    typedef double ext_vector_type_4_double __attribute__((ext_vector_type(4)))
---
 .../target-builtins-prototype-parser.td       | 20 +++++++++++++++++++
 clang/utils/TableGen/ClangBuiltinsEmitter.cpp | 10 ++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 clang/test/TableGen/target-builtins-prototype-parser.td

diff --git a/clang/test/TableGen/target-builtins-prototype-parser.td b/clang/test/TableGen/target-builtins-prototype-parser.td
new file mode 100644
index 00000000000000..681a607da7e115
--- /dev/null
+++ b/clang/test/TableGen/target-builtins-prototype-parser.td
@@ -0,0 +1,20 @@
+// RUN: clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins | FileCheck %s
+// RUN: not clang-tblgen -I %p/../../../clang/include/ %s --gen-clang-builtins -DERROR_EXPECTED_LANES 2>&1 | FileCheck %s --check-prefix=ERROR_EXPECTED_LANES
+
+include "clang/Basic/BuiltinsBase.td"
+
+def : Builtin {
+  let Prototype = "ext_vector_type_8_int(double, ext_vector_type_4_bool)";
+  let Spellings = ["__builtin_test_use_clang_extended_vectors"];
+}
+
+// CHECK: BUILTIN(__builtin_test_use_clang_extended_vectors, "E8idE4b", "")
+
+#ifdef ERROR_EXPECTED_LANES
+def : Builtin {
+// ERROR_EXPECTED_LANES: :[[# @LINE + 1]]:7: error: Expected number of lanes
+  let Prototype = "ext_vector_type__int(double, ext_vector_type_4_bool)";
+  let Spellings = ["__builtin_test_use_clang_extended_vectors"];
+}
+#endif
+
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 48f55b8af97e4e..774f703390a05e 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -85,6 +85,16 @@ class PrototypeParser {
       if (Substitution.empty())
         PrintFatalError(Loc, "Not a template");
       ParseType(Substitution);
+    } else if (T.consume_front("ext_vector_type_")) {
+      // Clang extended vector types are mangled as follows:
+      //
+      //    ext_vector_type_<lanes>_<scalar type>
+      unsigned long long Lanes;
+      if (llvm::consumeUnsignedInteger(T, 10, Lanes))
+        PrintFatalError(Loc, "Expected number of lanes ");
+      Type += "E" + std::to_string(Lanes);
+      T.consume_front("_");
+      ParseType(T);
     } else {
       auto ReturnTypeVal = StringSwitch<std::string>(T)
                                .Case("__builtin_va_list_ref", "A")



More information about the cfe-commits mailing list