xref: /freebsd/contrib/llvm-project/clang/lib/CodeGen/HLSLBufferLayoutBuilder.h (revision 9c77fb6aaa366cbabc80ee1b834bcfe4df135491)
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 
12 namespace clang {
13 class RecordType;
14 class FieldDecl;
15 
16 namespace CodeGen {
17 class CodeGenModule;
18 
19 //===----------------------------------------------------------------------===//
20 // Implementation of constant buffer layout common between DirectX and
21 // SPIR/SPIR-V.
22 //===----------------------------------------------------------------------===//
23 
24 class HLSLBufferLayoutBuilder {
25 private:
26   CodeGenModule &CGM;
27   llvm::StringRef LayoutTypeName;
28 
29 public:
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 
40 private:
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