This is an archive of the discontinued LLVM Phabricator instance.

[tablegen] Recursively evaluate values of variable initializers.
AbandonedPublic

Authored by tra on Feb 9 2018, 4:28 PM.

Details

Summary

Otherwise we often end up with partially evaluated fields even when
their (evaluated) values are known at the time of the record instantiation.

Event Timeline

tra created this revision.Feb 9 2018, 4:28 PM
tra added a comment.Feb 13 2018, 9:57 AM

@arsenm Can you take a look?

tra added a comment.Feb 15 2018, 3:37 PM

@craig.topper please take a look.

Wasn't the point of how this was written before so that we go through a loop in Record::resolveReferencesTo and resolve each field and call setValue. And the VarInit just loops up the value saved by that resolving. Now it looks we by pass those cached results and just recurse all the time. Won't this be a big perf hit?

tra added a comment.Feb 15 2018, 5:29 PM

Wasn't the point of how this was written before so that we go through a loop in Record::resolveReferencesTo and resolve each field and call setValue. And the VarInit just loops up the value saved by that resolving. Now it looks we by pass those cached results and just recurse all the time. Won't this be a big perf hit?

It should not impact performance much. If we've managed to fold the value at some point, then we'll return right away, because there's nothing to fold any more.
If folding failed we will attempt to fold again when the variable is used later. It should not happen often as all currently existing tablegen files apparently manage to provide enough information to fold the records and avoid the problem this patch solves.

Performance impact on my machine using bin/tblgen -I ~/work/llvm/repo/llvm/lib/Target/NVPTX -I ~/work/llvm/repo/llvm/lib/Target -I ~/work/llvm/repo/llvm/include ~/work/llvm/repo/llvm/lib/Target/NVPTX/NVPTX.td -o /dev/null is lost in the noise:
w/o changes: 0.261s-0.275s
with this patch: 0.265s-0.274s

Most of the time will be spent in the back-ends and that part is not affected by the patch.

I believe the change is correct, although the change D43564 should be doing the same thing with caching on top of it.

If this is urgent we could take it and resolve the conflicts, otherwise I'd prefer if we went with my changes if you're okay with them, but keep your test case around.

tra added a comment.Feb 21 2018, 9:29 AM

I believe the change is correct, although the change D43564 should be doing the same thing with caching on top of it.

If this is urgent we could take it and resolve the conflicts, otherwise I'd prefer if we went with my changes if you're okay with them, but keep your test case around.

I have few pending patches depending on this change, so I'd rather land this patch soon. The conflict will be easy to resolve -- just replace the changes to VarInit::resolveReferences with your version.
D43564 is currently the last patch in your set, which may take some time until it lands. If you can rebase D43564 to the bottom of your stack (and incorporate this test), I'd be OK going with it.

tra abandoned this revision.Mar 13 2018, 4:45 PM

The patch is no longer needed after recent tablegen improvements by @nhaehnle.