This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Option for reading thread pointer from coprocessor register
ClosedPublic

Authored by spetrovic on Jun 30 2017, 5:43 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

spetrovic created this revision.Jun 30 2017, 5:43 AM
bruno added a subscriber: bruno.Jul 24 2017, 12:04 PM

Hi Strahinja,

Does GCC already has a similar option? If so, does this share the same name?

Hi Bruno,

Yes, GCC has similar option (-mtp=soft/hard), but name is not same. I put the same option name as in backend (https://reviews.llvm.org/D34408).

bruno added a comment.Jul 25 2017, 9:53 AM

If there's a precedence for a flag name there, it's nice to be compatible here. You don't necessarily need to use the same name as the backend.

spetrovic updated this revision to Diff 109088.Aug 1 2017, 5:14 AM

Comments addressed.

bruno added inline comments.Aug 2 2017, 10:58 AM
lib/Driver/ToolChains/Arch/ARM.cpp
136

What happens if you pass an empty "-mtp=" to the driver? Will it silently assume soft? Shouldn't it be an error too?

138

Won't this assignment be covered by the code below anyway? Maybe remove it?

spetrovic updated this revision to Diff 109571.Aug 3 2017, 9:09 AM
spetrovic marked 2 inline comments as done.
spetrovic added inline comments.
lib/Driver/ToolChains/Arch/ARM.cpp
136

I agree, it should be an error, I fixed that.

kristof.beyls added inline comments.Sep 7 2017, 2:19 AM
include/clang/Driver/Options.td
1664–1665

Looking at the gcc documentation for this option (https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html), gcc accepts 3 values: 'soft', 'cp15' and 'auto', with the default setting being 'auto'.
This patch implements just 2 of those values: 'soft' and 'cp15'.
I think this is fine, as long as the default value is 'soft'.
The 'auto' value should automatically pick 'cp15' if that's going to work on what you're targeting. If I understood correctly, that depends both on the architecture version you're targeting and the operating system/kernel you're targeting. So, there could be a lot of details to go through to get 'auto' right in all cases. Which is why I think it's fine to leave an implementation of 'auto' for later.
Is the default value 'soft'?

lib/Driver/ToolChains/Arch/ARM.cpp
128

Wouldn't it be better to default to ReadTPMode::Soft when not -mtp command line option is given? ....

145–146

.... and always give an error if an invalid mtp command line option was given, rather than default back to soft mode?

lib/Driver/ToolChains/Clang.cpp
1348–1358

My inexperience in this part of the code base is probably showing, but why is this needed at all?
IIUC, in D34408, you modelled TPMode in the backend using a target feature, and there isn't a custom -mtp option there?
Maybe this is left-over code from an earlier revision of D34408, that's no longer needed?

test/Driver/clang-translation.c
78–82

It probably would be good to also have a test that when no mtp option is given, the equivalent of when '-mtp soft' is specified would happen.
Furthermore, my inexperience in this part of the code base probably shows, but I'm puzzled as to why this test is looking for '-mtp' in the output. Wouldn't the '-target-feature +read-tp-hard' be enough to convey the information to the mid- and back-end?

spetrovic marked 3 inline comments as done.Sep 8 2017, 3:03 AM
spetrovic added inline comments.
include/clang/Driver/Options.td
1664–1665

I agree with your opinion about 'auto'. If -mtp option is not specified, yes, default value is soft.

lib/Driver/ToolChains/Arch/ARM.cpp
128

When there is no -mtp in command line ReadTPMode::Soft is default value, ReadTPMode::Invalid is in case when someone try to put in -mtp value that is not cp15 or soft (e.g. -mtp=x).

145–146

If 'mtp' takes invalid value, error is always provided. This is the case when there is no -mtp option in command line, you can see how the case of invalid mtp argument is handled in the code above.

lib/Driver/ToolChains/Clang.cpp
1348–1358

Well, actually you are right, we can remove this part of the code, I was thinking that maybe someone in future will need in backend that '-mtp' option also can be recgonized, so I added this, but you are right, I will remove this.

test/Driver/clang-translation.c
78–82

Checks for '-mtp' in the output are unnecessary when we remove part of the code that you mentioned in previous comment.

spetrovic updated this revision to Diff 114329.Sep 8 2017, 3:05 AM
spetrovic marked 3 inline comments as done.
kristof.beyls added inline comments.Sep 11 2017, 12:59 AM
lib/Driver/ToolChains/Arch/ARM.cpp
145–146

Right.
I just thought that the function would be ever so slightly simpler if it had the following structure roughly:

if (Arg *A = ...) {
  ThreadPointer = llvm::StringSwitch... ;
  if (!Invalid)
    return ThreadPointer;
  if (empty)
    D.Diag();
  else
    D.Diag();
  return Invalid;
}
return ReadTPMode::Soft;

And probably is also slightly closer to the coding standard described in https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
But this is a really minor comment.

spetrovic updated this revision to Diff 114573.Sep 11 2017, 5:20 AM
spetrovic marked an inline comment as done.

Comments addressed.

kristof.beyls added inline comments.Sep 11 2017, 5:28 AM
lib/Driver/ToolChains/Arch/ARM.cpp
128

With the new version of the code, there's no need to have a ThreadPointer variable declared here; it can be declared inside the if statement below instead.

140–141

a return ReadTPMode::Invalid is missing here.

spetrovic added inline comments.Sep 11 2017, 5:34 AM
lib/Driver/ToolChains/Arch/ARM.cpp
140–141

Yes, my mistake, I will fix that.

spetrovic updated this revision to Diff 114582.Sep 11 2017, 6:15 AM
spetrovic marked 2 inline comments as done.
kristof.beyls accepted this revision.Sep 11 2017, 6:26 AM

Thanks Strahinja!
I thought that some indentations looked a bit strange, so I'd just still check that clang-format formats your changes the same way.
Otherwise LGTM!

This revision is now accepted and ready to land.Sep 11 2017, 6:26 AM

Thanks for the review! I will check indentations with clang format.

spetrovic updated this revision to Diff 114618.Sep 11 2017, 8:42 AM

Indentations fixed.

Still LGTM; please commit.

This revision was automatically updated to reflect the committed changes.