================
@@ -190,6 +192,71 @@ static void createResourceCtorArgs(CodeGenModule &CGM, 
CXXConstructorDecl *CD,
   Args.add(RValue::get(NameStr), AST.getPointerType(AST.CharTy.withConst()));
 }
 
+// Initializes local resource array variable. For multi-dimensional arrays it
+// calls itself recursively to initialize its sub-arrays. The Index used in the
+// resource constructor calls will begin at StartIndex and will be incremented
+// for each array element. The last used resource Index is returned to the
+// caller.
+static Value *initializeLocalResourceArray(
+    CodeGenFunction &CGF, AggValueSlot &ValueSlot,
+    const ConstantArrayType *ArrayTy, CXXConstructorDecl *CD,
+    llvm::Value *Range, llvm::Value *StartIndex, StringRef ResourceName,
+    HLSLResourceBindingAttr *RBA, HLSLVkBindingAttr *VkBinding,
+    ArrayRef<llvm::Value *> PrevGEPIndices, SourceLocation ArraySubsExprLoc) {
+
+  llvm::IntegerType *IntTy = CGF.CGM.IntTy;
+  llvm::Value *Index = StartIndex;
+  llvm::Value *One = llvm::ConstantInt::get(IntTy, 1);
+  uint64_t ArraySize = ArrayTy->getSExtSize();
+  QualType ElemType = ArrayTy->getElementType();
+  Address TmpArrayAddr = ValueSlot.getAddress();
+
+  // Add additional index to the getelementptr call indices.
+  // This index will be updated for each array element in the loops below.
+  SmallVector<llvm::Value *> GEPIndices(PrevGEPIndices);
+  GEPIndices.push_back(llvm::ConstantInt::get(IntTy, 0));
+
+  // array of arrays - recursively initialize the sub-arrays
+  if (ElemType->isArrayType()) {
+    const ConstantArrayType *SubArrayTy = cast<ConstantArrayType>(ElemType);
+    for (uint64_t I = 0; I < ArraySize; I++) {
+      if (I > 0) {
+        Index = CGF.Builder.CreateAdd(Index, One);
+        GEPIndices.back() = llvm::ConstantInt::get(IntTy, I);
+      }
+      // recursively initialize the sub-array
----------------
llvm-beanz wrote:

```suggestion
      // Recursively initialize the sub-array.
```

https://github.com/llvm/llvm-project/pull/154248
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to