summaryrefslogtreecommitdiffstats
path: root/llvm/docs/TableGen
diff options
context:
space:
mode:
authorSimon Tatham <simon.tatham@arm.com>2019-12-11 12:02:15 +0000
committerSimon Tatham <simon.tatham@arm.com>2019-12-11 12:05:22 +0000
commit1fed9a0c0c3e74c21dfbd1edf18411a33b742f52 (patch)
tree48690ac8255c77890878bbecb0cd72c83f88be0a /llvm/docs/TableGen
parentafb13afcf2232c81fe8097832e5b6a2bde6bb3a5 (diff)
downloadbcm5719-llvm-1fed9a0c0c3e74c21dfbd1edf18411a33b742f52.tar.gz
bcm5719-llvm-1fed9a0c0c3e74c21dfbd1edf18411a33b742f52.zip
[TableGen] Add bang-operators !getop and !setop.
Summary: These allow you to get and set the operator of a dag node, without affecting its list of arguments. `!getop` is slightly fiddly because in many contexts you need its return value to have a static type more specific than 'any record'. It works to say `!cast<BaseClass>(!getop(...))`, but it's cumbersome, so I made `!getop` take an optional type suffix itself, so that can be written as the shorter `!getop<BaseClass>(...)`. Reviewers: hfinkel, nhaehnle Reviewed By: nhaehnle Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71191
Diffstat (limited to 'llvm/docs/TableGen')
-rw-r--r--llvm/docs/TableGen/LangIntro.rst28
-rw-r--r--llvm/docs/TableGen/LangRef.rst3
2 files changed, 30 insertions, 1 deletions
diff --git a/llvm/docs/TableGen/LangIntro.rst b/llvm/docs/TableGen/LangIntro.rst
index 45104ac78b8..d72b61f6ab7 100644
--- a/llvm/docs/TableGen/LangIntro.rst
+++ b/llvm/docs/TableGen/LangIntro.rst
@@ -183,6 +183,34 @@ supported include:
Example: !dag(op, [a1, a2, ?], ["name1", "name2", "name3"]) results in
(op a1:$name1, a2:$name2, ?:$name3).
+``!setop(dag, op)``
+ Return a DAG node with the same arguments as ``dag``, but with its
+ operator replaced with ``op``.
+
+ Example: ``!setop((foo 1, 2), bar)`` results in ``(bar 1, 2)``.
+
+``!getop(dag)``
+
+``!getop<type>(dag)``
+ Return the operator of the given DAG node.
+ Example: ``!getop((foo 1, 2))`` results in ``foo``.
+
+ The result of ``!getop`` can be used directly in a context where
+ any record value at all is acceptable (typically placing it into
+ another dag value). But in other contexts, it must be explicitly
+ cast to a particular class type. The ``!getop<type>`` syntax is
+ provided to make this easy.
+
+ For example, to assign the result to a class-typed value, you
+ could write either of these:
+ ``BaseClass b = !getop<BaseClass>(someDag);``
+
+ ``BaseClass b = !cast<BaseClass>(!getop(someDag));``
+
+ But to build a new dag node reusing the operator from another, no
+ cast is necessary:
+ ``dag d = !dag(!getop(someDag), args, names);``
+
``!listconcat(a, b, ...)``
A list value that is the result of concatenating the 'a' and 'b' lists.
The lists must have the same element type.
diff --git a/llvm/docs/TableGen/LangRef.rst b/llvm/docs/TableGen/LangRef.rst
index 5079bc60e3f..8f8b3613db5 100644
--- a/llvm/docs/TableGen/LangRef.rst
+++ b/llvm/docs/TableGen/LangRef.rst
@@ -100,7 +100,8 @@ wide variety of meanings:
:!or !empty !subst !foreach !strconcat
:!cast !listconcat !size !foldl
:!isa !dag !le !lt !ge
- :!gt !ne !mul !listsplat
+ :!gt !ne !mul !listsplat !setop
+ :!getop
TableGen also has !cond operator that needs a slightly different
syntax compared to other "bang operators":
OpenPOWER on IntegriCloud