This is an archive of the discontinued LLVM Phabricator instance.

TargetParser prototype - NFC (ARM only)
ClosedPublic

Authored by rengolin on May 1 2015, 8:45 AM.

Details

Summary

This new class in a global context contain arch-specific knowledge in order
to provide LLVM libraries, tools and projects with the ability to understand
the architectures. For now, only FPU, ARCH and ARCH extensions on ARM are
supported.

Current behaviour it to parse from free-text to enum values and back, so that
all users can share the same parser and codes. This simplifies a lot both the
ASM/Obj streamers in the back-end (where this came from), and the front-end
parsers for command line arguments (where this is going to be used next).

The previous implementation, using .def/.h includes is deprecated due to its
inflexibility to be built without the backend support and for being too
cumbersome. As more architectures join this scheme, and as more features of
such architectures are added (such as hardware features, type sizes, etc) into
a full blown TargetDescription class, having a set of classes is the most
sane implementation.

The ultimate goal of this refactor both LLVM's and Clang's target description
classes into one unique interface, so that we can de-duplicate and standardise
the descriptions, as well as make it available for other front-ends, tools,
etc.

The FPU parsing for command line options in Clang has been converted to use
this new library and a number of aliases were added for compatibility:

  • A bogus neon-vfpv3 alias (neon defaults to vfp3)
  • armv5/v6
  • {fp4/fp5}-{sp/dp}-d16

Next steps:

  • Port Clang's FPU/ARCH/EXT parsing to use this library.
  • Create a TableGen back-end to generate this information.
  • Run this TableGen process regardless of which back-ends are built.
  • Expose more information and rename it to TargetDescription.
  • Re-factor Clang to use as much of it as possible.

Notes:

  • The patter is the same as ARMBuildAttrs, but uses a class instead of global functions. This is due to the fact that we may want later to extend the description abilities and remove the "ARM" from the TargetParser, making it a polymorphic class. For now, we only have target parser usage in target specific area, so it should work ok.
  • It's in Support because we don't want to tie to any specific back-end, but the arch-specific knowledge should later be generated by a TableGen back-end on a generic context, so some .td files will be exposed for the architectures supported even if we're not building those back-ends. This is to be done well later.
  • The IDs are in the exact same order as before, and the parsing is pretty much in the same way (StringSwitch vs. iteration), so no functional or performance changes should happen.
  • Clang's patch is in D9549.

Diff Detail

Event Timeline

rengolin updated this revision to Diff 24803.May 1 2015, 8:45 AM
rengolin retitled this revision from to TargetParser prototype - NFC (ARM only).
rengolin updated this object.
rengolin edited the test plan for this revision. (Show Details)
rengolin added reviewers: echristo, t.p.northover, rnk.
rengolin set the repository for this revision to rL LLVM.
rengolin added subscribers: Unknown Object (MLST), Unknown Object (MLST).
rengolin updated this revision to Diff 24804.May 1 2015, 8:52 AM
rengolin removed rL LLVM as the repository for this revision.

Cleaning some left-over comments.

rengolin updated this revision to Diff 24805.May 1 2015, 8:54 AM

New line at end of file warning.

A general question: how far are you planning to go with this, in particular are you going to sort out cpu <-> arch mapping (which is duplicated in several places)?

I ask because I'm currently thinking about adjusting the ARM -mcpu and -march handling in clang to be more like AArch64, in particular making -march=garbage not mean -mcpu=arm7tdmi (and instead give an error), and it's be nice to not collide with what you're doing.

include/llvm/Support/ARMTargetParser.h
91–92

Synonym.

lib/Support/ARMTargetParser.cpp
158–159

The -sp-d16 FP variants aren't synonyms for the -d16 variants. This preserves the current behaviour, where clang -S -mfpu=fpv5-sp-d16 gets you .fpu fpv5-d16 (which doesn't seem right to me), but it could at least do with a comment.

rengolin added inline comments.May 1 2015, 11:54 AM
include/llvm/Support/ARMTargetParser.h
91–92

