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 StripNonLineTableDebugLegacyPass__anonfab30aa50111::StripNonLineTableDebugLegacyPass23 StripNonLineTableDebugLegacyPass() : ModulePass(ID) { 24 initializeStripNonLineTableDebugLegacyPassPass( 25 *PassRegistry::getPassRegistry()); 26 } 27 getAnalysisUsage__anonfab30aa50111::StripNonLineTableDebugLegacyPass28 void getAnalysisUsage(AnalysisUsage &AU) const override { 29 AU.setPreservesAll(); 30 } 31 runOnModule__anonfab30aa50111::StripNonLineTableDebugLegacyPass32 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 createStripNonLineTableDebugLegacyPass()43ModulePass *llvm::createStripNonLineTableDebugLegacyPass() { 44 return new StripNonLineTableDebugLegacyPass(); 45 } 46 47 PreservedAnalyses run(Module & M,ModuleAnalysisManager & AM)48StripNonLineTableDebugInfoPass::run(Module &M, ModuleAnalysisManager &AM) { 49 llvm::stripNonLineTableDebugInfo(M); 50 return PreservedAnalyses::all(); 51 } 52