Skip to content

Commit 780cea1

Browse files
committed
Relaced UnknownDetails with MiscDetails
1 parent 3aa4ab2 commit 780cea1

File tree

149 files changed

+8460
-5297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+8460
-5297
lines changed

clang-tools-extra/docs/doxygen.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ CHM_FILE =
12301230
HHC_LOCATION =
12311231

12321232
# The GENERATE_CHI flag controls if a separate .chi index file is generated (
1233-
# YES) or that it should be included in the master .chm file ( NO).
1233+
# YES) or that it should be included in the main .chm file ( NO).
12341234
# The default value is: NO.
12351235
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
12361236

clang/docs/doxygen.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ CHM_FILE =
12191219
HHC_LOCATION =
12201220

12211221
# The GENERATE_CHI flag controls if a separate .chi index file is generated (
1222-
# YES) or that it should be included in the master .chm file ( NO).
1222+
# YES) or that it should be included in the main .chm file ( NO).
12231223
# The default value is: NO.
12241224
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
12251225

flang/docs/FlangDriver.md

Lines changed: 97 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,107 @@
1313
:local:
1414
```
1515

16+
17+
> **_NOTE:_** This document assumes that Flang's drivers can already generate code and
18+
> produce executables. However, this is still work-in-progress. By making this
19+
> assumption, we are able to prepare this document ahead-of-time and to provide
20+
> an overview of the design that we are working towards.
21+
1622
There are two main drivers in Flang:
1723
* the compiler driver, `flang-new`
1824
* the frontend driver, `flang-new -fc1`
1925

20-
The compiler driver will allow you to control all compilation phases (i.e.
21-
preprocessing, frontend code-generation, middlend/backend code-optimisation and
22-
lowering, linking). For frontend specific tasks, the compiler driver creates a
23-
Fortran compilation job and delegates it to `flang-new -fc1`, the frontend driver.
26+
> **_NOTE:_** The diagrams in this document refer to `flang` as opposed to
27+
> `flang-new`. This is because the diagrams reflect the final design that we
28+
> are still working towards. See the note on [the flang script](https://github.com/llvm/llvm-project/blob/main/flang/docs/FlangDriver.md#the-flang-script)
29+
> below for more context.
30+
31+
The **compiler driver** will allow you to control all compilation phases (e.g.
32+
preprocessing, semantic checks, code-generation, code-optimisation, lowering
33+
and linking). For frontend specific tasks, the compiler driver creates a
34+
Fortran compilation job and delegates it to `flang-new -fc1`, the frontend
35+
driver. For linking, it creates a linker job and calls an external linker (e.g.
36+
LLVM's [`lld`](https://lld.llvm.org/)). It can also call other tools such as
37+
external assemblers (e.g. [`as`](https://www.gnu.org/software/binutils/)). In
38+
Clang, the compiler driver can also link the generated binaries with LLVM's
39+
static analysis/sanitizer libraries (e.g.
40+
[MemorySanitizer](https://clang.llvm.org/docs/MemorySanitizer.html)). This is
41+
not yet available in Flang, but will be relatively easy to support once such
42+
libraries become available. Flang's compiler driver is intended for Flang's
43+
end-users - its interface needs to remain stable. Otherwise, Flang's users will
44+
have to adjust their build scripts every time a compiler flag is changed.
45+
46+
| ![Compiler Driver](compiler_driver.png) |
47+
|:--:|
48+
| *Flang’s compiler driver and the **tools** that it runs* |
49+
50+
The **frontend driver** glues together and drives all of the Flang's frontend
51+
libraries. As such, it provides an easy-to-use and intuitive interface to the
52+
frontend. It uses MLIR and LLVM for code-generation and can be viewed as a
53+
driver for Flang, LLVM and MLIR libraries. Contrary to the compiler driver, it
54+
is not capable of calling any external tools (including linkers). It is aware
55+
of all the frontend internals that are "hidden" from the compiler driver. It
56+
accepts many frontend-specific options not available in `flang-new` and as such
57+
it provides a finer control over the frontend. Note that this tool is mostly
58+
intended for Flang developers. In particular, there are no guarantees about the
59+
stability of its interface and compiler developers can use it to experiment
60+
with new flags.
61+
62+
| ![Frontend Driver](frontend_driver.png) |
63+
|:-:|
64+
| *Flang's frontend driver and the **libraries** that it drives* |
65+
66+
Note that similarly to `-Xclang` in `clang`, you can use `-Xflang` to forward a
67+
frontend specific flag from the _compiler_ directly to the _frontend_ driver,
68+
e.g.:
69+
70+
```lang=bash
71+
flang-new -Xflang -fdebug-dump-parse-tree input.f95
72+
```
2473

25-
The frontend driver glues all of the frontend libraries together and provides
26-
an easy-to-use and intuitive interface to the frontend. It accepts many
27-
frontend-specific options not available in `flang-new` and as such it provides a
28-
finer control over the frontend. Similarly to `-Xclang` in `clang`, you can use
29-
`-Xflang` to forward the frontend specific flags from the compiler directly to
30-
the frontend driver.
74+
In the invocation above, `-fdebug-dump-parse-tree` is forwarded to `flang-new
75+
-fc1`. Without the forwarding flag, `-Xflang`, you would see the following
76+
warning:
3177

32-
## Compiler Driver
78+
```lang=bash
79+
flang-new: warning: argument unused during compilation:
80+
```
81+
82+
As `-fdebug-dump-parse-tree` is only supported by `flang-new -fc1`, `flang-new`
83+
will ignore it when used without `Xflang`.
84+
85+
## Why Do We Need Two Drivers?
86+
As hinted above, `flang-new` and `flang-new -fc1` are two separate tools. The
87+
fact that these tools are accessed through one binary, `flang-new`, is just an
88+
implementation detail. Each tool has a separate list of options, albeit defined
89+
in the same file: `clang/include/clang/Driver/Options.td`.
90+
91+
The separation helps us split various tasks and allows us to implement more
92+
specialised tools. In particular, `flang-new` is not aware of various
93+
compilation phases within the frontend (e.g. scanning, parsing or semantic
94+
checks). It does not have to be. Conversely, the frontend driver, `flang-new
95+
-fc1`, needs not to be concerned with linkers or other external tools like
96+
assemblers. Nor does it need to know where to look for various systems
97+
libraries, which is usually OS and platform specific.
98+
99+
One helpful way of differentiating these tools is to keep in mind that:
100+
101+
* the compiler driver is an end-user tool
102+
* frontend driver is a compiler developer tool with many additional options,
103+
104+
Also, Since the compiler driver can call external tools, e.g. linkers, it can
105+
be used to generate **executables**. The frontend driver cannot call external
106+
tools and hence can only generate **object files**. A similar model is
107+
implemented in Clang (`clang` vs `clang -cc1` vs `clang -cc1as`), which is
108+
based on the [architecture of
109+
GCC](https://en.wikibooks.org/wiki/GNU_C_Compiler_Internals/GNU_C_Compiler_Architecture).
110+
In fact, Flang needs to adhere to this model in order to be able to re-use
111+
Clang's driver library. If you are more familiar with the [architecture of
112+
GFortran](https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gfortran/About-GNU-Fortran.html)
113+
than Clang, then `flang-new` corresponds to `gfortran` and `flang-new -fc1` to
114+
`f951`.
33115

116+
## Compiler Driver
34117
The main entry point for Flang's compiler driver is implemented in
35118
`flang/tools/flang-driver/driver.cpp`. Flang's compiler driver is implemented
36119
in terms of Clang's driver library, `clangDriver`. This approach allows us to:
@@ -92,9 +175,9 @@ You can read more on the design of `clangDriver` in Clang's [Driver Design &
92175
Internals](https://clang.llvm.org/docs/DriverInternals.html).
93176

94177
## Frontend Driver
95-
Flang's frontend driver is the main interface between end-users and the Flang
96-
frontend. The high-level design is similar to Clang's frontend driver, `clang
97-
-cc1` and consists of the following classes:
178+
Flang's frontend driver is the main interface between compiler developers and
179+
the Flang frontend. The high-level design is similar to Clang's frontend
180+
driver, `clang -cc1` and consists of the following classes:
98181
* `CompilerInstance`, which is a helper class that encapsulates and manages
99182
various objects that are always required by the frontend (e.g. `AllSources`,
100183
`AllCookedSources, `Parsing`, `CompilerInvocation`, etc.). In most cases

