about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorRich Kadel <richkadel@google.com>2020-10-22 14:30:03 -0700
committerRich Kadel <richkadel@google.com>2020-11-05 18:24:15 -0800
commit198ba3bd1cfedc7115f91d549a352da2b25050b7 (patch)
tree8a6b3755806c0e8a315dab3e3ea4caf87cd50b05 /compiler/rustc_codegen_llvm/src
parent3291d28e9ac1173f033d240bc5f3f145c9c8dd59 (diff)
downloadrust-198ba3bd1cfedc7115f91d549a352da2b25050b7.tar.gz
rust-198ba3bd1cfedc7115f91d549a352da2b25050b7.zip
Injecting expressions in place of counters where helpful
Implementing the Graph traits for the BasicCoverageBlock
graph.

optimized replacement of counters with expressions plus new BCB graphviz

* Avoid adding coverage to unreachable blocks.
* Special case for Goto at the end of the body. Make it non-reportable.

Improved debugging and formatting options (from env)

Don't automatically add counters to BCBs without CoverageSpans. They may
still get counters but only if there are dependencies from
other BCBs that have spans, I think.

Make CodeRegions optional for Counters too. It is
possible to inject counters (`llvm.instrprof.increment` intrinsic calls
without corresponding code regions in the coverage map. An expression
can still uses these counter values.

Refactored instrument_coverage.rs -> instrument_coverage/mod.rs, and
then broke up the mod into multiple files.

Compiling with coverage, with the expression optimization, works on
the json5format crate and its dependencies.

Refactored debug features from mod.rs to debug.rs
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
index c4b4032fd47..75e8abaf2a9 100644
--- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
+++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
@@ -58,7 +58,11 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
         unsafe { llvm::LLVMRustCoverageCreatePGOFuncNameVar(llfn, mangled_fn_name.as_ptr()) }
     }
 
-    fn set_function_source_hash(&mut self, instance: Instance<'tcx>, function_source_hash: u64) -> bool {
+    fn set_function_source_hash(
+        &mut self,
+        instance: Instance<'tcx>,
+        function_source_hash: u64,
+    ) -> bool {
         if let Some(coverage_context) = self.coverage_context() {
             debug!(
                 "ensuring function source hash is set for instance={:?}; function_source_hash={}",
@@ -69,6 +73,7 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
                 .entry(instance)
                 .or_insert_with(|| FunctionCoverage::new(self.tcx, instance))
                 .set_function_source_hash(function_source_hash);
+            true
         } else {
             false
         }
@@ -92,6 +97,7 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
                 .entry(instance)
                 .or_insert_with(|| FunctionCoverage::new(self.tcx, instance))
                 .add_counter(function_source_hash, id, region);
+            true
         } else {
             false
         }
@@ -105,8 +111,8 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
         op: Op,
         rhs: ExpressionOperandId,
         region: Option<CodeRegion>,
-    ) {
-        if let Some(coverage_context) = self.coverage_context() -> bool {
+    ) -> bool {
+        if let Some(coverage_context) = self.coverage_context() {
             debug!(
                 "adding counter expression to coverage_map: instance={:?}, id={:?}, {:?} {:?} {:?}; \
                 region: {:?}",
@@ -117,6 +123,7 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
                 .entry(instance)
                 .or_insert_with(|| FunctionCoverage::new(self.tcx, instance))
                 .add_counter_expression(id, lhs, op, rhs, region);
+            true
         } else {
             false
         }
@@ -124,12 +131,16 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
 
     fn add_coverage_unreachable(&mut self, instance: Instance<'tcx>, region: CodeRegion) -> bool {
         if let Some(coverage_context) = self.coverage_context() {
-            debug!("adding unreachable code to coverage_map: instance={:?}, at {:?}", instance, region,);
+            debug!(
+                "adding unreachable code to coverage_map: instance={:?}, at {:?}",
+                instance, region,
+            );
             let mut coverage_map = coverage_context.function_coverage_map.borrow_mut();
             coverage_map
                 .entry(instance)
                 .or_insert_with(|| FunctionCoverage::new(self.tcx, instance))
                 .add_unreachable_region(region);
+            true
         } else {
             false
         }