This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add elfiamcu triple support, and a workaround for PR3997
ClosedPublic

Authored by mkuper on Oct 22 2015, 3:39 AM.

Details

Summary

This patch has two parts:

  1. It adds support for "elfiamcu" triple to support the x86 Intel MCU psABI. This is something already supported by GCC trunk.
  1. It introduces elfiamcu-specific code, which is a workaround for PR3997. The IAMCU psABI requires everything, including library functions to pass the first 3 parameters in-reg (note that the ABI is slightly different from -mregparm 3). Unfortunately, inreg marking for x86-32 is done by the frontend. Optimistically speaking, RTLIB function signatures ought to be simple enough for this to work. If not, we'll have to reconsider solving PR3997 more thoroughly.

Any suggestions on how to make this work better are welcome.

Diff Detail

Repository
rL LLVM

Event Timeline

mkuper updated this revision to Diff 38101.Oct 22 2015, 3:39 AM
mkuper retitled this revision from to [X86] Add elfiamcu triple support, and a workaround for PR3997.
mkuper updated this object.
mkuper added a subscriber: llvm-commits.
DavidKreitzer added inline comments.Oct 22 2015, 9:04 AM
lib/Target/X86/X86ISelLowering.cpp
27523 ↗(On Diff #38101)

Is there an easy way to assert this, i.e. that there are no fancy types? Also, you probably want to explicitly handle varargs functions here, either by asserting that you cannot get here for varargs functions or by excluding them from the inreg marking.

rnk added a subscriber: rnk.Oct 22 2015, 9:52 AM

It'd be nice if we come come up with a more general solution to PR3997. If we had a way to send arbitrary module-wide flags through to the backend like TargetTuple, then we'd go ahead and put mregparm=3 there. Obviously we don't, and we've been trying to move towards per-function attributes. So, we could conceivably slap an attribute like "libcall-regparms"=N on every function, and then, during markInRegArguments, look at that after checking the triple.

What do you guys think?

In D13977#273248, @rnk wrote:

It'd be nice if we come come up with a more general solution to PR3997. If we had a way to send arbitrary module-wide flags through to the backend like TargetTuple, then we'd go ahead and put mregparm=3 there. Obviously we don't, and we've been trying to move towards per-function attributes. So, we could conceivably slap an attribute like "libcall-regparms"=N on every function, and then, during markInRegArguments, look at that after checking the triple.

What do you guys think?

My only objection to this is that it gives the impression that it's ok to mix different libcall-regparms functions in the same module. IIRC the main reasoning for relying mainly on per-function attributes is LTO - and I'm fairly sure this particular mix-and-match should never happen, regardless of LTO. Having said that, I don't think we currently have a better way to do this.

Also, given how long-standing the issue in PR3997 is, I'm somewhat reluctant (perhaps, scared) to fix it.
Is it reasonable to assume nobody is relying on the current ("broken/GCC-incompatible") behavior of -mregparm? And how much do we care about being backward compatible with that?

rnk accepted this revision.Oct 23 2015, 6:57 PM
rnk added a reviewer: rnk.

lgtm

Yeah, I can definitely understand not wanting to stir the pot. Users of mregparm=3 probably have #ifdefs to work around this on the declaration of memcpy.

This revision is now accepted and ready to land.Oct 23 2015, 6:57 PM
This revision was automatically updated to reflect the committed changes.