StripNonLineTableDebugInfo.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===- StripNonLineTableDebugInfo.cpp -- Strip parts of Debug Info --------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/Transforms/Utils/StripNonLineTableDebugInfo.h"
  9. #include "llvm/IR/DebugInfo.h"
  10. #include "llvm/InitializePasses.h"
  11. #include "llvm/Pass.h"
  12. #include "llvm/Transforms/Utils.h"
  13. using namespace llvm;
  14. namespace {
  15. /// This pass strips all debug info that is not related line tables.
  16. /// The result will be the same as if the program where compiled with
  17. /// -gline-tables-only.
  18. struct StripNonLineTableDebugLegacyPass : public ModulePass {
  19. static char ID; // Pass identification, replacement for typeid
  20. StripNonLineTableDebugLegacyPass() : ModulePass(ID) {
  21. initializeStripNonLineTableDebugLegacyPassPass(
  22. *PassRegistry::getPassRegistry());
  23. }
  24. void getAnalysisUsage(AnalysisUsage &AU) const override {
  25. AU.setPreservesAll();
  26. }
  27. bool runOnModule(Module &M) override {
  28. return llvm::stripNonLineTableDebugInfo(M);
  29. }
  30. };
  31. }
  32. char StripNonLineTableDebugLegacyPass::ID = 0;
  33. INITIALIZE_PASS(StripNonLineTableDebugLegacyPass,
  34. "strip-nonlinetable-debuginfo",
  35. "Strip all debug info except linetables", false, false)
  36. ModulePass *llvm::createStripNonLineTableDebugLegacyPass() {
  37. return new StripNonLineTableDebugLegacyPass();
  38. }
  39. PreservedAnalyses
  40. StripNonLineTableDebugInfoPass::run(Module &M, ModuleAnalysisManager &AM) {
  41. llvm::stripNonLineTableDebugInfo(M);
  42. return PreservedAnalyses::all();
  43. }