This is an archive of the discontinued LLVM Phabricator instance.

[IROutliner] Change Prioritization of Outlining to honor cost model
ClosedPublic

Authored by AndrewLitteken on Jul 21 2021, 7:01 AM.

Details

Summary

Currently, the IROutliner uses a simple metric to outline the largest amount of IR possible to outline first if it fits the cost model. This is model loses out on smaller blocks of code that have higher reductions in cost that are contained within larger blocks of IR.

This reverses the order, where we calculate all of the costs first, and then reorder and extract items based on the calculated results.

Diff Detail

Event Timeline

AndrewLitteken created this revision.Jul 21 2021, 7:01 AM
AndrewLitteken requested review of this revision.Jul 21 2021, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2021, 7:01 AM

Do you have data on the code size impact of this change?

llvm/include/llvm/Transforms/IPO/IROutliner.h
193

This seems to have an incorrect comment.

214

Should this say OutlinableRegion?

307

why?

llvm/lib/Transforms/IPO/IROutliner.cpp
136

Unnecessary whitespace change?

1354

clang format braces

1362

Might as well pull this above the if to avoid recalculating it.

1386

Probably don't need the variable here?

Just

return any_of(...);
1719

why?

Adjusting based on comments, cleaning up the code, and adding an additional check to make sure cost model is still correct when the regions are about to be outlined.

paquette added inline comments.Aug 20 2021, 4:25 PM
llvm/include/llvm/Transforms/IPO/IROutliner.h
185

Break up run-on?

191
  • isCompatibleWithAlreadyOutlinedCode might be a more descriptive name.
  • Does this function modify Region? Should it be const?
llvm/lib/Transforms/IPO/IROutliner.cpp
277

is it actually necessary to use this here?

278

Is ID a pointer? Can you loop over it like

for (IRInstructionData *ID ... )

to make that clear?

279

Why is this variable necessary?

1353

Comment?

1357

Comment?

1357

What happens if this is nullptr?

1371

none_of?

1382

Do you need this here?

also you can probably just write

return (std::next(...)->Inst != ID.Inst...) || !InstructionClassifier.visit(ID.Inst);
1711

Would this be better as a SmallVector?

1719

Why not grab this as a reference rather than as a pointer? That would probably reduce the size of this patch significantly.

1760

This could use a comment?

1807

I think you're using the llvm namespace, and std::stable_sort doesn't work with ranges, so I think you can just use

if (...)
  stable_sort(...)
1818

Comment?

1857

Can this use a SmallVector, or will the CodeExtractor not accept that?

AndrewLitteken added inline comments.Aug 25 2021, 9:18 AM
llvm/lib/Transforms/IPO/IROutliner.cpp
1357

For now, since it's never at the end of a module, this should not be an issue as there is always a branch instruction following, but I will add an assertion.

1382

I would rather keep it like this, the next few patches build on this and becomes more complex when the instruction could be a branch, and it isn't so easy to make it a one liner.

paquette added inline comments.Aug 25 2021, 1:41 PM
llvm/lib/Transforms/IPO/IROutliner.cpp
1382

SGTM

Updating for comments

This revision is now accepted and ready to land.Aug 26 2021, 3:06 PM