123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- //===----- CGHLSLRuntime.h - Interface to HLSL Runtimes -----*- C++ -*-===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //
- //===----------------------------------------------------------------------===//
- //
- // This provides an abstract class for HLSL code generation. Concrete
- // subclasses of this implement code generation for specific HLSL
- // runtime libraries.
- //
- //===----------------------------------------------------------------------===//
- #ifndef LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
- #define LLVM_CLANG_LIB_CODEGEN_CGHLSLRUNTIME_H
- #include "llvm/IR/IRBuilder.h"
- #include "clang/Basic/HLSLRuntime.h"
- #include "llvm/ADT/SmallVector.h"
- #include "llvm/ADT/StringRef.h"
- #include "llvm/Frontend/HLSL/HLSLResource.h"
- #include <optional>
- #include <vector>
- namespace llvm {
- class GlobalVariable;
- class Function;
- class StructType;
- } // namespace llvm
- namespace clang {
- class VarDecl;
- class ParmVarDecl;
- class HLSLBufferDecl;
- class HLSLResourceBindingAttr;
- class Type;
- class DeclContext;
- class FunctionDecl;
- namespace CodeGen {
- class CodeGenModule;
- class CGHLSLRuntime {
- public:
- struct BufferResBinding {
- // The ID like 2 in register(b2, space1).
- std::optional<unsigned> Reg;
- // The Space like 1 is register(b2, space1).
- // Default value is 0.
- unsigned Space;
- BufferResBinding(HLSLResourceBindingAttr *Attr);
- };
- struct Buffer {
- Buffer(const HLSLBufferDecl *D);
- llvm::StringRef Name;
- // IsCBuffer - Whether the buffer is a cbuffer (and not a tbuffer).
- bool IsCBuffer;
- BufferResBinding Binding;
- // Global variable and offset for each constant.
- std::vector<std::pair<llvm::GlobalVariable *, unsigned>> Constants;
- llvm::StructType *LayoutStruct = nullptr;
- };
- protected:
- CodeGenModule &CGM;
- llvm::Value *emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D,
- llvm::Type *Ty);
- public:
- CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
- virtual ~CGHLSLRuntime() {}
- void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
- void generateGlobalCtorDtorCalls();
- void addBuffer(const HLSLBufferDecl *D);
- void finishCodeGen();
- void setHLSLEntryAttributes(const FunctionDecl *FD, llvm::Function *Fn);
- void emitEntryFunction(const FunctionDecl *FD, llvm::Function *Fn);
- void setHLSLFunctionAttributes(llvm::Function *, const FunctionDecl *);
- private:
- void addBufferResourceAnnotation(llvm::GlobalVariable *GV,
- llvm::StringRef TyName,
- llvm::hlsl::ResourceClass RC,
- llvm::hlsl::ResourceKind RK,
- BufferResBinding &Binding);
- void addConstant(VarDecl *D, Buffer &CB);
- void addBufferDecls(const DeclContext *DC, Buffer &CB);
- llvm::SmallVector<Buffer> Buffers;
- };
- } // namespace CodeGen
- } // namespace clang
- #endif
|