From fb972e9c09422f988eb278883e5bde2da58b0f04 Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Fri, 30 Oct 2015 04:29:05 +0000 Subject: [PATCH] Revert r251680: Update the discriminator assignment algorithm * If a scope has already been assigned a discriminator, do not reassign a nested discriminator for it. * If the file and line both match, even if the column does not match, we should assign a new discriminator for the stmt. original code: ; #1 int foo(int i) { ; #2 if (i == 3 || i == 5) return 100; else return 99; ; #3 } ; i == 3: discriminator 0 ; i == 5: discriminator 2 ; return 100: discriminator 1 ; return 99: discriminator 3 llvm-svn: 251685 --- lib/Transforms/Utils/AddDiscriminators.cpp | 23 +++-- test/Transforms/AddDiscriminators/oneline.ll | 98 -------------------- 2 files changed, 11 insertions(+), 110 deletions(-) diff --git a/lib/Transforms/Utils/AddDiscriminators.cpp b/lib/Transforms/Utils/AddDiscriminators.cpp index 1a101879d26..34c2f4525ea 100644 --- a/lib/Transforms/Utils/AddDiscriminators.cpp +++ b/lib/Transforms/Utils/AddDiscriminators.cpp @@ -180,7 +180,7 @@ bool AddDiscriminators::runOnFunction(Function &F) { BasicBlock *Succ = Last->getSuccessor(I); Instruction *First = Succ->getFirstNonPHIOrDbgOrLifetime(); const DILocation *FirstDIL = First->getDebugLoc(); - if (!FirstDIL || FirstDIL->getDiscriminator()) + if (!FirstDIL) continue; // If the first instruction (First) of Succ is at the same file @@ -202,22 +202,21 @@ bool AddDiscriminators::runOnFunction(Function &F) { unsigned Discriminator = FirstDIL->computeNewDiscriminator(); auto *NewScope = Builder.createLexicalBlockFile(Scope, File, Discriminator); + auto *NewDIL = + DILocation::get(Ctx, FirstDIL->getLine(), FirstDIL->getColumn(), + NewScope, FirstDIL->getInlinedAt()); + DebugLoc newDebugLoc = NewDIL; // Attach this new debug location to First and every // instruction following First that shares the same location. for (BasicBlock::iterator I1(*First), E1 = Succ->end(); I1 != E1; ++I1) { - const DILocation *CurrentDIL = I1->getDebugLoc(); - if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() && - CurrentDIL->getFilename() == FirstDIL->getFilename()) { - I1->setDebugLoc(DILocation::get(Ctx, CurrentDIL->getLine(), - CurrentDIL->getColumn(), NewScope, - CurrentDIL->getInlinedAt())); - DEBUG(dbgs() << CurrentDIL->getFilename() << ":" - << CurrentDIL->getLine() << ":" - << CurrentDIL->getColumn() << ":" - << CurrentDIL->getDiscriminator() << *I1 << "\n"); - } + if (I1->getDebugLoc().get() != FirstDIL) + break; + I1->setDebugLoc(newDebugLoc); + DEBUG(dbgs() << NewDIL->getFilename() << ":" << NewDIL->getLine() + << ":" << NewDIL->getColumn() << ":" + << NewDIL->getDiscriminator() << *I1 << "\n"); } DEBUG(dbgs() << "\n"); Changed = true; diff --git a/test/Transforms/AddDiscriminators/oneline.ll b/test/Transforms/AddDiscriminators/oneline.ll index dcad5ae9176..e69de29bb2d 100644 --- a/test/Transforms/AddDiscriminators/oneline.ll +++ b/test/Transforms/AddDiscriminators/oneline.ll @@ -1,98 +0,0 @@ -; RUN: opt < %s -add-discriminators -S | FileCheck %s - -; Discriminator support for code that is written in one line: -; #1 int foo(int i) { -; #2 if (i == 3 || i == 5) return 100; else return 99; -; #3 } - -; i == 3: discriminator 0 -; i == 5: discriminator 2 -; return 100: discriminator 1 -; return 99: discriminator 3 - -define i32 @_Z3fooi(i32 %i) #0 { - %1 = alloca i32, align 4 - %2 = alloca i32, align 4 - store i32 %i, i32* %2, align 4, !tbaa !13 - call void @llvm.dbg.declare(metadata i32* %2, metadata !9, metadata !17), !dbg !18 - %3 = load i32, i32* %2, align 4, !dbg !19, !tbaa !13 - %4 = icmp eq i32 %3, 3, !dbg !21 - br i1 %4, label %8, label %5, !dbg !22 - -;