diff options
author | Peter Klausler <pklausler@nvidia.com> | 2022-03-23 14:05:50 -0700 |
---|---|---|
committer | Peter Klausler <pklausler@nvidia.com> | 2022-04-16 16:00:48 -0700 |
commit | cd03e96f00a8ab2489ae5af79375de2207f4e0ab (patch) | |
tree | 7ec29e507ad4ede017fbdbf35fdcabeb0ecb373d /flang/lib/Parser/tools.cpp | |
parent | c6fdb1de47bd5f26868838c37fa9e8cc1ac484bf (diff) | |
download | llvm-cd03e96f00a8ab2489ae5af79375de2207f4e0ab.zip llvm-cd03e96f00a8ab2489ae5af79375de2207f4e0ab.tar.gz llvm-cd03e96f00a8ab2489ae5af79375de2207f4e0ab.tar.bz2 |
[flang] Add & use a better visit() (take 2)
Adds flang/include/flang/Common/log2-visit.h, which defines
a Fortran::common::visit() template function that is a drop-in
replacement for std::visit(). Modifies most use sites in
the front-end and runtime to use common::visit().
The C++ standard mandates that std::visit() have O(1) execution
time, which forces implementations to build dispatch tables.
This new common::visit() is O(log2 N) in the number of alternatives
in a variant<>, but that N tends to be small and so this change
produces a fairly significant improvement in compiler build
memory requirements, a 5-10% improvement in compiler build time,
and a small improvement in compiler execution time.
Building with -DFLANG_USE_STD_VISIT causes common::visit()
to be an alias for std::visit().
Calls to common::visit() with multiple variant arguments
are referred to std::visit(), pending further work.
This change is enabled only for GCC builds with GCC >= 9;
an earlier attempt (D122441) ran into bugs in some versions of
clang and was reverted rather than simply disabled; and it is
not well tested with MSVC. In non-GCC and older GCC builds,
common::visit() is simply an alias for std::visit().
Diffstat (limited to 'flang/lib/Parser/tools.cpp')
-rw-r--r-- | flang/lib/Parser/tools.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/flang/lib/Parser/tools.cpp b/flang/lib/Parser/tools.cpp index 2db832a..899fb0f 100644 --- a/flang/lib/Parser/tools.cpp +++ b/flang/lib/Parser/tools.cpp @@ -17,7 +17,7 @@ const Name &GetLastName(const StructureComponent &x) { } const Name &GetLastName(const DataRef &x) { - return std::visit( + return common::visit( common::visitors{ [](const Name &name) -> const Name & { return name; }, [](const common::Indirection<StructureComponent> &sc) @@ -36,7 +36,7 @@ const Name &GetLastName(const Substring &x) { } const Name &GetLastName(const Designator &x) { - return std::visit( + return common::visit( [](const auto &y) -> const Name & { return GetLastName(y); }, x.u); } @@ -45,7 +45,7 @@ const Name &GetLastName(const ProcComponentRef &x) { } const Name &GetLastName(const ProcedureDesignator &x) { - return std::visit( + return common::visit( [](const auto &y) -> const Name & { return GetLastName(y); }, x.u); } @@ -56,7 +56,7 @@ const Name &GetLastName(const Call &x) { const Name &GetLastName(const FunctionReference &x) { return GetLastName(x.v); } const Name &GetLastName(const Variable &x) { - return std::visit( + return common::visit( [](const auto &indirection) -> const Name & { return GetLastName(indirection.value()); }, @@ -64,7 +64,7 @@ const Name &GetLastName(const Variable &x) { } const Name &GetLastName(const AllocateObject &x) { - return std::visit( + return common::visit( [](const auto &y) -> const Name & { return GetLastName(y); }, x.u); } @@ -75,7 +75,7 @@ const Name &GetFirstName(const StructureComponent &x) { } const Name &GetFirstName(const DataRef &x) { - return std::visit( + return common::visit( common::visitors{ [](const Name &name) -> const Name & { return name; }, [](const common::Indirection<StructureComponent> &sc) @@ -94,7 +94,7 @@ const Name &GetFirstName(const Substring &x) { } const Name &GetFirstName(const Designator &x) { - return std::visit( + return common::visit( [](const auto &y) -> const Name & { return GetFirstName(y); }, x.u); } @@ -103,7 +103,7 @@ const Name &GetFirstName(const ProcComponentRef &x) { } const Name &GetFirstName(const ProcedureDesignator &x) { - return std::visit( + return common::visit( [](const auto &y) -> const Name & { return GetFirstName(y); }, x.u); } @@ -116,7 +116,7 @@ const Name &GetFirstName(const FunctionReference &x) { } const Name &GetFirstName(const Variable &x) { - return std::visit( + return common::visit( [](const auto &indirect) -> const Name & { return GetFirstName(indirect.value()); }, @@ -124,7 +124,7 @@ const Name &GetFirstName(const Variable &x) { } const CoindexedNamedObject *GetCoindexedNamedObject(const DataRef &base) { - return std::visit( + return common::visit( common::visitors{ [](const Name &) -> const CoindexedNamedObject * { return nullptr; }, [](const common::Indirection<CoindexedNamedObject> &x) @@ -137,19 +137,19 @@ const CoindexedNamedObject *GetCoindexedNamedObject(const DataRef &base) { } const CoindexedNamedObject *GetCoindexedNamedObject( const Designator &designator) { - return std::visit(common::visitors{ - [](const DataRef &x) -> const CoindexedNamedObject * { - return GetCoindexedNamedObject(x); - }, - [](const Substring &x) -> const CoindexedNamedObject * { - return GetCoindexedNamedObject( - std::get<DataRef>(x.t)); - }, - }, + return common::visit( + common::visitors{ + [](const DataRef &x) -> const CoindexedNamedObject * { + return GetCoindexedNamedObject(x); + }, + [](const Substring &x) -> const CoindexedNamedObject * { + return GetCoindexedNamedObject(std::get<DataRef>(x.t)); + }, + }, designator.u); } const CoindexedNamedObject *GetCoindexedNamedObject(const Variable &variable) { - return std::visit( + return common::visit( common::visitors{ [](const common::Indirection<Designator> &designator) -> const CoindexedNamedObject * { @@ -161,7 +161,7 @@ const CoindexedNamedObject *GetCoindexedNamedObject(const Variable &variable) { } const CoindexedNamedObject *GetCoindexedNamedObject( const AllocateObject &allocateObject) { - return std::visit( + return common::visit( common::visitors{ [](const StructureComponent &x) -> const CoindexedNamedObject * { return GetCoindexedNamedObject(x.base); |