Oops. :)

lib/Support/ARMTargetParser.cpp
158–159

Yes, I'm trying to keep 100% compatibility, so that this doesn't break anything obscure and I have to revert the refactoring. Once the mechanism is in place, it'll be *a lot* easier to make it right in a single place.

I'll add a comment.

rengolin updated this revision to Diff 24830.May 1 2015, 2:05 PM

typo + fixme

rengolin updated this revision to Diff 25147.May 7 2015, 3:16 AM
rengolin updated this object.

A few new alias found while supporting Clang's FPU parser.

rengolin updated this object.
rengolin added reviewers: john.brawn, meadori.
rengolin removed a subscriber: john.brawn.
rengolin updated this revision to Diff 25193.May 7 2015, 8:50 AM

Adding more FIXMEs. I'll be doing them as soon as this patch is in.

rnk edited edge metadata.May 7 2015, 8:56 AM

I guess Support is an OK place to park this particular pile of strings, enums, and tables. The target feature CPU and feature parsing is very similar in nature to triple parsing.

If this reaches the logical conclusion, we'll have a file per in-tree LLVM backend, or 13 files. At that point, we might wish to make a new library.

include/llvm/Support/ARMTargetParser.h
24

Actually, I'd much rather use .def files if possible. TableGen slows down builds and is hard to understand. Sure, pre-processor macros are hard to reason about, but they're *still* easier to understand than tablegen.

Also, so long as this library is in Support, and I think it will be here for a while, this FIXME is unactionable because Support cannot depend on TableGen.

I think we can solve any inflexibility of .def files with a separate plain C++ source synonym table, like you currently have.

lib/Support/ARMTargetParser.cpp
105–106

This style of separating the class name and the method name appears in LLVM, but it's really uncommon and I don't want to encourage it. Do you mind not using it?

In D9435#168002, @rnk wrote:

I guess Support is an OK place to park this particular pile of strings, enums, and tables. The target feature CPU and feature parsing is very similar in nature to triple parsing.

Yes. The idea is to have triple parsing joined with this library, and possible ARM attributes, too, into one big TargetDescription library, which will probably reside in TargetDescription.h/cpp files.

If this reaches the logical conclusion, we'll have a file per in-tree LLVM backend, or 13 files. At that point, we might wish to make a new library.

I think I should rename it now to TargetParser, so that it's clear that this is not just ARM. Or I could call it TargetDescription.cpp/h and leave just the parser for now, then refactor it later.

cheers,
--renato

include/llvm/Support/ARMTargetParser.h
24

The reason for using TableGen is that this information is already there. We just need to extract it with a new back-end to just output a small number of tables, instead of duplicating it here and getting it out of sync, again.

We discussed this earlier, and the consensus was that having a common TableGen run for the basic target information independent of which back-ends are compiled. Again, because that information is *already* there, and new hardware information is added in TableGen files, so these tables will be updated automatically.

With .def files, we'd probably have to populate them via TableGen to get up-to-date information anyway. Doesn't make much difference. I personally would rather have a larger header than multiple .def files.

lib/Support/ARMTargetParser.cpp
105–106

sure! That was a side effect of refactoring. I also dislike it. :)

rengolin updated this revision to Diff 25304.May 8 2015, 4:31 AM
rengolin edited edge metadata.

Changes due to comments:

  • Re-write method names in a single line
  • Rename ARMTargetParser.h/cpp to TargetParser.h/cpp
  • Added a few comments about TableGen
rnk accepted this revision.May 8 2015, 11:08 AM
rnk edited edge metadata.

lgtm

include/llvm/Support/TargetParser.h
22 ↗(On Diff #25304)

"generated"

This revision is now accepted and ready to land.May 8 2015, 11:08 AM
rengolin closed this revision.May 8 2015, 2:09 PM

Thanks! r236900 with the typo fixed.

lib/Target/ARM/AsmParser/ARMAsmParser.cpp