This is an archive of the discontinued LLVM Phabricator instance.

Merge lines in print-changed by showing simple changes in place in the line
Needs ReviewPublic

Authored by jamieschmeiser on Jan 6 2023, 1:18 PM.

Details

Reviewers
aeubanks
Summary

Relative simple changes result in a line being flagged as changed, showing the entire line in both red and green in the cdiff and dot-cfg outputs.
For example, an unnamed variable being removed results in all the subsequent variables being renamed, showing all lines containing these variables
in red or green and much time can be spent just verifying that the only change is the variable. Similar things happen when attributes change.
Where possible, merge these changes into a single line, showing the colourized change in line with the common part shown in black rather
than showing the entire line twice, once in red and once in green. Also flag such lines with a (red) asterisk in print-changed=(c)diff to aid identifying such lines.

Diff Detail

Event Timeline

jamieschmeiser created this revision.Jan 6 2023, 1:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2023, 1:18 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
jamieschmeiser requested review of this revision.Jan 6 2023, 1:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2023, 1:18 PM

do you have an example that I can try this on to see the difference?

jamieschmeiser added a comment.EditedJan 11 2023, 7:51 AM

This will show some of the differences:

int f() {
  unsigned total = 0;
  for (unsigned i = 0; i < 5; ++i)
    total += i;
  return total;
}

int main() {
  return f();
}
clang -mllvm -print-changed=cdiff-quiet -emit-llvm -O2 test.C -c

Look for lines that have a * at the front. It shows better in colour. I originally had it limited to cdiff and dot-cfg, but then added the * to make it easier to spot in diff and cdiff (also helps if using grep -e "^\*" -e "^+"-e "^-")

*** IR Dump After SimplifyCFGPass on _Z1fv ***
...
*for.cond:                                         ; preds = -%for.inc+%for.body, %entry
...
 for.body:                                         ; preds = %for.cond
*  -%1+%2 = load i32, ptr %i, align 4, !tbaa !5
*  -%2+%3 = load i32, ptr %total, align 4, !tbaa !5
*  %add = add i32 -%2+%3, -%1+%2

Normally, for.body would have 3 red (delete) lines, followed by 3 green (add) lines and the first thing I would do is compare all of the text in the lines, trying to identify that everything other the unnamed variables was unchanged.
The example shows that when an unnamed variable is added or deleted, it has a ripple effect and such changes are easier to spot. Also, changes to just the attributes will also be displayed in a similar manner (eg: -!6+!7). I find it means I don't have to compare lines token by token to recognize simple changes. It also makes it a little more compact.