[esan|cfrag] Compute the struct field access difference ratio

Summary:
Computes the struct field access variation based on each field access
count.

Adds a flag to control the report thresholds.

Updates struct-simple.cpp with variance report output.

Reviewers: aizatsky

Subscribers: kubabrecka, zhaoqin, llvm-commits, eugenis, vitalybuka, kcc, bruening

Differential Revision: http://reviews.llvm.org/D20914

llvm-svn: 271734
diff --git a/compiler-rt/test/esan/TestCases/struct-simple.cpp b/compiler-rt/test/esan/TestCases/struct-simple.cpp
index 560f79c..0e6dbab 100644
--- a/compiler-rt/test/esan/TestCases/struct-simple.cpp
+++ b/compiler-rt/test/esan/TestCases/struct-simple.cpp
@@ -138,22 +138,52 @@
   return 0;
   // CHECK:      in esan::finalizeLibrary
   // CHECK-NEXT: in esan::finalizeCacheFrag
-  // CHECK-NEXT: {{.*}}EfficiencySanitizer is not finished: nothing yet to report
   // CHECK-NEXT: in esan::processCompilationUnitExit
   // CHECK-NEXT: in esan::processCacheFragCompilationUnitExit: {{.*}}struct-simple.cpp with 5 class(es)/struct(s)
   // CHECK-NEXT:  Unregister class.C#3#14#13#13:  3 fields
+  // CHECK-NEXT:   {{.*}} class C
+  // CHECK-NEXT:   {{.*}}  count = 5, ratio = 3
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2, type = %struct.anon = type { i32, i32 }
+  // CHECK-NEXT:   {{.*}}  # 1: count = 2, type = %union.anon = type { double }
+  // CHECK-NEXT:   {{.*}}  # 2: count = 1, type = [10 x i8]
   // CHECK-NEXT:  Unregister struct.anon#2#11#11: 2 fields
+  // CHECK-NEXT:   {{.*}} struct anon
+  // CHECK-NEXT:   {{.*}}  count = 2, ratio = 1
+  // CHECK-NEXT:   {{.*}}  # 0: count = 1, type = i32
+  // CHECK-NEXT:   {{.*}}  # 1: count = 1, type = i32
   // CHECK-NEXT:  Unregister union.anon#1#3:      1 fields
   // CHECK-NEXT:  Unregister struct.S#2#11#11:    2 fields
+  // CHECK-NEXT:   {{.*}} struct S
+  // CHECK-NEXT:   {{.*}}  count = 2, ratio = 2
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2, type = i32
+  // CHECK-NEXT:   {{.*}}  # 1: count = 0, type = i32
   // CHECK-NEXT:  Unregister struct.D#3#11#11#11: 3 fields
+  // CHECK-NEXT:   {{.*}} struct D
+  // CHECK-NEXT:   {{.*}}  count = 2, ratio = 2
+  // CHECK-NEXT:   {{.*}}  # 0: count = 1, type = i32
+  // CHECK-NEXT:   {{.*}}  # 1: count = 1, type = i32
+  // CHECK-NEXT:   {{.*}}  # 2: count = 0, type = i32
   // CHECK-NEXT: in esan::processCompilationUnitExit
   // CHECK-NEXT: in esan::processCacheFragCompilationUnitExit: {{.*}}struct-simple.cpp with 0 class(es)/struct(s)
   // CHECK-NEXT: in esan::processCompilationUnitExit
   // CHECK-NEXT: in esan::processCacheFragCompilationUnitExit: {{.*}}struct-simple.cpp with 5 class(es)/struct(s)
   // CHECK-NEXT:  Unregister struct.A#2#11#11:    2 fields
+  // CHECK-NEXT:   {{.*}} struct A
+  // CHECK-NEXT:   {{.*}}  count = 2049, ratio = 2048
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2048, type = i32
+  // CHECK-NEXT:   {{.*}}  # 1: count = 1, type = i32
   // CHECK-NEXT:  Unregister struct.B#2#3#2:      2 fields
+  // CHECK-NEXT:   {{.*}} struct B
+  // CHECK-NEXT:   {{.*}}  count = 2097153, ratio = 2097152
+  // CHECK-NEXT:   {{.*}}  # 0: count = 1, type = float
+  // CHECK-NEXT:   {{.*}}  # 1: count = 2097152, type = double
   // CHECK-NEXT:  Unregister union.U#1#3:         1 fields
   // CHECK-NEXT:  Duplicated struct.S#2#11#11:    2 fields
   // CHECK-NEXT:  Unregister struct.D#2#11#11:    2 fields
+  // CHECK-NEXT:   {{.*}} struct D
+  // CHECK-NEXT:   {{.*}}  count = 1, ratio = 1
+  // CHECK-NEXT:   {{.*}}  # 0: count = 1, type = i32
+  // CHECK-NEXT:   {{.*}}  # 1: count = 0, type = i32
+  // CHECK-NEXT: {{.*}}EfficiencySanitizer: total struct field access count = 2099214
 }
 #endif // MAIN