HLOperationLowerExtension.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // HLOperationLowerExtension.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Functions to lower HL operations coming from HLSL extensions to DXIL //
  9. // operations. //
  10. // //
  11. ///////////////////////////////////////////////////////////////////////////////
  12. #pragma once
  13. #include "dxc/HLSL/HLSLExtensionsCodegenHelper.h"
  14. #include "llvm/ADT/StringRef.h"
  15. #include <string>
  16. #include <unordered_map>
  17. namespace llvm {
  18. class Value;
  19. class CallInst;
  20. class Function;
  21. class StringRef;
  22. class Instruction;
  23. }
  24. namespace hlsl {
  25. class OP;
  26. struct HLResourceLookup
  27. {
  28. // Lookup resource kind based on handle. Return true on success.
  29. virtual bool GetResourceKindName(llvm::Value *HLHandle, const char **ppName) = 0;
  30. virtual ~HLResourceLookup() {}
  31. };
  32. // Lowers HLSL extensions from HL operation to DXIL operation.
  33. class ExtensionLowering {
  34. public:
  35. // Strategy used for lowering extensions.
  36. enum class Strategy {
  37. Unknown, // Do not know how to lower. This is an error condition.
  38. NoTranslation, // Propagate the call arguments as is down to dxil.
  39. Replicate, // Scalarize the vector arguments and replicate the call.
  40. Pack, // Convert the vector arguments into structs.
  41. Resource, // Convert return value to resource return and explode vectors.
  42. Dxil, // Convert call to a dxil intrinsic.
  43. };
  44. // Create the lowering using the given strategy and custom codegen helper.
  45. ExtensionLowering(llvm::StringRef strategy, HLSLExtensionsCodegenHelper *helper, OP& hlslOp, HLResourceLookup &resourceHelper);
  46. ExtensionLowering(Strategy strategy, HLSLExtensionsCodegenHelper *helper, OP& hlslOp, HLResourceLookup &resourceHelper);
  47. // Translate the HL op call to a DXIL op call.
  48. // Returns a new value if translation was successful.
  49. // Returns nullptr if translation failed or made no changes.
  50. llvm::Value *Translate(llvm::CallInst *CI);
  51. // Translate the strategy string to an enum. The strategy string is
  52. // added as a custom attribute on the high level extension function.
  53. // It is translated as follows:
  54. // "r" -> Replicate
  55. // "n" -> NoTranslation
  56. // "c" -> Custom
  57. static Strategy GetStrategy(llvm::StringRef strategy);
  58. // Translate the strategy enum into a name. This is the inverse of the
  59. // GetStrategy() function.
  60. static llvm::StringRef GetStrategyName(Strategy strategy);
  61. // Get the name that will be used for the extension function call after
  62. // lowering.
  63. std::string GetExtensionName(llvm::CallInst *CI);
  64. private:
  65. Strategy m_strategy;
  66. HLSLExtensionsCodegenHelper *m_helper;
  67. OP &m_hlslOp;
  68. HLResourceLookup &m_hlResourceLookup;
  69. std::string m_extraStrategyInfo;
  70. llvm::Value *Unknown(llvm::CallInst *CI);
  71. llvm::Value *NoTranslation(llvm::CallInst *CI);
  72. llvm::Value *Replicate(llvm::CallInst *CI);
  73. llvm::Value *Pack(llvm::CallInst *CI);
  74. llvm::Value *Resource(llvm::CallInst *CI);
  75. llvm::Value *Dxil(llvm::CallInst *CI);
  76. llvm::Value *CustomResource(llvm::CallInst *CI);
  77. };
  78. }