clang 23.0.0git
HLSLBufferLayoutBuilder.h
Go to the documentation of this file.
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
10#include "llvm/ADT/StringRef.h"
11#include "llvm/IR/DerivedTypes.h"
12
13namespace clang {
14namespace CodeGen {
16class CodeGenModule;
18
19//===----------------------------------------------------------------------===//
20// Implementation of constant buffer layout common between DirectX and
21// SPIR/SPIR-V.
22//===----------------------------------------------------------------------===//
23
25private:
26 CodeGenModule &CGM;
27
28 /// Pads an array of elements to 16-byte cbuffer row boundaries.
29 /// This implements the common pattern of padding all-but-the-last element.
30 llvm::Type *padArrayElements(llvm::Type *EltTy, uint64_t Count);
31
32public:
34
35 /// Lays out a struct type following HLSL buffer rules and considering any
36 /// explicit offset information. Previously created layout structs are cached
37 /// by CGHLSLRuntime.
38 ///
39 /// The function iterates over all fields of the record type (including base
40 /// classes) and works out a padded llvm type to represent the buffer layout.
41 ///
42 /// If a non-empty OffsetInfo is provided (ie, from `packoffset` annotations
43 /// in the source), any provided offsets offsets will be respected. If the
44 /// OffsetInfo is available but has empty entries, those will be layed out at
45 /// the end of the structure.
46 llvm::StructType *layOutStruct(const RecordType *StructType,
47 const CGHLSLOffsetInfo &OffsetInfo);
48
49 /// Lays out an array type following HLSL buffer rules.
50 llvm::Type *layOutArray(const ConstantArrayType *AT);
51
52 /// Lays out a matrix type following HLSL buffer rules.
53 llvm::Type *layOutMatrix(const ConstantMatrixType *MT);
54
55 /// Lays out a type following HLSL buffer rules. Arrays and structures will be
56 /// padded appropriately and nested objects will be converted as appropriate.
57 llvm::Type *layOutType(QualType Type);
58};
59
60} // namespace CodeGen
61} // namespace clang
C Language Family Type Representation.
This class organizes the cross-function state that is used while generating LLVM code.
llvm::StructType * layOutStruct(const RecordType *StructType, const CGHLSLOffsetInfo &OffsetInfo)
Lays out a struct type following HLSL buffer rules and considering any explicit offset information.
llvm::Type * layOutArray(const ConstantArrayType *AT)
Lays out an array type following HLSL buffer rules.
llvm::Type * layOutMatrix(const ConstantMatrixType *MT)
Lays out a matrix type following HLSL buffer rules.
llvm::Type * layOutType(QualType Type)
Lays out a type following HLSL buffer rules.
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3768
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4395
A (possibly-)qualified type.
Definition TypeBase.h:937
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
Definition CGValue.h:155
The JSON file list parser is used to communicate input to InstallAPI.