Commit Graph

4809 Commits

Author SHA1 Message Date
Kazu Hirata 7aa77c5a67 [flang] Fix a warning
This patch fixes:

  llvm-project/flang/lib/Semantics/expression.cpp:405:12: error:
  moving a local object in a return statement prevents copy elision
  [-Werror,-Wpessimizing-move]
2022-07-22 17:56:10 -07:00
Peter Klausler 60b1fcb1a5 [flang] Correct folding of TRANSFER(integer, character array)
The code that copies data from a constant source array into a character
array constant result was failing to copy its last element if it was
only partially defined due to misalignment.

Differential Revision: https://reviews.llvm.org/D130376
2022-07-22 17:28:08 -07:00
Peter Klausler e03664d40c [flang] Fix parsing and semantics for array element substring%KIND/%LEN
A type-param-inquiry of %KIND or %LEN applies to a designator, and
so must also be allowed for a substring.  F18 presently (mis)parses
instances of a type-param-inquiry as structure component references
and then fixes them in expression semantics when types are known and
we can distinguish them.  But when the base of a type-param-inquiry is
a substring of an array element, as in "charArray(i)(j:k)%len",
parsing fails.

Adjust the grammar to parse these cases, and extend expression semantics
to process the new production.

Differential Revision: https://reviews.llvm.org/D130375
2022-07-22 16:54:46 -07:00
Peter Klausler c105d9b3d6 [flang] Admit trailing blanks when checking I/O specifiers
Fortran specifically allows character-valued I/O specifiers
to have trailing blanks, e.g. OPEN(666,STATUS='SCRATCH ').
The runtime I/O library already handles them, but the I/O
static checks in semantics do not.

Differential Revision: https://reviews.llvm.org/D130381
2022-07-22 16:21:32 -07:00
Peter Klausler 0b8377534e [flang] Fold SET_EXPONENT() and FRACTION()
Fold the intrinsic function SET_EXPONENT() and its special case,
FRACTION().

Differential Revision: https://reviews.llvm.org/D130378
2022-07-22 15:44:54 -07:00
Dylan Fleming 846439dd97 [Flang] Generate documentation for compiler flags
This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html

This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.

Note:
Some headings in the generated documentation will incorrectly
contain references to Clang, e.g.
"Flags controlling the behaviour of Clang during compilation"
This is because Options.td (Which is shared between both Clang and Flang)
contains hard-coded DocBrief sections. I couldn't find a non-intrusive way
to make this target-dependant, as such I've left this as is, and it will need revisiting later.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D129864
2022-07-22 17:05:04 +00:00
Slava Zakharin f5759add70 [flang] Try to lower math intrinsics to math operations first.
This commit changes how math intrinsics are lowered: we, first,
try to lower them into MLIR operations or libm calls via
mathOperations table and only then fallback to pgmath runtime calls.

The pgmath fallback is needed, because mathOperations does not
support all intrinsics that pgmath supports. The main purpose
of this change is to get rid of llvmIntrinsics table so that
we do not have to update both llvmIntrinsics and mathOperations
when adding new intrinsic support.

mathOperations lowering should phase out pgmath lowering, when
more operations are available (e.g. power operations being
added in D129809 and D129811; complex type operations from
Complex dialect).

Differential Revision: https://reviews.llvm.org/D130129
2022-07-22 09:04:44 -07:00
Slava Zakharin fa3c770438 [flang] Reduced CHECKs for transpose_opt.f90
This commit addresses concerns raised in D129497.

Differential Revision: https://reviews.llvm.org/D130300
2022-07-22 08:50:42 -07:00
Ivan Butygin 917e4519bc [mlir][arith] cmpi: move constant to the right side
Convert arith.cmpi to the canonical form with constants on the right side
to simplify further optimizations and open more opportunities for CSE.


Differential Revision: https://reviews.llvm.org/D129929
2022-07-22 12:39:17 +02:00
Tarun Prabhu 71ee3570f4 [flang] Lower F08 mask intrinsics
Lower F08 maskl and maskr intrinsics.

