This is an archive of the discontinued LLVM Phabricator instance.

Add a "probe-stack" attribute
AbandonedPublic

Authored by Zoxc on Jul 29 2014, 10:35 PM.

Details

Reviewers
nadav
Summary

This attribute is used to ensure the guard page is triggered on stack overflow. Stack frames larger than the guard page size will generate a call to __probestack to touch each page so the guard page won't be skipped.

Diff Detail

Event Timeline

Zoxc updated this revision to Diff 12010.Jul 29 2014, 10:35 PM
Zoxc retitled this revision from to Add a stackprobe attribute.
Zoxc updated this object.
Zoxc edited the test plan for this revision. (Show Details)
Zoxc set the repository for this revision to rL LLVM.
Zoxc added a subscriber: Unknown Object (MLST).
Zoxc added a reviewer: nadav.Jul 30 2014, 2:11 AM
silvas added a subscriber: silvas.Jul 30 2014, 10:15 AM

Has this been discussed on LLVMdev? Our development process requires
changes to the IR to have a design discussion on LLVMdev first.

  • Sean Silva
Zoxc added a comment.Jul 30 2014, 1:58 PM

No, this has not yet been discussed on LLVMdev.

Zoxc updated this revision to Diff 12169.Aug 4 2014, 11:09 AM
Zoxc retitled this revision from Add a stackprobe attribute to Add a "probe-stack" attribute.

This now uses the string attribute "probe-stack". Dynamic allocations will have stack probes added. I also added a fast path for smaller frames.

Zoxc updated this revision to Diff 12186.Aug 4 2014, 8:07 PM

Fixed up the tests some.

Zoxc updated this revision to Diff 12236.Aug 6 2014, 8:14 AM

Used the right scale value on the OR instruction. Change the relocation to the __probestack call on non-Windows x86-64 platforms.

rnk added a subscriber: rnk.Aug 6 2014, 11:58 AM

This seems like a reasonable implementation of useful functionality.

lib/Target/X86/X86FrameLowering.cpp
675–706

This change seems like a separable optimization, correct? I'd like to have a separate patch for it.

749

Should be 2 space indentation

Zoxc added a comment.Aug 6 2014, 12:12 PM
lib/Target/X86/X86FrameLowering.cpp
749

The original code has 4 space indentation here. Don't blame me.

reames added a subscriber: reames.Aug 6 2014, 4:17 PM

Overall, I like the direction of the change, but there's a number of details which need adjusted before it's ready for submission. The biggest is that this patch seems to combine a bunch of separate pieces and it would be better to factor this apart into a series of patches which each do one thing. This would make it much easier to review.

include/llvm/CodeGen/MachineFunction.h
271

Could you define the term "probing the stack" here? This is likely be where an LLVM developer might encounter the concept. One short sentence is fine.

lib/Target/ARM/ARMFrameLowering.cpp
304

Seems like you should rename WindowsRequiredStackProbe since this is no longer Windows specific.

lib/Target/X86/X86FrameLowering.cpp
500

What is this magic constant? At minimum, comment it.

This looks like it might be an independent bugfix? If so, please submit separately.

673

This section is a large diff that I'm having trouble understanding. If you can split this up into a set of smaller patches, that would help a lot.

675–705

Magic numbers? What do these mean?

708–709

In a separate change, exacting out this code out as a helper function (getStackProbeSymbol(..)) would make the functional diff easier to follow.

712

I don't understand this section at all. What's the motivation here?

Again, could this be separate patch?

lib/Target/X86/X86ISelLowering.cpp
18214

This condition "feels" wrong. It looks like you're only avoiding this case for 32 bit Windows? Why? The old code didn't.

18249

I'm not clear on what this change is doing. In addition to the changed symbol, it looks like you're adding 64 vs 32 bit case? Is this an unrelated bugfix?

lib/Transforms/IPO/Inliner.cpp
140

Add a comment to justify.

Would it be better to just prevent inlining when only one has probe-stack? (i.e. is this expected to ever happen?)

test/CodeGen/X86/mingw-alloca.ll
32

Why are you modifying the existing test rather than adding a new one? Is this test incorrect? It doesn't seem to be on first read.

test/CodeGen/X86/pr17631.ll
21

This looks like it goes with an optimization?

Can you add a test case for the unoptimized case?

Again, optimizations should be separate patches.

test/CodeGen/X86/stack-probes.ll
2

Why bother with a custom prefix if they are the same? You can just use the default CHECK prefix.

24

A comment describing what each test is checking for would be helpful.

test/CodeGen/X86/win64_alloca_dynalloca.ll
13

Why are you modify existing tests rather than adding new ones? Is this because of a new optimization?

Zoxc abandoned this revision.Aug 9 2014, 6:31 AM

A newer version was posted to the mailing list.

lib/Target/X86/X86ISelLowering.cpp
18214

The old code did also just avoid 32-bit Windows (the only other case was 64-bit Windows)

18249

This calls the x86-32 probestack function the same way as x86-64 chkstk/__probestack. I'll make this more explicit.

test/CodeGen/X86/stack-probes.ll
2

A custom prefix seems to be the pattern, and it makes sense if tests for other platforms will be added.