10b57cec5SDimitry Andric //===- StripNonLineTableDebugInfo.cpp -- Strip parts of Debug Info --------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
9*af732203SDimitry Andric #include "llvm/Transforms/Utils/StripNonLineTableDebugInfo.h"
100b57cec5SDimitry Andric #include "llvm/IR/DebugInfo.h"
11480093f4SDimitry Andric #include "llvm/InitializePasses.h"
120b57cec5SDimitry Andric #include "llvm/Pass.h"
130b57cec5SDimitry Andric #include "llvm/Transforms/Utils.h"
140b57cec5SDimitry Andric using namespace llvm;
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric namespace {
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric /// This pass strips all debug info that is not related line tables.
190b57cec5SDimitry Andric /// The result will be the same as if the program where compiled with
200b57cec5SDimitry Andric /// -gline-tables-only.
21*af732203SDimitry Andric struct StripNonLineTableDebugLegacyPass : public ModulePass {
220b57cec5SDimitry Andric   static char ID; // Pass identification, replacement for typeid
StripNonLineTableDebugLegacyPass__anon02c199c20111::StripNonLineTableDebugLegacyPass23*af732203SDimitry Andric   StripNonLineTableDebugLegacyPass() : ModulePass(ID) {
24*af732203SDimitry Andric     initializeStripNonLineTableDebugLegacyPassPass(
25*af732203SDimitry Andric         *PassRegistry::getPassRegistry());
260b57cec5SDimitry Andric   }
270b57cec5SDimitry Andric 
getAnalysisUsage__anon02c199c20111::StripNonLineTableDebugLegacyPass280b57cec5SDimitry Andric   void getAnalysisUsage(AnalysisUsage &AU) const override {
290b57cec5SDimitry Andric     AU.setPreservesAll();
300b57cec5SDimitry Andric   }
310b57cec5SDimitry Andric 
runOnModule__anon02c199c20111::StripNonLineTableDebugLegacyPass320b57cec5SDimitry Andric   bool runOnModule(Module &M) override {
330b57cec5SDimitry Andric     return llvm::stripNonLineTableDebugInfo(M);
340b57cec5SDimitry Andric   }
350b57cec5SDimitry Andric };
360b57cec5SDimitry Andric }
370b57cec5SDimitry Andric 
38*af732203SDimitry Andric char StripNonLineTableDebugLegacyPass::ID = 0;
39*af732203SDimitry Andric INITIALIZE_PASS(StripNonLineTableDebugLegacyPass,
40*af732203SDimitry Andric                 "strip-nonlinetable-debuginfo",
410b57cec5SDimitry Andric                 "Strip all debug info except linetables", false, false)
420b57cec5SDimitry Andric 
createStripNonLineTableDebugLegacyPass()43*af732203SDimitry Andric ModulePass *llvm::createStripNonLineTableDebugLegacyPass() {
44*af732203SDimitry Andric   return new StripNonLineTableDebugLegacyPass();
45*af732203SDimitry Andric }
46*af732203SDimitry Andric 
47*af732203SDimitry Andric PreservedAnalyses
run(Module & M,ModuleAnalysisManager & AM)48*af732203SDimitry Andric StripNonLineTableDebugInfoPass::run(Module &M, ModuleAnalysisManager &AM) {
49*af732203SDimitry Andric   llvm::stripNonLineTableDebugInfo(M);
50*af732203SDimitry Andric   return PreservedAnalyses::all();
510b57cec5SDimitry Andric }
52