[PATCH] D145108: [RISCV][llvm-tblgen] Support conditional definitions using !exists clauses

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 12:35:57 PST 2023


reames created this revision.
reames added reviewers: RKSimon, craig.topper, michaelmaitland, rriddle, jyknight, wangpc.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, asb, hiraditya, kristof.beyls, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

The core part of this change is an extension to the tablegen language to allow conditional definition of records using if-clauses based on !exists.

The RISCV td file change is mostly to illustrate the potential use of conditional definitions.  I am deliberately not maximally simplifying in this change to make merging with downstream code (or simply rebasing while this on review) easier.

Some background to make the change understandable.

TableGen does not have an if statement internally.  It has if expressions - in the form of TernInitOp with IF opcode - and foreach statements.  It implements an if-statement as a foreach which iterates either 0 or 1 times.

Foreach nodes are then evaluated via unrolling inside the parser.  Specifically, they are evaluated, at latest, when the outermost multiclass or loop containing them reaches end of scope.  The unrolled statements remain (potentially) unresolved after unrolling, but the number of iterations must be known at this point.

An !exists clause can only evaluate at final evaluation.  (Specifically, forward references to definitions are allowed - up to the end of the containing scope at least.)  The existing code did not set the final flag on the resolver, and thus would leave the !exists clause in an unresolved state.  This would then cause an error since we don't know how many iterations on which to unroll the (synthetic) foreach loop.

I chose to only finally-evaluate the condition of the if-expression.  This allows us to pick an arm at scope exit without inhibiting definitions in the arm from having self references.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145108

Files:
  llvm/lib/TableGen/Record.cpp
  llvm/lib/TableGen/TGParser.cpp
  llvm/lib/Target/RISCV/RISCVScheduleV.td
  llvm/test/TableGen/exists.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145108.501627.patch
Type: text/x-patch
Size: 8348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230301/9bb34d0e/attachment.bin>


More information about the llvm-commits mailing list