summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMehdi Amini <mehdi.amini@apple.com>2016-05-07 01:42:36 +0000
committerMehdi Amini <mehdi.amini@apple.com>2016-05-07 01:42:36 +0000
commit6eef08138eef67fbf3946d46efd9d1dbaf8a0baf (patch)
treeff01af3e9efc8b7bc537c2aaf4f97fd0ba646225 /llvm/lib
parent04a8fc2e37baf725aa641e789b7237f19d5b515d (diff)
downloadbcm5719-llvm-6eef08138eef67fbf3946d46efd9d1dbaf8a0baf.tar.gz
bcm5719-llvm-6eef08138eef67fbf3946d46efd9d1dbaf8a0baf.zip
Refactor stripDebugInfo(Function) to handle intrinsic
This moves the code that handles stripping debug info intrinsic from StripDebugInfo(Module) to StripDebugInfo(Function). The latter is already walking every instructions so it makes sense to do it at the same time. This makes also stripDebugInfo(Function) as an API more useful: it is really dropping every debug info in the Function. Finally the existing code is trigerring an assertion when the Module is not fully materialized. From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 268832
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp34
1 files changed, 13 insertions, 21 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index e8c62961eba..18ec7cdfdba 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -247,8 +247,20 @@ bool llvm::stripDebugInfo(Function &F) {
Changed = true;
F.setSubprogram(nullptr);
}
+
+ Function *Declare = F.getParent()->getFunction("llvm.dbg.declare");
+ Function *DbgVal = F.getParent()->getFunction("llvm.dbg.value");
for (BasicBlock &BB : F) {
- for (Instruction &I : BB) {
+ for (auto II = BB.begin(), End = BB.end(); II != End;) {
+ Instruction &I = *II++; // We may delete the instruction, increment now.
+ // Remove all of the calls to the debugger intrinsics, and remove them
+ // from the module.
+ CallInst *CI = dyn_cast<CallInst>(&I);
+ if (CI && (CI->getCalledFunction() == Declare ||
+ CI->getCalledFunction() == DbgVal)) {
+ CI->eraseFromParent();
+ Changed = true;
+ }
if (I.getDebugLoc()) {
Changed = true;
I.setDebugLoc(DebugLoc());
@@ -261,26 +273,6 @@ bool llvm::stripDebugInfo(Function &F) {
bool llvm::StripDebugInfo(Module &M) {
bool Changed = false;
- // Remove all of the calls to the debugger intrinsics, and remove them from
- // the module.
- if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
- while (!Declare->use_empty()) {
- CallInst *CI = cast<CallInst>(Declare->user_back());
- CI->eraseFromParent();
- }
- Declare->eraseFromParent();
- Changed = true;
- }
-
- if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
- while (!DbgVal->use_empty()) {
- CallInst *CI = cast<CallInst>(DbgVal->user_back());
- CI->eraseFromParent();
- }
- DbgVal->eraseFromParent();
- Changed = true;
- }
-
for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
NME = M.named_metadata_end(); NMI != NME;) {
NamedMDNode *NMD = &*NMI;
OpenPOWER on IntegriCloud