This is an archive of the discontinued LLVM Phabricator instance.

StackColoring for SafeStack.
ClosedPublic

Authored by eugenis on Jun 15 2016, 5:45 PM.

Details

Reviewers
chandlerc
pcc
Summary

This is a fix for PR27842.

An IR-level implementation of stack coloring tailored to work with
SafeStack. It is a bit weaker than the MI implementation in that it
does not the "lifetime start at first access" logic. This can be
improved in the future.

This patch also replaces the naive implementation of stack frame
layout with a greedy algorithm that can split existing stack slots
and even fit small objects inside the alignment padding of other
objects.

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 60939.Jun 15 2016, 5:45 PM
eugenis retitled this revision from to StackColoring for SafeStack..
eugenis updated this object.
eugenis added reviewers: pcc, chandlerc.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
hiraditya added inline comments.
lib/CodeGen/SafeStack.cpp
532

DataLayout::getPrefTypeAlignment already returns unsigned.

lib/CodeGen/SafeStackColoring.h
62

It seems you can use DenseMap<const BasicBlock *, std::pair<unsigned, unsigned>>. Also it will be good if you could add some comments about what the numbers in 'std::pair<unsigned, unsigned>' represent; similar to what you have in line 77-78

eugenis updated this revision to Diff 61835.Jun 24 2016, 1:58 PM
eugenis marked 2 inline comments as done.
pcc added inline comments.Jun 28 2016, 1:39 PM
lib/CodeGen/SafeStack.cpp
527

Since the GrowsDown parameter is always true, can you remove it?

lib/CodeGen/SafeStackColoring.cpp
230–234

You can remove all braces here.

lib/CodeGen/SafeStackColoring.h
41

Say which instructions.

42–50

Inconsistent capitalization of member functions.

59

Define "interesting"

73

Define "interesting"

lib/CodeGen/SafeStackLayout.cpp
70

This could be a range-for loop.

110

Same here

127

Same here

lib/CodeGen/SafeStackLayout.h
19

Is this the right name for this class? The name suggests that it handles layout for the safe stack.

eugenis updated this revision to Diff 62153.Jun 28 2016, 4:38 PM
eugenis marked 8 inline comments as done.
eugenis added inline comments.
lib/CodeGen/SafeStackColoring.h
59

I've added a few words in the class-level comment.

lib/CodeGen/SafeStackLayout.h
19

Would you prefer UnsafeStackLayout?
There is nothing in this class that deals with the notion of safe or unsafe alloca - it's frame layout code for the "SafeStack" feature, and I like that it starts with "SafeStack".

pcc accepted this revision.Jun 28 2016, 6:04 PM
pcc edited edge metadata.

LGTM

lib/CodeGen/SafeStackColoring.h
25

Nitpick: "as sets".

lib/CodeGen/SafeStackLayout.h
20

I'm partial to the pattern of moving pass implementation details into a namespace named after the pass, so maybe something like llvm::safestack::StackLayout?

But I'd be happy with whatever you decide to do here.

This revision is now accepted and ready to land.Jun 28 2016, 6:04 PM
eugenis updated this revision to Diff 62265.Jun 29 2016, 12:08 PM
eugenis edited edge metadata.
eugenis marked an inline comment as done.
eugenis added inline comments.
lib/CodeGen/SafeStackLayout.h
20

I like this!
Done.
I've also renamed SafeStackColoring to safestack::StackColoring.

eugenis closed this revision.Jun 29 2016, 1:45 PM

r274162
Thanks for the review!