HLMetadataPasses.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // HLMetadataPasses.cpp //
  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. ///////////////////////////////////////////////////////////////////////////////
  9. #include "dxc/HLSL/DxilGenerationPass.h"
  10. #include "dxc/HLSL/HLModule.h"
  11. #include "llvm/IR/Module.h"
  12. #include "llvm/IR/PassManager.h"
  13. using namespace llvm;
  14. using namespace hlsl;
  15. namespace {
  16. class HLEmitMetadata : public ModulePass {
  17. public:
  18. static char ID; // Pass identification, replacement for typeid
  19. explicit HLEmitMetadata() : ModulePass(ID) {}
  20. const char *getPassName() const override { return "HLSL High-Level Metadata Emit"; }
  21. bool runOnModule(Module &M) override {
  22. if (M.HasHLModule()) {
  23. HLModule::ClearHLMetadata(M);
  24. M.GetHLModule().EmitHLMetadata();
  25. return true;
  26. }
  27. return false;
  28. }
  29. };
  30. }
  31. char HLEmitMetadata::ID = 0;
  32. ModulePass *llvm::createHLEmitMetadataPass() {
  33. return new HLEmitMetadata();
  34. }
  35. INITIALIZE_PASS(HLEmitMetadata, "hlsl-hlemit", "HLSL High-Level Metadata Emit", false, false)
  36. ///////////////////////////////////////////////////////////////////////////////
  37. namespace {
  38. class HLEnsureMetadata : public ModulePass {
  39. public:
  40. static char ID; // Pass identification, replacement for typeid
  41. explicit HLEnsureMetadata() : ModulePass(ID) {}
  42. const char *getPassName() const override { return "HLSL High-Level Metadata Ensure"; }
  43. bool runOnModule(Module &M) override {
  44. if (!M.HasHLModule()) {
  45. M.GetOrCreateHLModule();
  46. return true;
  47. }
  48. return false;
  49. }
  50. };
  51. }
  52. char HLEnsureMetadata::ID = 0;
  53. ModulePass *llvm::createHLEnsureMetadataPass() {
  54. return new HLEnsureMetadata();
  55. }
  56. INITIALIZE_PASS(HLEnsureMetadata, "hlsl-hlensure", "HLSL High-Level Metadata Ensure", false, false)