Skip to content

Commit 271a7bb

Browse files
[flang] Add new documentation main page
Add a new index page to be the Flang documentation mainpage instead of Overview.md, which jumps straight into the compiler Design. The index file needs to be in .rst format to use the toctree directive to create table of contents. Also use the sphinx_markdown_tables extension to generate html tables form markdown. A number of additional style changes to the existing docs were needed to make this work well: * Convert all headings to the # style, which works better with toctree's titlesonly option. Ensure that there is only one top-level heading per document. * Add a title to documents that don't have one for rendering on the index. * Convert the grammar docs from .txt to .md. for better rendering * Fixed broken link to a section in another document - sphinx does not seem to support anchor links in markdown files. Depends on D87226 Reviewed By: sameeranjoshi Differential Revision: https://reviews.llvm.org/D87242
1 parent 9fda213 commit 271a7bb

29 files changed

+399
-199
lines changed

flang/docs/ArrayComposition.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
77
-->
88

9+
# Array Composition
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
916
This note attempts to describe the motivation for and design of an
1017
implementation of Fortran 90 (and later) array expression evaluation that
1118
minimizes the use of dynamically allocated temporary storage for
@@ -34,8 +41,8 @@ Other Fortran intrinsic functions are technically transformational (e.g.,
3441
`COMMAND_ARGUMENT_COUNT`) but not of interest for this note.
3542
The generic `REDUCE` is also not considered here.
3643

37-
Arrays as functions
38-
===================
44+
## Arrays as functions
45+
3946
A whole array can be viewed as a function that maps its indices to the values
4047
of its elements.
4148
Specifically, it is a map from a tuple of integers to its element type.
@@ -45,8 +52,8 @@ and the shape of the array delimits the domain of the map.
4552
`REAL :: A(N,M)` can be seen as a function mapping ordered pairs of integers
4653
`(J,K)` with `1<=J<=N` and `1<=J<=M` to real values.
4754

48-
Array expressions as functions
49-
==============================
55+
## Array expressions as functions
56+
5057
The same perspective can be taken of an array expression comprising
5158
intrinsic operators and elemental functions.
5259
Fortran doesn't allow one to apply subscripts directly to an expression,
@@ -83,8 +90,8 @@ side variable as an operand of the right-hand side expression, and any
8390
function calls on the right-hand side are elemental or scalar-valued,
8491
we can avoid the use of a temporary.
8592

86-
Transformational intrinsic functions as function composition
87-
============================================================
93+
## Transformational intrinsic functions as function composition
94+
8895
Many of the transformational intrinsic functions listed above
8996
can, when their array arguments are viewed as functions over their
9097
index tuples, be seen as compositions of those functions with
@@ -127,8 +134,8 @@ More completely:
127134
* `SPREAD(A,DIM=d,NCOPIES=n)` for compile-time `d` simply
128135
applies `A` to a reduced index tuple.
129136

130-
Determination of rank and shape
131-
===============================
137+
## Determination of rank and shape
138+
132139
An important part of evaluating array expressions without the use of
133140
temporary storage is determining the shape of the result prior to,
134141
or without, evaluating the elements of the result.
@@ -173,17 +180,17 @@ In cases where the analyzed shape is known at compile time, we should
173180
be able to have the opportunity to avoid heap allocation in favor of
174181
stack storage, if the scope of the variable is local.
175182

176-
Automatic reallocation of allocatables
177-
======================================
183+
## Automatic reallocation of allocatables
184+
178185
Fortran 2003 introduced the ability to assign non-conforming array expressions
179186
to ALLOCATABLE arrays with the implied semantics of reallocation to the
180187
new shape.
181188
The implementation of this feature also becomes more straightforward if
182189
our implementation of array expressions has decoupled calculation of shapes
183190
from the evaluation of the elements of the result.
184191

185-
Rewriting rules
186-
===============
192+
## Rewriting rules
193+
187194
Let `{...}` denote an ordered tuple of 1-based indices, e.g. `{j,k}`, into
188195
the result of an array expression or subexpression.
189196

flang/docs/BijectiveInternalNameUniquing.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## Bijective Internal Name Uniquing
1+
# Bijective Internal Name Uniquing
2+
3+
```eval_rst
4+
.. contents::
5+
:local:
6+
```
27

38
FIR has a flat namespace. No two objects may have the same name at
49
the module level. (These would be functions, globals, etc.)
@@ -13,14 +18,14 @@ Fortran is case insensitive, which allows the compiler to convert the
1318
user's identifiers to all lower case. Such a universal conversion implies
1419
that all upper case letters are available for use in uniquing.
1520

