15#ifndef LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
16#define LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/ADT/StringRef.h"
26#include "llvm/Frontend/HLSL/HLSLResource.h"
27#include "llvm/IR/IRBuilder.h"
28#include "llvm/IR/Intrinsics.h"
29#include "llvm/IR/IntrinsicsDirectX.h"
30#include "llvm/IR/IntrinsicsSPIRV.h"
37#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix) \
38 llvm::Intrinsic::ID get##FunctionName##Intrinsic() { \
39 llvm::Triple::ArchType Arch = getArch(); \
41 case llvm::Triple::dxil: \
42 return llvm::Intrinsic::dx_##IntrinsicPostfix; \
43 case llvm::Triple::spirv: \
44 return llvm::Intrinsic::spv_##IntrinsicPostfix; \
46 llvm_unreachable("Intrinsic " #IntrinsicPostfix \
47 " not supported by target architecture"); \
67class HLSLVkBindingAttr;
68class HLSLResourceBindingAttr;
72class HLSLPackOffsetAttr;
114 bool empty()
const {
return Offsets.empty(); }
129 flattened_thread_id_in_group)
176 resource_samplecmplevelzero)
178 resource_handlefrombinding)
180 resource_handlefromimplicitbinding)
182 resource_nonuniformindex)
185 group_memory_barrier_with_group_sync)
202 HLSLAppliedSemanticAttr *Semantic,
203 std::optional<
unsigned> Index);
207 HLSLAppliedSemanticAttr *Semantic,
208 std::optional<
unsigned> Index);
214 HLSLAppliedSemanticAttr *Semantic);
219 HLSLAppliedSemanticAttr *Semantic);
272 llvm::StructType *LayoutTy);
275 std::optional<LValue>
282 llvm::function_ref<llvm::Value *(
bool Promote)> EmitIdxAfterBase);
294 llvm::GlobalVariable *BufGV,
297 llvm::GlobalVariable *GV);
299 llvm::GlobalVariable *GV,
300 HLSLResourceBindingAttr *RBA);
302 llvm::Value *emitSPIRVUserSemanticLoad(llvm::IRBuilder<> &B, llvm::Type *
Type,
304 HLSLAppliedSemanticAttr *Semantic,
305 std::optional<unsigned> Index);
306 llvm::Value *emitDXILUserSemanticLoad(llvm::IRBuilder<> &B, llvm::Type *
Type,
307 HLSLAppliedSemanticAttr *Semantic,
308 std::optional<unsigned> Index);
309 llvm::Value *emitUserSemanticLoad(llvm::IRBuilder<> &B, llvm::Type *
Type,
311 HLSLAppliedSemanticAttr *Semantic,
312 std::optional<unsigned> Index);
314 void emitSPIRVUserSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
316 HLSLAppliedSemanticAttr *Semantic,
317 std::optional<unsigned> Index);
318 void emitDXILUserSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
319 HLSLAppliedSemanticAttr *Semantic,
320 std::optional<unsigned> Index);
321 void emitUserSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source,
323 HLSLAppliedSemanticAttr *Semantic,
324 std::optional<unsigned> Index);
326 llvm::Triple::ArchType getArch();
328 llvm::DenseMap<const clang::RecordType *, llvm::StructType *> LayoutTypes;
329 unsigned SPIRVLastAssignedInputSemanticLocation = 0;
330 unsigned SPIRVLastAssignedOutputSemanticLocation = 0;
Defines enum values for all the target-independent builtin functions.
#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix)
llvm::dxil::ResourceClass ResourceClass
Defines helper utilities for supporting the HLSL runtime environment.
__DEVICE__ bool isnan(float __x)
Test for a NaN.
__DEVICE__ bool isinf(float __x)
Test for infinity value (+ve or -ve) .
__DEVICE__ double rsqrt(double __a)
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
static const uint32_t Unspecified
static bool compareOffsets(uint32_t LHS, uint32_t RHS)
Comparison function for offsets received from operator[] suitable for use in a stable_sort.
static CGHLSLOffsetInfo fromDecl(const HLSLBufferDecl &BufDecl)
Iterates over all declarations in the HLSL buffer and based on the packoffset or register(c#) annotat...
uint32_t operator[](size_t I) const
Get the given offset, or ~0U if there is no offset for the member.
llvm::Instruction * getConvergenceToken(llvm::BasicBlock &BB)
void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn)
specific_attr_iterator< HLSLAppliedSemanticAttr > handleSemanticStore(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source, const clang::DeclaratorDecl *Decl, specific_attr_iterator< HLSLAppliedSemanticAttr > AttrBegin, specific_attr_iterator< HLSLAppliedSemanticAttr > AttrEnd)
llvm::StructType * getHLSLBufferLayoutType(const RecordType *LayoutStructTy)
void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn)
void handleGlobalVarDefinition(const VarDecl *VD, llvm::GlobalVariable *Var)
void emitSystemSemanticStore(llvm::IRBuilder<> &B, llvm::Value *Source, const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic, std::optional< unsigned > Index)
std::pair< llvm::Value *, specific_attr_iterator< HLSLAppliedSemanticAttr > > handleStructSemanticLoad(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type, const clang::DeclaratorDecl *Decl, specific_attr_iterator< HLSLAppliedSemanticAttr > begin, specific_attr_iterator< HLSLAppliedSemanticAttr > end)
specific_attr_iterator< HLSLAppliedSemanticAttr > handleStructSemanticStore(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source, const clang::DeclaratorDecl *Decl, specific_attr_iterator< HLSLAppliedSemanticAttr > AttrBegin, specific_attr_iterator< HLSLAppliedSemanticAttr > AttrEnd)
llvm::Value * handleScalarSemanticLoad(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type, const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic)
void addHLSLBufferLayoutType(const RecordType *LayoutStructTy, llvm::StructType *LayoutTy)
void handleScalarSemanticStore(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Value *Source, const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic)
std::pair< llvm::Value *, specific_attr_iterator< HLSLAppliedSemanticAttr > > handleSemanticLoad(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type, const clang::DeclaratorDecl *Decl, specific_attr_iterator< HLSLAppliedSemanticAttr > begin, specific_attr_iterator< HLSLAppliedSemanticAttr > end)
CGHLSLRuntime(CodeGenModule &CGM)
std::optional< LValue > emitBufferArraySubscriptExpr(const ArraySubscriptExpr *E, CodeGenFunction &CGF, llvm::function_ref< llvm::Value *(bool Promote)> EmitIdxAfterBase)
std::optional< LValue > emitResourceArraySubscriptExpr(const ArraySubscriptExpr *E, CodeGenFunction &CGF)
void addRootSignature(const HLSLRootSignatureDecl *D)
bool emitResourceArrayCopy(LValue &LHS, Expr *RHSExpr, CodeGenFunction &CGF)
LValue emitBufferMemberExpr(CodeGenFunction &CGF, const MemberExpr *E)
bool emitBufferCopy(CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, QualType CType)
llvm::Type * convertHLSLSpecificType(const Type *T)
llvm::Type * convertHLSLSpecificType(const Type *T, const CGHLSLOffsetInfo &OffsetInfo)
resource_getpointer resource_handlefrombinding resource_nonuniformindex GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync, group_memory_barrier_with_group_sync) protected llvm::Value * emitSystemSemanticLoad(llvm::IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type, const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic, std::optional< unsigned > Index)
RawAddress createBufferMatrixTempAddress(const LValue &LV, SourceLocation Loc, CodeGenFunction &CGF)
GENERATE_HLSL_INTRINSIC_FUNCTION(FlattenedThreadIdInGroup, flattened_thread_id_in_group) GENERATE_HLSL_INTRINSIC_FUNCTION(CreateResourceGetPointer
void addBuffer(const HLSLBufferDecl *D)
void generateGlobalCtorDtorCalls()
void setHLSLFunctionAttributes(const FunctionDecl *FD, llvm::Function *Fn)
void emitInitListOpaqueValues(CodeGenFunction &CGF, InitListExpr *E)
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
LValue - This represents an lvalue references.
An abstract representation of an aligned address.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Represents a ValueDecl that came out of a declarator.
This represents one expression.
Represents a function declaration or definition.
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
Describes an C or C++ initializer list.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
This represents a decl that may have a name.
Represents a parameter to a function.
A (possibly-)qualified type.
Encodes a location in the source.
The base class of the type hierarchy.
Represents a variable declaration or definition.
specific_attr_iterator - Iterates over a subrange of an AttrVec, only providing attributes that are o...
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
float __ovld __cnfn step(float, float)
Returns 0.0 if x < edge, otherwise it returns 1.0.
float __ovld __cnfn sign(float)
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if x < 0.
float __ovld __cnfn radians(float)
Converts degrees to radians, i.e.
float __ovld __cnfn degrees(float)
Converts radians to degrees, i.e.
int __ovld __cnfn all(char)
Returns 1 if the most significant bit in all components of x is set; otherwise returns 0.
float __ovld __cnfn normalize(float)
Returns a vector in the same direction as p but with a length of 1.
int __ovld __cnfn any(char)
Returns 1 if the most significant bit in any component of x is set; otherwise returns 0.
float4 __ovld __cnfn cross(float4, float4)
Returns the cross product of p0.xyz and p1.xyz.