flang/docs/compiler_driver.png

143 KB
Loading

flang/docs/doxygen.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ CHM_FILE =
12221222
HHC_LOCATION =
12231223

12241224
# The GENERATE_CHI flag controls if a separate .chi index file is generated (
1225-
# YES) or that it should be included in the master .chm file ( NO).
1225+
# YES) or that it should be included in the main .chm file ( NO).
12261226
# The default value is: NO.
12271227
# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
12281228

flang/docs/frontend_driver.png

162 KB
Loading

flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.cpp

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ bool OpenMPCounterVisitor::Pre(const OpenMPConstruct &c) {
156156
ompWrapperStack.push_back(ow);
157157
return true;
158158
}
159-
bool OpenMPCounterVisitor::Pre(const OmpEndLoopDirective &c) { return true; }
160-
bool OpenMPCounterVisitor::Pre(const DoConstruct &) {
161-
loopLogRecordStack.push_back(curLoopLogRecord);
162-
return true;
163-
}
164159

165160
void OpenMPCounterVisitor::Post(const OpenMPDeclarativeConstruct &) {
166161
PostConstructsCommon();
@@ -178,27 +173,11 @@ void OpenMPCounterVisitor::PostConstructsCommon() {
178173
clauseStrings[curConstruct]};
179174
constructClauses.push_back(r);
180175

181-
// Keep track of loop log records if it can potentially have the
182-
// nowait clause added on later.
183-
if (const auto *oc = std::get_if<const OpenMPConstruct *>(curConstruct)) {
184-
if (const auto *olc = std::get_if<OpenMPLoopConstruct>(&(*oc)->u)) {
185-
const auto &beginLoopDir{
186-
std::get<Fortran::parser::OmpBeginLoopDirective>(olc->t)};
187-
const auto &beginDir{
188-
std::get<Fortran::parser::OmpLoopDirective>(beginLoopDir.t)};
189-
if (beginDir.v == llvm::omp::Directive::OMPD_do ||
190-
beginDir.v == llvm::omp::Directive::OMPD_do_simd) {
191-
curLoopLogRecord = &constructClauses.back();
192-
}
193-
}
194-
}
195-
196176
auto it = clauseStrings.find(curConstruct);
197177
clauseStrings.erase(it);
198178
ompWrapperStack.pop_back();
199179
delete curConstruct;
200180
}
201-
void OpenMPCounterVisitor::Post(const OmpEndLoopDirective &c) {}
202181

