#pragma once #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/StringMap.h" #include "dxc/DXIL/DxilCBuffer.h" #include #include namespace clang { class HLSLPatchConstantFuncAttr; namespace CodeGen { class CodeGenModule; } } namespace llvm { class Function; class Module; class Value; class DebugLoc; class Constant; class GlobalVariable; class CallInst; template class SmallVector; } namespace hlsl { class HLModule; struct DxilResourceProperties; struct DxilFunctionProps; class DxilFieldAnnotation; enum class IntrinsicOp; namespace dxilutil { class ExportMap; } } namespace CGHLSLMSHelper { struct EntryFunctionInfo { clang::SourceLocation SL = clang::SourceLocation(); llvm::Function *Func = nullptr; }; // Map to save patch constant functions struct PatchConstantInfo { clang::SourceLocation SL = clang::SourceLocation(); llvm::Function *Func = nullptr; std::uint32_t NumOverloads = 0; }; /// Use this class to represent HLSL cbuffer in high-level DXIL. class HLCBuffer : public hlsl::DxilCBuffer { public: HLCBuffer() = default; virtual ~HLCBuffer() = default; void AddConst(std::unique_ptr &pItem) { pItem->SetID(constants.size()); constants.push_back(std::move(pItem)); } std::vector> &GetConstants() { return constants; } private: std::vector> constants; // constants inside const buffer }; // Align cbuffer offset in legacy mode (16 bytes per row). unsigned AlignBufferOffsetInLegacy(unsigned offset, unsigned size, unsigned scalarSizeInBytes, bool bNeedNewRow); void FinishEntries(hlsl::HLModule &HLM, const EntryFunctionInfo &Entry, clang::CodeGen::CodeGenModule &CGM, llvm::StringMap &entryFunctionMap, std::unordered_map &HSEntryPatchConstantFuncAttr, llvm::StringMap &patchConstantFunctionMap, std::unordered_map> &patchConstantFunctionPropsMap); void FinishIntrinsics( hlsl::HLModule &HLM, std::vector> &intrinsicMap, llvm::DenseMap &valToResPropertiesMap); void AddDxBreak(llvm::Module &M, const llvm::SmallVector &DxBreaks); void ReplaceConstStaticGlobals( std::unordered_map> &staticConstGlobalInitListMap, std::unordered_map &staticConstGlobalCtorMap); void FinishClipPlane(hlsl::HLModule &HLM, std::vector &clipPlaneFuncList, std::unordered_map &debugInfoMap, clang::CodeGen::CodeGenModule &CGM); void AddRegBindingsForResourceInConstantBuffer( hlsl::HLModule &HLM, llvm::DenseMap, 1>> &constantRegBindingMap); void FinishCBuffer( hlsl::HLModule &HLM, llvm::Type *CBufferType, std::unordered_map &AnnotationMap); void ProcessCtorFunctions(llvm::Module &M, llvm::StringRef globalName, llvm::Instruction *InsertPt); void TranslateRayQueryConstructor(hlsl::HLModule &HLM); void UpdateLinkage( hlsl::HLModule &HLM, clang::CodeGen::CodeGenModule &CGM, hlsl::dxilutil::ExportMap &exportMap, llvm::StringMap &entryFunctionMap, llvm::StringMap &patchConstantFunctionMap); llvm::Value *TryEvalIntrinsic(llvm::CallInst *CI, hlsl::IntrinsicOp intriOp); void SimpleTransformForHLDXIR(llvm::Module *pM); void ExtensionCodeGen(hlsl::HLModule &HLM, clang::CodeGen::CodeGenModule &CGM); } // namespace CGHLSLMSHelper