This is an archive of the discontinued LLVM Phabricator instance.

[mips] Enable `long_call/short_call` attributes on MIPS64
ClosedPublic

Authored by atanasyan on Aug 1 2017, 10:18 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan created this revision.Aug 1 2017, 10:18 PM
sdardis edited edge metadata.Aug 2 2017, 3:19 AM

Some comments:

Currently there is no support in the backend for the interrupt attribute for mips64 / using N32 & N64 abis, it will give a fatal error. Previously the backend lacked support for the static relocation model which is an expected requirement for interrupt handlers.

microMIPS32r(3|6) is only supported for the O32 ABI, as microMIPS64R6 is deprecated and going to be removed. There is no support for the published microMIPS64R3 ISA.

Currently there is no support in the backend for the interrupt attribute for mips64 / using N32 & N64 abis, it will give a fatal error. Previously the backend lacked support for the static relocation model which is an expected requirement for interrupt handlers.

microMIPS32r(3|6) is only supported for the O32 ABI, as microMIPS64R6 is deprecated and going to be removed. There is no support for the published microMIPS64R3 ISA.

I see. What is the better solution to handle unsupported attributes: a) silently ignore them; b) show a warning; c) show an error?

Currently there is no support in the backend for the interrupt attribute for mips64 / using N32 & N64 abis, it will give a fatal error. Previously the backend lacked support for the static relocation model which is an expected requirement for interrupt handlers.

microMIPS32r(3|6) is only supported for the O32 ABI, as microMIPS64R6 is deprecated and going to be removed. There is no support for the published microMIPS64R3 ISA.

I see. What is the better solution to handle unsupported attributes: a) silently ignore them; b) show a warning; c) show an error?

If the attribute is semantically critical, an error is reasonable. Otherwise, we typically warn the user under the ignored attributes group and then drop the attribute from the AST.

include/clang/Basic/DiagnosticSemaKinds.td
263 ↗(On Diff #109272)

This diagnostic could be more helpful by telling the user how to enable the o32 ABI.

lib/Sema/SemaDeclAttr.cpp
5979–5981 ↗(On Diff #109272)

Please do not put logic into the switch statement, but instead sink it into a helper function. We hope to remove the boilerplate switch someday, so keeping with the handleFooAttr() pattern is preferred. Same below.

Further, why is this not handled by a TargetSpecificAttr in Attr.td? See TargetMicrosoftCXXABI and MSNoVTable for an example.

I think for the interrupt attribute, it should be an error. Currently it's an implementation detail that it errors out in the backend but in principal it can be supported (I haven't gotten around to addressing it.)

For the micromips attribute, I believe it should be an error. My rational there is that the user has requested something that the compiler cannot perform.

I think for the interrupt attribute, it should be an error. Currently it's an implementation detail that it errors out in the backend but in principal it can be supported (I haven't gotten around to addressing it.)

For the interrupt attribute, I think it should behave the same as the other target-specific interrupt attributes unless there's a very good reason to be inconsistent.

For the micromips attribute, I believe it should be an error. My rational there is that the user has requested something that the compiler cannot perform.

That's not really sufficient rationale, because the same logic can be said of any ignored attribute. As best I can tell from the docs on this attribute, this controls code generation to turn on or off micromips code generation, which sounds like the code otherwise generated may still work just fine. e.g., void f(void) __attribute__((micromips)) {} -- if you compile that code on a non-MIPS target, why should it produce an error instead of merely warning the user that the attribute is ignored?

@aaron.ballman I missed your first comments when I'd submitted mine.

I think for the interrupt attribute, it should be an error. Currently it's an implementation detail that it errors out in the backend but in principal it can be supported (I haven't gotten around to addressing it.)

For the interrupt attribute, I think it should behave the same as the other target-specific interrupt attributes unless there's a very good reason to be inconsistent.

My primary thought there was that the backend will error out with "LLVM ERROR: "interrupt" attribute is only supported for the O32 ABI on MIPS32R2+ at the present time." if the attribute is seen anywhere by the backend for MIPS64. Having clang detect this case and being able to point out where in the code being compiled the attribute exists is better than having LLVM declaring there's an error somewhere and giving up. It is semantically critical as interrupt handlers need specific prologue+epilog sequences. I don't object to preserving the current behaviour of warning + ignoring it though.

