xref: /freebsd/contrib/llvm-project/llvm/lib/Transforms/Utils/StripNonLineTableDebugInfo.cpp (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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 
9 #include "llvm/Transforms/Utils/StripNonLineTableDebugInfo.h"
10 #include "llvm/IR/DebugInfo.h"
11 #include "llvm/InitializePasses.h"
12 #include "llvm/Pass.h"
13 #include "llvm/Transforms/Utils.h"
14 using namespace llvm;
15 
16 namespace {
17 
18 /// This pass strips all debug info that is not related line tables.
19 /// The result will be the same as if the program where compiled with
20 /// -gline-tables-only.
21 struct StripNonLineTableDebugLegacyPass : public ModulePass {
22   static char ID; // Pass identification, replacement for typeid
23   StripNonLineTableDebugLegacyPass() : ModulePass(ID) {
24     initializeStripNonLineTableDebugLegacyPassPass(
25         *PassRegistry::getPassRegistry());
26   }
27 
28   void getAnalysisUsage(AnalysisUsage &AU) const override {
29     AU.setPreservesAll();
30   }
31 
32   bool runOnModule(Module &M) override {
33     return llvm::stripNonLineTableDebugInfo(M);
34   }
35 };
36 }
37 
38 char StripNonLineTableDebugLegacyPass::ID = 0;
39 INITIALIZE_PASS(StripNonLineTableDebugLegacyPass,
40                 "strip-nonlinetable-debuginfo",
41                 "Strip all debug info except linetables", false, false)
42 
43 ModulePass *llvm::createStripNonLineTableDebugLegacyPass() {
44   return new StripNonLineTableDebugLegacyPass();
45 }
46 
47 PreservedAnalyses
48 StripNonLineTableDebugInfoPass::run(Module &M, ModuleAnalysisManager &AM) {
49   llvm::stripNonLineTableDebugInfo(M);
50   return PreservedAnalyses::all();
51 }
52