[llvm-branch-commits] [clang] [HLSL] Constant buffers codegen (PR #124886)

Farzon Lotfi via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 12 06:52:02 PST 2025


================
@@ -0,0 +1,201 @@
+//===- HLSLTargetInto.cpp--------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "HLSLTargetInfo.h"
+#include "CGHLSLRuntime.h"
+#include "TargetInfo.h"
+#include "clang/AST/DeclCXX.h"
+
+//===----------------------------------------------------------------------===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+// Creates a new array type with the same dimentions
+// but with the new element type.
+static llvm::Type *
+createArrayWithNewElementType(CodeGenModule &CGM,
+                              const ConstantArrayType *ArrayType,
+                              llvm::Type *NewElemType) {
+  const clang::Type *ArrayElemType = ArrayType->getArrayElementTypeNoTypeQual();
+  if (ArrayElemType->isConstantArrayType())
+    NewElemType = createArrayWithNewElementType(
+        CGM, cast<const ConstantArrayType>(ArrayElemType), NewElemType);
+  return llvm::ArrayType::get(NewElemType, ArrayType->getSExtSize());
+}
+
+// Returns the size of a scalar or vector in bytes/
+static unsigned getScalarOrVectorSize(llvm::Type *Ty) {
----------------
farzonl wrote:

This function could use from a more descript name. Below are some suggestions:
```suggestion
static unsigned getScalarOrVectorByteSize(llvm::Type *Ty) {
```
```suggestion
static unsigned getScalarOrVectorStorageSize(llvm::Type *Ty) {
```
```suggestion
static unsigned getScalarOrVectorMemorySize(llvm::Type *Ty) {
```


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


More information about the llvm-branch-commits mailing list