This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Unify the priority of variables
ClosedPublic

Authored by pcwang-thead on Apr 23 2023, 2:50 AM.

Details

Summary

In D148197, we have made defvar statement able to refer to class
template arguments. However, the priority of class/multiclass
template argument is higher than variables defined by defvar, which
is a little counterintuitive.

In this patch, we unify the priority of variables. Each pair of
braces introduces a new scope, which may contain some additional
variables like template arguments, loop iterators, etc. We can
define local variables inside this scope via defvar and these
variables are of higher priority than additional variables. This
means that defvar will shadow additional variables with the same
name. The scope can be nested, and we use the innermost variable.

This make variables defined by defvar prior to class/multiclass
template arguments, loop iterators, etc. The shadow rules now are:

  • V in a record body shadows a global V.
  • V in a record body shadows template argument V.
  • V in template arguments shadows a global V.
  • V in a foreach statement list shadows any V in surrounding record or global scopes.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2023, 2:50 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
pcwang-thead requested review of this revision.Apr 23 2023, 2:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2023, 2:50 AM
pcwang-thead edited the summary of this revision. (Show Details)
pcwang-thead edited the summary of this revision. (Show Details)
pcwang-thead edited the summary of this revision. (Show Details)Apr 23 2023, 2:53 AM
pcwang-thead edited the summary of this revision. (Show Details)
pcwang-thead edited the summary of this revision. (Show Details)Apr 23 2023, 9:10 PM
tra accepted this revision.Apr 24 2023, 11:40 AM

LGTM with a test nit.

llvm/test/TableGen/defvar.td
155

Can we make the checks more granular? While the failure here will catch the problem, it will be hard to tell which part, exactly got broken.

Having an individual test for each of the shadowing scenarious would be useful, IMO.

This revision is now accepted and ready to land.Apr 24 2023, 11:40 AM
  • Rebase
  • Add more tests.
  • Unify the priority of variables.
pcwang-thead retitled this revision from [TableGen] Make defvar prior to class template arguments to [TableGen] Unify the priority of variables.May 16 2023, 12:18 AM
pcwang-thead edited the summary of this revision. (Show Details)

@tra Can you review this again? I have made some big changes to unify the implementation. Thanks in advance!

Fix wrong qualified argument name inside multiclass.

tra accepted this revision.May 23 2023, 9:49 AM

Still LGTM.

Still LGTM.

Thanks!

pcwang-thead marked an inline comment as done.May 23 2023, 8:31 PM
This revision was landed with ongoing or failed builds.May 23 2023, 9:44 PM
This revision was automatically updated to reflect the committed changes.