summaryrefslogtreecommitdiffstats
path: root/llvm/docs/TableGen
diff options
context:
space:
mode:
authorJaved Absar <javed.absar@arm.com>2019-01-25 10:25:25 +0000
committerJaved Absar <javed.absar@arm.com>2019-01-25 10:25:25 +0000
commita3e3d8528644b3e432538853804553c62fea7722 (patch)
tree797687c37a0bb0af848b5346f88d14cce00164c9 /llvm/docs/TableGen
parent7a35bdb7ec6958429bebd42f3ce40f19cdc9fbd8 (diff)
downloadbcm5719-llvm-a3e3d8528644b3e432538853804553c62fea7722.tar.gz
bcm5719-llvm-a3e3d8528644b3e432538853804553c62fea7722.zip
[TblGen] Extend !if semantics through new feature !cond
This patch extends TableGen language with !cond operator. Instead of embedding !if inside !if which can get cumbersome, one can now use !cond. Below is an example to convert an integer 'x' into a string: !cond(!lt(x,0) : "Negative", !eq(x,0) : "Zero", !eq(x,1) : "One, 1 : "MoreThanOne") Reviewed By: hfinkel, simon_tatham, greened Differential Revision: https://reviews.llvm.org/D55758 llvm-svn: 352185
Diffstat (limited to 'llvm/docs/TableGen')
-rw-r--r--llvm/docs/TableGen/LangIntro.rst14
-rw-r--r--llvm/docs/TableGen/LangRef.rst10
2 files changed, 23 insertions, 1 deletions
diff --git a/llvm/docs/TableGen/LangIntro.rst b/llvm/docs/TableGen/LangIntro.rst
index ea46550ffc0..390f941f0ca 100644
--- a/llvm/docs/TableGen/LangIntro.rst
+++ b/llvm/docs/TableGen/LangIntro.rst
@@ -258,6 +258,20 @@ supported include:
``!if(a,b,c)``
'b' if the result of 'int' or 'bit' operator 'a' is nonzero, 'c' otherwise.
+``!cond(condition_1 : val1, condition_2 : val2, ..., condition_n : valn)``
+ Instead of embedding !if inside !if which can get cumbersome,
+ one can use !cond. !cond returns 'val1' if the result of 'int' or 'bit'
+ operator 'condition1' is nonzero. Otherwise, it checks 'condition2'.
+ If 'condition2' is nonzero, returns 'val2', and so on.
+ If all conditions are zero, it reports an error.
+
+ Below is an example to convert an integer 'x' into a string:
+
+ !cond(!lt(x,0) : "Negative",
+ !eq(x,0) : "Zero",
+ !eq(x,1) : "One,
+ 1 : "MoreThanOne")
+
``!eq(a,b)``
'bit 1' if string a is equal to string b, 0 otherwise. This only operates
on string, int and bit objects. Use !cast<string> to compare other types of
diff --git a/llvm/docs/TableGen/LangRef.rst b/llvm/docs/TableGen/LangRef.rst
index 2efee12ec9d..a3dbf363151 100644
--- a/llvm/docs/TableGen/LangRef.rst
+++ b/llvm/docs/TableGen/LangRef.rst
@@ -102,6 +102,12 @@ wide variety of meanings:
:!isa !dag !le !lt !ge
:!gt !ne
+TableGen also has !cond operator that needs a slightly different
+syntax compared to other "bang operators":
+
+.. productionlist::
+ CondOperator: !cond
+
Syntax
======
@@ -140,7 +146,7 @@ considered to define the class if any of the following is true:
#. The :token:`Body` in the :token:`ObjectBody` is present and is not empty.
#. The :token:`BaseClassList` in the :token:`ObjectBody` is present.
-You can declare an empty class by giving and empty :token:`TemplateArgList`
+You can declare an empty class by giving an empty :token:`TemplateArgList`
and an empty :token:`ObjectBody`. This can serve as a restricted form of
forward declaration: note that records deriving from the forward-declared
class will inherit no fields from it since the record expansion is done
@@ -315,6 +321,8 @@ The initial :token:`DagArg` is called the "operator" of the dag.
.. productionlist::
SimpleValue: `BangOperator` ["<" `Type` ">"] "(" `ValueListNE` ")"
+ :| `CondOperator` "(" `CondVal` ("," `CondVal`)* ")"
+ CondVal: `Value` ":" `Value`
Bodies
------
OpenPOWER on IntegriCloud