Open Quuxplusone opened 6 years ago
The property you want to check is that the alloca is between a stacksave/stackrestore pair. That said, once you have code to detect that, you might as well just use it to hoist the alloca to the entry block instead.
(In reply to Eli Friedman from comment #1)
> The property you want to check is that the alloca is between a
> stacksave/stackrestore pair. That said, once you have code to detect that,
> you might as well just use it to hoist the alloca to the entry block instead.
Thanks Eli, that makes sense.
I suppose if we hoist the alloca to the entry block of the outlined function,
we can eliminate the stack{save,restore} pair. I'll split that out into a
different patch.
Seems very useful to implement. Let me know if you need any help. Thanks for bringing this example.
I’ll send out a patch for this today. I tested it yesterday and found that it lets CodeExtractor successfully outline a lot of expensive logging code in some frameworks.
Why is this alloca a VLA in the first place? LLVM doesn't really like dynamic allocas. If you can figure out how to have this not be a dynamic alloca, you might get better code all around.
If you do hoist the alloca, I'd recommend making sure you replace the stacksave and restore with lifetime markers to try to save stack space.
(In reply to Reid Kleckner from comment #5)
> Why is this alloca a VLA in the first place?
I'm not sure. I suspect it's because this logging routine was designed to work
in environments where malloc isn't available.
> LLVM doesn't really like
> dynamic allocas. If you can figure out how to have this not be a dynamic
> alloca, you might get better code all around.
>
> If you do hoist the alloca, I'd recommend making sure you replace the
> stacksave and restore with lifetime markers to try to save stack space.
Thanks, that's a good idea.
On Darwin, there is an extremely pervasive kind of cold code (error logging) which CodeExtractor has trouble with:
By default, extracting regions containing allocas is not enabled. In general this seems difficult to do. But here, all uses of the alloca are within the outlined region...
Can we do something simple to permit outlining in this scenario? Maybe check that the transitive closure of the alloca's uses all live within the alloca's block?