Differential Revision: https://reviews.llvm.org/D129296
2022-07-22 00:03:09 -06:00
Tarun Prabhu 72ac3e90da [flang] Lower F08 shift intrinsics
Lower F08 shift (shiftl, shiftr, shifta) and combined shift (dshiftl, dshiftr)
intrinsics. The combined shift intrinsics are implemented using the
definitions of shiftl and shiftr as described by the standard.

For non-conformant arguments to the shift intrinsics, the implementation tries
to replicate the behavior of other compilers if most of the other behave
consistently.

Differential Revision: https://reviews.llvm.org/D129316
2022-07-21 23:36:08 -06:00
Tarun Prabhu 2ab0aeaae2 [flang][NFC] Test folding F08 mask intrinsics
Test compile-time folding of F08 maskl and maskr intrinsics.

Differential Revision: https://reviews.llvm.org/D129663
2022-07-21 23:30:38 -06:00
Tarun Prabhu 3d85879bbf [flang][NFC] Test folding of F08 shift intrinsics
Test compile-time folding of F08 shift (shiftl, shiftr, shifta) and combined shift (dshiftl, dshiftr) intrinsics.

Differential Revision: https://reviews.llvm.org/D129696
2022-07-21 23:25:45 -06:00
Tarun Prabhu ccfee46bc7 [flang] Lower F08 bit population count intrinsics
Lower F08 bit population count intrinsics popcnt, poppar, leadz and trailz. popcnt, leadz and trailz are implemented using the corresponding MLIR math intrinsics. poppar is implemented in terms of popcnt.

