Devang Patel | dc6699e | 2008-11-11 00:53:02 +0000 | [diff] [blame] | 1 | //===-- DbgInfoUtils.cpp - DbgInfo Utilities -------------------------------==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Utility functions to manipulate debugging information. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Transforms/Utils/DbgInfoUtils.h" |
| 15 | #include "llvm/IntrinsicInst.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | /// RemoveDeadDbgIntrinsics - Remove dead dbg intrinsics from this |
| 20 | /// basic block. |
| 21 | void llvm::RemoveDeadDbgIntrinsics(BasicBlock &BB) { |
| 22 | BasicBlock::iterator BI = BB.begin(), BE = BB.end(); |
| 23 | if (BI == BE) return; |
| 24 | |
| 25 | Instruction *Prev = BI; ++BI; |
| 26 | while (BI != BE) { |
| 27 | Instruction *Next = BI; ++BI; |
| 28 | DbgInfoIntrinsic *DBI_Prev = dyn_cast<DbgInfoIntrinsic>(Prev); |
| 29 | if (!DBI_Prev) { |
| 30 | Prev = Next; |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | // If there are two consecutive llvm.dbg.stoppoint calls then |
| 35 | // it is likely that the optimizer deleted code in between these |
| 36 | // two intrinsics. |
| 37 | DbgInfoIntrinsic *DBI_Next = dyn_cast<DbgInfoIntrinsic>(Next); |
| 38 | if (DBI_Next |
| 39 | && DBI_Prev->getIntrinsicID() == llvm::Intrinsic::dbg_stoppoint |
| 40 | && DBI_Next->getIntrinsicID() == llvm::Intrinsic::dbg_stoppoint) |
| 41 | Prev->eraseFromParent(); |
| 42 | |
| 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(); |
| 49 | } |
| 50 | |
| 51 | Prev = Next; |
| 52 | } |
| 53 | } |
| 54 | |
| 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(); |
| 58 | FI != FE; ++FI) |
| 59 | RemoveDeadDbgIntrinsics(*FI); |
| 60 | } |