16-
### Prefix `_Q`
21+
## Prefix `_Q`
1722

1823
All uniqued names have the prefix sequence `_Q` to indicate the name has
1924
been uniqued. (Q is chosen because it is a
2025
[low frequency letter](http://pi.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html)
2126
in English.)
2227

23-
### Scope Building
28+
## Scope Building
2429

2530
Symbols can be scoped by the module, submodule, or procedure that contains
2631
that symbol. After the `_Q` sigil, names are constructed from outermost to
@@ -45,7 +50,7 @@ The uniqued name of `fun` becomes:
4550
_QMmodSs1modSs2modFsubPfun
4651
```
4752

48-
### Common blocks
53+
## Common blocks
4954

5055
* A common block name will be prefixed with `B`
5156

@@ -69,7 +74,7 @@ The uniqued name in case of `blank common block` becomes:
6974
_QB
7075
```
7176

72-
### Module scope global data
77+
## Module scope global data
7378

7479
* A global data entity is prefixed with `E`
7580
* A global entity that is constant (parameter) will be prefixed with `EC`
@@ -92,7 +97,7 @@ The uniqued name of `pi` becomes:
9297
_QMmodECpi
9398
```
9499

95-
### Procedures/Subprograms
100+
## Procedures/Subprograms
96101

97102
* A procedure/subprogram is prefixed with `P`
98103

@@ -105,7 +110,7 @@ The uniqued name of `sub` becomes:
105110
_QPsub
106111
```
107112

108-
### Derived types and related
113+
## Derived types and related
109114

110115
* A derived type is prefixed with `T`
111116
* If a derived type has KIND parameters, they are listed in a consistent
@@ -148,7 +153,7 @@ The uniqued name of `yourtype` where `k1=4` and `k2=-6` (at compile-time):
148153
type `yourtype` above would be `_QCTyourtypeK4KN6`. The type
149154
descriptor for `REAL(4)` would be `_QCrealK4`.
150155

151-
### Compiler generated names
156+
## Compiler generated names
152157

153158
Compiler generated names do not have to be mapped back to Fortran. These
154159
names will be prefixed with `_QQ` and followed by a unique compiler

flang/docs/C++17.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
77
-->
88

9-
## C++14/17 features used in f18
9+
# C++14/17 features used in f18
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
1015

1116
The C++ dialect used in this project constitutes a subset of the
1217
standard C++ programming language and library features.
@@ -32,7 +37,7 @@ The most important of these are:
3237
(`std::tuple` is actually a C++11 feature, but I include it
3338
in this list because it's not particularly well known.)
3439

35-
### Sum types
40+
## Sum types
3641

3742
First, some background information to explain the need for sum types
3843
in f18.
@@ -111,7 +116,7 @@ would be to:
111116
functions (or the forbidden `dynamic_cast`) to identify alternatives
112117
during analysis
113118

114-
### Product types
119+
## Product types
115120

116121
Many productions in the Fortran grammar describe a sequence of various
117122
sub-parses.
@@ -133,7 +138,7 @@ So we use `std::tuple` for such things.
133138
It has also been handy for template metaprogramming that needs to work
134139
with lists of types.
135140

136-
### `std::optional`
141+
## `std::optional`
137142

138143
This simple little type is used wherever a value might or might not be
139144
present.

flang/docs/C++style.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
77
-->
88

9+
# Flang C++ Style Guide
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
16+
This document captures the style guide rules that are followed in the Flang codebase.
17+
918
## In brief:
1019
* Use *clang-format*
1120
from llvm 7

flang/docs/Calls.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
77
-->
88

9+
# Representation of Fortran function calls
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
916
## Procedure reference implementation protocol
1017

1118
Fortran function and subroutine references are complicated.

flang/docs/Character.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
77
-->
88

9-
## Implementation of `CHARACTER` types in f18
9+
# Implementation of `CHARACTER` types in f18
1010

11-
### Kinds and Character Sets
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
16+
## Kinds and Character Sets
1217

1318
The f18 compiler and runtime support three kinds of the intrinsic
1419
`CHARACTER` type of Fortran 2018.
@@ -48,7 +53,7 @@ We might want to support one or more environment variables to change these
4853
assumptions, especially for `KIND=1` users of ISO-8859 character sets
4954
besides Latin-1.
5055

51-
### Lengths
56+
## Lengths
5257

5358
Allocatable `CHARACTER` objects in Fortran may defer the specification
5459
of their lengths until the time of their allocation or whole (non-substring)
@@ -76,7 +81,7 @@ Fortran substrings are rather like subscript triplets into a hidden
7681
"zero" dimension of a scalar `CHARACTER` value, but they cannot have
7782
strides.
7883

79-
### Concatenation
84+
## Concatenation
8085

8186
Fortran has one `CHARACTER`-valued intrinsic operator, `//`, which
8287
concatenates its operands (10.1.5.3).
@@ -105,7 +110,7 @@ The result of `//` may be used
105110
The f18 compiler has a general (but slow) means of implementing concatenation
106111
and a specialized (fast) option to optimize the most common case.
107112

108-
#### General concatenation
113+
### General concatenation
109114

110115
In the most general case, the f18 compiler's generated code and
111116
runtime support library represent the result as a deferred-length allocatable
@@ -130,7 +135,7 @@ When the left-hand side of a `CHARACTER` assignment is a deferred-length
130135
allocatable and the right-hand side is a temporary, use of the runtime's
131136
`MoveAlloc()` subroutine instead can save an allocation and a copy.
132137

133-
#### Optimized concatenation
138+
### Optimized concatenation
134139

135140
Scalar `CHARACTER(KIND=1)` expressions evaluated as the right-hand sides of
136141
assignments to independent substrings or whole variables that are not

flang/docs/ControlFlowGraph.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
77
-->
88

9+
# Control Flow Graph
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
916
## Concept
1017
After a Fortran subprogram has been parsed, its names resolved, and all its
1118
semantic constraints successfully checked, the parse tree of its

flang/docs/Directives.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
77
-->
88

9-
Compiler directives supported by F18
10-
====================================
9+
# Compiler directives supported by Flang
10+
11+
A list of non-standard directives supported by Flang
1112

1213
* `!dir$ fixed` and `!dir$ free` select Fortran source forms. Their effect
1314
persists to the end of the current source file.

flang/docs/Extensions.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
77
-->
88

9+
# Fortran Extensions supported by Flang
10+
11+
```eval_rst
12+
.. contents::
13+
:local:
14+
```
15+
916
As a general principle, this compiler will accept by default and
1017
without complaint many legacy features, extensions to the standard
1118
language, and features that have been deleted from the standard,
@@ -16,8 +23,8 @@ Other non-standard features, which do conflict with the current
1623
standard specification of the Fortran programming language, are
1724
accepted if enabled by command-line options.
1825

19-
Intentional violations of the standard
20-
======================================
26+
## Intentional violations of the standard
27+
2128
* Scalar `INTEGER` actual argument expressions (not variables!)
2229
are converted to the kinds of scalar `INTEGER` dummy arguments
2330
when the interface is explicit and the kinds differ.
@@ -29,8 +36,8 @@ Intentional violations of the standard
2936
so long as they contain no executable code, no internal subprograms,
3037
and allocate no storage outside a named `COMMON` block. (C1415)
3138

32-
Extensions, deletions, and legacy features supported by default
33-
===============================================================
39+
## Extensions, deletions, and legacy features supported by default
40+
3441
* Tabs in source
3542
* `<>` as synonym for `.NE.` and `/=`
3643
* `$` and `@` as legal characters in names
@@ -123,8 +130,8 @@ Extensions, deletions, and legacy features supported by default
123130
* DATA statement initialization is allowed for procedure pointers outside
124131
structure constructors.
125132

126-
Extensions supported when enabled by options
127-
--------------------------------------------
133+
### Extensions supported when enabled by options
134+
128135
* C-style backslash escape sequences in quoted CHARACTER literals
129136
(but not Hollerith) [-fbackslash]
130137
* Logical abbreviations `.T.`, `.F.`, `.N.`, `.A.`, `.O.`, and `.X.`
@@ -145,8 +152,8 @@ Extensions supported when enabled by options
145152
* Ignore occurrences of `IMPLICIT NONE` and `IMPLICIT NONE(TYPE)`
146153
[-fimplicit-none-type-never]
147154

148-
Extensions and legacy features deliberately not supported
149-
---------------------------------------------------------
155+
### Extensions and legacy features deliberately not supported
156+
150157
* `.LG.` as synonym for `.NE.`
151158
* `REDIMENSION`
152159
* Allocatable `COMMON`
@@ -189,8 +196,8 @@ Extensions and legacy features deliberately not supported
189196
PGI, Intel, and XLF support this in ways that are not numerically equivalent.
190197
PGI converts the arguments while Intel and XLF replace the specific by the related generic.
191198

192-
Preprocessing behavior
193-
======================
199+
## Preprocessing behavior
200+
194201
* The preprocessor is always run, whatever the filename extension may be.
195202
* We respect Fortran comments in macro actual arguments (like GNU, Intel, NAG;
196203
unlike PGI and XLF) on the principle that macro calls should be treated

0 commit comments

Comments
 (0)