1 //===-- DbgInfoUtils.cpp - DbgInfo Utilities -------------------------------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Utility functions to manipulate debugging information.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Transforms/Utils/DbgInfoUtils.h"
15 #include "llvm/IntrinsicInst.h"
19 /// RemoveDeadDbgIntrinsics - Remove dead dbg intrinsics from this
21 void llvm::RemoveDeadDbgIntrinsics(BasicBlock &BB) {
22 BasicBlock::iterator BI = BB.begin(), BE = BB.end();
25 Instruction *Prev = BI; ++BI;
27 Instruction *Next = BI; ++BI;
28 DbgInfoIntrinsic *DBI_Prev = dyn_cast<DbgInfoIntrinsic>(Prev);
34 // If there are two consecutive llvm.dbg.stoppoint calls then
35 // it is likely that the optimizer deleted code in between these
37 DbgInfoIntrinsic *DBI_Next = dyn_cast<DbgInfoIntrinsic>(Next);
39 && DBI_Prev->getIntrinsicID() == llvm::Intrinsic::dbg_stoppoint
40 && DBI_Next->getIntrinsicID() == llvm::Intrinsic::dbg_stoppoint)
41 Prev->eraseFromParent();
43 // If a llvm.dbg.stoppoint is placed just before an unconditional
44 // branch then remove the llvm.dbg.stoppoint intrinsic.
45 else if (BranchInst *UC = dyn_cast<BranchInst>(Next)) {
46 if (UC->isUnconditional()
47 && DBI_Prev->getIntrinsicID() == llvm::Intrinsic::dbg_stoppoint)
48 Prev->eraseFromParent();
55 /// RemoveDeadDbgIntrinsics - Remove dead dbg intrinsics from this function.
56 void llvm::RemoveDeadDbgIntrinsics(Function &F) {
57 for (Function::iterator FI = F.begin(), FE = F.end();
59 RemoveDeadDbgIntrinsics(*FI);