[clang] [Clang][Sema] Extend test coverage for SVE/SME builtin usage. (PR #156908)

Graham Hunter via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 8 07:27:15 PDT 2025


================
@@ -0,0 +1,539 @@
+#!/usr/bin/env python3
+"""
+Generate C test files that call ACLE builtins found in a JSON manifest.
+
+Expected JSON input format (array of objects):
+[
+  {
+    "guard": "sve,(sve2p1|sme)",
+    "streaming_guard": "sme",
+    "flags": "feature-dependent",
+    "builtin": "svint16_t svrevd_s16_z(svbool_t, svint16_t);"
+  },
+  ...
+]
+"""
+
+from __future__ import annotations
+
+import argparse
+import json
+import re
+import sys
+from collections import defaultdict
+from dataclasses import dataclass
+from enum import Enum
+from itertools import product
+from pathlib import Path
+from typing import Any, Dict, Iterable, List, Sequence, Tuple
+
+assert sys.version_info >= (3, 7), "Only Python 3.7+ is supported."
+
+
+# Are we testing arm_sve.h or arm_sme.h based builtins.
+class Mode(Enum):
+    SVE = "sve"
+    SME = "sme"
+
+
+class FunctionType(Enum):
+    NORMAL = "normal"
+    STREAMING = "streaming"
+    STREAMING_COMPATIBLE = "streaming-compatible"
+
+
+# Builtins are grouped by their required features.
+ at dataclass(frozen=True, order=True)
+class BuiltinContext:
+    guard: str
+    streaming_guard: str
+    flags: tuple[str, ...]
+
+    def __str__(self) -> str:
+        return (
+            f"// Properties: "
+            f'guard="{self.guard}" '
+            f'streaming_guard="{self.streaming_guard}" '
+            f'flags="{",".join(self.flags)}"'
+        )
+
+    @classmethod
+    def from_json(cls, obj: dict[str, Any]) -> "BuiltinContext":
+        flags = tuple(p.strip() for p in obj["flags"].split(",") if p.strip())
+        return cls(obj["guard"], obj["streaming_guard"], flags)
+
+
+# --- Parsing builtins -------------------------------------------------------
+
+# Captures the full function *declaration* inside the builtin string, e.g.:
+#   "svint16_t svrevd_s16_z(svbool_t, svint16_t);"
+# group(1) => "svint16_t svrevd_s16_z"
+# group(2) => "svbool_t, svint16_t"
+FUNC_RE = re.compile(r"^\s*([a-zA-Z_][\w\s\*]*[\w\*])\s*\(\s*([^)]*)\s*\)\s*;\s*$")
+
+# Pulls the final word out of the left side (the function name).
+NAME_RE = re.compile(r"([a-zA-Z_][\w]*)\s*$")
+
+
+def parse_builtin_declaration(decl: str) -> Tuple[str, List[str]]:
+    """Return (func_name, param_types) from a builtin declaration string.
+
+    Example:
+      decl = "svint16_t svrevd_s16_z(svbool_t, svint16_t);"
+      => ("svrevd_s16_z", ["svbool_t", "svint16_t"])
+    """
+    m = FUNC_RE.match(decl)
+    if not m:
+        raise ValueError(f"Unrecognized builtin declaration syntax: {decl!r}")
+
+    left = m.group(1)  # return type + name
+    params = m.group(2).strip()
+
+    name_m = NAME_RE.search(left)
+    if not name_m:
+        raise ValueError(f"Could not find function name in: {decl!r}")
+    func_name = name_m.group(1)
+
+    if not params:
+        param_types: List[str] = []
----------------
huntergr-arm wrote:

nit: Could just initialize to [] always, then use `if params:` to overwrite.

https://github.com/llvm/llvm-project/pull/156908


More information about the cfe-commits mailing list