Page MenuHomePhabricator

[Attributor] Make attributor aware of aligned_alloc for heap to stack conversion
ClosedPublic

Authored by bondhugula on Mar 28 2020, 12:20 AM.

Details

Summary

Make the attributor pass aware of aligned_alloc for converting heap
allocations to stack ones.

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Depends on D76971.

Diff Detail

Event Timeline

bondhugula created this revision.Mar 28 2020, 12:20 AM
Herald added a reviewer: uenoku. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
jdoerfert added inline comments.Mar 28 2020, 12:28 AM
llvm/lib/Transforms/IPO/Attributor.cpp
5053

Nit: Alignment

5206

Why a signed comparison?

bondhugula marked 3 inline comments as done.Mar 28 2020, 1:12 AM
bondhugula added inline comments.
llvm/lib/Transforms/IPO/Attributor.cpp
5206

Fixed, thanks.

bondhugula marked an inline comment as done.

Address review comments.

bondhugula retitled this revision from Make attributor aware of aligned_alloc for heap to stack conversion to [Attributor] Make attributor aware of aligned_alloc for heap to stack conversion.Mar 31 2020, 10:48 AM

Ping reviewers - @jdoerfert - thanks!

lebedev.ri added inline comments.
llvm/lib/Transforms/IPO/Attributor.cpp
5033–5040

Hmm, what is the 'default' alignment for alloca?
Even for non-aligned_alloc, there's some alignment guarantees for the allocation functions..

bondhugula marked 2 inline comments as done.Mar 31 2020, 11:44 AM
bondhugula added inline comments.
llvm/lib/Transforms/IPO/Attributor.cpp
5033–5040

For alloca, by default the target will typically align to sizeof elt type boundary (per LangRef). For alloc functions without alignment args, it's all system dependent. Glibc's malloc will provide alignment in line with the largest primitive (non-vector) type supported on the system which is typically 16 bytes (fp80, fp128 are the largest).

xbolva00 added inline comments.Mar 31 2020, 12:01 PM
llvm/lib/Transforms/IPO/Attributor.cpp
5033–5040

we could detect if GNU environment (glibc) is used for compilation so I am wondering if we can annotate malloc with such alignment (16B) if isGNU() == true.

bondhugula marked 2 inline comments as done.Mar 31 2020, 12:27 PM
bondhugula added inline comments.
llvm/lib/Transforms/IPO/Attributor.cpp
5033–5040

Even if it's the GNU env, the 16 byte alignment isn't guaranteed by malloc (although nearly always true on today's systems). It could be 8 bytes on really old ones - I don't know!

lebedev.ri marked an inline comment as done.Mar 31 2020, 2:31 PM
lebedev.ri added inline comments.
llvm/lib/Transforms/IPO/Attributor.cpp
5033–5040

While yes, we should be doing that, llvm is really too late for this, it must be done in clang, similarly to D73380.

No comments from me.

xbolva00 accepted this revision.Apr 1 2020, 9:07 AM

Ok too

This revision is now accepted and ready to land.Apr 1 2020, 9:07 AM
This revision was automatically updated to reflect the committed changes.