[clang] [HLSL] add IsLineVectorLayoutCompatible type trait (PR #113730)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 11:11:40 PDT 2024


================
@@ -2163,6 +2163,51 @@ static void BuildFlattenedTypeList(QualType BaseTy,
   }
 }
 
+bool SemaHLSL::IsLineVectorLayoutCompatibleType(clang::QualType QT) {
+  if (QT.isNull())
+    return false;
+
+  llvm::SmallVector<QualType, 16> QTTypes;
+  BuildFlattenedTypeList(QT, QTTypes);
+
+  assert(QTTypes.size() > 0 &&
+         "expected at least one constituent type from non-null type");
+  QualType FirstQT = QTTypes[0];
+
+  // element count cannot exceed 4
+  if (QTTypes.size() > 4)
+    return false;
+
+  // check if the outer type was an array type
+  if (llvm::isa<clang::ArrayType>(QT.getTypePtr()))
+    return false;
+
+  for (QualType TempQT : QTTypes) {
+    // ensure homogeneity
+    if (TempQT != FirstQT)
+      return false;
+
+    if (const BuiltinType *BT = TempQT->getAs<BuiltinType>()) {
+      if (BT->getKind() == BuiltinType::Bool ||
+          BT->getKind() == BuiltinType::Enum)
+        return false;
+
+      // Check if it is an array type.
+      if (llvm::isa<clang::ArrayType>(TempQT.getTypePtr()))
----------------
hekota wrote:

```suggestion
      if (TempQT->isArrayType())
```

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


More information about the cfe-commits mailing list