diff options
| author | Devang Patel <dpatel@apple.com> | 2009-03-06 00:19:37 +0000 | 
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2009-03-06 00:19:37 +0000 | 
| commit | 0c970f94e9d18913b09ac7d438512643d9f7efe0 (patch) | |
| tree | c88cc195e3b49d320ec9a1f3f04a1bf0e0ed37a9 /llvm/lib/Transforms/Utils | |
| parent | 9676015e8668c998a170570c8c3dcc01c601af3d (diff) | |
| download | bcm5719-llvm-0c970f94e9d18913b09ac7d438512643d9f7efe0.tar.gz bcm5719-llvm-0c970f94e9d18913b09ac7d438512643d9f7efe0.zip | |
Add "check/remove dbg var" helper routines.
llvm-svn: 66223
Diffstat (limited to 'llvm/lib/Transforms/Utils')
| -rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 44 | 
1 files changed, 44 insertions, 0 deletions
| diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index d2cbec0226e..4be1b8717d2 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -14,11 +14,13 @@  #include "llvm/Transforms/Utils/Local.h"  #include "llvm/Constants.h" +#include "llvm/GlobalVariable.h"  #include "llvm/DerivedTypes.h"  #include "llvm/Instructions.h"  #include "llvm/Intrinsics.h"  #include "llvm/IntrinsicInst.h"  #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/Analysis/DebugInfo.h"  #include "llvm/Target/TargetData.h"  #include "llvm/Support/GetElementPtrTypeIterator.h"  #include "llvm/Support/MathExtras.h" @@ -273,3 +275,45 @@ bool llvm::OnlyUsedByDbgInfoIntrinsics(Instruction *I,    }    return true;  } + +/// UserIsDebugInfo - Return true if U is a constant expr used by  +/// llvm.dbg.variable or llvm.dbg.global_variable +bool llvm::UserIsDebugInfo(User *U) { +  ConstantExpr *CE = dyn_cast<ConstantExpr>(U); + +  if (!CE || CE->getNumUses() != 1) +    return false; + +  Constant *Init = dyn_cast<Constant>(CE->use_back()); +  if (!Init || Init->getNumUses() != 1) +    return false; + +  GlobalVariable *GV = dyn_cast<GlobalVariable>(Init->use_back()); +  if (!GV || !GV->hasInitializer() || GV->getInitializer() != Init) +    return false; + +  DIVariable DV(GV); +  if (!DV.isNull())  +    return true; // User is llvm.dbg.variable + +  DIGlobalVariable DGV(GV); +  if (!DGV.isNull()) +    return true; // User is llvm.dbg.global_variable + +  return false; +} + +/// RemoveDbgInfoUser - Remove an User which is representing debug info. +void llvm::RemoveDbgInfoUser(User *U) { +  assert (UserIsDebugInfo(U) && "Unexpected User!"); +  ConstantExpr *CE = cast<ConstantExpr>(U); +  while (!CE->use_empty()) { +    Constant *C = cast<Constant>(CE->use_back()); +    while (!C->use_empty()) { +      GlobalVariable *GV = cast<GlobalVariable>(C->use_back()); +      GV->eraseFromParent(); +    } +    C->destroyConstant(); +  } +  CE->destroyConstant(); +} | 

