Skip to content

[MLIR][SPIRV] Replace some auto to concrete type #113877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2025
Merged

Conversation

trdthg
Copy link
Contributor

@trdthg trdthg commented Oct 28, 2024

Resolve #112018 (comment)

As described in clang-tidy, the auto type specifier will only be introduced in

  • Iterators
  • New expressions
  • Cast expressions

https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-auto.html

@llvmbot
Copy link
Member

llvmbot commented Oct 28, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-spirv

Author: MingZhu Yan (trdthg)

Changes

Resolve #112018 (comment)

As described in clang-tidy, the auto type specifier will only be introduced in

  • Iterators
  • New expressions
  • Cast expressions

https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-auto.html


Full diff: https://github.com/llvm/llvm-project/pull/113877.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp (+11-11)
diff --git a/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp b/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp
index b19495bc374452..b9b565539774bb 100644
--- a/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp
+++ b/mlir/lib/Dialect/SPIRV/Utils/LayoutUtils.cpp
@@ -43,7 +43,7 @@ VulkanLayoutUtils::decorateType(spirv::StructType structType,
     Size memberSize = 0;
     Size memberAlignment = 1;
 
-    auto memberType =
+    Type memberType =
         decorateType(structType.getElementType(i), memberSize, memberAlignment);
     structMemberOffset = llvm::alignTo(structMemberOffset, memberAlignment);
     memberTypes.push_back(memberType);
@@ -105,12 +105,12 @@ Type VulkanLayoutUtils::decorateType(Type type, VulkanLayoutUtils::Size &size,
 Type VulkanLayoutUtils::decorateType(VectorType vectorType,
                                      VulkanLayoutUtils::Size &size,
                                      VulkanLayoutUtils::Size &alignment) {
-  const auto numElements = vectorType.getNumElements();
-  auto elementType = vectorType.getElementType();
+  const unsigned numElements = vectorType.getNumElements();
+  Type elementType = vectorType.getElementType();
   Size elementSize = 0;
   Size elementAlignment = 1;
 
-  auto memberType = decorateType(elementType, elementSize, elementAlignment);
+  Type memberType = decorateType(elementType, elementSize, elementAlignment);
   // According to the Vulkan spec:
   // 1. "A two-component vector has a base alignment equal to twice its scalar
   // alignment."
@@ -124,12 +124,12 @@ Type VulkanLayoutUtils::decorateType(VectorType vectorType,
 Type VulkanLayoutUtils::decorateType(spirv::ArrayType arrayType,
                                      VulkanLayoutUtils::Size &size,
                                      VulkanLayoutUtils::Size &alignment) {
-  const auto numElements = arrayType.getNumElements();
-  auto elementType = arrayType.getElementType();
+  const unsigned numElements = arrayType.getNumElements();
+  Type elementType = arrayType.getElementType();
   Size elementSize = 0;
   Size elementAlignment = 1;
 
-  auto memberType = decorateType(elementType, elementSize, elementAlignment);
+  Type memberType = decorateType(elementType, elementSize, elementAlignment);
   // According to the Vulkan spec:
   // "An array has a base alignment equal to the base alignment of its element
   // type."
@@ -140,10 +140,10 @@ Type VulkanLayoutUtils::decorateType(spirv::ArrayType arrayType,
 
 Type VulkanLayoutUtils::decorateType(spirv::RuntimeArrayType arrayType,
                                      VulkanLayoutUtils::Size &alignment) {
-  auto elementType = arrayType.getElementType();
+  Type elementType = arrayType.getElementType();
   Size elementSize = 0;
 
-  auto memberType = decorateType(elementType, elementSize, alignment);
+  Type memberType = decorateType(elementType, elementSize, alignment);
   return spirv::RuntimeArrayType::get(memberType, elementSize);
 }
 
@@ -154,7 +154,7 @@ VulkanLayoutUtils::getScalarTypeAlignment(Type scalarType) {
   // 2. "A scalar has a base alignment equal to its scalar alignment."
   // 3. "A scalar, vector or matrix type has an extended alignment equal to its
   // base alignment."
-  auto bitWidth = scalarType.getIntOrFloatBitWidth();
+  unsigned bitWidth = scalarType.getIntOrFloatBitWidth();
   if (bitWidth == 1)
     return 1;
   return bitWidth / 8;
@@ -166,7 +166,7 @@ bool VulkanLayoutUtils::isLegalType(Type type) {
     return true;
   }
 
-  auto storageClass = ptrType.getStorageClass();
+  std::optional<spirv::StorageClass> storageClass = ptrType.getStorageClass();
   auto structType = dyn_cast<spirv::StructType>(ptrType.getPointeeType());
   if (!structType) {
     return true;

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@antiagainst antiagainst merged commit 213eeb9 into llvm:main May 25, 2025
8 checks passed
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Resolve
llvm#112018 (comment)

As described in clang-tidy, the auto type specifier will only be
introduced in

- Iterators
- New expressions
- Cast expressions

https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-auto.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants