clang  16.0.0git
CGHLSLRuntime.h
Go to the documentation of this file.
1 //===----- CGHLSLRuntime.h - Interface to HLSL Runtimes -----*- C++ -*-===//
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 // This provides an abstract class for HLSL code generation. Concrete
10 // subclasses of this implement code generation for specific HLSL
11 // runtime libraries.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
16 #define LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
17 
18 #include "llvm/IR/IRBuilder.h"
19 
21 
22 #include "llvm/ADT/Optional.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Frontend/HLSL/HLSLResource.h"
26 
27 #include <vector>
28 
29 namespace llvm {
30 class GlobalVariable;
31 class Function;
32 class StructType;
33 } // namespace llvm
34 
35 namespace clang {
36 class VarDecl;
37 class ParmVarDecl;
38 class HLSLBufferDecl;
39 class HLSLResourceBindingAttr;
40 class Type;
41 class DeclContext;
42 
43 class FunctionDecl;
44 
45 namespace CodeGen {
46 
47 class CodeGenModule;
48 
50 public:
52  // The ID like 2 in register(b2, space1).
54  // The Space like 1 is register(b2, space1).
55  // Default value is 0.
56  unsigned Space;
57  BufferResBinding(HLSLResourceBindingAttr *Attr);
58  };
59  struct Buffer {
60  Buffer(const HLSLBufferDecl *D);
61  llvm::StringRef Name;
62  // IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
63  bool IsCBuffer;
65  // Global variable and offset for each constant.
66  std::vector<std::pair<llvm::GlobalVariable *, unsigned>> Constants;
67  llvm::StructType *LayoutStruct = nullptr;
68  };
69 
70 protected:
72 
73  llvm::Value *emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D,
74  llvm::Type *Ty);
75 
76 public:
78  virtual ~CGHLSLRuntime() {}
79 
80  void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
82 
83  void addBuffer(const HLSLBufferDecl *D);
84  void finishCodeGen();
85 
86  void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn);
87 
88  void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn);
89  void setHLSLFunctionAttributes(llvm::Function *, const FunctionDecl *);
90 
91 private:
92  void addBufferResourceAnnotation(llvm::GlobalVariable *GV,
93  llvm::StringRef TyName,
94  llvm::hlsl::ResourceClass RC,
95  llvm::hlsl::ResourceKind RK,
96  BufferResBinding &Binding);
97  void addConstant(VarDecl *D, Buffer &CB);
98  void addBufferDecls(const DeclContext *DC, Buffer &CB);
100 };
101 
102 } // namespace CodeGen
103 } // namespace clang
104 
105 #endif
clang::CodeGen::CGHLSLRuntime::setHLSLFunctionAttributes
void setHLSLFunctionAttributes(llvm::Function *, const FunctionDecl *)
llvm
YAML serialization mapping.
Definition: Dominators.h:30
clang::CodeGen::CGHLSLRuntime
Definition: CGHLSLRuntime.h:49
clang::CodeGen::CGHLSLRuntime::Buffer::Constants
std::vector< std::pair< llvm::GlobalVariable *, unsigned > > Constants
Definition: CGHLSLRuntime.h:66
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1389
clang::CodeGen::CGHLSLRuntime::Buffer
Definition: CGHLSLRuntime.h:59
clang::CodeGen::CGHLSLRuntime::Buffer::Buffer
Buffer(const HLSLBufferDecl *D)
Definition: CGHLSLRuntime.cpp:191
llvm::SmallVector
Definition: LLVM.h:38
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1712
llvm::Optional< unsigned >
clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes
void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn)
Definition: CGHLSLRuntime.cpp:312
clang::CodeGen::CGHLSLRuntime::~CGHLSLRuntime
virtual ~CGHLSLRuntime()
Definition: CGHLSLRuntime.h:78
clang::CodeGen::CGHLSLRuntime::CGM
CodeGenModule & CGM
Definition: CGHLSLRuntime.h:71
clang::CodeGen::CGHLSLRuntime::Buffer::Binding
BufferResBinding Binding
Definition: CGHLSLRuntime.h:64
clang::CodeGen::CGHLSLRuntime::emitInputSemantic
llvm::Value * emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D, llvm::Type *Ty)
Definition: CGHLSLRuntime.cpp:340
clang::CodeGen::CGHLSLRuntime::finishCodeGen
void finishCodeGen()
Definition: CGHLSLRuntime.cpp:162
clang::CodeGen::CGHLSLRuntime::CGHLSLRuntime
CGHLSLRuntime(CodeGenModule &CGM)
Definition: CGHLSLRuntime.h:77
clang::CodeGen::CGHLSLRuntime::Buffer::Name
llvm::StringRef Name
Definition: CGHLSLRuntime.h:61
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:906
clang::CodeGen::CGHLSLRuntime::generateGlobalCtorDtorCalls
void generateGlobalCtorDtorCalls()
Definition: CGHLSLRuntime.cpp:427
clang::CodeGen::CGHLSLRuntime::addBuffer
void addBuffer(const HLSLBufferDecl *D)
Definition: CGHLSLRuntime.cpp:157
clang::CodeGen::CGHLSLRuntime::BufferResBinding
Definition: CGHLSLRuntime.h:51
clang::HLSLBufferDecl
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
Definition: Decl.h:4757
HLSLRuntime.h
clang::CodeGen::CodeGenModule
This class organizes the cross-function state that is used while generating LLVM code.
Definition: CodeGenModule.h:279
clang::CodeGen::CGHLSLRuntime::BufferResBinding::Reg
llvm::Optional< unsigned > Reg
Definition: CGHLSLRuntime.h:53
clang::CodeGen::CGHLSLRuntime::Buffer::IsCBuffer
bool IsCBuffer
Definition: CGHLSLRuntime.h:63
clang
Definition: CalledOnceCheck.h:17
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:40
clang::CodeGen::CGHLSLRuntime::annotateHLSLResource
void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV)
Definition: CGHLSLRuntime.cpp:276
clang::CodeGen::CGHLSLRuntime::Buffer::LayoutStruct
llvm::StructType * LayoutStruct
Definition: CGHLSLRuntime.h:67
clang::index::SymbolKind::Function
@ Function
clang::CodeGen::CGHLSLRuntime::BufferResBinding::BufferResBinding
BufferResBinding(HLSLResourceBindingAttr *Attr)
Definition: CGHLSLRuntime.cpp:298
clang::CodeGen::CGHLSLRuntime::emitEntryFunction
void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn)
Definition: CGHLSLRuntime.cpp:357
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1904
clang::CodeGen::CGHLSLRuntime::BufferResBinding::Space
unsigned Space
Definition: CGHLSLRuntime.h:56
Type
MatchType Type
Definition: ASTMatchFinder.cpp:71