Return cost-benefit stuff which is computed by cost-benefit analysis.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/include/llvm/Analysis/InlineCost.h | ||
---|---|---|
273 | why do you need the 2 of them? (I don't see a user for either... well, ok, the second calls the first, but other than that) I think it would be good to hook up to where you want to use this. In particular, if the user will always want the InlineCost, too, it wouldn't be ideal if the callsite analysis happened twice (once for InlineCost, once for the cost benefit pair). So one way you could expose the cost/benefit pair is by having it as a field in the InlineCost; at that point, too, you could either just have the 'cost' and 'benefit' as fields of InlineCost, or see if the struct design I mention below makes more sense. | |
llvm/lib/Analysis/InlineCost.cpp | ||
495 | Nit: the problem with std::pair where both elements are of the same type is that it's not clear to the reader which is which, without reading comments - which is added work (also comments go out of sync eventually). Alternative: define a little struct with named fields, makes it all crystal-clear; additionally, when using an IDE, autocompletion makes it very easily discoverable. Even better alternative, from maintainability perspective: define the struct, and make the fields const and set them through the ctor. So then a reader understands that the object, once constructed, won't mutate, so it removes a concern from understanding the code (basically, the values could only have come from when it was constructed, so less code to chase around) |
- add struct to represent cost-benefit pair
- remove redundant interface to return cost-benefit pair
llvm/include/llvm/Analysis/InlineCost.h | ||
---|---|---|
63 | const, both here and below. |
llvm/include/llvm/Analysis/InlineCost.h | ||
---|---|---|
63 | I have been trying to use const, but it still doesn't go well. It still needs an assignment operation. Optional<InlineCost> InlineRecommended = None; if (Iter != InlineSitesFromRemarks.end()) { InlineRecommended = llvm::InlineCost::getAlways("found in replay"); } By the way, it is always passed by value, just like the Cost or Threshold. |
llvm/include/llvm/Analysis/InlineCost.h | ||
---|---|---|
63 | It's not about safety, it's readability and maintainability: avoiding folks later having to chase down fields to figure out where they are set. A way to address this would be to make CostBenefitPair a class, expose the fields through const accessors, and then you can have the default assignment operator. |
lgtm, one comment
llvm/include/llvm/Analysis/InlineCost.h | ||
---|---|---|
64 | you can return const APInt &, I think APInt is a bit larger than a pointer |
const, both here and below.