1//===- HLSLBufferLayoutBuilder.h ------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ADT/StringRef.h"
10#include "llvm/IR/DerivedTypes.h"
11
12namespace clang {
13class RecordType;
14class FieldDecl;
15
16namespace CodeGen {
17class CodeGenModule;
18
19//===----------------------------------------------------------------------===//
20// Implementation of constant buffer layout common between DirectX and
21// SPIR/SPIR-V.
22//===----------------------------------------------------------------------===//
23
24class HLSLBufferLayoutBuilder {
25private:
26 CodeGenModule &CGM;
27 llvm::StringRef LayoutTypeName;
28
29public:
30 HLSLBufferLayoutBuilder(CodeGenModule &CGM, llvm::StringRef LayoutTypeName)
31 : CGM(CGM), LayoutTypeName(LayoutTypeName) {}
32
33 // Returns LLVM target extension type with the name LayoutTypeName
34 // for given structure type and layout data. The first number in
35 // the Layout is the size followed by offsets for each struct element.
36 llvm::TargetExtType *
37 createLayoutType(const RecordType *StructType,
38 const llvm::SmallVector<int32_t> *Packoffsets = nullptr);
39
40private:
41 bool layoutField(const clang::FieldDecl *FD, unsigned &EndOffset,
42 unsigned &FieldOffset, llvm::Type *&FieldType,
43 int Packoffset = -1);
44};
45
46} // namespace CodeGen
47} // namespace clang
48