HLDeadFunctionElimination.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // HLDeadFunctionElimination.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/DXIL/DxilUtil.h"
  10. #include "dxc/HLSL/DxilGenerationPass.h"
  11. #include "dxc/HLSL/HLModule.h"
  12. #include "llvm/IR/Function.h"
  13. #include "llvm/IR/Module.h"
  14. #include "llvm/IR/PassManager.h"
  15. using namespace llvm;
  16. using namespace hlsl;
  17. namespace {
  18. class HLDeadFunctionElimination : public ModulePass {
  19. public:
  20. static char ID; // Pass identification, replacement for typeid
  21. explicit HLDeadFunctionElimination () : ModulePass(ID) {}
  22. const char *getPassName() const override { return "Remove all unused function except entry from HLModule"; }
  23. bool runOnModule(Module &M) override {
  24. if (M.HasHLModule()) {
  25. HLModule &HLM = M.GetHLModule();
  26. bool IsLib = HLM.GetShaderModel()->IsLib();
  27. // Remove unused functions except entry and patch constant func.
  28. // For library profile, only remove unused external functions.
  29. Function *EntryFunc = HLM.GetEntryFunction();
  30. Function *PatchConstantFunc = HLM.GetPatchConstantFunction();
  31. return dxilutil::RemoveUnusedFunctions(M, EntryFunc, PatchConstantFunc,
  32. IsLib);
  33. }
  34. return false;
  35. }
  36. };
  37. }
  38. char HLDeadFunctionElimination::ID = 0;
  39. ModulePass *llvm::createHLDeadFunctionEliminationPass() {
  40. return new HLDeadFunctionElimination();
  41. }
  42. INITIALIZE_PASS(HLDeadFunctionElimination, "hl-dfe", "Remove all unused function except entry from HLModule", false, false)