HLOperationLowerExtension.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // Lowers HLSL extensions from HL operation to DXIL operation.
  27. class ExtensionLowering {
  28. public:
  29. // Strategy used for lowering extensions.
  30. enum class Strategy {
  31. Unknown, // Do not know how to lower. This is an error condition.
  32. NoTranslation, // Propagate the call arguments as is down to dxil.
  33. Replicate, // Scalarize the vector arguments and replicate the call.
  34. Pack, // Convert the vector arguments into structs.
  35. Resource, // Convert return value to resource return and explode vectors.
  36. Dxil, // Convert call to a dxil intrinsic.
  37. };
  38. // Create the lowering using the given strategy and custom codegen helper.
  39. ExtensionLowering(llvm::StringRef strategy, HLSLExtensionsCodegenHelper *helper, OP& hlslOp);
  40. ExtensionLowering(Strategy strategy, HLSLExtensionsCodegenHelper *helper, OP& hlslOp);
  41. // Translate the HL op call to a DXIL op call.
  42. // Returns a new value if translation was successful.
  43. // Returns nullptr if translation failed or made no changes.
  44. llvm::Value *Translate(llvm::CallInst *CI);
  45. // Translate the strategy string to an enum. The strategy string is
  46. // added as a custom attribute on the high level extension function.
  47. // It is translated as follows:
  48. // "r" -> Replicate
  49. // "n" -> NoTranslation
  50. // "c" -> Custom
  51. static Strategy GetStrategy(llvm::StringRef strategy);
  52. // Translate the strategy enum into a name. This is the inverse of the
  53. // GetStrategy() function.
  54. static llvm::StringRef GetStrategyName(Strategy strategy);
  55. // Get the name that will be used for the extension function call after
  56. // lowering.
  57. std::string GetExtensionName(llvm::CallInst *CI);
  58. private:
  59. Strategy m_strategy;
  60. HLSLExtensionsCodegenHelper *m_helper;
  61. OP &m_hlslOp;
  62. llvm::Value *Unknown(llvm::CallInst *CI);
  63. llvm::Value *NoTranslation(llvm::CallInst *CI);
  64. llvm::Value *Replicate(llvm::CallInst *CI);
  65. llvm::Value *Pack(llvm::CallInst *CI);
  66. llvm::Value *Resource(llvm::CallInst *CI);
  67. llvm::Value *Dxil(llvm::CallInst *CI);
  68. };
  69. }