[PATCH] D15306: [llvm-profdata] Add support for weighted merge of profile data (2nd try)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 8 01:07:43 PST 2015


David Li via llvm-commits <llvm-commits at lists.llvm.org> writes:
> davidxl added a comment.
>
> I think the right fix is:
>
> StringRef WeightStr;
> ​std::tie(FileName, WeightStr) = Input.rsplit(':');
> ​ if (!sys::fs::exists(FileName) && !sys::fs::exists(Input)) {
>
>     // report missing file error;
>   }
>   else if (sys::fs::exists(Input)) {
>     // add input 
>    }
>   else {
>      assert (!WeightStr.empty());
>      // check WeightStr format 
>      ...
>   }


If WeightStr isn't a number I think that "no such file" is more likely
to be the correct error message, so I'd probably go with something like
so:

  static Optional<WeightedFile> parseWeightedFile(StringRef Input) {
    if (sys::fs::exists(Input))
      return WeightedFile(Input, 1);
    StringRef FileName, WeightStr;
    int Weight;
    std::tie(FileName, WeightStr) = Input.rsplit(':');
    if (WeightStr.getAsInteger(10, &Weight)) {
      if (Weight >= 1)
        return WeightedFile(FileName, WeightStr);
      // Report invalid weight
      return None;
    }
    // Report missing file
    return None;
  }

Then things like /path/to/foo:0 or /path/to/foo:-1 say things like
"invalid weight: -1", but /path/with:colon/doesnotexist says "no such
file" rather than "invalid weight: colon/doesnotexist" or whatever.


More information about the llvm-commits mailing list