llvm-project/llvm/docs/TableGen
wangpc 634484885c [TableGen] Add new operator !exists
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, we add a new operator `!exists<T>(s)` to check whether
a record with type `T` and name `s` exists. Self-references are allowed
just like `!cast`.

By doing these, we can write code like:
```
class dyn_cast_to_record<string name> {
  R value = !if(!exists<R>(name), !cast<R>(name), default_value);
}
defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value.
```

Reviewed By: tra, nhaehnle

Differential Revision: https://reviews.llvm.org/D127948
2022-06-23 11:11:47 +08:00
..
BackEnds.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
BackGuide.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
ProgRef.rst [TableGen] Add new operator !exists 2022-06-23 11:11:47 +08:00
index.rst [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00