This is an archive of the discontinued LLVM Phabricator instance.

Support for the mno-stack-arg-probe flag
ClosedPublic

Authored by nruslan on Feb 8 2018, 5:57 PM.

Details

Summary

Adds support for this flag. There is also another piece for clang (separate review). More info: https://bugs.llvm.org/show_bug.cgi?id=36221

Related: D43108

Diff Detail

Repository
rL LLVM

Event Timeline

nruslan created this revision.Feb 8 2018, 5:57 PM
nruslan updated this revision to Diff 133551.Feb 8 2018, 6:08 PM

@craig.topper, @MatzeB, @hans: Can someone take a look at this change?

hans added inline comments.Feb 12 2018, 1:36 AM
docs/LangRef.rst
1564 ↗(On Diff #133551)

Is the "arg" part of the name significant? It seems to me this applies to stack probing in general, and that's not just for arguments?

lib/Target/X86/X86WinAllocaExpander.cpp
243 ↗(On Diff #133551)

It seems odd that we end up in this case when we're not actually going to probe. Could the code be changed so that we end up in the Sub case instead, since that seems to do what we want here?

nruslan updated this revision to Diff 134378.Feb 14 2018, 9:44 PM
nruslan marked 2 inline comments as done.
nruslan added inline comments.
docs/LangRef.rst
1564 ↗(On Diff #133551)

It is just to be consistent and compatible with MinGW

lib/Target/X86/X86WinAllocaExpander.cpp
243 ↗(On Diff #133551)

I am not sure what would be better here without major code changes. I tried initially to put it under Sub, but the problem is that it assumes specific fixed value which is -1 if unknown, so offsets will not be calculated correctly. So, I figured, it may be better to do directly under Probe. BTW -- It is the only place Probe is used, so possibly it can be renamed to something else?

nruslan marked 2 inline comments as done.Feb 14 2018, 9:46 PM

@craig.topper: Updated the diff.

@hans: I responded to the comments and also updated diff for clang with new changes.

hans added inline comments.Feb 16 2018, 1:57 AM
test/CodeGen/X86/no-stack-arg-probe.ll
28 ↗(On Diff #134378)

This test passes even if I comment out the code in X86WinAllocaExpander::lower. It probably needs a test with a dynamic alloca.

  • Have you considered using stack-probe-size=0 instead?
  • Doing it as a separate no-stack-arg-probe probably needs an IR verifier rule that forbids setting stack-probe-size and no-stack-arg-probe at the same time. Maybe also some attribute compatibility rules for inlining?

@MatzeB : mstack-probe-size=0 is already used for a different purpose. It basically, if I remember correctly, always forces calls to chkstk regardless of the actual stack usage. Normally that would only happen after 4K. Regarding your second question -- do we really need to have these flags to be mutually-exclusive? They are related but serve a different purpose. stack-probe-size merely changes the default probe size from 4K to the specified value. mstack-arg-probe/mno-stack-arg-probe enables/disables stack probes. If we disable stack probes, their size no longer matters, but we do not necessarily have to prohibit stack-probe-size. So, in fact, I can imagine somebody may even define system-wide alias if they want to override 4K (for whatever reason). Then some Makefile (which is unaware of this alias) may, for example, disable stack probes completely (like in UEFI code case), and we do not necessarily want to prohibit this combination.

nruslan updated this revision to Diff 134786.Feb 16 2018, 8:13 PM

added a test case for variable-sized alloca

nruslan marked an inline comment as done.Feb 16 2018, 8:15 PM

@hans, @MatzeB : I have updated the diff (added the test case for variable-sized alloca). Please let me know if it looks good now.

nruslan updated this revision to Diff 134810.Feb 17 2018, 11:07 AM

Added a small change to set max value for StackProbeSize in WinAlloca. This is to (potentially) avoid generating suboptimal code if -mno-stack-arg-probe is specified

hans accepted this revision.Feb 19 2018, 2:52 AM

Seems fine to me, but MatzeB should probably sign off too.

This revision is now accepted and ready to land.Feb 19 2018, 2:52 AM

@MatzeB: do you need more time for the review, or should we just go ahead and merge this and clang changes?

@hans: I probably cannot commit the change myself, right? Who should I ask to do that?

MatzeB edited reviewers, added: aemerson, whitequark; removed: MatzeB.EditedFeb 19 2018, 5:20 PM

@MatzeB : mstack-probe-size=0 is already used for a different purpose. It basically, if I remember correctly, always forces calls to chkstk regardless of the actual stack usage. Normally that would only happen after 4K. Regarding your second question -- do we really need to have these flags to be mutually-exclusive? They are related but serve a different purpose. stack-probe-size merely changes the default probe size from 4K to the specified value. mstack-arg-probe/mno-stack-arg-probe enables/disables stack probes. If we disable stack probes, their size no longer matters, but we do not necessarily have to prohibit stack-probe-size. So, in fact, I can imagine somebody may even define system-wide alias if they want to override 4K (for whatever reason). Then some Makefile (which is unaware of this alias) may, for example, disable stack probes completely (like in UEFI code case), and we do not necessarily want to prohibit this combination.

  • I don't really know what the current stack-probe-size=0 would be useful for; but then again I'm not actively working on it either.
  • There's a difference in what flags clang allows and what IR allows. While I see your point for what clang should allow, for llvm IR I think it would be more desirable to be have things stricter and generally disallow non-useful/ambiguous combinations.

Anyway I don't care deeply about this and don't do that much middle-end work anyway so don't wait for my approval and go with what you think is best.

MatzeB added a subscriber: MatzeB.Feb 19 2018, 5:21 PM

I don't really know what the current stack-probe-size=0 would be useful for; but then again I'm not actively working on it either.

@MatzeB It is useful in cases where you want to perform manual stack probing, i.e. if you don't have an MMU or MPU and compare the requested stack size to some thread-local stack limit on every chkstk call. This is useful for microcontrollers.

@hans: I can modify the clang patch to make sure it does not set stack-probe-size for IR if no-stack-arg-probe is set. Do you think, it is necessary? Also, if we want to further have some changes in the IR verifier, please let me know what example(s) I can take a look at.

@MatzeB, @hans, @whitequark: Should we go ahead and merge both clang and llvm changes as is? (since they are both approved already). We can add IR checks in a separate commit if you think it is necessary.

hans added a comment.Feb 21 2018, 3:20 AM

@hans: I can modify the clang patch to make sure it does not set stack-probe-size for IR if no-stack-arg-probe is set. Do you think, it is necessary? Also, if we want to further have some changes in the IR verifier, please let me know what example(s) I can take a look at.

I don't know whether it's necessary to enforce that the attributes can't be used together, but I don't have a lot of experience in what the IR allows in this regard. I don't really see that setting both flags would cause problems, though it would of course be a little bit redundant.

I'm fine with the change as it is.

@hans, @craig.topper, @MatzeB: Can someone commit D43108 and D43107 (this) on my behalf? I do not think, I have commit access.

This revision was automatically updated to reflect the committed changes.

@hans: Thanks! Is it already too late to cherry-pick these changes to the upcoming 6.0 version?

hans added a comment.Feb 26 2018, 2:10 AM

@hans: Thanks! Is it already too late to cherry-pick these changes to the upcoming 6.0 version?

Yes, it's too late for 6.0.