[flang] Add & use a better visit() (take 2)
authorPeter Klausler <pklausler@nvidia.com>
Wed, 23 Mar 2022 21:05:50 +0000 (14:05 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Sat, 16 Apr 2022 23:00:48 +0000 (16:00 -0700)
commitcd03e96f00a8ab2489ae5af79375de2207f4e0ab
tree7ec29e507ad4ede017fbdbf35fdcabeb0ecb373d
parentc6fdb1de47bd5f26868838c37fa9e8cc1ac484bf
[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().
62 files changed:
flang/include/flang/Common/idioms.h
flang/include/flang/Common/template.h
flang/include/flang/Common/unwrap.h
flang/include/flang/Common/visit.h [new file with mode: 0644]
flang/include/flang/Evaluate/expression.h
flang/include/flang/Evaluate/fold-designator.h
flang/include/flang/Evaluate/initial-image.h
flang/include/flang/Evaluate/shape.h
flang/include/flang/Evaluate/tools.h
flang/include/flang/Evaluate/traverse.h
flang/include/flang/Parser/parse-tree-visitor.h
flang/include/flang/Parser/tools.h
flang/include/flang/Semantics/expression.h
flang/include/flang/Semantics/symbol.h
flang/include/flang/Semantics/tools.h
flang/lib/Evaluate/call.cpp
flang/lib/Evaluate/characteristics.cpp
flang/lib/Evaluate/check-expression.cpp
flang/lib/Evaluate/expression.cpp
flang/lib/Evaluate/fold-designator.cpp
flang/lib/Evaluate/fold-implementation.h
flang/lib/Evaluate/fold-integer.cpp
flang/lib/Evaluate/fold-logical.cpp
flang/lib/Evaluate/fold-real.cpp
flang/lib/Evaluate/fold.cpp
flang/lib/Evaluate/formatting.cpp
flang/lib/Evaluate/shape.cpp
flang/lib/Evaluate/tools.cpp
flang/lib/Evaluate/type.cpp
flang/lib/Evaluate/variable.cpp
flang/lib/Parser/message.cpp
flang/lib/Parser/parse-tree.cpp
flang/lib/Parser/provenance.cpp
flang/lib/Parser/tools.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/canonicalize-do.cpp
flang/lib/Semantics/check-allocate.cpp
flang/lib/Semantics/check-call.cpp
flang/lib/Semantics/check-case.cpp
flang/lib/Semantics/check-data.cpp
flang/lib/Semantics/check-deallocate.cpp
flang/lib/Semantics/check-declarations.cpp
flang/lib/Semantics/check-do-forall.cpp
flang/lib/Semantics/check-io.cpp
flang/lib/Semantics/check-nullify.cpp
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-select-rank.cpp
flang/lib/Semantics/check-select-type.cpp
flang/lib/Semantics/data-to-inits.cpp
flang/lib/Semantics/expression.cpp
flang/lib/Semantics/mod-file.cpp
flang/lib/Semantics/pointer-assignment.cpp
flang/lib/Semantics/program-tree.cpp
flang/lib/Semantics/resolve-directives.cpp
flang/lib/Semantics/resolve-names-utils.cpp
flang/lib/Semantics/resolve-names.cpp
flang/lib/Semantics/rewrite-parse-tree.cpp
flang/lib/Semantics/runtime-type-info.cpp
flang/lib/Semantics/symbol.cpp
flang/lib/Semantics/tools.cpp
flang/runtime/io-stmt.cpp
flang/runtime/io-stmt.h