This is an archive of the discontinued LLVM Phabricator instance.

[tblgen] Track CodeInit origins when possible
ClosedPublic

Authored by dsanders on Feb 12 2019, 11:52 AM.

Details

Summary

Add an SMLoc to CodeInit that records the source line it originated from.
This allows tablegen to point precisely at portions of code when reporting
errors within the CodeInit. For example, in the upcoming GlobalISel
combiner, it can report undefined expansions and point at the instance of
the expansion. This is achieved using something like:

SMLoc::getFromPointer(SMLoc::getPointer() +
                      (StringRef - CodeInit::getValue()))

The location is lost when producing a CodeInit by string concatenation so
a fallback SMLoc is required (e.g. the Record::getLoc()) but that's pretty
rare for CodeInits.

There's a reasonable case for extending tracking of a couple other Init
objects, for example StringInit's are often parsed and it would be good to
point inside the string when reporting errors about that. However, location
tracking also harms de-duplication. This is fine for CodeInit where there's
only a few hundred of them (~160 for X86) and it may be worth it for
StringInit (~86k up to ~1.9M for roughly 15MB increase for X86).
However the origin tracking would be a _terrible_ idea for IntInit, BitInit,
and UnsetInit. I haven't measured either of those three but BitInit would
most likely be on the order of increasing the current 2 BitInit values up
to billions.

Diff Detail

Event Timeline

dsanders created this revision.Feb 12 2019, 11:52 AM
paquette accepted this revision.Mar 1 2019, 11:48 AM

Better error-reporting sounds like a net win to me. LGTM aside from spelling nit.

lib/TableGen/Record.cpp
525

s/CodeInit's/CodeInits/

This revision is now accepted and ready to land.Mar 1 2019, 11:48 AM
This revision was automatically updated to reflect the committed changes.