This is an archive of the discontinued LLVM Phabricator instance.

[RFC]Add unittests to {ARM | AArch64}TargetParser
ClosedPublic

Authored by jojo on Jun 27 2016, 11:07 PM.

Details

Summary
  • Add unittest to {ARM | AArch64}TargetParser
  • Correct a incorrect indexing problem in AArch64TargetParser The architecture enumeration is shared across ARM and AArch64 in original implementation.But In the code,I just used the index which was offset by the ARM, and this would index into the array incorrectly. To make AArch64 has its own arch enum,or we will do a lot of slowly iterating.
  • Correct a spelling error by the way. parameter of llvm::AArch64::getArchExtName
  • Correct a writing mistake, in llvm::ARM::parseArchISA

Diff Detail

Repository
rL LLVM

Event Timeline

jojo updated this revision to Diff 62057.Jun 27 2016, 11:07 PM
jojo retitled this revision from to [RFC]Add unittests to AArch64TargetParser.
jojo updated this object.
jojo added a subscriber: llvm-commits.
jojo added a child revision: Restricted Differential Revision.Jun 27 2016, 11:21 PM
jojo updated this revision to Diff 62062.Jun 27 2016, 11:38 PM

Remove unnecessary whitespace.

jojo updated this revision to Diff 62063.Jun 27 2016, 11:42 PM
compnerd added inline comments.Jun 28 2016, 9:52 AM
include/llvm/Support/TargetParser.h
152 ↗(On Diff #62063)

I think that you should use the AK_ prefix as is the norm. That said, you could do something else which IMO is better: use enum class and drop the prefix.

unittests/Support/TargetParserTest.cpp
24 ↗(On Diff #62063)

Please delete this. I had added it to avoid hardcoding the offset. Just iterate over the enumeration below. In fact, it is unused.

68 ↗(On Diff #62063)

This set really feels weird to me.

jojo added a child revision: Restricted Differential Revision.Jun 28 2016, 7:38 PM
jojo updated this revision to Diff 62648.Jul 3 2016, 8:11 PM

Remove uncessary items according to inline comments.

include/llvm/Support/TargetParser.h
152 ↗(On Diff #62063)

If we use enum class, we must do type casting when we perform operations between "unsigned int" and archkind. There are a lot of cases like this, in the TargetParser and places using it. And some generic structure definition shared between arm and aarch64, should be made a set for each.
Do we have to do this? Let AK_ point to ARM, and AAK_ point to AArch64 seems to make sense also.

unittests/Support/TargetParserTest.cpp
24 ↗(On Diff #62063)

Indeed,remove it.

68 ↗(On Diff #62063)

I removed two of these which are unnecessary.
The remaining two arrays are needed for some test items,with the help of def file can avoid writing a long array.And if there are changes happened on arch or cpu in def,we can do as small
changes as possible.
Hi,compnerd,If you still feel it can not be accepted,Could you say it further? Can't you accept the way they are defined? Or just don't want to have something like that? so it can get me more clear.
Thank you very much! :)

jojo updated this revision to Diff 62834.Jul 6 2016, 2:35 AM
  • Add unittest to ARMTargetParser
  • Correct a writing mistake,in llvm::ARM::parseArchISA.
  • Make some small changes on AArch64TargetParser
jojo retitled this revision from [RFC]Add unittests to AArch64TargetParser to [RFC]Add unittests to {ARM | AArch64}TargetParser.Jul 6 2016, 2:38 AM
jojo updated this object.
jojo updated this object.
rengolin added inline comments.Jul 6 2016, 2:43 AM
include/llvm/Support/TargetParser.h
152 ↗(On Diff #62834)

I think we should leave that discussion for when we change this to a class design, or when we move to table-generated tables. I think it should be fine as is, for now.

rengolin edited edge metadata.Jul 8 2016, 4:17 PM

Hi Jojo,

Thanks for the patch. I like how thorough were your tests, and it'll certainly cover a lot more than the current TripleTest. At some point, after we finish this, I think we should clean that one up, so that it stops redundant (and slow) tests.

Saleem (@compnerd), are you happy with the changes? I think we can discuss style in the class discussion (since it's going to change again, anyway), and just get all tools to use the parser for now.

cheers,
--renato

compnerd edited edge metadata.Jul 8 2016, 5:38 PM

I think that Id still prefer the AK_ prefix. However, the only thing that is preventing me from accepting the change is that I haven't really carefully looked through all the cases. If you have done so, and everything looks okay, fine by me :-).

jojo updated this revision to Diff 63468.Jul 11 2016, 12:52 AM
jojo edited edge metadata.

Add test for ARM::parseArchISA and ARM::parseArchEndian.

jojo added a comment.EditedJul 13 2016, 1:55 AM

Dear all,

I‘m not so sure about the changes.That would be appreciated if you could give any advice.
It will take some time to read through all the changes,Thank you very much for your review.

I think that Id still prefer the AK_ prefix. However, the only thing that is preventing me from accepting the change is that I haven't really carefully looked through all the cases. If you have done so, and everything looks okay, fine by me :-).

I don't mind either way (AK, AAK), but if there is anything stopping us from using AK, we should move that discussion later.

If not, I agree we should just keep AK instead. AK means "ArchKind", not "ARMKind", so AArch64 would also be "ArchKind", thus AK.

That would also make this change a lot smaller, and clearer.

thanks,
--renato

jojo updated this revision to Diff 64080.Jul 14 2016, 7:56 PM

Looks like that keep using prefix AK is more reasonable.Update diff to use AK instead.

rengolin added inline comments.Jul 19 2016, 6:35 AM
lib/Support/TargetParser.cpp
455 ↗(On Diff #64080)

Now I see why you wanted a different enum.

@compnerd, I really don't mind either way, so I'll leave it up to you. :)

There are a bunch of place that could use a range based for loop, please prefer them instead.

lib/Support/TargetParser.cpp
419 ↗(On Diff #64080)

Isn't this the original bug that is being fixed rather than just adding tests for the target parser?

455 ↗(On Diff #64080)

I don't think that this is necessarily bad. It does make it more obvious if you are targeting a newer architecture variant.

463 ↗(On Diff #64080)

Given that you are doing explicit checks, why not simplify this to:

if (ArchKind == ...)
  ...
if (ArchKind == ...)
  ...
return ArchKind > AArch64::ArchKind::AK_INVALID && ArchKind < AArch64::ArchKind::AK_LAST;
468 ↗(On Diff #64080)

Shouldn't this check for AK_INVALID as well?

488 ↗(On Diff #64080)

Shouldn't this check for AK_INVALID as well?

unittests/Support/TargetParserTest.cpp
180 ↗(On Diff #64080)

space before the <.

Why not use a range based loop?

for (const auto &ARMCPUName : kARMCPUNames)
  EXPECT_EQ(ARMCPUName.DefaultFPU, ARM::getDefaultFPU(ARMCPUName.Name, 0));
192 ↗(On Diff #64080)

Similar.

263 ↗(On Diff #64080)

clang-format this

jojo updated this revision to Diff 64644.Jul 20 2016, 12:26 AM
jojo added inline comments.
lib/Support/TargetParser.cpp
419 ↗(On Diff #64080)

Yes.this is a bug fixing. For AArch64,it's unnecessary to OR the ArchBaseExtensions,as the tables for ARM and AArch64 have not exactly the same design.
The original bug is fixed by correcting the incorrect indexing problem and removing the ORing here.All the changes are included in this revision.

468 ↗(On Diff #64080)

There is a record for "invalid" in ARCHNames table.
It will return what we want for ArchName and ArchAttr, no need to do additional check.

488 ↗(On Diff #64080)

the same as above

unittests/Support/TargetParserTest.cpp
180 ↗(On Diff #64080)

Yes,indeed.
Replace all similar cases.

263 ↗(On Diff #64080)

Do you mean like this?

{ "crc", "+crc"},
... ...
{ "nocrc", "-crc"},
... ...

rengolin added inline comments.Jul 22 2016, 9:49 AM
unittests/Support/TargetParserTest.cpp
261 ↗(On Diff #64644)

He probably just mean running "clang-format" over the file.

$ clang-format unittests/Support/TargetParserTest.cpp

should do.

jojo updated this revision to Diff 65308.Jul 25 2016, 12:54 AM

clang-format unittests/Support/TargetParserTest.cpp

jojo added inline comments.Jul 25 2016, 12:55 AM
unittests/Support/TargetParserTest.cpp
261 ↗(On Diff #64644)

Oh, No brainer.

rengolin accepted this revision.Jul 26 2016, 2:39 AM
rengolin edited edge metadata.

LGTM. Thanks!

This revision is now accepted and ready to land.Jul 26 2016, 2:39 AM
This revision was automatically updated to reflect the committed changes.