Allocas whose life range is fully contained inside the outlined region should be pushed to the outlined function. This not only reduces the number of live-in variables to the outline function (thus reduced number of parameters), but can also avoid 'escaping' the address of the locals (if not shrink wrapped in).
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
This is a really important optimization, IMHO (and for my usecase). Thanks for working on this.
Some comments inline.
include/llvm/Transforms/Utils/CodeExtractor.h | ||
---|---|---|
99–108 ↗ | (On Diff #100537) | Can you update this comment to reflect what's the Allocas argument here? |
lib/Transforms/Utils/CodeExtractor.cpp | ||
145 ↗ | (On Diff #100537) | Now that I look at this more closely, findInputsOutputs is a slightly inaccurate description after you change. Maybe we can consider splitting this in a separate function, as this one is growing quite a bit? |
178–188 ↗ | (On Diff #100537) | I think this can be expressed much more concisely using std/llvm::any_of. |
200–202 ↗ | (On Diff #100537) | While you're here, I'd see if you can use a range for instead (and maybe avoid the extra assignment to value, but I'm not sure if it's possible). |
817 ↗ | (On Diff #100537) | I'm not entirely sure I like this bit. |
lib/Transforms/Utils/CodeExtractor.cpp | ||
---|---|---|
200–202 ↗ | (On Diff #100537) | This will need begin/end methods in Instruction. |
lib/Transforms/Utils/CodeExtractor.cpp | ||
---|---|---|
146–167 ↗ | (On Diff #100554) | Here it requires lifetime.start and lifetime.end are in the blocks to be extracted.
For the testcase, the lifetime.start and lifetime.end are not in the blocks to be extracted, but it is beneficial to have the alloca sinked. |
yes, those cases can be and will be handled but as a follow up. This patch handles cases where locals are declared in the outlined region.
I have no other comments. See whether Davide has further comments.
lib/Transforms/Utils/CodeExtractor.cpp | ||
---|---|---|
783 ↗ | (On Diff #100581) | They can be moved closer to their uses. |