Finding DebugInfo Loss

In order to fix DebugInfo loss I need to find where and when it occurs. Many transformations result in DI loss due to the simple fact that they change and optimize code and thus the resulting llvm IR doesn't match the original code.

The opt tool has the -debugify and -check-debugify flags to attach DI to everything and then check if it's correct.

Find culprit transformations

With a simple bash script I can run tests under a transformation folder like so:

for i in $(ls ~/code/llvm/test/Transforms/$TRANSFORMATION/*.ll -1); do 
    echo -e $i":\n-------"; 
    opt -debugify -$TRANSFORMATION -check-debugify -disable-output $i;
    echo -e "-------\n"; 
done > results 2>&1

and then proceed to view the results.

For example here is the command for the LICM transformation:

for i in $(ls ~/code/llvm/test/Transforms/LICM/*.ll -1); do 
    echo -e $i":\n-------"; 
    opt -debugify -licm -check-debugify -disable-output $i; 
    echo -e "-------\n"; 
done > results 2>&1

Here is a sample of the results file:

/home/gramanas/code/llvm/test/Transforms/LICM/2003-02-27-StoreSinkPHIs.ll:
-------
CheckDebugify: PASS
-------

/home/gramanas/code/llvm/test/Transforms/LICM/2003-05-02-LoadHoist.ll:
-------
ERROR: Instruction with empty DebugLoc --   %B.lcssa = phi i32 [ %B, %Loop ]
CheckDebugify: FAIL
-------

/home/gramanas/code/llvm/test/Transforms/LICM/2004-09-14-AliasAnalysisInvalidate.ll:
-------
WARNING: Missing line 3
WARNING: Missing line 4
CheckDebugify: PASS
-------

/home/gramanas/code/llvm/test/Transforms/LICM/2003-02-28-PromoteDifferentType.ll:
-------
ERROR: Instruction with empty DebugLoc --   %P2 = bitcast i32* %P to i8*
WARNING: Missing line 3
CheckDebugify: FAIL
-------