203182
void OpenMPCounterVisitor::Post(const OmpProcBindClause::Type &c) {
204183
clauseDetails += "type=" + OmpProcBindClause::EnumToString(c) + ";";
@@ -242,26 +221,9 @@ void OpenMPCounterVisitor::Post(const OmpClause &c) {
242221
clauseDetails.clear();
243222
}
244223
void OpenMPCounterVisitor::PostClauseCommon(const ClauseInfo &ci) {
245-
// The end loop construct (!$omp end do) can contain a nowait clause.
246-
// The flang parser does not parse the end loop construct as part of
247-
// the OpenMP construct for the loop construct. So the end loop is left
248-
// hanging as a separate executable construct. If a nowait clause is seen in
249-
// an end loop construct we have to find the associated loop construct and
250-
// add nowait to its list of clauses. Note: This is not a bug in flang, the
251-
// parse tree is corrected during semantic analysis.
252-
if (ci.clause == "nowait") {
253-
assert(curLoopLogRecord &&
254-
"loop Construct should be visited before a nowait clause");
255-
curLoopLogRecord->clauses.push_back(ci);
256-
} else {
257-
assert(!ompWrapperStack.empty() &&
258-
"Construct should be visited before clause");
259-
clauseStrings[ompWrapperStack.back()].push_back(ci);
260-
}
261-
}
262-
void OpenMPCounterVisitor::Post(const DoConstruct &) {
263-
curLoopLogRecord = loopLogRecordStack.back();
264-
loopLogRecordStack.pop_back();
224+
assert(
225+
!ompWrapperStack.empty() && "Construct should be visited before clause");
226+
clauseStrings[ompWrapperStack.back()].push_back(ci);
265227
}
266228
} // namespace parser
267229
} // namespace Fortran

