[PATCH] D127739: [TableGen] Check if input string of !isa is an instance of record type

Wang Pengcheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 05:17:31 PDT 2022


pcwang-thead created this revision.
pcwang-thead added reviewers: nhaehnle, craig.topper, jdoerfert, tra.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
pcwang-thead requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We can cast a string to a record via !cast, but we have no mechanism
to check if it is valid and TableGen will raise an error if failed to
cast. Besides, we have no semantic null in TableGen (we have `?` but
different backends handle uninitialized value differently), so operator
like dyn_cast<> is hard to implement.

In this patch, when input of !isa is a string and type to check is a
record, we will treat the input string as record name and loop up all
defined records with the type to see if we can find one. We do this
check until the final resolving step is done to match what !cast has
done.

By doing these, we can write code like:

  class dyn_cast_to_record<string r> {
    R value = !if(!isa<R>(r), !cast<R>(r), default_value);
  }
  defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127739

Files:
  llvm/docs/TableGen/ProgRef.rst
  llvm/include/llvm/TableGen/Record.h
  llvm/lib/TableGen/Record.cpp
  llvm/test/TableGen/isa.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127739.436742.patch
Type: text/x-patch
Size: 3700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220614/ef06521e/attachment.bin>


More information about the llvm-commits mailing list