For the micromips attribute, I believe it should be an error. My rational there is that the user has requested something that the compiler cannot perform.

That's not really sufficient rationale, because the same logic can be said of any ignored attribute. As best I can tell from the docs on this attribute, this controls code generation to turn on or off micromips code generation, which sounds like the code otherwise generated may still work just fine. e.g., void f(void) __attribute__((micromips)) {} -- if you compile that code on a non-MIPS target, why should it produce an error instead of merely warning the user that the attribute is ignored?

I stand corrected, we should just warn + ignore the micromips attribute for MIPS64 then.

@aaron.ballman I missed your first comments when I'd submitted mine.

I think for the interrupt attribute, it should be an error. Currently it's an implementation detail that it errors out in the backend but in principal it can be supported (I haven't gotten around to addressing it.)

For the interrupt attribute, I think it should behave the same as the other target-specific interrupt attributes unless there's a very good reason to be inconsistent.

My primary thought there was that the backend will error out with "LLVM ERROR: "interrupt" attribute is only supported for the O32 ABI on MIPS32R2+ at the present time." if the attribute is seen anywhere by the backend for MIPS64.

Having the backend error out is not the best user experience, so I agree that Clang should help prevent that. However, it seems just as likely the issue should be solved in the backend instead.

Having clang detect this case and being able to point out where in the code being compiled the attribute exists is better than having LLVM declaring there's an error somewhere and giving up. It is semantically critical as interrupt handlers need specific prologue+epilog sequences. I don't object to preserving the current behaviour of warning + ignoring it though.

I agree that Clang should definitely let the user know what's going on rather than leaving it to a backend error, but I think the behavior where we warn that the attribute is ignored and drop it is the best approach. I believe that if we gate the attribute on the ABI, that should happen automatically.

atanasyan added inline comments.Aug 2 2017, 11:57 PM
lib/Sema/SemaDeclAttr.cpp
5979–5981 ↗(On Diff #109272)

Further, why is this not handled by a TargetSpecificAttr in Attr.td? See TargetMicrosoftCXXABI and MSNoVTable for an example.

I thought about this, but in that case compiler will show "unknown attribute 'mips16' ignored" warning in case of using mips16 on MIPS64 targets. As to me this warning is not quite correct in that case because mips16, micromips, interrupt all are known MIPS-specific attributes, but not applicable on MIPS64 by various reasons.

atanasyan updated this revision to Diff 109528.Aug 3 2017, 5:48 AM
atanasyan retitled this revision from [mips] Enable target-specific attributes for MIPS64 to [mips] Enable `long_call/short_call` attributes on MIPS64.
atanasyan edited the summary of this revision. (Show Details)

Simplify and reduce the patch. Keep mips16, micromips, and interrupt attributes handling unchanged. The only MIPS specific attributes supported on MIPS64 targets are long_call/short_call/far/near.

aaron.ballman added inline comments.Aug 8 2017, 5:41 AM
include/clang/Basic/Attr.td
268 ↗(On Diff #109528)

Can you also rename TargetMips to something that distinguishes it from TargetAnyMips, like we have with TargetX86 vs TargetAnyX86? I'd be hard-pressed to notice the difference between these two target names when reviewing an attribute, but I'm not familiar enough with the MIPS architecture to have a particularly good suggestion for improvement.

lib/Sema/SemaDeclAttr.cpp
5979–5981 ↗(On Diff #109272)

As to me this warning is not quite correct in that case because mips16, micromips, interrupt all are known MIPS-specific attributes, but not applicable on MIPS64 by various reasons.

The same is true of all target-specific attributes -- they're known to the compiler, but their usage is not known on that specific target architecture. I would not be opposed to a patch that distinguished between the two situations, however (completely unknown attribute/and attribute that's known to be prohibited).

atanasyan updated this revision to Diff 110252.Aug 8 2017, 12:27 PM
  • Renamed TargetMips to TargetMips32
aaron.ballman accepted this revision.Aug 8 2017, 12:46 PM

LGTM, thanks!

This revision is now accepted and ready to land.Aug 8 2017, 12:46 PM
This revision was automatically updated to reflect the committed changes.

Thanks for review.