The patch adds extra diagnostics for the inline cost analysis. The diagnostic is available under the new command line flag ("print-cost-annotation-writer") for the "inline-cost" pass. When enabled along with -debug-only=inline-cost it prints the IR of inline candidate annotated with cost and threshold increase per every instruction.
This should help analyze inliner decisions.
Details
Diff Detail
Event Timeline
llvm/lib/Analysis/InlineCost.cpp | ||
---|---|---|
1832–1833 | Code style, { should be on the same line. Please clang-format. |
Sorry for the delay due to the changes in structure of InlineCost.cpp in this patch: https://reviews.llvm.org/D71733 .
Structural changes mostly.
Added test to llvm/test/DebugInfo to test the new flag.
llvm/lib/Analysis/InlineCost.cpp | ||
---|---|---|
107 | Nit: consider replacing std::pair<int,int> with a struct, e.g. struct InliningCostDetail {int Cost, int Threshold} - for readability. | |
578 | I initially thought that the map stores a snapshot of Cost & Threshold values. It seems it actually stores cost and threshold variations due to the analysis of a specific instruction - relative cost of that one instruction, and threshold effects. If that's correct, could you please detail this in the comment describing the map (or struct members, if using a struct instead of std::pair) |
Changed pait<int, int> to struct InlineCostDetails in DenseMap and changed comment defining CostThrehsoldMap.
@mtrofin : Yes, the DenseMap stores the delta of the cost and threshold after inlining the instruction, not just a snapshot.
This is done in order to see the exact cost/change in the threshold it would take to inline the instruction.
lgtm
llvm/lib/Analysis/InlineCost.cpp | ||
---|---|---|
103 | Nit: CostDelta / ThresholdDelta? (I realize I proposed 'Cost/Threshold' initially, but that was before understanding the usage further below) Also nit: now that we have a struct, if we had CostBefore/CostAfter and ThresholdBefore/ThresholdAfter, the intent would be even more evident, and we could, if we wanted, also output the raw costs (i.e. costs and delta). But this could be done at a later stage, too. |
Answering @mtrofin comments.
Refactoring, little changes:
- Separated the initial flag into two: one prints the whole info on instruction cost and threshold, the other one prints only deltas of cost and threshold
- Changed the InlineCostDetail structure - introduced CostBefore, CostAfter, CostDelta, ThresholdBefore, ThresholdAfter, ThresholdDelta
- Changed the test that I wrote to match the check of new flags
- Little comment changes
llvm/test/DebugInfo/debuginline-cost-delta.ll | ||
---|---|---|
118 | Is all this necessary? |
llvm/lib/Analysis/InlineCost.cpp | ||
---|---|---|
105–110 | You don't have to store deltas in the struct. They are easily computable from other fields. |
Addressed @apilipenko 's comments
- Switched to one flag
- Small changes in struct and comments
Couple of nit comments inlined, LGTM once addressed.
llvm/lib/Analysis/InlineCost.cpp | ||
---|---|---|
51 | Suggest to rename the global and the flag to PrintDebugInstructionDeltas("print-instruction-deltas", ...) | |
118–119 | There are still redundant llvm:: prefixes. | |
1823–1827 | This comment is specific to InlineCostCallAnalyzer and doesn't belong here. |
Fixed small inaccuracies
As the patch is done, @apilipenko , can you please push it for me?
Suggest to rename the global and the flag to PrintDebugInstructionDeltas("print-instruction-deltas", ...)