flang/examples/flang-omp-report-plugin/flang-omp-report-visitor.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringRef.h"
1919

20-
#include <deque>
2120
#include <string>
2221

2322
namespace Fortran {
@@ -62,13 +61,10 @@ struct OpenMPCounterVisitor {
6261
template <typename A> void Post(const A &) {}
6362
bool Pre(const OpenMPDeclarativeConstruct &c);
6463
bool Pre(const OpenMPConstruct &c);
65-
bool Pre(const OmpEndLoopDirective &c);
66-
bool Pre(const DoConstruct &);
6764

6865
void Post(const OpenMPDeclarativeConstruct &);
6966
void Post(const OpenMPConstruct &);
7067
void PostConstructsCommon();
71-
void Post(const OmpEndLoopDirective &c);
7268

7369
void Post(const OmpProcBindClause::Type &c);
7470
void Post(const OmpDefaultClause::Type &c);
@@ -83,20 +79,9 @@ struct OpenMPCounterVisitor {
8379
void Post(const OmpCancelType::Type &c);
8480
void Post(const OmpClause &c);
8581
void PostClauseCommon(const ClauseInfo &ci);
86-
void Post(const DoConstruct &);
8782

8883
std::string clauseDetails{""};
89-
90-
// curLoopLogRecord and loopLogRecordStack store
91-
// pointers to this datastructure's entries. Hence a
92-
// vector cannot be used since pointers are invalidated
93-
// on resize. Next best option seems to be deque. Also a
94-
// list cannot be used since YAML gen requires a
95-
// datastructure which can be accessed through indices.
96-
std::deque<LogRecord> constructClauses;
97-
98-
LogRecord *curLoopLogRecord{nullptr};
99-
llvm::SmallVector<LogRecord *> loopLogRecordStack;
84+
llvm::SmallVector<LogRecord> constructClauses;
10085
llvm::SmallVector<OmpWrapperType *> ompWrapperStack;
10186
llvm::DenseMap<OmpWrapperType *, llvm::SmallVector<ClauseInfo>> clauseStrings;
10287
Parsing *parsing{nullptr};

flang/examples/flang-omp-report-plugin/flang-omp-report.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ namespace llvm {
3333
namespace yaml {
3434
using llvm::yaml::IO;
3535
using llvm::yaml::MappingTraits;
36-
template <typename T>
37-
struct SequenceTraits<std::deque<T>,
38-
std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
39-
: SequenceTraitsImpl<std::deque<T>, SequenceElementTraits<T>::flow> {};
4036
template <> struct MappingTraits<ClauseInfo> {
4137
static void mapping(IO &io, ClauseInfo &info) {
4238
io.mapRequired("clause", info.clause);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ruamel.yaml==0.17.16
2+
ruamel.yaml.clib==0.2.6

0 commit comments

Comments
 (0)