Skip to content

Commit

Permalink
[Docs] Fix IR and TableGen grammar inconsistencies
Browse files Browse the repository at this point in the history
IR:
- globals (and functions, ifuncs, aliases) can have a partition
- catchret has a `to` before the label
- the sint/int types do not exist
- signext comes after the type
- a variable was missing its type

TableGen:
- The second value after a `#` concatenation is optional
  See e.g. llvm/lib/Target/X86/X86InstrAVX512.td:L3351
- IncludeDirective and PreprocessorDirective were never referenced in
  the grammar
- Add some missing ;
- Parent classes of multiclasses can have generic arguments.
  Reuse the `ParentClassList` that is already used in other places.

MIR:
- liveins only allows physical registers, which start with a $

Differential Revision: https://reviews.llvm.org/D116674
  • Loading branch information
Flakebi committed Jan 13, 2022
1 parent b65f21a commit f413944
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
22 changes: 13 additions & 9 deletions llvm/docs/LangRef.rst
Expand Up @@ -738,8 +738,9 @@ Syntax::
[(unnamed_addr|local_unnamed_addr)] [AddrSpace]
[ExternallyInitialized]
<global | constant> <Type> [<InitializerConstant>]
[, section "name"] [, comdat [($name)]]
[, align <Alignment>] (, !name !N)*
[, section "name"] [, partition "name"]
[, comdat [($name)]] [, align <Alignment>]
(, !name !N)*

For example, the following defines a global in a numbered address space
with an initializer, section, and alignment:
Expand Down Expand Up @@ -836,8 +837,9 @@ Syntax::
[cconv] [ret attrs]
<ResultType> @<FunctionName> ([argument list])
[(unnamed_addr|local_unnamed_addr)] [AddrSpace] [fn Attrs]
[section "name"] [comdat [($name)]] [align N] [gc] [prefix Constant]
[prologue Constant] [personality Constant] (!name !N)* { ... }
[section "name"] [partition "name"] [comdat [($name)]] [align N]
[gc] [prefix Constant] [prologue Constant] [personality Constant]
(!name !N)* { ... }

The argument list is a comma separated sequence of arguments where each
argument is of the following form:
Expand Down Expand Up @@ -866,6 +868,7 @@ Aliases may have an optional :ref:`linkage type <linkage>`, an optional
Syntax::

@<Name> = [Linkage] [PreemptionSpecifier] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
[, partition "name"]

The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
Expand Down Expand Up @@ -908,6 +911,7 @@ IFunc may have an optional :ref:`linkage type <linkage>` and an optional
Syntax::

@<Name> = [Linkage] [PreemptionSpecifier] [Visibility] ifunc <IFuncTy>, <ResolverTy>* @<Resolver>
[, partition "name"]


.. _langref_comdats:
Expand Down Expand Up @@ -8421,7 +8425,7 @@ Example:

.. code-block:: text

catchret from %catch label %continue
catchret from %catch to label %continue

.. _i_cleanupret:

Expand Down Expand Up @@ -11026,8 +11030,8 @@ Example:
.. code-block:: text

%X = bitcast i8 255 to i8 ; yields i8 :-1
%Y = bitcast i32* %x to sint* ; yields sint*:%x
%Z = bitcast <2 x int> %V to i64; ; yields i64: %V (depends on endianess)
%Y = bitcast i32* %x to i16* ; yields i16*:%x
%Z = bitcast <2 x i32> %V to i64; ; yields i64: %V (depends on endianess)
%Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>

.. _i_addrspacecast:
Expand Down Expand Up @@ -11604,7 +11608,7 @@ Example:
call i32 (i8*, ...)* @printf(i8* %msg, i32 12, i8 42) ; yields i32
%X = tail call i32 @foo() ; yields i32
%Y = tail call fastcc i32 @foo() ; yields i32
call void %foo(i8 97 signext)
call void %foo(i8 signext 97)

%struct.A = type { i32, i8 }
%r = call %struct.A @foo() ; yields { i32, i8 }
Expand Down Expand Up @@ -11752,7 +11756,7 @@ Example:
;; A landing pad which can catch an integer and can only throw a double.
%res = landingpad { i8*, i32 }
catch i8** @_ZTIi
filter [1 x i8**] [@_ZTId]
filter [1 x i8**] [i8** @_ZTId]

.. _i_catchpad:

Expand Down
15 changes: 9 additions & 6 deletions llvm/docs/TableGen/ProgRef.rst
Expand Up @@ -330,7 +330,7 @@ to an entity of type ``bits<4>``.

.. productionlist::
Value: `SimpleValue` `ValueSuffix`*
:| `Value` "#" `Value`
:| `Value` "#" [`Value`]
ValueSuffix: "{" `RangeList` "}"
:| "[" `RangeList` "]"
:| "." `TokIdentifier`
Expand Down Expand Up @@ -536,6 +536,9 @@ previous case, if the *right-hand-side* operand is an undefined name or a
global name, it is treated as a verbatim string of characters. The
left-hand-side operand is treated normally.

Values can have a trailing paste operator, in which case the left-hand-side
operand is concatenated to an empty string.

`Appendix B: Paste Operator Examples`_ presents examples of the behavior of
the paste operator.

Expand All @@ -546,7 +549,8 @@ The following statements may appear at the top level of TableGen source
files.

.. productionlist::
TableGenFile: `Statement`*
TableGenFile: (`Statement` | `IncludeDirective`
:| `PreprocessorDirective`)*
Statement: `Assert` | `Class` | `Def` | `Defm` | `Defset` | `Defvar`
:| `Foreach` | `If` | `Let` | `MultiClass`

Expand Down Expand Up @@ -694,7 +698,7 @@ to that record's parent classes. For example:
dag the_dag = d;
}
def rec1 : A<(ops rec1)>
def rec1 : A<(ops rec1)>;
The DAG ``(ops rec1)`` is passed as a template argument to class ``A``. Notice
that the DAG includes ``rec1``, the record being defined.
Expand Down Expand Up @@ -886,9 +890,8 @@ template that expands into multiple records.

.. productionlist::
MultiClass: "multiclass" `TokIdentifier` [`TemplateArgList`]
: [":" `ParentMultiClassList`]
: `ParentClassList`
: "{" `MultiClassStatement`+ "}"
ParentMultiClassList: `MultiClassID` ("," `MultiClassID`)*
MultiClassID: `TokIdentifier`
MultiClassStatement: `Assert` | `Def` | `Defm` | `Defvar` | `Foreach` | `If` | `Let`

Expand Down Expand Up @@ -1194,7 +1197,7 @@ Variables defined in a top-level ``foreach`` go out of scope at the end of
each loop iteration, so their value in one iteration is not available in
the next iteration. The following ``defvar`` will not work::

defvar i = !add(i, 1)
defvar i = !add(i, 1);

Variables can also be defined with ``defvar`` in a record body. See
`Defvar in a Record Body`_ for more details.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/MIRParser/MIParser.cpp
Expand Up @@ -875,11 +875,11 @@ bool MIParser::parseBasicBlock(MachineBasicBlock &MBB,
// N.B: Multiple lists of successors and liveins are allowed and they're
// merged into one.
// Example:
// liveins: %edi
// liveins: %esi
// liveins: $edi
// liveins: $esi
//
// is equivalent to
// liveins: %edi, %esi
// liveins: $edi, $esi
bool ExplicitSuccessors = false;
while (true) {
if (Token.is(MIToken::kw_successors)) {
Expand Down

0 comments on commit f413944

Please sign in to comment.