Differential Revision: https://reviews.llvm.org/D129584
2022-07-21 23:09:05 -06:00
John Ericson 07b749800c [cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS
builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as
`CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when
downstream projects try to install there too this breaks because our
builds always install to fresh directories for isolation's sake.

Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the
other specially crafted `LLVM_CONFIG_*` variables substituted in
`llvm/cmake/modules/LLVMConfig.cmake.in`.

@beanz added it in d0e1c2a550 to fix a
dangling reference in `AddLLVM`, but I am suspicious of how this
variable doesn't follow the pattern.

Those other ones are carefully made to be build-time vs install-time
variables depending on which `LLVMConfig.cmake` is being generated, are
carefully made relative as appropriate, etc. etc. For my NixOS use-case
they are also fine because they are never used as downstream install
variables, only for reading not writing.

To avoid the problems I face, and restore symmetry, I deleted the
exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s.
`AddLLVM` now instead expects each project to define its own, and they
do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports
`LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in
the usual way, matching the other remaining exported variables.

For the `AddLLVM` changes, I tried to copy the existing pattern of
internal vs non-internal or for LLVM vs for downstream function/macro
names, but it would good to confirm I did that correctly.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D117977
2022-07-21 19:04:00 +00:00
Slava Zakharin 9c0acc42e8 [flang] Run algebraic simplification optimization pass.
Try 2 to merge 4fbd1d6c87.

Flang algebraic simplification pass will run algebraic simplification
rewrite patterns for Math/Complex/etc. dialects. It is enabled
under opt-for-speed optimization levels (i.e. for O1/O2/O3; Os/Oz will not
enable it).

With this change the FIR/MLIR optimization pipeline becomes affected
by the -O* optimization level switches. Until now these switches
only affected the middle-end and back-end.

Differential Revision: https://reviews.llvm.org/D130035
2022-07-21 11:43:39 -07:00
Tarun Prabhu b6fef08853 [flang] Lower F08 merge_bits intrinsic.
Lower F08 merge_bits intrinsic.

Differential Revision: https://reviews.llvm.org/D129779
2022-07-21 10:42:25 -06:00
Tarun Prabhu 9e16fb72dd [flang][NFC] Test folding of F08 merge_bits intrinsic.
Test compile-time folding of the F2008 merge_bits intrinsic.

Differential Revision: https://reviews.llvm.org/D129780
2022-07-21 10:30:51 -06:00
Andrzej Warzynski ce824078de Revert "[Flang] Generate documentation for compiler flags"
This reverts commit 396e944d82.

Failing bot: https://lab.llvm.org/buildbot/#/builders/89/builds/30096
2022-07-21 11:54:49 +00:00
Dylan Fleming 396e944d82 [Flang] Generate documentation for compiler flags
This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html

This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D129864
2022-07-21 11:33:19 +00:00
Andrzej Warzynski 7c49f56956 [flang][nfc] Add missing `REQUIRES: asserts` in tests
Tests that use `--mlir-pass-statistics-display=` from MLIR require the
following condition to hold: (extracted from LLVM's Statistics.h):
```
  #define LLVM_ENABLE_STATS 1
```
This is normally enforced with `REQUIRES: asserts`. This patch updates
relevant Flang tests accordingly.

For "Release" builds (with assertions disabled), the affected tests will
be failing without this change.

Differential Revision: https://reviews.llvm.org/D130185
2022-07-21 09:22:01 +00:00
Slava Zakharin 7434375666 Revert "[flang] Run algebraic simplification optimization pass."
This reverts commit 4fbd1d6c87.
2022-07-20 16:56:28 -07:00
Slava Zakharin 4fbd1d6c87 [flang] Run algebraic simplification optimization pass.
Flang algebraic simplification pass will run algebraic simplification
rewrite patterns for Math/Complex/etc. dialects. It is enabled
under opt-for-speed optimization levels (i.e. for O1/O2/O3; Os/Oz will not
enable it).

With this change the FIR/MLIR optimization pipeline becomes affected
by the -O* optimization level switches. Until now these switches
only affected the middle-end and back-end.

Differential Revision: https://reviews.llvm.org/D130035
2022-07-20 16:33:52 -07:00
Tarun Prabhu 8e48783dcb [flang][nfc] Test folding of bit-population count intrinsics
Test compile-time folding of the leadz, trailz, popcnt and poppar Fortran 2008 intrinsics.

Differential Revision: https://reviews.llvm.org/D129610
2022-07-20 11:34:02 -05:00
Kazu Hirata 993625be80 [flang] Use value instead of getValue (NFC)
Flang C++ Style Guide tells us to use x.value() when no presence test
is obviously protecting the reference.  Since assert can be disabled,
I don't count it as "protection" here.

Differential Revision: https://reviews.llvm.org/D130144
2022-07-20 08:56:23 -07:00
Andrzej Warzynski bbdf5c37e3 [flang][driver] Fix opt-level option parsing
This update makes sure that `flang-new -O2 -O0` will run at `-O0` rather
than `-O2`.

This bug was identified and originally fixed by Vyacheslav Zakharin in
https://reviews.llvm.org/D130035. I've extracted the fix into a separate
patch.

co-authored by: Vyacheslav Zakharin <vyacheslav.p.zakharin@intel.com>

Differential Revision: https://reviews.llvm.org/D130104
2022-07-20 11:14:29 +00:00
Kazu Hirata afb9d89ffc [flang] Use value instead of getValue (NFC)
Flang C++ Style Guide tells us to use x.value() when no presence test
is obviously protecting the reference.
2022-07-19 21:49:15 -07:00
Slava Zakharin fd4afa7a29 [flang] Support late math lowering for intrinsics from the llvm table.
mathOperations should now support all intrinsics that are handled
by the llvmIntrinsics table + `tan` lowered as Math dialect operation +
f128 flavor of abs.

I am going to flip the default to late math lowering after this change,
but still keep the fallback via pgmath. This will allow getting rid
of the llvmIntrinsics table and continue populating
only the mathOperations table, otherwise, updating both tables
seems to be inconvenient.

Differential Revision: https://reviews.llvm.org/D130048
2022-07-19 14:07:59 -07:00
Tarun Prabhu 7709f12ed0 Bitwise comparison intrinsics
This patch implements lowering for the F08 bitwise comparison intrinsics
(BGE, BGT, BLE and BLT).

This does not create any runtime functions since the functionality is
simple enough to carry out in IR.

The existing semantic check has been changed because it unconditionally
converted the arguments to the largest possible integer type. This
resulted in the argument with the smaller bit-size being sign-extended.
However, the standard requires the argument with the smaller bit-size to
be zero-extended.

Reviewed By: klausler, jeanPerier

Differential Revision: https://reviews.llvm.org/D127805
2022-07-19 16:41:04 +00:00
Daniil Dudkin ea1cdb58cc [flang][NFC] Drop `AbstractResultOptions` structure
`AbstractResultOptions` is obsolete structure because `newArg` is used
only in `ReturnOpConversion`.
This change removes this struct, making dependencies of conversions more
straight-forward.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D129485
2022-07-19 17:23:09 +03:00
serge-sans-paille 90af9b4111 [flang] Fix flang-to-external-fc --version
Substitution of @FLANG_VERSION@ wasn't correctly performed.

Differential Revision: https://reviews.llvm.org/D130074
2022-07-19 14:10:46 +02:00
Valentin Clement f372142740
[flang] Add dump-symbols option to bbc
Restore the `--dump-symbols` option in the `bbc`
tool.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D129850
2022-07-18 13:40:25 +02:00
Valentin Clement 048aaab194
[flang][openacc] Use TableGen to generate the clause parser
This patch introduce an automatic generation of the clause parser from the TableGen
information.

New information can be stored directly in the TableGen file:
- The different aliases that a clause support.
- prefix before a value.
- whether a prefix is optional or not.

Makes it easier to add new clauses and also avoid some error (`write` clause incorrect until now).

This patch is updating only the OpenACC part. A patch with a modification of the OpenMP clause parser will follow.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106968
2022-07-18 09:26:57 +02:00
Kazu Hirata 8b3ed1fa98 Remove redundant return statements (NFC)
Identified with readability-redundant-control-flow.
2022-07-17 15:37:46 -07:00
Kazu Hirata c715e2ff92 [flang] Use value_or (NFC) 2022-07-16 00:51:54 -07:00
Kazu Hirata 009ab1728d [flang] Use *X instead of X.getValue() (NFC)
Per Flang C++ Style Guide, this patch replaces X.getValue() with *X
where *X is protected by a presence test.
2022-07-16 00:24:02 -07:00
Nimish Mishra 58753dea15 [flang][OpenMP] Fix warning due to uninitialized pointer dereference during atomic update lowering
Reviewed By: kiranchandramohan, kazu

Differential Revision: https://reviews.llvm.org/D129914
2022-07-16 12:23:37 +05:30
Naje George 42129b66d7 [flang] Add semantics test for EVENT POST statement
Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D129515
2022-07-15 16:03:29 -07:00
Jonathon Penix a560eea8bb [Flang] Set constructExit for Where and Forall constructs
Evaluations for the Where and Forall constructs previously did
not have their constructExit field fixed up. This could lead to
falling through to subsequent case blocks in select case
statements if either a Where or Forall construct was the final part
of one case block. Setting the constructExit field results in the
proper branching behavior.

Fixes issue: https://github.com/llvm/llvm-project/issues/56500

Differential Revision: https://reviews.llvm.org/D129879

Change-Id: Ia868df12084520a935f087524e118bcdf47f6d7a
2022-07-15 12:34:28 -07:00
Katherine Rasmussen ebf3dbbe15 Revert "[flang] Add co_sum to the list of intrinsics and update test"
This reverts commit d2460d9008.

Reverting this commit because after pushing to main it caused
unexpected test failures.
2022-07-14 14:44:34 -07:00
Katherine Rasmussen d2460d9008 [flang] Add co_sum to the list of intrinsics and update test
Add the collective subroutine, co_sum, to the list of intrinsics.
In accordance with 16.9.50 and 16.9.137, add a check for and an
error if coindexed objects are being passed to certain arguments
in co_sum and in move_alloc. Add a semantics test to check that
this error is successfully caught in calls to move_alloc. Remove
the XFAIL directive, update the ERROR directives and add both
standard-conforming and non-standard conforming calls to the
semantics test for co_sum.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D114134
2022-07-14 13:49:38 -07:00
Nimish Mishra 7dc18a62e4 [flang][OpenMP] Added semantic checks for hint clause
This patch improves semantic checks for hint clause.
It checks "hint-expression is a constant expression
that evaluates to a scalar value with kind
`omp_sync_hint_kind` and a value that is a valid
synchronization hint."

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D127615
2022-07-14 18:24:57 +05:30
Nimish Mishra a56b76d9ca [flang][OpenMP] Lowering support for atomic update construct
This patch adds lowering support for atomic update construct. A region
is associated with every `omp.atomic.update` operation wherein resides:
(1) the evaluation of the expression on the RHS of the atomic assignment
statement, and (2) a `omp.yield` operation that yields the extended value
of expression evaluated in (1).

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D125668
2022-07-14 18:22:12 +05:30
Peter Klausler b7f8314270 [flang] Avoid crash from forward referenced derived type
Fortran permits forward references to derived types in contexts that don't
require knowledge of the derived type definition for semantic analysis,
such as in the declaration of a pointer or allocatable variable or component.
But when the forward-referenced derived type is used later for a component
reference, it is possible for the DerivedTypeSpec in he base variable or component
declaration to still have a null scope pointer even if the type has been defined,
since DerivedTypeSpec and TypeSpec objects are created in scopes of use
rather than in scopes of definition.  The fix is to call
DerivedTypeSpec::Instantiate() in the name resolution of each component
name so that the scope gets filled in if it is still null.

Differential Revision: https://reviews.llvm.org/D129681
2022-07-13 16:58:26 -07:00
Peter Klausler be68a6adfb [flang] Error detection/avoidance for TRANSFER with empty MOLD= type
When MOLD= is an array and there is no SIZE= in a call to TRANSFER(),
the size of an element of the MOLD= is used as the denominator in a
division to establish the extent of the vector result.  When the
total storage size of the SOURCE= is known to be zero, the result is
empty and no division is needed.

To avoid a division by zero at runtime, we need to check for a zero-sized
MOLD= element type when the storage size of SOURCE= is nonzero and there
is no SIZE=.  Further, in the compilation-time rewriting of calls to
SHAPE(TRANSFER(...)) and SIZE(TRANSFER(...)) for constant folding and
simplification purposes, we can't replace the call with an arithmetic
element count expression when the storage size of SOURCE= is not known
to be zero and the element size of MOLD= is not known to be nonzero at
compilation time.

These changes mostly affect tests using a MOLD= argument that is an
assumed-length character.

Differential Revision: https://reviews.llvm.org/D129680
2022-07-13 16:50:57 -07:00
Peter Klausler cb193931fa [flang][runtime] Complete list-directed character input with DECIMAL='COMMA'
Most of the infrastructure for DECIMAL='COMMA' mode was in place
in the I/O runtime support library, but I dropped the ball for
list-directed character input, which has its own detection of
input separators.  Finish the job.

Differential Revision: https://reviews.llvm.org/D129679
2022-07-13 16:37:44 -07:00
Peter Klausler 0406c0cda6 [flang] Ensure name resolution visits "=>NULL()" in entity-decl
Most modern Fortran programs declare procedure pointers with a
procedure-declaration-stmt, but it's also possible to declare one
with a type-declaration-stmt with a POINTER attribute.  In this
case, e.g. "real, external, pointer :: p => null()" the initializer
is required to be a null-init.  The parse tree traversal in name
resolution would visit the null-init if the symbol were an object
pointer only, leading to a crash in the case of a procedure pointer.

That explanation of the bug is longer than the fix.  In short,
ensure that a null-init in an entity-decl is visited for both
species of pointers.

Differential Revision: https://reviews.llvm.org/D129676
2022-07-13 16:36:25 -07:00
Peter Klausler 1a65d09dcf [flang][runtime] Keep frame buffer in sync with file when truncating
When the I/O runtime is truncating an external file due to an
implied ENDFILE or explicit ENDFILE, ensure that the unit's frame
buffer for the file discards any data that have become obsolete.

This bug caused trouble with ACCESS='STREAM' I/O using POS= on
a WRITE, but it may have not been limited to that scenario.

Differential Revision: https://reviews.llvm.org/D129673
2022-07-13 16:12:12 -07:00
Peter Klausler faffcc3a46 [flang][runtime] Refine list-directed REAL(2) output
The rule used by list-directed REAL output editing to select
between Ew.d and Fw.d output editing breaks down for 16-bit
floating-point data, since the number of significant decimal
digits is so low that Ew,d output editing is nearly always selected.
Cap the test so that five-digit values will be output with Fw.d
editing.

Differential Revision: https://reviews.llvm.org/D129672
2022-07-13 16:10:46 -07:00
Peter Klausler ae93d8ea42 [flang] Fold TRANSFER()
Fold usage of the raw data reinterpretation intrinsic function TRANSFER().

Differential Revision: https://reviews.llvm.org/D129671
2022-07-13 15:34:48 -07:00