CGHLSLRuntime.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //===----- CGMSHLSLRuntime.h - Interface to HLSL Runtime ----------------===//
  2. ///////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // CGHLSLRuntime.h //
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. // This file is distributed under the University of Illinois Open Source //
  7. // License. See LICENSE.TXT for details. //
  8. // //
  9. // This provides a class for HLSL code generation. //
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #pragma once
  13. #include <functional>
  14. namespace llvm {
  15. class Function;
  16. template <typename T, unsigned N> class SmallVector;
  17. class Value;
  18. class Constant;
  19. class TerminatorInst;
  20. class Type;
  21. template <typename T> class ArrayRef;
  22. }
  23. namespace clang {
  24. class Decl;
  25. class QualType;
  26. class ExtVectorType;
  27. class ASTContext;
  28. class FunctionDecl;
  29. class CallExpr;
  30. class InitListExpr;
  31. class Expr;
  32. class Stmt;
  33. class Attr;
  34. class VarDecl;
  35. class HLSLRootSignatureAttr;
  36. namespace CodeGen {
  37. class CodeGenModule;
  38. class ReturnValueSlot;
  39. class CodeGenFunction;
  40. class RValue;
  41. class LValue;
  42. class CGHLSLRuntime {
  43. protected:
  44. CodeGenModule &CGM;
  45. public:
  46. CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
  47. virtual ~CGHLSLRuntime();
  48. virtual void addResource(Decl *D) = 0;
  49. virtual void FinishCodeGen() = 0;
  50. virtual RValue EmitHLSLBuiltinCallExpr(CodeGenFunction &CGF,
  51. const FunctionDecl *FD,
  52. const CallExpr *E,
  53. ReturnValueSlot ReturnValue) = 0;
  54. // Is E is a c++ init list not a hlsl init list which only match size.
  55. virtual bool IsTrivalInitListExpr(CodeGenFunction &CGF, InitListExpr *E) = 0;
  56. virtual llvm::Value *EmitHLSLInitListExpr(CodeGenFunction &CGF, InitListExpr *E,
  57. // The destPtr when emiting aggregate init, for normal case, it will be null.
  58. llvm::Value *DestPtr) = 0;
  59. virtual llvm::Constant *EmitHLSLConstInitListExpr(CodeGenModule &CGM, InitListExpr *E) = 0;
  60. virtual void EmitHLSLOutParamConversionInit(
  61. CodeGenFunction &CGF, const FunctionDecl *FD, const CallExpr *E,
  62. llvm::SmallVector<LValue, 8> &castArgList,
  63. llvm::SmallVector<const Stmt *, 8> &argList,
  64. const std::function<void(const VarDecl *, llvm::Value *)> &TmpArgMap) = 0;
  65. virtual void EmitHLSLOutParamConversionCopyBack(
  66. CodeGenFunction &CGF, llvm::SmallVector<LValue, 8> &castArgList) = 0;
  67. virtual llvm::Value *EmitHLSLMatrixOperationCall(CodeGenFunction &CGF, const clang::Expr *E, llvm::Type *RetType,
  68. llvm::ArrayRef<llvm::Value*> paramList) = 0;
  69. virtual void EmitHLSLDiscard(CodeGenFunction &CGF) = 0;
  70. // For [] on matrix
  71. virtual llvm::Value *EmitHLSLMatrixSubscript(CodeGenFunction &CGF,
  72. llvm::Type *RetType,
  73. llvm::Value *Ptr, llvm::Value *Idx,
  74. clang::QualType Ty) = 0;
  75. // For ._m on matrix
  76. virtual llvm::Value *EmitHLSLMatrixElement(CodeGenFunction &CGF,
  77. llvm::Type *RetType,
  78. llvm::ArrayRef<llvm::Value*> paramList,
  79. clang::QualType Ty) = 0;
  80. virtual llvm::Value *EmitHLSLMatrixLoad(CodeGenFunction &CGF,
  81. llvm::Value *Ptr,
  82. clang::QualType Ty) = 0;
  83. virtual void EmitHLSLMatrixStore(CodeGenFunction &CGF, llvm::Value *Val,
  84. llvm::Value *DestPtr,
  85. clang::QualType Ty) = 0;
  86. virtual void EmitHLSLAggregateCopy(CodeGenFunction &CGF, llvm::Value *SrcPtr,
  87. llvm::Value *DestPtr,
  88. clang::QualType Ty) = 0;
  89. virtual void EmitHLSLAggregateStore(CodeGenFunction &CGF, llvm::Value *Val,
  90. llvm::Value *DestPtr,
  91. clang::QualType Ty) = 0;
  92. virtual void EmitHLSLFlatConversionToAggregate(CodeGenFunction &CGF, llvm::Value *Val,
  93. llvm::Value *DestPtr,
  94. clang::QualType Ty, clang::QualType SrcTy) = 0;
  95. virtual void EmitHLSLFlatConversionAggregateCopy(CodeGenFunction &CGF, llvm::Value *SrcPtr,
  96. clang::QualType SrcTy,
  97. llvm::Value *DestPtr,
  98. clang::QualType DestTy) = 0;
  99. virtual void EmitHLSLRootSignature(CodeGenFunction &CGF,
  100. clang::HLSLRootSignatureAttr *RSA,
  101. llvm::Function *Fn) = 0;
  102. virtual llvm::Value *EmitHLSLLiteralCast(CodeGenFunction &CGF, llvm::Value *Src, clang::QualType SrcType,
  103. clang::QualType DstType) = 0;
  104. virtual void AddHLSLFunctionInfo(llvm::Function *, const FunctionDecl *FD) = 0;
  105. virtual void EmitHLSLFunctionProlog(llvm::Function *, const FunctionDecl *FD) = 0;
  106. virtual bool IsHlslObjectType(llvm::Type *Ty) = 0;
  107. virtual void AddControlFlowHint(CodeGenFunction &CGF, const Stmt &S, llvm::TerminatorInst *TI, llvm::ArrayRef<const Attr *> Attrs) = 0;
  108. virtual void FinishAutoVar(CodeGenFunction &CGF, const VarDecl &D, llvm::Value *V) = 0;
  109. static const clang::ExtVectorType *
  110. ConvertHLSLVecMatTypeToExtVectorType(const clang::ASTContext &context,
  111. clang::QualType &type);
  112. static bool IsHLSLVecMatType(clang::QualType &type);
  113. static clang::QualType GetHLSLVecMatElementType(clang::QualType type);
  114. };
  115. /// Create an instance of a HLSL runtime class.
  116. CGHLSLRuntime *CreateMSHLSLRuntime(CodeGenModule &CGM);
  117. }
  118. }