This is an archive of the discontinued LLVM Phabricator instance.

Add extra operand to CALLSEQ_START to keep frame part set up previously
ClosedPublic

Authored by sepavloff on Apr 23 2017, 2:18 AM.

Details

Summary

Using arguments with attribute inalloca creates problems for verification
of machine representation. This attribute instructs the backend that the
argument is prepared in stack prior to CALLSEQ_START..CALLSEQ_END
sequence (see http://llvm.org/docs/InAlloca.htm for details). Frame size
stored in CALLSEQ_START in this case does not count the size of this
argument. However CALLSEQ_END still keeps total frame size, as caller can
be responsible for cleanup of entire frame. So CALLSEQ_START and
CALLSEQ_END keep different frame size and the difference is treated by
MachineVerifier as stack error. Currently there is no way to distinguish
this case from actual errors.

This patch adds additional argument to CALLSEQ_START and its
target-specific counterparts to keep size of stack that is set up prior to
the call frame sequence. This argument allows MachineVerifier to calculate
actual frame size associated with frame setup instruction and correctly
process the case of inalloca arguments.

The changes made by the patch are:

  • Frame setup instructions get the second mandatory argument. It affects all targets that use frame pseudo instructions and touched many files although the changes are uniform.
  • Access to frame properties are implemented using special instructions rather than calls getOperand(N).getImm(). For X86 and ARM such replacement was made previously.
  • Changes that reflect appearance of additional argument of frame setup instruction. These involve proper instruction initialization and methods that access instruction arguments.
  • MachineVerifier retrieves frame size using method, which reports sum of frame parts initialized inside frame instruction pair and outside it.

The patch implements approach proposed by Quentin Colombet in
https://bugs.llvm.org/show_bug.cgi?id=27481#c1.
It fixes 9 tests failed with machine verifier enabled and listed
in PR27481.

Event Timeline

sepavloff created this revision.Apr 23 2017, 2:18 AM
RKSimon edited edge metadata.May 1 2017, 10:58 AM

A few initial style comments

include/llvm/CodeGen/SelectionDAG.h
728

Can this be removed/deprecated?

include/llvm/Target/TargetInstrInfo.h
185

assert message

lib/Target/MSP430/MSP430InstrInfo.h
91

Merge asserts and message

lib/Target/PowerPC/PPCISelLowering.cpp
5088

getConstantOperand() ?

sepavloff marked 2 inline comments as done.May 2 2017, 9:38 AM
sepavloff added inline comments.
include/llvm/CodeGen/SelectionDAG.h
728

Removed it.

lib/Target/PowerPC/PPCISelLowering.cpp
5088

Indeed, thank you.

sepavloff updated this revision to Diff 97461.May 2 2017, 9:39 AM

Addressed reviewer's notes and rebased.

Anyone else got any comments?

include/llvm/Target/TargetSelectionDAG.td
286

Is it worth merging these into a single class SDCallSeq class?

davide added a subscriber: davide.May 4 2017, 9:02 AM
sepavloff added inline comments.May 4 2017, 10:08 AM
include/llvm/Target/TargetSelectionDAG.td
286

There is no reason why CALLSEQ_START and CALLSEQ_END must have the same set of arguments, so these classes probably are not worth merging.

RKSimon accepted this revision.May 8 2017, 11:24 AM

LGTM

This revision is now accepted and ready to land.May 8 2017, 11:24 AM
This revision was automatically updated to reflect the committed changes.