2
0
Эх сурвалжийг харах

[spirv] Pull certain type probing functions into its own file (#1608)

Lei Zhang 7 жил өмнө
parent
commit
302ec8c505

+ 69 - 0
tools/clang/include/clang/SPIRV/AstTypeProbe.h

@@ -0,0 +1,69 @@
+//===-- TypeProbe.h - Static functions for probing QualType -----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_SPIRV_TYPEPROBE_H
+#define LLVM_CLANG_SPIRV_TYPEPROBE_H
+
+#include <string>
+
+#include "clang/AST/Type.h"
+
+namespace clang {
+namespace spirv {
+
+/// Returns a string name for the given type.
+std::string getAstTypeName(QualType type);
+
+/// Returns true if the given type will be translated into a SPIR-V scalar type.
+///
+/// This includes normal scalar types, vectors of size 1, and 1x1 matrices.
+///
+/// If scalarType is not nullptr, writes the scalar type to *scalarType.
+bool isScalarType(QualType type, QualType *scalarType = nullptr);
+
+/// Returns true if the given type will be translated into a SPIR-V vector type.
+///
+/// This includes normal vector types (either ExtVectorType or HLSL vector type)
+/// with more than one elements and matrices with exactly one row or one column.
+///
+/// Writes the element type and count into *elementType and *count respectively
+/// if they are not nullptr.
+bool isVectorType(QualType type, QualType *elemType = nullptr,
+                  uint32_t *elemCount = nullptr);
+
+/// Returns true if the given type is a 1x1 matrix type.
+///
+/// If elemType is not nullptr, writes the element type to *elemType.
+bool is1x1Matrix(QualType type, QualType *elemType = nullptr);
+
+/// Returns true if the given type is a 1xN (N > 1) matrix type.
+///
+/// If elemType is not nullptr, writes the element type to *elemType.
+/// If count is not nullptr, writes the value of N into *count.
+bool is1xNMatrix(QualType type, QualType *elemType = nullptr,
+                 uint32_t *count = nullptr);
+
+/// Returns true if the given type is a Mx1 (M > 1) matrix type.
+///
+/// If elemType is not nullptr, writes the element type to *elemType.
+/// If count is not nullptr, writes the value of M into *count.
+bool isMx1Matrix(QualType type, QualType *elemType = nullptr,
+                 uint32_t *count = nullptr);
+
+/// Returns true if the given type is a matrix with more than 1 row and
+/// more than 1 column.
+///
+/// If elemType is not nullptr, writes the element type to *elemType.
+/// If rowCount is not nullptr, writes the number of rows (M) into *rowCount.
+/// If colCount is not nullptr, writes the number of cols (N) into *colCount.
+bool isMxNMatrix(QualType type, QualType *elemType = nullptr,
+                 uint32_t *rowCount = nullptr, uint32_t *colCount = nullptr);
+
+} // namespace spirv
+} // namespace clang
+
+#endif // LLVM_CLANG_SPIRV_TYPEPROBE_H

+ 215 - 0
tools/clang/lib/SPIRV/AstTypeProbe.cpp

@@ -0,0 +1,215 @@
+//===--- TypeProbe.cpp - Static functions for probing QualType ---*- C++ -*-==//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/SPIRV/AstTypeProbe.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/HlslTypes.h"
+
+namespace clang {
+namespace spirv {
+
+std::string getAstTypeName(QualType type) {
+  {
+    QualType ty = {};
+    if (isScalarType(type, &ty))
+      if (const auto *builtinType = ty->getAs<BuiltinType>())
+        switch (builtinType->getKind()) {
+        case BuiltinType::Void:
+          return "void";
+        case BuiltinType::Bool:
+          return "bool";
+        case BuiltinType::Int:
+          return "int";
+        case BuiltinType::UInt:
+          return "uint";
+        case BuiltinType::Float:
+          return "float";
+        case BuiltinType::Double:
+          return "double";
+        case BuiltinType::LongLong:
+          return "int64";
+        case BuiltinType::ULongLong:
+          return "uint64";
+        case BuiltinType::Short:
+          return "short";
+        case BuiltinType::UShort:
+          return "ushort";
+        case BuiltinType::Half:
+        case BuiltinType::HalfFloat:
+          return "half";
+        case BuiltinType::Min12Int:
+          return "min12int";
+        case BuiltinType::Min16Int:
+          return "min16int";
+        case BuiltinType::Min16UInt:
+          return "min16uint";
+        case BuiltinType::Min16Float:
+          return "min16float";
+        case BuiltinType::Min10Float:
+          return "min10float";
+        default:
+          return "";
+        }
+  }
+
+  {
+    QualType elemType = {};
+    uint32_t elemCount = {};
+    if (isVectorType(type, &elemType, &elemCount))
+      return "v" + std::to_string(elemCount) + getAstTypeName(elemType);
+  }
+
+  {
+    QualType elemType = {};
+    uint32_t rowCount = 0, colCount = 0;
+    if (isMxNMatrix(type, &elemType, &rowCount, &colCount))
+      return "mat" + std::to_string(rowCount) + "v" + std::to_string(colCount) +
+             getAstTypeName(elemType);
+  }
+
+  if (const auto *structType = type->getAs<RecordType>())
+    return structType->getDecl()->getName();
+
+  return "";
+}
+
+bool isScalarType(QualType type, QualType *scalarType) {
+  bool isScalar = false;
+  QualType ty = {};
+
+  if (type->isBuiltinType()) {
+    isScalar = true;
+    ty = type;
+  } else if (hlsl::IsHLSLVecType(type) && hlsl::GetHLSLVecSize(type) == 1) {
+    isScalar = true;
+    ty = hlsl::GetHLSLVecElementType(type);
+  } else if (const auto *extVecType =
+                 dyn_cast<ExtVectorType>(type.getTypePtr())) {
+    if (extVecType->getNumElements() == 1) {
+      isScalar = true;
+      ty = extVecType->getElementType();
+    }
+  } else if (is1x1Matrix(type)) {
+    isScalar = true;
+    ty = hlsl::GetHLSLMatElementType(type);
+  }
+
+  if (isScalar && scalarType)
+    *scalarType = ty;
+
+  return isScalar;
+}
+
+bool isVectorType(QualType type, QualType *elemType, uint32_t *elemCount) {
+  bool isVec = false;
+  QualType ty = {};
+  uint32_t count = 0;
+
+  if (hlsl::IsHLSLVecType(type)) {
+    ty = hlsl::GetHLSLVecElementType(type);
+    count = hlsl::GetHLSLVecSize(type);
+    isVec = count > 1;
+  } else if (const auto *extVecType =
+                 dyn_cast<ExtVectorType>(type.getTypePtr())) {
+    ty = extVecType->getElementType();
+    count = extVecType->getNumElements();
+    isVec = count > 1;
+  } else if (hlsl::IsHLSLMatType(type)) {
+    uint32_t rowCount = 0, colCount = 0;
+    hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
+
+    ty = hlsl::GetHLSLMatElementType(type);
+    count = rowCount == 1 ? colCount : rowCount;
+    isVec = (rowCount == 1) != (colCount == 1);
+  }
+
+  if (isVec) {
+    if (elemType)
+      *elemType = ty;
+    if (elemCount)
+      *elemCount = count;
+  }
+  return isVec;
+}
+
+bool is1x1Matrix(QualType type, QualType *elemType) {
+  if (!hlsl::IsHLSLMatType(type))
+    return false;
+
+  uint32_t rowCount = 0, colCount = 0;
+  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
+
+  if (rowCount == 1 && colCount == 1) {
+    if (elemType)
+      *elemType = hlsl::GetHLSLMatElementType(type);
+    return true;
+  }
+
+  return false;
+}
+
+bool is1xNMatrix(QualType type, QualType *elemType, uint32_t *elemCount) {
+  if (!hlsl::IsHLSLMatType(type))
+    return false;
+
+  uint32_t rowCount = 0, colCount = 0;
+  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
+
+  if (rowCount == 1 && colCount > 1) {
+    if (elemType)
+      *elemType = hlsl::GetHLSLMatElementType(type);
+    if (elemCount)
+      *elemCount = colCount;
+    return true;
+  }
+
+  return false;
+}
+
+bool isMx1Matrix(QualType type, QualType *elemType, uint32_t *elemCount) {
+  if (!hlsl::IsHLSLMatType(type))
+    return false;
+
+  uint32_t rowCount = 0, colCount = 0;
+  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
+
+  if (rowCount > 1 && colCount == 1) {
+    if (elemType)
+      *elemType = hlsl::GetHLSLMatElementType(type);
+    if (elemCount)
+      *elemCount = rowCount;
+    return true;
+  }
+
+  return false;
+}
+
+bool isMxNMatrix(QualType type, QualType *elemType, uint32_t *numRows,
+                 uint32_t *numCols) {
+  if (!hlsl::IsHLSLMatType(type))
+    return false;
+
+  uint32_t rowCount = 0, colCount = 0;
+  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
+
+  if (rowCount > 1 && colCount > 1) {
+    if (elemType)
+      *elemType = hlsl::GetHLSLMatElementType(type);
+    if (numRows)
+      *numRows = rowCount;
+    if (numCols)
+      *numCols = colCount;
+    return true;
+  }
+
+  return false;
+}
+
+} // namespace spirv
+} // namespace clang

+ 1 - 0
tools/clang/lib/SPIRV/CMakeLists.txt

@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_clang_library(clangSPIRV
+  AstTypeProbe.cpp
   BlockReadableOrder.cpp
   Constant.cpp
   DeclResultIdMapper.cpp

+ 5 - 5
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -18,7 +18,7 @@
 #include "dxc/DXIL/DxilTypeSystem.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/HlslTypes.h"
-#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/SPIRV/AstTypeProbe.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSet.h"
@@ -45,9 +45,9 @@ bool isBooleanStageIOVar(const NamedDecl *decl, QualType type,
 
   // TODO: support boolean matrix stage I/O variable if needed.
   QualType elemType = {};
-  const bool isBooleanType = ((TypeTranslator::isScalarType(type, &elemType) ||
-                               TypeTranslator::isVectorType(type, &elemType)) &&
-                              elemType->isBooleanType());
+  const bool isBooleanType =
+      ((isScalarType(type, &elemType) || isVectorType(type, &elemType)) &&
+       elemType->isBooleanType());
 
   return isBooleanType && !isBooleanBuiltin;
 }
@@ -480,7 +480,7 @@ uint32_t DeclResultIdMapper::getMatrixStructType(const VarDecl *matVar,
                                                  spv::StorageClass sc,
                                                  SpirvLayoutRule rule) {
   const auto matType = matVar->getType();
-  assert(TypeTranslator::isMxNMatrix(matType));
+  assert(isMxNMatrix(matType));
 
   auto &context = *theBuilder.getSPIRVContext();
   llvm::SmallVector<const Decoration *, 4> decorations;

+ 16 - 15
tools/clang/lib/SPIRV/GlPerVertex.cpp

@@ -13,6 +13,7 @@
 
 #include "clang/AST/Attr.h"
 #include "clang/AST/HlslTypes.h"
+#include "clang/SPIRV/AstTypeProbe.h"
 
 namespace clang {
 namespace spirv {
@@ -61,11 +62,11 @@ inline bool hasGSPrimitiveTypeQualifier(const DeclaratorDecl *decl) {
 
 GlPerVertex::GlPerVertex(const hlsl::ShaderModel &sm, ASTContext &context,
                          ModuleBuilder &builder, TypeTranslator &translator)
-    : shaderModel(sm), astContext(context), theBuilder(builder),
-      inClipVar(0), inCullVar(0), outClipVar(0),
-      outCullVar(0), inArraySize(0), outArraySize(0), inClipArraySize(1),
-      outClipArraySize(1), inCullArraySize(1), outCullArraySize(1),
-      inSemanticStrs(2, ""), outSemanticStrs(2, "") {}
+    : shaderModel(sm), astContext(context), theBuilder(builder), inClipVar(0),
+      inCullVar(0), outClipVar(0), outCullVar(0), inArraySize(0),
+      outArraySize(0), inClipArraySize(1), outClipArraySize(1),
+      inCullArraySize(1), outCullArraySize(1), inSemanticStrs(2, ""),
+      outSemanticStrs(2, "") {}
 
 void GlPerVertex::generateVars(uint32_t inArrayLen, uint32_t outArrayLen) {
   inArraySize = inArrayLen;
@@ -295,9 +296,9 @@ void GlPerVertex::calculateClipCullDistanceArraySize() {
       QualType elemType = {};
       uint32_t count = 0;
 
-      if (TypeTranslator::isScalarType(type)) {
+      if (isScalarType(type)) {
         (*offsetMap)[index] = (*totalSize)++;
-      } else if (TypeTranslator::isVectorType(type, &elemType, &count)) {
+      } else if (isVectorType(type, &elemType, &count)) {
         (*offsetMap)[index] = *totalSize;
         *totalSize += count;
       } else {
@@ -395,14 +396,14 @@ uint32_t GlPerVertex::readClipCullArrayAsType(bool isClip, uint32_t offset,
     QualType elemType = {};
     uint32_t count = {};
 
-    if (TypeTranslator::isScalarType(asType)) {
+    if (isScalarType(asType)) {
       const uint32_t offsetId = theBuilder.getConstantUint32(offset);
       const uint32_t ptr =
           theBuilder.createAccessChain(ptrType, clipCullVar, {offsetId});
       return theBuilder.createLoad(f32Type, ptr);
     }
 
-    if (TypeTranslator::isVectorType(asType, &elemType, &count)) {
+    if (isVectorType(asType, &elemType, &count)) {
       // The target SV_ClipDistance/SV_CullDistance variable is of vector
       // type, then we need to construct a vector out of float array elements.
       llvm::SmallVector<uint32_t, 4> elements;
@@ -434,7 +435,7 @@ uint32_t GlPerVertex::readClipCullArrayAsType(bool isClip, uint32_t offset,
   uint32_t arrayType = {};
   uint32_t arraySize = theBuilder.getConstantUint32(inArraySize);
 
-  if (TypeTranslator::isScalarType(asType)) {
+  if (isScalarType(asType)) {
     arrayType = theBuilder.getArrayType(f32Type, arraySize);
     for (uint32_t i = 0; i < inArraySize; ++i) {
       const uint32_t ptr = theBuilder.createAccessChain(
@@ -443,7 +444,7 @@ uint32_t GlPerVertex::readClipCullArrayAsType(bool isClip, uint32_t offset,
            theBuilder.getConstantUint32(offset)});
       arrayElements.push_back(theBuilder.createLoad(f32Type, ptr));
     }
-  } else if (TypeTranslator::isVectorType(asType, &elemType, &count)) {
+  } else if (isVectorType(asType, &elemType, &count)) {
     arrayType = theBuilder.getArrayType(theBuilder.getVecType(f32Type, count),
                                         arraySize);
     for (uint32_t i = 0; i < inArraySize; ++i) {
@@ -517,7 +518,7 @@ void GlPerVertex::writeClipCullArrayFromType(
     QualType elemType = {};
     uint32_t count = {};
 
-    if (TypeTranslator::isScalarType(fromType)) {
+    if (isScalarType(fromType)) {
       const uint32_t offsetId = theBuilder.getConstantUint32(offset);
       const uint32_t ptr =
           theBuilder.createAccessChain(ptrType, clipCullVar, {offsetId});
@@ -525,7 +526,7 @@ void GlPerVertex::writeClipCullArrayFromType(
       return;
     }
 
-    if (TypeTranslator::isVectorType(fromType, &elemType, &count)) {
+    if (isVectorType(fromType, &elemType, &count)) {
       // The target SV_ClipDistance/SV_CullDistance variable is of vector
       // type. We need to write each component in the vector out.
       for (uint32_t i = 0; i < count; ++i) {
@@ -561,7 +562,7 @@ void GlPerVertex::writeClipCullArrayFromType(
   QualType elemType = {};
   uint32_t count = {};
 
-  if (TypeTranslator::isScalarType(fromType)) {
+  if (isScalarType(fromType)) {
     const uint32_t ptr =
         theBuilder.createAccessChain(ptrType, clipCullVar,
                                      {arrayIndex, // Block array index
@@ -570,7 +571,7 @@ void GlPerVertex::writeClipCullArrayFromType(
     return;
   }
 
-  if (TypeTranslator::isVectorType(fromType, &elemType, &count)) {
+  if (isVectorType(fromType, &elemType, &count)) {
     // For each gl_PerVertex block, we need to write a vector into it.
     for (uint32_t i = 0; i < count; ++i) {
       const uint32_t ptr = theBuilder.createAccessChain(

+ 108 - 148
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -15,6 +15,7 @@
 
 #include "dxc/HlslIntrinsicOp.h"
 #include "spirv-tools/optimizer.hpp"
+#include "clang/SPIRV/AstTypeProbe.h"
 #include "llvm/ADT/StringExtras.h"
 
 #include "InitListHandler.h"
@@ -54,8 +55,7 @@ bool patchConstFuncTakesHullOutputPatch(FunctionDecl *pcf) {
 /// Returns true if the given type is a bool or vector of bool type.
 bool isBoolOrVecOfBoolType(QualType type) {
   QualType elemType = {};
-  return (TypeTranslator::isScalarType(type, &elemType) ||
-          TypeTranslator::isVectorType(type, &elemType)) &&
+  return (isScalarType(type, &elemType) || isVectorType(type, &elemType)) &&
          elemType->isBooleanType();
 }
 
@@ -63,8 +63,7 @@ bool isBoolOrVecOfBoolType(QualType type) {
 /// integer type.
 bool isSintOrVecOfSintType(QualType type) {
   QualType elemType = {};
-  return (TypeTranslator::isScalarType(type, &elemType) ||
-          TypeTranslator::isVectorType(type, &elemType)) &&
+  return (isScalarType(type, &elemType) || isVectorType(type, &elemType)) &&
          elemType->isSignedIntegerType();
 }
 
@@ -72,16 +71,14 @@ bool isSintOrVecOfSintType(QualType type) {
 /// integer type.
 bool isUintOrVecOfUintType(QualType type) {
   QualType elemType = {};
-  return (TypeTranslator::isScalarType(type, &elemType) ||
-          TypeTranslator::isVectorType(type, &elemType)) &&
+  return (isScalarType(type, &elemType) || isVectorType(type, &elemType)) &&
          elemType->isUnsignedIntegerType();
 }
 
 /// Returns true if the given type is a float or vector of float type.
 bool isFloatOrVecOfFloatType(QualType type) {
   QualType elemType = {};
-  return (TypeTranslator::isScalarType(type, &elemType) ||
-          TypeTranslator::isVectorType(type, &elemType)) &&
+  return (isScalarType(type, &elemType) || isVectorType(type, &elemType)) &&
          elemType->isFloatingType();
 }
 
@@ -961,8 +958,7 @@ SpirvEvalInfo SPIRVEmitter::loadIfGLValue(const Expr *expr,
       const auto exprType = expr->getType();
       QualType uintType = astContext.UnsignedIntTy;
       QualType boolType = astContext.BoolTy;
-      if (TypeTranslator::isScalarType(exprType) ||
-          TypeTranslator::isVectorType(exprType, nullptr, &vecSize)) {
+      if (isScalarType(exprType) || isVectorType(exprType, nullptr, &vecSize)) {
         const auto fromType =
             vecSize == 1 ? uintType
                          : astContext.getExtVectorType(uintType, vecSize);
@@ -971,8 +967,7 @@ SpirvEvalInfo SPIRVEmitter::loadIfGLValue(const Expr *expr,
                          : astContext.getExtVectorType(boolType, vecSize);
         loadedId = castToBool(loadedId, fromType, toType);
       } else {
-        const bool isMat =
-            TypeTranslator::isMxNMatrix(exprType, nullptr, &numRows, &numCols);
+        const bool isMat = isMxNMatrix(exprType, nullptr, &numRows, &numCols);
         assert(isMat);
         (void)isMat;
         const auto uintRowQualType =
@@ -1208,8 +1203,7 @@ bool SPIRVEmitter::validateVKAttributes(const NamedDecl *decl) {
     const auto elementType =
         hlsl::GetHLSLResourceResultType(cast<VarDecl>(decl)->getType());
 
-    if (!TypeTranslator::isScalarType(elementType) &&
-        !TypeTranslator::isVectorType(elementType)) {
+    if (!isScalarType(elementType) && !isVectorType(elementType)) {
       emitError(
           "only scalar/vector types allowed as SubpassInput(MS) parameter type",
           decl->getLocation());
@@ -2095,10 +2089,9 @@ SpirvEvalInfo SPIRVEmitter::processCall(const CallExpr *callExpr) {
           objectEvalInfo.getStorageClass() != spv::StorageClass::Function;
 
       if (needsTempVar) {
-        objectId =
-            createTemporaryVar(objectType, TypeTranslator::getName(objectType),
-                               // May need to load to use as initializer
-                               loadIfGLValue(object, objectEvalInfo));
+        objectId = createTemporaryVar(objectType, getAstTypeName(objectType),
+                                      // May need to load to use as initializer
+                                      loadIfGLValue(object, objectEvalInfo));
       }
 
       args.push_back(objectId);
@@ -2302,7 +2295,7 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
   case CastKind::CK_HLSLVectorToMatrixCast: {
     // If target type is already an 1xN matrix type, we just return the
     // underlying vector.
-    if (TypeTranslator::is1xNMatrix(toType))
+    if (is1xNMatrix(toType))
       return doExpr(subExpr);
 
     // A vector can have no more than 4 elements. The only remaining case
@@ -2312,8 +2305,7 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
 
     QualType elemType = {};
     uint32_t rowCount = 0, colCount = 0;
-    const bool isMat =
-        TypeTranslator::isMxNMatrix(toType, &elemType, &rowCount, &colCount);
+    const bool isMat = isMxNMatrix(toType, &elemType, &rowCount, &colCount);
 
     assert(isMat && rowCount == 2 && colCount == 2);
     (void)isMat;
@@ -2370,8 +2362,8 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
     // The front-end disallows float1x3 --> float2x1.
     {
       uint32_t srcVecSize = 0, dstVecSize = 0;
-      if (TypeTranslator::isVectorType(srcType, nullptr, &srcVecSize) &&
-          TypeTranslator::isVectorType(toType, nullptr, &dstVecSize)) {
+      if (isVectorType(srcType, nullptr, &srcVecSize) &&
+          isVectorType(toType, nullptr, &dstVecSize)) {
         for (uint32_t i = 0; i < dstVecSize; ++i)
           indexes.push_back(i);
         const auto valId =
@@ -2416,13 +2408,12 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
   }
   case CastKind::CK_HLSLMatrixToScalarCast: {
     // The underlying should already be a matrix of 1x1.
-    assert(TypeTranslator::is1x1Matrix(subExprType));
+    assert(is1x1Matrix(subExprType));
     return doExpr(subExpr);
   }
   case CastKind::CK_HLSLMatrixToVectorCast: {
     // The underlying should already be a matrix of 1xN.
-    assert(TypeTranslator::is1xNMatrix(subExprType) ||
-           TypeTranslator::isMx1Matrix(subExprType));
+    assert(is1xNMatrix(subExprType) || isMx1Matrix(subExprType));
     return doExpr(subExpr);
   }
   case CastKind::CK_FunctionToPointerDecay:
@@ -2515,7 +2506,7 @@ uint32_t SPIRVEmitter::processFlatConversion(const QualType type,
   // Primitive types
   {
     QualType ty = {};
-    if (TypeTranslator::isScalarType(type, &ty)) {
+    if (isScalarType(type, &ty)) {
       if (const auto *builtinType = ty->getAs<BuiltinType>()) {
         switch (builtinType->getKind()) {
         case BuiltinType::Void: {
@@ -2557,7 +2548,7 @@ uint32_t SPIRVEmitter::processFlatConversion(const QualType type,
   {
     QualType elemType = {};
     uint32_t elemCount = {};
-    if (TypeTranslator::isVectorType(type, &elemType, &elemCount)) {
+    if (isVectorType(type, &elemType, &elemCount)) {
       const uint32_t elemId =
           processFlatConversion(elemType, initType, initId, srcLoc);
       llvm::SmallVector<uint32_t, 4> constituents(size_t(elemCount), elemId);
@@ -2570,7 +2561,7 @@ uint32_t SPIRVEmitter::processFlatConversion(const QualType type,
   {
     QualType elemType = {};
     uint32_t rowCount = 0, colCount = 0;
-    if (TypeTranslator::isMxNMatrix(type, &elemType, &rowCount, &colCount)) {
+    if (isMxNMatrix(type, &elemType, &rowCount, &colCount)) {
       // By default HLSL matrices are row major, while SPIR-V matrices are
       // column major. We are mapping what HLSL semantically mean a row into a
       // column here.
@@ -2701,14 +2692,13 @@ SPIRVEmitter::doConditionalOperator(const ConditionalOperator *expr) {
   // For cases where the return type is a scalar or a vector, we can use
   // OpSelect to choose between the two. OpSelect's return type must be either
   // scalar or vector.
-  if (TypeTranslator::isScalarType(type) ||
-      TypeTranslator::isVectorType(type)) {
+  if (isScalarType(type) || isVectorType(type)) {
     // The SPIR-V OpSelect instruction must have a selection argument that is
     // the same size as the return type. If the return type is a vector, the
     // selection must be a vector of booleans (one per output component).
     uint32_t count = 0;
-    if (TypeTranslator::isVectorType(expr->getType(), nullptr, &count) &&
-        !TypeTranslator::isVectorType(expr->getCond()->getType())) {
+    if (isVectorType(expr->getType(), nullptr, &count) &&
+        !isVectorType(expr->getCond()->getType())) {
       const uint32_t condVecType =
           theBuilder.getVecType(theBuilder.getBoolType(), count);
       const llvm::SmallVector<uint32_t, 4> components(size_t(count), condition);
@@ -3223,7 +3213,7 @@ SpirvEvalInfo SPIRVEmitter::processBufferTextureLoad(
   bool isTemplateOverStruct = false;
 
   // Check whether the template type is a vector type or struct type.
-  if (!TypeTranslator::isVectorType(sampledType, &elemType, &elemCount)) {
+  if (!isVectorType(sampledType, &elemType, &elemCount)) {
     if (sampledType->getAsStructureType()) {
       isTemplateOverStruct = true;
       // For struct type, we need to make sure it can fit into a 4-component
@@ -3995,11 +3985,10 @@ uint32_t SPIRVEmitter::createImageSample(
   QualType elemType = {};
   uint32_t elemTypeId = 0;
   uint32_t retVecSize = 0;
-  if (TypeTranslator::isVectorType(retType, &elemType, &retVecSize) &&
-      retVecSize != 4) {
+  if (isVectorType(retType, &elemType, &retVecSize) && retVecSize != 4) {
     elemTypeId = typeTranslator.translateType(elemType);
     texelTypeId = theBuilder.getVecType(elemTypeId, 4);
-  } else if (TypeTranslator::isScalarType(retType)) {
+  } else if (isScalarType(retType)) {
     retVecSize = 1;
     elemTypeId = typeTranslator.translateType(retType);
     texelTypeId = theBuilder.getVecType(elemTypeId, 4);
@@ -4710,7 +4699,7 @@ SpirvEvalInfo SPIRVEmitter::doUnaryOperator(const UnaryOperator *expr) {
                              ? getMatElemValueOne(subType)
                              : getValueOne(subType);
     uint32_t incValue = 0;
-    if (TypeTranslator::isMxNMatrix(subType)) {
+    if (isMxNMatrix(subType)) {
       // For matrices, we can only increment/decrement each vector of it.
       const auto actOnEachVec = [this, spvOp, one](uint32_t /*index*/,
                                                    uint32_t vecType,
@@ -4919,12 +4908,11 @@ void SPIRVEmitter::storeValue(const SpirvEvalInfo &lhsPtr,
     lhsValType = refType->getPointeeType();
 
   QualType matElemType = {};
-  const bool lhsIsMat = typeTranslator.isMxNMatrix(lhsValType, &matElemType);
+  const bool lhsIsMat = isMxNMatrix(lhsValType, &matElemType);
   const bool lhsIsFloatMat = lhsIsMat && matElemType->isFloatingType();
   const bool lhsIsNonFpMat = lhsIsMat && !matElemType->isFloatingType();
 
-  if (typeTranslator.isScalarType(lhsValType) ||
-      typeTranslator.isVectorType(lhsValType) || lhsIsFloatMat) {
+  if (isScalarType(lhsValType) || isVectorType(lhsValType) || lhsIsFloatMat) {
     uint32_t rhsValId = rhsVal;
 
     // Special-case: According to the SPIR-V Spec: There is no physical size
@@ -4934,8 +4922,7 @@ void SPIRVEmitter::storeValue(const SpirvEvalInfo &lhsPtr,
     if (isBoolOrVecOfBoolType(lhsValType) &&
         lhsPtr.getLayoutRule() != SpirvLayoutRule::Void) {
       uint32_t vecSize = 1;
-      const bool isVec =
-          TypeTranslator::isVectorType(lhsValType, nullptr, &vecSize);
+      const bool isVec = isVectorType(lhsValType, nullptr, &vecSize);
       const auto toType =
           isVec ? astContext.getExtVectorType(astContext.UnsignedIntTy, vecSize)
                 : astContext.UnsignedIntTy;
@@ -5049,7 +5036,7 @@ uint32_t SPIRVEmitter::reconstructValue(const SpirvEvalInfo &srcVal,
       return val;
 
     uint32_t vecSize = 1;
-    TypeTranslator::isVectorType(valType, nullptr, &vecSize);
+    isVectorType(valType, nullptr, &vecSize);
     QualType boolType =
         vecSize == 1 ? astContext.BoolTy
                      : astContext.getExtVectorType(astContext.BoolTy, vecSize);
@@ -5095,7 +5082,7 @@ uint32_t SPIRVEmitter::reconstructValue(const SpirvEvalInfo &srcVal,
   QualType matElemType = {};
   uint32_t numRows = 0, numCols = 0;
   const bool isNonFpMat =
-      typeTranslator.isMxNMatrix(valType, &matElemType, &numRows, &numCols) &&
+      isMxNMatrix(valType, &matElemType, &numRows, &numCols) &&
       !matElemType->isFloatingType();
 
   if (isNonFpMat) {
@@ -5158,8 +5145,7 @@ SpirvEvalInfo SPIRVEmitter::processBinaryOp(const Expr *lhs, const Expr *rhs,
   // If the operands are of matrix type, we need to dispatch the operation
   // onto each element vector iff the operands are not degenerated matrices
   // and we don't have a matrix specific SPIR-V instruction for the operation.
-  if (!isSpirvMatrixOp(mandateGenOpcode) &&
-      TypeTranslator::isMxNMatrix(lhsType)) {
+  if (!isSpirvMatrixOp(mandateGenOpcode) && isMxNMatrix(lhsType)) {
     return processMatrixBinaryOp(lhs, rhs, opcode, sourceRange);
   }
 
@@ -5545,11 +5531,10 @@ uint32_t SPIRVEmitter::convertVectorToStruct(QualType structType,
   llvm::SmallVector<uint32_t, 4> members;
 
   for (const auto *field : structDecl->fields()) {
-    if (TypeTranslator::isScalarType(field->getType())) {
+    if (isScalarType(field->getType())) {
       members.push_back(theBuilder.createCompositeExtract(elemTypeId, vector,
                                                           {vectorIndex++}));
-    } else if (TypeTranslator::isVectorType(field->getType(), nullptr,
-                                            &elemCount)) {
+    } else if (isVectorType(field->getType(), nullptr, &elemCount)) {
       llvm::SmallVector<uint32_t, 4> indices;
       for (uint32_t i = 0; i < elemCount; ++i)
         indices.push_back(vectorIndex++);
@@ -5575,8 +5560,7 @@ SPIRVEmitter::tryToGenFloatVectorScale(const BinaryOperator *expr) {
   // We can only translate floatN * float into OpVectorTimesScalar.
   // So the result type must be floatN. Note that float1 is not a valid vector
   // in SPIR-V.
-  if (!(TypeTranslator::isVectorType(type, &elemType) &&
-        elemType->isFloatingType()))
+  if (!(isVectorType(type, &elemType) && elemType->isFloatingType()))
     return 0;
 
   const Expr *lhs = expr->getLHS();
@@ -5634,8 +5618,7 @@ SPIRVEmitter::tryToGenFloatMatrixScale(const BinaryOperator *expr) {
   // OpVectorTimesScalar.
   // So the result type can be floatMxN, floatMx1, or float1xN.
   if (!hlsl::IsHLSLMatType(type) ||
-      !hlsl::GetHLSLMatElementType(type)->isFloatingType() ||
-      TypeTranslator::is1x1Matrix(type))
+      !hlsl::GetHLSLMatElementType(type)->isFloatingType() || is1x1Matrix(type))
     return 0;
 
   const Expr *lhs = expr->getLHS();
@@ -5644,9 +5627,8 @@ SPIRVEmitter::tryToGenFloatMatrixScale(const BinaryOperator *expr) {
   const QualType rhsType = rhs->getType();
 
   const auto selectOpcode = [](const QualType ty) {
-    return TypeTranslator::isMx1Matrix(ty) || TypeTranslator::is1xNMatrix(ty)
-               ? spv::Op::OpVectorTimesScalar
-               : spv::Op::OpMatrixTimesScalar;
+    return isMx1Matrix(ty) || is1xNMatrix(ty) ? spv::Op::OpVectorTimesScalar
+                                              : spv::Op::OpMatrixTimesScalar;
   };
 
   // Multiplying a float matrix with a float scalar will be represented in
@@ -5893,7 +5875,7 @@ SpirvEvalInfo SPIRVEmitter::processEachVectorInMatrix(
     llvm::function_ref<uint32_t(uint32_t, uint32_t, uint32_t)>
         actOnEachVector) {
   const auto matType = matrix->getType();
-  assert(TypeTranslator::isMxNMatrix(matType));
+  assert(isMxNMatrix(matType));
   const uint32_t vecType = typeTranslator.getComponentVectorType(matType);
 
   uint32_t rowCount = 0, colCount = 0;
@@ -5984,7 +5966,7 @@ SPIRVEmitter::processMatrixBinaryOp(const Expr *lhs, const Expr *rhs,
                                     SourceRange range) {
   // TODO: some code are duplicated from processBinaryOp. Try to unify them.
   const auto lhsType = lhs->getType();
-  assert(TypeTranslator::isMxNMatrix(lhsType));
+  assert(isMxNMatrix(lhsType));
   const spv::Op spvOp = translateOp(opcode, lhsType);
 
   uint32_t rhsVal, lhsPtr, lhsVal;
@@ -6118,8 +6100,7 @@ const Expr *SPIRVEmitter::collectArrayStructIndices(
 
       if ((hlsl::IsHLSLVecType(thisBaseType) &&
            (hlsl::GetHLSLVecSize(thisBaseType) == 1)) ||
-          typeTranslator.is1x1Matrix(thisBaseType) ||
-          typeTranslator.is1xNMatrix(thisBaseType)) {
+          is1x1Matrix(thisBaseType) || is1xNMatrix(thisBaseType)) {
         // If this is a size-1 vector or 1xN matrix, ignore the index.
       } else {
         indices->push_back(doExpr(indexing->getArg(1)));
@@ -6154,7 +6135,7 @@ SpirvEvalInfo &SPIRVEmitter::turnIntoElementPtr(
   const bool needTempVar = base.isRValue();
 
   if (needTempVar) {
-    auto varName = TypeTranslator::getName(baseType);
+    auto varName = getAstTypeName(baseType);
     const auto var = createTemporaryVar(baseType, varName, base);
     base.setResultId(var)
         .setLayoutRule(SpirvLayoutRule::Void)
@@ -6193,8 +6174,7 @@ uint32_t SPIRVEmitter::castToBool(const uint32_t fromVal, QualType fromType,
   { // Special case handling for converting to a matrix of booleans.
     QualType elemType = {};
     uint32_t rowCount = 0, colCount = 0;
-    if (TypeTranslator::isMxNMatrix(fromType, &elemType, &rowCount,
-                                    &colCount)) {
+    if (isMxNMatrix(fromType, &elemType, &rowCount, &colCount)) {
       const auto fromRowQualType =
           astContext.getExtVectorType(elemType, colCount);
       const auto fromRowQualTypeId =
@@ -6255,12 +6235,12 @@ uint32_t SPIRVEmitter::castToInt(uint32_t fromVal, QualType fromType,
   {
     QualType elemType = {};
     uint32_t numRows = 0, numCols = 0;
-    if (TypeTranslator::isMxNMatrix(fromType, &elemType, &numRows, &numCols)) {
+    if (isMxNMatrix(fromType, &elemType, &numRows, &numCols)) {
       // The source matrix and the target matrix must have the same dimensions.
       QualType toElemType = {};
       uint32_t toNumRows = 0, toNumCols = 0;
-      const bool isMat = TypeTranslator::isMxNMatrix(toIntType, &toElemType,
-                                                     &toNumRows, &toNumCols);
+      const bool isMat =
+          isMxNMatrix(toIntType, &toElemType, &toNumRows, &toNumCols);
       assert(isMat && numRows == toNumRows && numCols == toNumCols);
       (void)isMat;
       (void)toNumRows;
@@ -6356,12 +6336,12 @@ uint32_t SPIRVEmitter::castToFloat(uint32_t fromVal, QualType fromType,
   {
     QualType elemType = {};
     uint32_t numRows = 0, numCols = 0;
-    if (TypeTranslator::isMxNMatrix(fromType, &elemType, &numRows, &numCols)) {
+    if (isMxNMatrix(fromType, &elemType, &numRows, &numCols)) {
       // The source matrix and the target matrix must have the same dimensions.
       QualType toElemType = {};
       uint32_t toNumRows = 0, toNumCols = 0;
-      const auto isMat = TypeTranslator::isMxNMatrix(toFloatType, &toElemType,
-                                                     &toNumRows, &toNumCols);
+      const auto isMat =
+          isMxNMatrix(toFloatType, &toElemType, &toNumRows, &toNumCols);
       assert(isMat && numRows == toNumRows && numCols == toNumCols);
       (void)isMat;
       (void)toNumRows;
@@ -6852,8 +6832,8 @@ SPIRVEmitter::processIntrinsicInterlockedMethod(const CallExpr *expr,
         // OpImageTexelPointer's Image argument must have a type of
         // OpTypePointer with Type OpTypeImage. Need to create a temporary
         // variable if the baseId is an rvalue.
-        baseId = createTemporaryVar(
-            base->getType(), TypeTranslator::getName(base->getType()), baseId);
+        baseId = createTemporaryVar(base->getType(),
+                                    getAstTypeName(base->getType()), baseId);
       }
       const auto coordId = doExpr(index);
       ptr = theBuilder.createImageTexelPointer(ptrType, baseId, coordId, zero);
@@ -7361,8 +7341,7 @@ uint32_t SPIRVEmitter::processIntrinsicModf(const CallExpr *callExpr) {
 
   // For scalar and vector argument types.
   {
-    if (TypeTranslator::isScalarType(argType) ||
-        TypeTranslator::isVectorType(argType)) {
+    if (isScalarType(argType) || isVectorType(argType)) {
       const auto argTypeId = typeTranslator.translateType(argType);
       // The struct members *must* have the same type.
       const auto modfStructTypeId = theBuilder.getStructType(
@@ -7383,7 +7362,7 @@ uint32_t SPIRVEmitter::processIntrinsicModf(const CallExpr *callExpr) {
   {
     uint32_t rowCount = 0, colCount = 0;
     QualType elemType = {};
-    if (TypeTranslator::isMxNMatrix(argType, &elemType, &rowCount, &colCount)) {
+    if (isMxNMatrix(argType, &elemType, &rowCount, &colCount)) {
       const auto elemTypeId = typeTranslator.translateType(elemType);
       const auto colTypeId = theBuilder.getVecType(elemTypeId, colCount);
       const auto modfStructTypeId = theBuilder.getStructType(
@@ -7478,8 +7457,7 @@ uint32_t SPIRVEmitter::processIntrinsicFrexp(const CallExpr *callExpr) {
   // For scalar and vector argument types.
   {
     uint32_t elemCount = 1;
-    if (TypeTranslator::isScalarType(argType) ||
-        TypeTranslator::isVectorType(argType, nullptr, &elemCount)) {
+    if (isScalarType(argType) || isVectorType(argType, nullptr, &elemCount)) {
       const auto argTypeId = typeTranslator.translateType(argType);
       const auto expTypeId =
           elemCount == 1 ? intId : theBuilder.getVecType(intId, elemCount);
@@ -7504,7 +7482,7 @@ uint32_t SPIRVEmitter::processIntrinsicFrexp(const CallExpr *callExpr) {
   // For matrix argument types.
   {
     uint32_t rowCount = 0, colCount = 0;
-    if (TypeTranslator::isMxNMatrix(argType, nullptr, &rowCount, &colCount)) {
+    if (isMxNMatrix(argType, nullptr, &rowCount, &colCount)) {
       const auto floatId = theBuilder.getFloat32Type();
       const auto expTypeId = theBuilder.getVecType(intId, colCount);
       const auto colTypeId = theBuilder.getVecType(floatId, colCount);
@@ -7555,8 +7533,7 @@ uint32_t SPIRVEmitter::processIntrinsicLdexp(const CallExpr *callExpr) {
   const uint32_t expId = doExpr(callExpr->getArg(1));
 
   // For scalar and vector argument types.
-  if (TypeTranslator::isScalarType(paramType) ||
-      TypeTranslator::isVectorType(paramType)) {
+  if (isScalarType(paramType) || isVectorType(paramType)) {
     const auto paramTypeId = typeTranslator.translateType(paramType);
     const auto twoExp = theBuilder.createExtInst(
         paramTypeId, glsl, GLSLstd450::GLSLstd450Exp2, {expId});
@@ -7566,7 +7543,7 @@ uint32_t SPIRVEmitter::processIntrinsicLdexp(const CallExpr *callExpr) {
   // For matrix argument types.
   {
     uint32_t rowCount = 0, colCount = 0;
-    if (TypeTranslator::isMxNMatrix(paramType, nullptr, &rowCount, &colCount)) {
+    if (isMxNMatrix(paramType, nullptr, &rowCount, &colCount)) {
       const auto actOnEachVec = [this, glsl, expId](uint32_t index,
                                                     uint32_t vecType,
                                                     uint32_t xRowId) {
@@ -7625,18 +7602,17 @@ uint32_t SPIRVEmitter::processIntrinsicClip(const CallExpr *callExpr) {
 
   QualType elemType = {};
   uint32_t elemCount = 0, rowCount = 0, colCount = 0;
-  if (TypeTranslator::isScalarType(argType)) {
+  if (isScalarType(argType)) {
     const auto zero = getValueZero(argType);
     condition = theBuilder.createBinaryOp(spv::Op::OpFOrdLessThan, boolType,
                                           argId, zero);
-  } else if (TypeTranslator::isVectorType(argType, nullptr, &elemCount)) {
+  } else if (isVectorType(argType, nullptr, &elemCount)) {
     const auto zero = getValueZero(argType);
     const auto boolVecType = theBuilder.getVecType(boolType, elemCount);
     const auto cmp = theBuilder.createBinaryOp(spv::Op::OpFOrdLessThan,
                                                boolVecType, argId, zero);
     condition = theBuilder.createUnaryOp(spv::Op::OpAny, boolType, cmp);
-  } else if (TypeTranslator::isMxNMatrix(argType, &elemType, &rowCount,
-                                         &colCount)) {
+  } else if (isMxNMatrix(argType, &elemType, &rowCount, &colCount)) {
     const uint32_t elemTypeId = typeTranslator.translateType(elemType);
     const uint32_t floatVecType = theBuilder.getVecType(elemTypeId, colCount);
     const uint32_t elemZeroId = getValueZero(elemType);
@@ -7702,7 +7678,7 @@ uint32_t SPIRVEmitter::processIntrinsicClamp(const CallExpr *callExpr) {
 
   // FClamp, UClamp, and SClamp do not operate on matrices, so we should perform
   // the operation on each vector of the matrix.
-  if (TypeTranslator::isMxNMatrix(argX->getType())) {
+  if (isMxNMatrix(argX->getType())) {
     const auto actOnEachVec = [this, glslInstSetId, glslOpcode, argMinId,
                                argMaxId](uint32_t index, uint32_t vecType,
                                          uint32_t curRowId) {
@@ -7793,8 +7769,7 @@ uint32_t SPIRVEmitter::processNonFpMatrixTranspose(QualType matType,
   // flattened elements. (for a mat4x4).
   QualType elemType = {};
   uint32_t numRows = 0, numCols = 0;
-  const bool isMat =
-      TypeTranslator::isMxNMatrix(matType, &elemType, &numRows, &numCols);
+  const bool isMat = isMxNMatrix(matType, &elemType, &numRows, &numCols);
   assert(isMat && !elemType->isFloatingType());
   (void)isMat;
 
@@ -7851,11 +7826,10 @@ uint32_t SPIRVEmitter::processNonFpScalarTimesMatrix(QualType scalarType,
                                                      uint32_t scalarId,
                                                      QualType matrixType,
                                                      uint32_t matrixId) {
-  assert(TypeTranslator::isScalarType(scalarType));
+  assert(isScalarType(scalarType));
   QualType elemType = {};
   uint32_t numRows = 0, numCols = 0;
-  const bool isMat =
-      TypeTranslator::isMxNMatrix(matrixType, &elemType, &numRows, &numCols);
+  const bool isMat = isMxNMatrix(matrixType, &elemType, &numRows, &numCols);
   assert(isMat);
   assert(typeTranslator.isSameType(scalarType, elemType));
   (void)isMat;
@@ -7891,10 +7865,8 @@ uint32_t SPIRVEmitter::processNonFpVectorTimesMatrix(QualType vecType,
   // are the same.
   QualType vecElemType = {}, matElemType = {};
   uint32_t vecSize = 0, numRows = 0, numCols = 0;
-  const bool isVec =
-      TypeTranslator::isVectorType(vecType, &vecElemType, &vecSize);
-  const bool isMat =
-      TypeTranslator::isMxNMatrix(matType, &matElemType, &numRows, &numCols);
+  const bool isVec = isVectorType(vecType, &vecElemType, &vecSize);
+  const bool isMat = isMxNMatrix(matType, &matElemType, &numRows, &numCols);
   assert(typeTranslator.isSameType(vecElemType, matElemType));
   assert(isVec);
   assert(isMat);
@@ -7930,10 +7902,8 @@ uint32_t SPIRVEmitter::processNonFpMatrixTimesVector(QualType matType,
   // are the same.
   QualType vecElemType = {}, matElemType = {};
   uint32_t vecSize = 0, numRows = 0, numCols = 0;
-  const bool isVec =
-      TypeTranslator::isVectorType(vecType, &vecElemType, &vecSize);
-  const bool isMat =
-      TypeTranslator::isMxNMatrix(matType, &matElemType, &numRows, &numCols);
+  const bool isVec = isVectorType(vecType, &vecElemType, &vecSize);
+  const bool isMat = isMxNMatrix(matType, &matElemType, &numRows, &numCols);
   assert(typeTranslator.isSameType(vecElemType, matElemType));
   assert(isVec);
   assert(isMat);
@@ -7966,10 +7936,10 @@ uint32_t SPIRVEmitter::processNonFpMatrixTimesMatrix(QualType lhsType,
   QualType lhsElemType = {}, rhsElemType = {};
   uint32_t lhsNumRows = 0, lhsNumCols = 0;
   uint32_t rhsNumRows = 0, rhsNumCols = 0;
-  const bool lhsIsMat = TypeTranslator::isMxNMatrix(lhsType, &lhsElemType,
-                                                    &lhsNumRows, &lhsNumCols);
-  const bool rhsIsMat = TypeTranslator::isMxNMatrix(rhsType, &rhsElemType,
-                                                    &rhsNumRows, &rhsNumCols);
+  const bool lhsIsMat =
+      isMxNMatrix(lhsType, &lhsElemType, &lhsNumRows, &lhsNumCols);
+  const bool rhsIsMat =
+      isMxNMatrix(rhsType, &rhsElemType, &rhsNumRows, &rhsNumCols);
   assert(typeTranslator.isSameType(lhsElemType, rhsElemType));
   assert(lhsIsMat && rhsIsMat);
   assert(lhsNumCols == rhsNumRows);
@@ -8014,8 +7984,7 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   // mul(scalar, vector)
   {
     uint32_t elemCount = 0;
-    if (TypeTranslator::isScalarType(arg0Type) &&
-        TypeTranslator::isVectorType(arg1Type, nullptr, &elemCount)) {
+    if (isScalarType(arg0Type) && isVectorType(arg1Type, nullptr, &elemCount)) {
 
       const uint32_t arg1Id = doExpr(arg1);
 
@@ -8034,8 +8003,7 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   // mul(vector, scalar)
   {
     uint32_t elemCount = 0;
-    if (TypeTranslator::isVectorType(arg0Type, nullptr, &elemCount) &&
-        TypeTranslator::isScalarType(arg1Type)) {
+    if (isVectorType(arg0Type, nullptr, &elemCount) && isScalarType(arg1Type)) {
 
       const uint32_t arg0Id = doExpr(arg0);
 
@@ -8051,8 +8019,7 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   }
 
   // mul(vector, vector)
-  if (TypeTranslator::isVectorType(arg0Type) &&
-      TypeTranslator::isVectorType(arg1Type))
+  if (isVectorType(arg0Type) && isVectorType(arg1Type))
     return processIntrinsicDot(callExpr);
 
   // All the following cases require handling arg0 and arg1 expressions first.
@@ -8060,16 +8027,14 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   const uint32_t arg1Id = doExpr(arg1);
 
   // mul(scalar, scalar)
-  if (TypeTranslator::isScalarType(arg0Type) &&
-      TypeTranslator::isScalarType(arg1Type))
+  if (isScalarType(arg0Type) && isScalarType(arg1Type))
     return theBuilder.createBinaryOp(translateOp(BO_Mul, arg0Type),
                                      returnTypeId, arg0Id, arg1Id);
 
   // mul(scalar, matrix)
   {
     QualType elemType = {};
-    if (TypeTranslator::isScalarType(arg0Type) &&
-        TypeTranslator::isMxNMatrix(arg1Type, &elemType)) {
+    if (isScalarType(arg0Type) && isMxNMatrix(arg1Type, &elemType)) {
       // OpMatrixTimesScalar can only be used if *both* the matrix element type
       // and the scalar type are float.
       if (arg0Type->isFloatingType() && elemType->isFloatingType())
@@ -8084,8 +8049,7 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   // mul(matrix, scalar)
   {
     QualType elemType = {};
-    if (TypeTranslator::isScalarType(arg1Type) &&
-        TypeTranslator::isMxNMatrix(arg0Type, &elemType)) {
+    if (isScalarType(arg1Type) && isMxNMatrix(arg0Type, &elemType)) {
       // OpMatrixTimesScalar can only be used if *both* the matrix element type
       // and the scalar type are float.
       if (arg1Type->isFloatingType() && elemType->isFloatingType())
@@ -8101,8 +8065,8 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   {
     QualType vecElemType = {}, matElemType = {};
     uint32_t elemCount = 0, numRows = 0;
-    if (TypeTranslator::isVectorType(arg0Type, &vecElemType, &elemCount) &&
-        TypeTranslator::isMxNMatrix(arg1Type, &matElemType, &numRows)) {
+    if (isVectorType(arg0Type, &vecElemType, &elemCount) &&
+        isMxNMatrix(arg1Type, &matElemType, &numRows)) {
       assert(elemCount == numRows);
 
       if (vecElemType->isFloatingType() && matElemType->isFloatingType())
@@ -8118,9 +8082,8 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
   {
     QualType vecElemType = {}, matElemType = {};
     uint32_t elemCount = 0, numCols = 0;
-    if (TypeTranslator::isMxNMatrix(arg0Type, &matElemType, nullptr,
-                                    &numCols) &&
-        TypeTranslator::isVectorType(arg1Type, &vecElemType, &elemCount)) {
+    if (isMxNMatrix(arg0Type, &matElemType, nullptr, &numCols) &&
+        isVectorType(arg1Type, &vecElemType, &elemCount)) {
       assert(elemCount == numCols);
       if (vecElemType->isFloatingType() && matElemType->isFloatingType())
         return theBuilder.createBinaryOp(spv::Op::OpVectorTimesMatrix,
@@ -8136,8 +8099,8 @@ uint32_t SPIRVEmitter::processIntrinsicMul(const CallExpr *callExpr) {
     // The front-end ensures that the two matrix element types match.
     QualType elemType = {};
     uint32_t lhsCols = 0, rhsRows = 0;
-    if (TypeTranslator::isMxNMatrix(arg0Type, &elemType, nullptr, &lhsCols) &&
-        TypeTranslator::isMxNMatrix(arg1Type, nullptr, &rhsRows, nullptr)) {
+    if (isMxNMatrix(arg0Type, &elemType, nullptr, &lhsCols) &&
+        isMxNMatrix(arg1Type, nullptr, &rhsRows, nullptr)) {
       assert(lhsCols == rhsRows);
       if (elemType->isFloatingType())
         return theBuilder.createBinaryOp(spv::Op::OpMatrixTimesMatrix,
@@ -8239,7 +8202,7 @@ uint32_t SPIRVEmitter::processIntrinsicRcp(const CallExpr *callExpr) {
   // For cases with matrix argument.
   QualType elemType = {};
   uint32_t numRows = 0, numCols = 0;
-  if (TypeTranslator::isMxNMatrix(argType, &elemType, &numRows, &numCols)) {
+  if (isMxNMatrix(argType, &elemType, &numRows, &numCols)) {
     const uint32_t vecOne = getVecValueOne(elemType, numCols);
     const auto actOnEachVec = [this, vecOne](uint32_t /*index*/,
                                              uint32_t vecType,
@@ -8268,7 +8231,7 @@ uint32_t SPIRVEmitter::processIntrinsicAllOrAny(const CallExpr *callExpr,
   // Optimization: can directly cast them to boolean. No need for OpAny/OpAll.
   {
     QualType scalarType = {};
-    if (TypeTranslator::isScalarType(argType, &scalarType) &&
+    if (isScalarType(argType, &scalarType) &&
         (scalarType->isBooleanType() || scalarType->isFloatingType() ||
          scalarType->isIntegerType()))
       return castToBool(doExpr(arg), argType, returnType);
@@ -8279,7 +8242,7 @@ uint32_t SPIRVEmitter::processIntrinsicAllOrAny(const CallExpr *callExpr,
   {
     QualType elemType = {};
     uint32_t size = 0;
-    if (TypeTranslator::isVectorType(argType, &elemType, &size)) {
+    if (isVectorType(argType, &elemType, &size)) {
       const QualType castToBoolType =
           astContext.getExtVectorType(returnType, size);
       uint32_t castedToBoolId =
@@ -8292,8 +8255,7 @@ uint32_t SPIRVEmitter::processIntrinsicAllOrAny(const CallExpr *callExpr,
   {
     QualType elemType = {};
     uint32_t matRowCount = 0, matColCount = 0;
-    if (TypeTranslator::isMxNMatrix(argType, &elemType, &matRowCount,
-                                    &matColCount)) {
+    if (isMxNMatrix(argType, &elemType, &matRowCount, &matColCount)) {
       uint32_t matrixId = doExpr(arg);
       const uint32_t vecType = typeTranslator.getComponentVectorType(argType);
       llvm::SmallVector<uint32_t, 4> rowResults;
@@ -8375,8 +8337,7 @@ uint32_t SPIRVEmitter::processIntrinsicAsType(const CallExpr *callExpr) {
     QualType fromElemType = {};
     uint32_t numRows = 0, numCols = 0;
     // For non-matrix arguments (scalar or vector), just do an OpBitCast.
-    if (!TypeTranslator::isMxNMatrix(argType, &fromElemType, &numRows,
-                                     &numCols)) {
+    if (!isMxNMatrix(argType, &fromElemType, &numRows, &numCols)) {
       return theBuilder.createUnaryOp(spv::Op::OpBitcast, returnTypeId, argId);
     }
 
@@ -8513,7 +8474,7 @@ uint32_t SPIRVEmitter::processIntrinsicSaturate(const CallExpr *callExpr) {
 
   QualType elemType = {};
   uint32_t vecSize = 0;
-  if (TypeTranslator::isVectorType(argType, &elemType, &vecSize)) {
+  if (isVectorType(argType, &elemType, &vecSize)) {
     const uint32_t vecZero = getVecValueZero(elemType, vecSize);
     const uint32_t vecOne = getVecValueOne(elemType, vecSize);
     return theBuilder.createExtInst(returnType, glslInstSetId,
@@ -8522,7 +8483,7 @@ uint32_t SPIRVEmitter::processIntrinsicSaturate(const CallExpr *callExpr) {
   }
 
   uint32_t numRows = 0, numCols = 0;
-  if (TypeTranslator::isMxNMatrix(argType, &elemType, &numRows, &numCols)) {
+  if (isMxNMatrix(argType, &elemType, &numRows, &numCols)) {
     const uint32_t vecZero = getVecValueZero(elemType, numCols);
     const uint32_t vecOne = getVecValueOne(elemType, numCols);
     const auto actOnEachVec = [this, vecZero, vecOne, glslInstSetId](
@@ -8552,7 +8513,7 @@ uint32_t SPIRVEmitter::processIntrinsicFloatSign(const CallExpr *callExpr) {
   uint32_t floatSignResultId = 0;
 
   // For matrices, we can perform the instruction on each vector of the matrix.
-  if (TypeTranslator::isMxNMatrix(argType)) {
+  if (isMxNMatrix(argType)) {
     const auto actOnEachVec = [this, glslInstSetId](uint32_t /*index*/,
                                                     uint32_t vecType,
                                                     uint32_t curRowId) {
@@ -8582,7 +8543,7 @@ uint32_t SPIRVEmitter::processIntrinsicF16ToF32(const CallExpr *callExpr) {
 
   uint32_t elemCount = {};
 
-  if (TypeTranslator::isVectorType(arg->getType(), nullptr, &elemCount)) {
+  if (isVectorType(arg->getType(), nullptr, &elemCount)) {
     // The input is a vector. We need to handle each element separately.
     llvm::SmallVector<uint32_t, 4> elements;
 
@@ -8618,7 +8579,7 @@ uint32_t SPIRVEmitter::processIntrinsicF32ToF16(const CallExpr *callExpr) {
   const uint32_t argId = doExpr(arg);
   uint32_t elemCount = {};
 
-  if (TypeTranslator::isVectorType(arg->getType(), nullptr, &elemCount)) {
+  if (isVectorType(arg->getType(), nullptr, &elemCount)) {
     // The input is a vector. We need to handle each element separately.
     llvm::SmallVector<uint32_t, 4> elements;
 
@@ -8672,7 +8633,7 @@ uint32_t SPIRVEmitter::processIntrinsicUsingSpirvInst(
 
     // If the instruction does not operate on matrices, we can perform the
     // instruction on each vector of the matrix.
-    if (actPerRowForMatrices && TypeTranslator::isMxNMatrix(arg->getType())) {
+    if (actPerRowForMatrices && isMxNMatrix(arg->getType())) {
       const auto actOnEachVec = [this, opcode](uint32_t /*index*/,
                                                uint32_t vecType,
                                                uint32_t curRowId) {
@@ -8687,7 +8648,7 @@ uint32_t SPIRVEmitter::processIntrinsicUsingSpirvInst(
     const uint32_t arg1Id = doExpr(callExpr->getArg(1));
     // If the instruction does not operate on matrices, we can perform the
     // instruction on each vector of the matrix.
-    if (actPerRowForMatrices && TypeTranslator::isMxNMatrix(arg0->getType())) {
+    if (actPerRowForMatrices && isMxNMatrix(arg0->getType())) {
       const auto actOnEachVec = [this, opcode, arg1Id](uint32_t index,
                                                        uint32_t vecType,
                                                        uint32_t arg0RowId) {
@@ -8716,7 +8677,7 @@ uint32_t SPIRVEmitter::processIntrinsicUsingGLSLInst(
 
     // If the instruction does not operate on matrices, we can perform the
     // instruction on each vector of the matrix.
-    if (actPerRowForMatrices && TypeTranslator::isMxNMatrix(arg->getType())) {
+    if (actPerRowForMatrices && isMxNMatrix(arg->getType())) {
       const auto actOnEachVec = [this, glslInstSetId,
                                  opcode](uint32_t /*index*/, uint32_t vecType,
                                          uint32_t curRowId) {
@@ -8732,7 +8693,7 @@ uint32_t SPIRVEmitter::processIntrinsicUsingGLSLInst(
     const uint32_t arg1Id = doExpr(callExpr->getArg(1));
     // If the instruction does not operate on matrices, we can perform the
     // instruction on each vector of the matrix.
-    if (actPerRowForMatrices && TypeTranslator::isMxNMatrix(arg0->getType())) {
+    if (actPerRowForMatrices && isMxNMatrix(arg0->getType())) {
       const auto actOnEachVec = [this, glslInstSetId, opcode,
                                  arg1Id](uint32_t index, uint32_t vecType,
                                          uint32_t arg0RowId) {
@@ -8752,7 +8713,7 @@ uint32_t SPIRVEmitter::processIntrinsicUsingGLSLInst(
     const uint32_t arg2Id = doExpr(callExpr->getArg(2));
     // If the instruction does not operate on matrices, we can perform the
     // instruction on each vector of the matrix.
-    if (actPerRowForMatrices && TypeTranslator::isMxNMatrix(arg0->getType())) {
+    if (actPerRowForMatrices && isMxNMatrix(arg0->getType())) {
       const auto actOnEachVec = [this, glslInstSetId, opcode, arg1Id,
                                  arg2Id](uint32_t index, uint32_t vecType,
                                          uint32_t arg0RowId) {
@@ -8783,9 +8744,9 @@ uint32_t SPIRVEmitter::processIntrinsicLog10(const CallExpr *callExpr) {
       processIntrinsicUsingGLSLInst(callExpr, GLSLstd450::GLSLstd450Log2, true);
   const auto returnType = callExpr->getType();
   const auto returnTypeId = typeTranslator.translateType(returnType);
-  spv::Op scaleOp = TypeTranslator::isScalarType(returnType)
+  spv::Op scaleOp = isScalarType(returnType)
                         ? spv::Op::OpFMul
-                        : TypeTranslator::isVectorType(returnType)
+                        : isVectorType(returnType)
                               ? spv::Op::OpVectorTimesScalar
                               : spv::Op::OpMatrixTimesScalar;
   return theBuilder.createBinaryOp(scaleOp, returnTypeId, log2, scale);
@@ -8794,7 +8755,7 @@ uint32_t SPIRVEmitter::processIntrinsicLog10(const CallExpr *callExpr) {
 uint32_t SPIRVEmitter::getValueZero(QualType type) {
   {
     QualType scalarType = {};
-    if (TypeTranslator::isScalarType(type, &scalarType)) {
+    if (isScalarType(type, &scalarType)) {
       if (scalarType->isSignedIntegerType()) {
         return theBuilder.getConstantInt32(0);
       }
@@ -8812,7 +8773,7 @@ uint32_t SPIRVEmitter::getValueZero(QualType type) {
   {
     QualType elemType = {};
     uint32_t size = {};
-    if (TypeTranslator::isVectorType(type, &elemType, &size)) {
+    if (isVectorType(type, &elemType, &size)) {
       return getVecValueZero(elemType, size);
     }
   }
@@ -8820,7 +8781,7 @@ uint32_t SPIRVEmitter::getValueZero(QualType type) {
   {
     QualType elemType = {};
     uint32_t rowCount = 0, colCount = 0;
-    if (TypeTranslator::isMxNMatrix(type, &elemType, &rowCount, &colCount)) {
+    if (isMxNMatrix(type, &elemType, &rowCount, &colCount)) {
       const auto row = getVecValueZero(elemType, colCount);
       llvm::SmallVector<uint32_t, 4> rows((size_t)rowCount, row);
       return theBuilder.createCompositeConstruct(
@@ -8849,7 +8810,7 @@ uint32_t SPIRVEmitter::getVecValueZero(QualType elemType, uint32_t size) {
 uint32_t SPIRVEmitter::getValueOne(QualType type) {
   {
     QualType scalarType = {};
-    if (TypeTranslator::isScalarType(type, &scalarType)) {
+    if (isScalarType(type, &scalarType)) {
       if (scalarType->isBooleanType()) {
         return theBuilder.getConstantBool(true);
       }
@@ -8891,7 +8852,7 @@ uint32_t SPIRVEmitter::getValueOne(QualType type) {
   {
     QualType elemType = {};
     uint32_t size = {};
-    if (TypeTranslator::isVectorType(type, &elemType, &size)) {
+    if (isVectorType(type, &elemType, &size)) {
       return getVecValueOne(elemType, size);
     }
   }
@@ -8931,8 +8892,7 @@ uint32_t SPIRVEmitter::getMaskForBitwidthValue(QualType type) {
   QualType elemType = {};
   uint32_t count = 1;
 
-  if (TypeTranslator::isScalarType(type, &elemType) ||
-      TypeTranslator::isVectorType(type, &elemType, &count)) {
+  if (isScalarType(type, &elemType) || isVectorType(type, &elemType, &count)) {
     const auto bitwidth = typeTranslator.getElementSpirvBitwidth(elemType);
     uint32_t mask = 0;
     uint32_t elemTypeId = 0;

+ 12 - 216
tools/clang/lib/SPIRV/TypeTranslator.cpp

@@ -16,6 +16,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/HlslTypes.h"
+#include "clang/SPIRV/AstTypeProbe.h"
 
 namespace clang {
 namespace spirv {
@@ -33,7 +34,7 @@ inline uint32_t roundToPow2(uint32_t val, uint32_t pow2) {
 /// Returns true if the given vector type (of the given size) crosses the
 /// 4-component vector boundary if placed at the given offset.
 bool improperStraddle(QualType type, int size, int offset) {
-  assert(TypeTranslator::isVectorType(type));
+  assert(isVectorType(type));
   return size <= 16 ? offset / 16 != (offset + size - 1) / 16
                     : offset % 16 != 0;
 }
@@ -433,15 +434,15 @@ uint32_t TypeTranslator::getElementSpirvBitwidth(QualType type) {
 
   // Typedefs
   if (const auto *typedefType = type->getAs<TypedefType>())
-    return getLocationCount(typedefType->desugar());
+    return getElementSpirvBitwidth(typedefType->desugar());
 
   // Reference types
   if (const auto *refType = type->getAs<ReferenceType>())
-    return getLocationCount(refType->getPointeeType());
+    return getElementSpirvBitwidth(refType->getPointeeType());
 
   // Pointer types
   if (const auto *ptrType = type->getAs<PointerType>())
-    return getLocationCount(ptrType->getPointeeType());
+    return getElementSpirvBitwidth(ptrType->getPointeeType());
 
   // Scalar types
   QualType ty = {};
@@ -717,33 +718,6 @@ uint32_t TypeTranslator::getACSBufferCounter() {
                                   decorations);
 }
 
-bool TypeTranslator::isScalarType(QualType type, QualType *scalarType) {
-  bool isScalar = false;
-  QualType ty = {};
-
-  if (type->isBuiltinType()) {
-    isScalar = true;
-    ty = type;
-  } else if (hlsl::IsHLSLVecType(type) && hlsl::GetHLSLVecSize(type) == 1) {
-    isScalar = true;
-    ty = hlsl::GetHLSLVecElementType(type);
-  } else if (const auto *extVecType =
-                 dyn_cast<ExtVectorType>(type.getTypePtr())) {
-    if (extVecType->getNumElements() == 1) {
-      isScalar = true;
-      ty = extVecType->getElementType();
-    }
-  } else if (is1x1Matrix(type)) {
-    isScalar = true;
-    ty = hlsl::GetHLSLMatElementType(type);
-  }
-
-  if (isScalar && scalarType)
-    *scalarType = ty;
-
-  return isScalar;
-}
-
 bool TypeTranslator::isRWByteAddressBuffer(QualType type) {
   if (const auto *rt = type->getAs<RecordType>()) {
     return rt->getDecl()->getName() == "RWByteAddressBuffer";
@@ -971,118 +945,6 @@ bool TypeTranslator::isSubpassInputMS(QualType type) {
   return false;
 }
 
-bool TypeTranslator::isVectorType(QualType type, QualType *elemType,
-                                  uint32_t *elemCount) {
-  bool isVec = false;
-  QualType ty = {};
-  uint32_t count = 0;
-
-  if (hlsl::IsHLSLVecType(type)) {
-    ty = hlsl::GetHLSLVecElementType(type);
-    count = hlsl::GetHLSLVecSize(type);
-    isVec = count > 1;
-  } else if (const auto *extVecType =
-                 dyn_cast<ExtVectorType>(type.getTypePtr())) {
-    ty = extVecType->getElementType();
-    count = extVecType->getNumElements();
-    isVec = count > 1;
-  } else if (hlsl::IsHLSLMatType(type)) {
-    uint32_t rowCount = 0, colCount = 0;
-    hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
-
-    ty = hlsl::GetHLSLMatElementType(type);
-    count = rowCount == 1 ? colCount : rowCount;
-    isVec = (rowCount == 1) != (colCount == 1);
-  }
-
-  if (isVec) {
-    if (elemType)
-      *elemType = ty;
-    if (elemCount)
-      *elemCount = count;
-  }
-  return isVec;
-}
-
-bool TypeTranslator::is1x1Matrix(QualType type, QualType *elemType) {
-  if (!hlsl::IsHLSLMatType(type))
-    return false;
-
-  uint32_t rowCount = 0, colCount = 0;
-  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
-
-  const bool is1x1 = rowCount == 1 && colCount == 1;
-
-  if (!is1x1)
-    return false;
-
-  if (elemType)
-    *elemType = hlsl::GetHLSLMatElementType(type);
-  return true;
-}
-
-bool TypeTranslator::is1xNMatrix(QualType type, QualType *elemType,
-                                 uint32_t *count) {
-  if (!hlsl::IsHLSLMatType(type))
-    return false;
-
-  uint32_t rowCount = 0, colCount = 0;
-  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
-
-  const bool is1xN = rowCount == 1 && colCount > 1;
-
-  if (!is1xN)
-    return false;
-
-  if (elemType)
-    *elemType = hlsl::GetHLSLMatElementType(type);
-  if (count)
-    *count = colCount;
-  return true;
-}
-
-bool TypeTranslator::isMx1Matrix(QualType type, QualType *elemType,
-                                 uint32_t *count) {
-  if (!hlsl::IsHLSLMatType(type))
-    return false;
-
-  uint32_t rowCount = 0, colCount = 0;
-  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
-
-  const bool isMx1 = rowCount > 1 && colCount == 1;
-
-  if (!isMx1)
-    return false;
-
-  if (elemType)
-    *elemType = hlsl::GetHLSLMatElementType(type);
-  if (count)
-    *count = rowCount;
-  return true;
-}
-
-bool TypeTranslator::isMxNMatrix(QualType type, QualType *elemType,
-                                 uint32_t *numRows, uint32_t *numCols) {
-  if (!hlsl::IsHLSLMatType(type))
-    return false;
-
-  uint32_t rowCount = 0, colCount = 0;
-  hlsl::GetHLSLMatRowColCount(type, rowCount, colCount);
-
-  const bool isMxN = rowCount > 1 && colCount > 1;
-
-  if (!isMxN)
-    return false;
-
-  if (elemType)
-    *elemType = hlsl::GetHLSLMatElementType(type);
-  if (numRows)
-    *numRows = rowCount;
-  if (numCols)
-    *numCols = colCount;
-  return true;
-}
-
 bool TypeTranslator::isOrContainsNonFpColMajorMatrix(QualType type,
                                                      const Decl *decl) const {
   const auto isColMajorDecl = [this](const Decl *decl) {
@@ -1185,16 +1047,15 @@ bool TypeTranslator::canTreatAsSameScalarType(QualType type1, QualType type2) {
 bool TypeTranslator::isSameScalarOrVecType(QualType type1, QualType type2) {
   { // Scalar types
     QualType scalarType1 = {}, scalarType2 = {};
-    if (TypeTranslator::isScalarType(type1, &scalarType1) &&
-        TypeTranslator::isScalarType(type2, &scalarType2))
+    if (isScalarType(type1, &scalarType1) && isScalarType(type2, &scalarType2))
       return canTreatAsSameScalarType(scalarType1, scalarType2);
   }
 
   { // Vector types
     QualType elemType1 = {}, elemType2 = {};
     uint32_t count1 = {}, count2 = {};
-    if (TypeTranslator::isVectorType(type1, &elemType1, &count1) &&
-        TypeTranslator::isVectorType(type2, &elemType2, &count2))
+    if (isVectorType(type1, &elemType1, &count1) &&
+        isVectorType(type2, &elemType2, &count2))
       return count1 == count2 && canTreatAsSameScalarType(elemType1, elemType2);
   }
 
@@ -1211,8 +1072,8 @@ bool TypeTranslator::isSameType(QualType type1, QualType type2) {
   { // Matrix types
     QualType elemType1 = {}, elemType2 = {};
     uint32_t row1 = 0, row2 = 0, col1 = 0, col2 = 0;
-    if (TypeTranslator::isMxNMatrix(type1, &elemType1, &row1, &col1) &&
-        TypeTranslator::isMxNMatrix(type2, &elemType2, &row2, &col2))
+    if (isMxNMatrix(type1, &elemType1, &row1, &col1) &&
+        isMxNMatrix(type2, &elemType2, &row2, &col2))
       return row1 == row2 && col1 == col2 &&
              canTreatAsSameScalarType(elemType1, elemType2);
   }
@@ -1526,7 +1387,7 @@ uint32_t TypeTranslator::translateResourceType(QualType type,
     if (innerType->isStructureType())
       structName = innerType->getAs<RecordType>()->getDecl()->getName();
     else
-      structName = getName(innerType);
+      structName = getAstTypeName(innerType);
 
     const bool isRowMajor = isRowMajorMatrix(s);
     llvm::SmallVector<const Decoration *, 4> decorations;
@@ -1541,7 +1402,7 @@ uint32_t TypeTranslator::translateResourceType(QualType type,
     decorations.clear();
 
     // Attach majorness decoration if this is a *StructuredBuffer<matrix>.
-    if (TypeTranslator::isMxNMatrix(s))
+    if (isMxNMatrix(s))
       decorations.push_back(isRowMajor ? Decoration::getColMajor(context, 0)
                                        : Decoration::getRowMajor(context, 0));
 
@@ -2017,71 +1878,6 @@ TypeTranslator::getAlignmentAndSize(QualType type, SpirvLayoutRule rule,
   return {0, 0};
 }
 
-std::string TypeTranslator::getName(QualType type) {
-  {
-    QualType ty = {};
-    if (isScalarType(type, &ty))
-      if (const auto *builtinType = ty->getAs<BuiltinType>())
-        switch (builtinType->getKind()) {
-        case BuiltinType::Void:
-          return "void";
-        case BuiltinType::Bool:
-          return "bool";
-        case BuiltinType::Int:
-          return "int";
-        case BuiltinType::UInt:
-          return "uint";
-        case BuiltinType::Float:
-          return "float";
-        case BuiltinType::Double:
-          return "double";
-        case BuiltinType::LongLong:
-          return "int64";
-        case BuiltinType::ULongLong:
-          return "uint64";
-        case BuiltinType::Short:
-          return "short";
-        case BuiltinType::UShort:
-          return "ushort";
-        case BuiltinType::Half:
-        case BuiltinType::HalfFloat:
-          return "half";
-        case BuiltinType::Min12Int:
-          return "min12int";
-        case BuiltinType::Min16Int:
-          return "min16int";
-        case BuiltinType::Min16UInt:
-          return "min16uint";
-        case BuiltinType::Min16Float:
-          return "min16float";
-        case BuiltinType::Min10Float:
-          return "min10float";
-        default:
-          return "";
-        }
-  }
-
-  {
-    QualType elemType = {};
-    uint32_t elemCount = {};
-    if (isVectorType(type, &elemType, &elemCount))
-      return "v" + std::to_string(elemCount) + getName(elemType);
-  }
-
-  {
-    QualType elemType = {};
-    uint32_t rowCount = 0, colCount = 0;
-    if (isMxNMatrix(type, &elemType, &rowCount, &colCount))
-      return "mat" + std::to_string(rowCount) + "v" + std::to_string(colCount) +
-             getName(elemType);
-  }
-
-  if (const auto *structType = type->getAs<RecordType>())
-    return structType->getDecl()->getName();
-
-  return "";
-}
-
 QualType TypeTranslator::desugarType(QualType type) {
   if (const auto *attrType = type->getAs<AttributedType>()) {
     switch (auto kind = attrType->getAttrKind()) {

+ 0 - 42
tools/clang/lib/SPIRV/TypeTranslator.h

@@ -130,45 +130,6 @@ public:
   /// realized SPIR-V bitwidth of the vector elements.
   uint32_t getElementSpirvBitwidth(QualType type);
 
-  /// \brief Returns true if the given type will be translated into a SPIR-V
-  /// scalar type. This includes normal scalar types, vectors of size 1, and
-  /// 1x1 matrices. If scalarType is not nullptr, writes the scalar type to
-  /// *scalarType.
-  static bool isScalarType(QualType type, QualType *scalarType = nullptr);
-
-  /// \breif Returns true if the given type will be translated into a SPIR-V
-  /// vector type. This includes normal types (either ExtVectorType or HLSL
-  /// vector type) with more than one elements and matrices with exactly one
-  /// row or one column. Writes the element type and count into *elementType and
-  /// *count respectively if they are not nullptr.
-  static bool isVectorType(QualType type, QualType *elemType = nullptr,
-                           uint32_t *count = nullptr);
-
-  /// \brief Returns true if the given type is a 1x1 matrix type.
-  /// If elemType is not nullptr, writes the element type to *elemType.
-  static bool is1x1Matrix(QualType type, QualType *elemType = nullptr);
-
-  /// \brief Returns true if the given type is a 1xN (N > 1) matrix type.
-  /// If elemType is not nullptr, writes the element type to *elemType.
-  /// If count is not nullptr, writes the value of N into *count.
-  static bool is1xNMatrix(QualType type, QualType *elemType = nullptr,
-                          uint32_t *count = nullptr);
-
-  /// \brief Returns true if the given type is a Mx1 (M > 1) matrix type.
-  /// If elemType is not nullptr, writes the element type to *elemType.
-  /// If count is not nullptr, writes the value of M into *count.
-  static bool isMx1Matrix(QualType type, QualType *elemType = nullptr,
-                          uint32_t *count = nullptr);
-
-  /// \brief returns true if the given type is a matrix with more than 1 row and
-  /// more than 1 column.
-  /// If elemType is not nullptr, writes the element type to *elemType.
-  /// If rowCount is not nullptr, writes the number of rows (M) into *rowCount.
-  /// If colCount is not nullptr, writes the number of cols (N) into *colCount.
-  static bool isMxNMatrix(QualType type, QualType *elemType = nullptr,
-                          uint32_t *rowCount = nullptr,
-                          uint32_t *colCount = nullptr);
-
   /// \brief Returns true if type is a row-major matrix, either with explicit
   /// attribute or implicit command-line option.
   bool isRowMajorMatrix(QualType type) const;
@@ -219,9 +180,6 @@ public:
   /// Note: legalization specific code
   static bool isOpaqueStructType(QualType tye);
 
-  /// \brief Returns a string name for the given type.
-  static std::string getName(QualType type);
-
   /// \brief Returns the the element type for the given scalar, vector, matrix,
   /// or array type. Returns empty QualType for other cases.
   QualType getElementType(QualType type);