1 //===----- CGHLSLRuntime.h - Interface to HLSL Runtimes -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This provides an abstract class for HLSL code generation. Concrete
10 // subclasses of this implement code generation for specific HLSL
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
18 #include "llvm/IR/IRBuilder.h"
20 #include "clang/Basic/HLSLRuntime.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Frontend/HLSL/HLSLResource.h"
39 class HLSLResourceBindingAttr
;
51 struct BufferResBinding
{
52 // The ID like 2 in register(b2, space1).
53 std::optional
<unsigned> Reg
;
54 // The Space like 1 is register(b2, space1).
55 // Default value is 0.
57 BufferResBinding(HLSLResourceBindingAttr
*Attr
);
60 Buffer(const HLSLBufferDecl
*D
);
62 // IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
64 BufferResBinding Binding
;
65 // Global variable and offset for each constant.
66 std::vector
<std::pair
<llvm::GlobalVariable
*, unsigned>> Constants
;
67 llvm::StructType
*LayoutStruct
= nullptr;
73 llvm::Value
*emitInputSemantic(llvm::IRBuilder
<> &B
, const ParmVarDecl
&D
,
77 CGHLSLRuntime(CodeGenModule
&CGM
) : CGM(CGM
) {}
78 virtual ~CGHLSLRuntime() {}
80 void annotateHLSLResource(const VarDecl
*D
, llvm::GlobalVariable
*GV
);
81 void generateGlobalCtorDtorCalls();
83 void addBuffer(const HLSLBufferDecl
*D
);
86 void setHLSLEntryAttributes(const FunctionDecl
*FD
, llvm::Function
*Fn
);
88 void emitEntryFunction(const FunctionDecl
*FD
, llvm::Function
*Fn
);
89 void setHLSLFunctionAttributes(llvm::Function
*, const FunctionDecl
*);
92 void addBufferResourceAnnotation(llvm::GlobalVariable
*GV
,
93 llvm::hlsl::ResourceClass RC
,
94 llvm::hlsl::ResourceKind RK
, bool IsROV
,
95 llvm::hlsl::ElementType ET
,
96 BufferResBinding
&Binding
);
97 void addConstant(VarDecl
*D
, Buffer
&CB
);
98 void addBufferDecls(const DeclContext
*DC
, Buffer
&CB
);
99 llvm::SmallVector
<Buffer
> Buffers
;
102 } // namespace CodeGen