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
213

Should this say OutlinableRegion?

259

This seems to have an incorrect comment.

375

why?

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

Unnecessary whitespace change?

1279

clang format braces

1287

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

1311

Probably don't need the variable here?

Just

return any_of(...);
1643–1644

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
251

Break up run-on?

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

is it actually necessary to use this here?

207

Is ID a pointer? Can you loop over it like

for (IRInstructionData *ID ... )

to make that clear?

208

Why is this variable necessary?

1278

Comment?

1282

Comment?

1282

What happens if this is nullptr?

1296

none_of?

1307

Do you need this here?

also you can probably just write

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

Would this be better as a SmallVector?

1643–1644

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

1682

This could use a comment?

1730

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(...)
1741

Comment?

1765

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
1282

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.

1307

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
1307

SGTM

Updating for comments

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