# [PATCH] llvm-cov: Added -b option for branch probabilities.

Justin Bogner mail at justinbogner.com
Thu Dec 12 14:54:59 PST 2013

``` ...
> From cf3b0d1d047a1933590861c4f67b35c7e2ecbf94 Mon Sep 17 00:00:00 2001
> From: Yuchen Wu <yuchen_wu at apple.com>
> Date: Tue, 3 Dec 2013 14:27:17 -0800
> Subject: [PATCH 2/7] llvm-cov: Added -b option for branch probabilities.
>
> This option tells llvm-cov to print out branch probabilities when
> a basic block contains multiple branches. It also prints out some
> function summary info including the number of times the function enters,
> the percent of time it returns, and how many blocks were executed.
>
> Also updated tests.
...
> +// Safe integer division, returns 0 if divisor is 0.

This comment is wrong now,

> +static uint32_t safeDiv(uint64_t Numerator, uint64_t Divisor) {
> +  if (!Numerator && !Divisor)

No point in checking Divisor.

> +    return 0;
> +  return Numerator/Divisor;
> +}
> +
> +// This custom division function mimics gcov's branch ouputs:
> +//   - Round to closest whole number
> +//   - Only output 0% or 100% if it's exactly that value
> +static uint32_t branchDiv(uint64_t Numerator, uint64_t Divisor) {
> +  if (!Numerator)
> +    return 0;
> +  if (Numerator == Divisor)
> +    return 100;
> +
> +  uint8_t Res = (Numerator*100+Divisor/2) / Divisor;
> +  if (Res == 0)
> +    return 1;
> +  if (Res == 100)
> +    return 99;
> +  return Res;
> +}

If you could simplify this, it'd be nice, otherwise LGTM

```