Debian Codegraph @

clang/lib/CodeGen/HLSLBufferLayoutBuilder.h

raw
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 "clang/AST/TypeBase.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/IR/DerivedTypes.h"
12
13 namespace clang {
14 namespace CodeGen {
15 class CGHLSLOffsetInfo;
16 class CodeGenModule;
17 class CGHLSLOffsetInfo;
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
28 public:
29 HLSLBufferLayoutBuilder(CodeGenModule &CGM) : CGM(CGM) {}
30
31 /// Lays out a struct type following HLSL buffer rules and considering any
32 /// explicit offset information. Previously created layout structs are cached
33 /// by CGHLSLRuntime.
34 ///
35 /// The function iterates over all fields of the record type (including base
36 /// classes) and works out a padded llvm type to represent the buffer layout.
37 ///
38 /// If a non-empty OffsetInfo is provided (ie, from `packoffset` annotations
39 /// in the source), any provided offsets offsets will be respected. If the
40 /// OffsetInfo is available but has empty entries, those will be layed out at
41 /// the end of the structure.
42 llvm::StructType *layOutStruct(const RecordType *StructType,
43 const CGHLSLOffsetInfo &OffsetInfo);
44
45 /// Lays out an array type following HLSL buffer rules.
46 llvm::Type *layOutArray(const ConstantArrayType *AT);
47
48 /// Lays out a type following HLSL buffer rules. Arrays and structures will be
49 /// padded appropriately and nested objects will be converted as appropriate.
50 llvm::Type *layOutType(QualType Type);
51 };
52
53 } // namespace CodeGen
54 } // namespace clang