CGHLSLMSHelper.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #pragma once
  2. #include "clang/Basic/SourceLocation.h"
  3. #include "llvm/ADT/StringMap.h"
  4. #include "dxc/DXIL/DxilCBuffer.h"
  5. #include <memory>
  6. #include <vector>
  7. namespace clang {
  8. class HLSLPatchConstantFuncAttr;
  9. namespace CodeGen {
  10. class CodeGenModule;
  11. }
  12. }
  13. namespace llvm {
  14. class Function;
  15. class Module;
  16. class Value;
  17. class DebugLoc;
  18. class Constant;
  19. class GlobalVariable;
  20. class CallInst;
  21. template <typename T, unsigned N> class SmallVector;
  22. }
  23. namespace hlsl {
  24. class HLModule;
  25. struct DxilResourceProperties;
  26. struct DxilFunctionProps;
  27. class DxilFieldAnnotation;
  28. enum class IntrinsicOp;
  29. namespace dxilutil {
  30. class ExportMap;
  31. }
  32. }
  33. namespace CGHLSLMSHelper {
  34. struct EntryFunctionInfo {
  35. clang::SourceLocation SL = clang::SourceLocation();
  36. llvm::Function *Func = nullptr;
  37. };
  38. // Map to save patch constant functions
  39. struct PatchConstantInfo {
  40. clang::SourceLocation SL = clang::SourceLocation();
  41. llvm::Function *Func = nullptr;
  42. std::uint32_t NumOverloads = 0;
  43. };
  44. /// Use this class to represent HLSL cbuffer in high-level DXIL.
  45. class HLCBuffer : public hlsl::DxilCBuffer {
  46. public:
  47. HLCBuffer() = default;
  48. virtual ~HLCBuffer() = default;
  49. void AddConst(std::unique_ptr<DxilResourceBase> &pItem) {
  50. pItem->SetID(constants.size());
  51. constants.push_back(std::move(pItem));
  52. }
  53. std::vector<std::unique_ptr<DxilResourceBase>> &GetConstants() {
  54. return constants;
  55. }
  56. private:
  57. std::vector<std::unique_ptr<DxilResourceBase>>
  58. constants; // constants inside const buffer
  59. };
  60. // Align cbuffer offset in legacy mode (16 bytes per row).
  61. unsigned AlignBufferOffsetInLegacy(unsigned offset, unsigned size,
  62. unsigned scalarSizeInBytes,
  63. bool bNeedNewRow);
  64. void FinishEntries(hlsl::HLModule &HLM, const EntryFunctionInfo &Entry,
  65. clang::CodeGen::CodeGenModule &CGM,
  66. llvm::StringMap<EntryFunctionInfo> &entryFunctionMap,
  67. std::unordered_map<llvm::Function *,
  68. const clang::HLSLPatchConstantFuncAttr *>
  69. &HSEntryPatchConstantFuncAttr,
  70. llvm::StringMap<PatchConstantInfo> &patchConstantFunctionMap,
  71. std::unordered_map<llvm::Function *,
  72. std::unique_ptr<hlsl::DxilFunctionProps>>
  73. &patchConstantFunctionPropsMap);
  74. void FinishIntrinsics(
  75. hlsl::HLModule &HLM, std::vector<std::pair<llvm::Function *, unsigned>> &intrinsicMap,
  76. llvm::DenseMap<llvm::Value *, hlsl::DxilResourceProperties>
  77. &valToResPropertiesMap);
  78. void AddDxBreak(llvm::Module &M, const llvm::SmallVector<llvm::BranchInst*, 16> &DxBreaks);
  79. void ReplaceConstStaticGlobals(
  80. std::unordered_map<llvm::GlobalVariable *, std::vector<llvm::Constant *>>
  81. &staticConstGlobalInitListMap,
  82. std::unordered_map<llvm::GlobalVariable *, llvm::Function *> &staticConstGlobalCtorMap);
  83. void FinishClipPlane(hlsl::HLModule &HLM, std::vector<llvm::Function *> &clipPlaneFuncList,
  84. std::unordered_map<llvm::Value *, llvm::DebugLoc> &debugInfoMap,
  85. clang::CodeGen::CodeGenModule &CGM);
  86. void AddRegBindingsForResourceInConstantBuffer(
  87. hlsl::HLModule &HLM,
  88. llvm::DenseMap<llvm::Constant *,
  89. llvm::SmallVector<std::pair<hlsl::DXIL::ResourceClass, unsigned>,
  90. 1>> &constantRegBindingMap);
  91. void FinishCBuffer(
  92. hlsl::HLModule &HLM, llvm::Type *CBufferType,
  93. std::unordered_map<llvm::Constant *, hlsl::DxilFieldAnnotation>
  94. &AnnotationMap);
  95. void ProcessCtorFunctions(llvm::Module &M, llvm::StringRef globalName,
  96. llvm::Instruction *InsertPt);
  97. void TranslateRayQueryConstructor(hlsl::HLModule &HLM);
  98. void UpdateLinkage(
  99. hlsl::HLModule &HLM, clang::CodeGen::CodeGenModule &CGM,
  100. hlsl::dxilutil::ExportMap &exportMap,
  101. llvm::StringMap<EntryFunctionInfo> &entryFunctionMap,
  102. llvm::StringMap<PatchConstantInfo> &patchConstantFunctionMap);
  103. llvm::Value *TryEvalIntrinsic(llvm::CallInst *CI, hlsl::IntrinsicOp intriOp);
  104. void SimpleTransformForHLDXIR(llvm::Module *pM);
  105. void ExtensionCodeGen(hlsl::HLModule &HLM, clang::CodeGen::CodeGenModule &CGM);
  106. } // namespace CGHLSLMSHelper