[llvm] [DirectX] Flatten arrays (PR #114332)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 4 11:18:31 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff a779dc3754fe6cd2d72766f6313b3e88c0fd7d35 9d36d73404a1a9f9bca9bcb276147f4542119337 --extensions cpp,h -- llvm/lib/Target/DirectX/DXILFlattenArrays.cpp llvm/lib/Target/DirectX/DXILFlattenArrays.h llvm/lib/Target/DirectX/DirectX.h llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp b/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
index 65b5c2a276..299ef63313 100644
--- a/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
+++ b/llvm/lib/Target/DirectX/DXILFlattenArrays.cpp
@@ -83,11 +83,11 @@ private:
   DenseMap<GetElementPtrInst *, GEPData> GEPChainMap;
   bool finish();
   ConstantInt *genConstFlattenIndices(ArrayRef<Value *> Indices,
-                                   ArrayRef<uint64_t> Dims,
-                                   IRBuilder<> &Builder);
+                                      ArrayRef<uint64_t> Dims,
+                                      IRBuilder<> &Builder);
   Value *genInstructionFlattenIndices(ArrayRef<Value *> Indices,
-                                   ArrayRef<uint64_t> Dims,
-                                   IRBuilder<> &Builder);
+                                      ArrayRef<uint64_t> Dims,
+                                      IRBuilder<> &Builder);
   void
   recursivelyCollectGEPs(GetElementPtrInst &CurrGEP,
                          ArrayType *FlattenedArrayType, Value *PtrOperand,
@@ -112,7 +112,8 @@ bool DXILFlattenArraysVisitor::isMultiDimensionalArray(Type *T) {
   return false;
 }
 
-std::pair<unsigned, Type *> DXILFlattenArraysVisitor::getElementCountAndType(Type *ArrayTy) {
+std::pair<unsigned, Type *>
+DXILFlattenArraysVisitor::getElementCountAndType(Type *ArrayTy) {
   unsigned TotalElements = 1;
   Type *CurrArrayTy = ArrayTy;
   while (auto *InnerArrayTy = dyn_cast<ArrayType>(CurrArrayTy)) {
@@ -197,8 +198,7 @@ bool DXILFlattenArraysVisitor::visitAllocaInst(AllocaInst &AI) {
   IRBuilder<> Builder(&AI);
   auto [TotalElements, BaseType] = getElementCountAndType(ArrType);
 
-  ArrayType *FattenedArrayType =
-      ArrayType::get(BaseType, TotalElements);
+  ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
   AllocaInst *FlatAlloca =
       Builder.CreateAlloca(FattenedArrayType, nullptr, AI.getName() + ".flat");
   FlatAlloca->setAlignment(AI.getAlign());
@@ -279,8 +279,7 @@ bool DXILFlattenArraysVisitor::visitGetElementPtrInst(GetElementPtrInst &GEP) {
   ArrayType *ArrType = cast<ArrayType>(GEP.getSourceElementType());
   IRBuilder<> Builder(&GEP);
   auto [TotalElements, BaseType] = getElementCountAndType(ArrType);
-  ArrayType *FlattenedArrayType =
-      ArrayType::get(BaseType, TotalElements);
+  ArrayType *FlattenedArrayType = ArrayType::get(BaseType, TotalElements);
 
   Value *PtrOperand = GEP.getPointerOperand();
 
@@ -337,7 +336,7 @@ static void collectElements(Constant *Init,
       collectElements(DataArrayConstant->getElementAsConstant(I), Elements);
     }
   } else {
-    llvm_unreachable (
+    llvm_unreachable(
         "Expected a ConstantArray or ConstantDataArray for array initializer!");
   }
 }
@@ -373,9 +372,9 @@ flattenGlobalArrays(Module &M,
       continue;
 
     ArrayType *ArrType = cast<ArrayType>(OrigType);
-    auto [TotalElements, BaseType] = DXILFlattenArraysVisitor::getElementCountAndType(ArrType);
-    ArrayType *FattenedArrayType = ArrayType::get(
-        BaseType, TotalElements);
+    auto [TotalElements, BaseType] =
+        DXILFlattenArraysVisitor::getElementCountAndType(ArrType);
+    ArrayType *FattenedArrayType = ArrayType::get(BaseType, TotalElements);
 
     // Create a new global variable with the updated type
     // Note: Initializer is set via transformInitializer

``````````

</details>


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


More information about the llvm-commits mailing list