Commit Graph

4849 Commits

Author SHA1 Message Date
Kazu Hirata 5bc0e7b73c Convert for_each to range-based for loops (NFC) 2022-07-30 10:35:52 -07:00
Naje George 6ee9e25fd9 [flang] Add semantics test for EVENT WAIT statement
Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D130608
2022-07-29 17:14:04 -07:00
tlattner 520d29f381 Update references to mailing lists that have moved to Discourse. 2022-07-28 16:54:58 -07:00
V Donaldson 05b3c900c9 [flang] Fix build failure 2022-07-28 16:41:05 -07:00
Mats Petersson 7ae391148d [flang]Fix incorrect array type transformation
When an array is defined with "unknown" size, such as fir.array<2x?x5xi32>,
it should be converted to llvm.array<10 x i32>. The code so far has
been converting it to llvm.ptr<i32>.

Using a different function to check the if there starting are constant
dimensions, rather than if ALL dimensions are constant, it now produces
the correct array form.

Some tests has been updated, so they are now checking the new behaviour
rather than the old behaviour - so there's no need to add further tests
for this particular scenario.

This was originally found when compiling Spec 17 code, where an assert
in a GepOP was hit. That is bug #56141, which this change fixes.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D129196
2022-07-28 21:00:04 +01:00
Prabhdeep Singh Soni f5efa1892e [Flang][MLIR][OpenMP] Add support for simdlen clause
This supports lowering from parse-tree to MLIR and translation from
MLIR to LLVM IR using OMPIRBuilder for OpenMP simdlen clause in SIMD
construct.

Reviewed By: shraiysh, peixin, arnamoy10

Differential Revision: https://reviews.llvm.org/D130195
2022-07-28 23:49:17 +08:00
Prabhdeep Singh Soni 79a5ff45cb [Flang][Driver] Add support for AsmPrinter -mmlir options
This patch adds support for AsmPrinter  `-mmlir` options to the Flang driver.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D130598
2022-07-27 16:11:11 -04:00
Peixin Qiao 8df63a23d2 [flang] Support the color diagnostics on scanning, parsing, and semantics
The options -f{no-}color-diagnostics have been supported in driver. This
supports the behaviors in scanning, parsing, and semantics, and the
behaviors are exactly the same as the driver.

To illustrate the added behaviour, consider the following input file:
```! file.f90
program m
  integer :: i = k
end
```
In the following invocations, "error: Must be a constant value" _will be_
formatted:
```
$ flang-new file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
```
Note that "error: Semantic errors in file.f90" is also formatted, which
is supported in https://reviews.llvm.org/D126164.

Also note that only "error", "warning" and "portability" are formatted.
Check the following input file:
```! file2.f90
program m
  integer :: i =
end
```
```
$ flang-new test2.f90
error: Could not parse test2.f90
./test2.f90:2:11: error: expected '('
    integer :: i =
            ^
./test2.f90:2:3: in the context: statement function definition
    integer :: i =
    ^
...
```
The "error: Could not parse test2.f90" and "error: expected '('" are
formatted. Others such as "in the context" are not formatted yet, which
may or may not be supported.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D126166
2022-07-27 23:45:41 +08:00
Peixin Qiao 4640a8a22c [NFC][flang] Add FIXME for privatization of loop bounds in Bridge.cpp
There is post comment of adding TODO/FIXME for privatization of loop
bounds in D127137. D127137 fixes the bug in OpenMP firstprivate clause,
which should be refactored later according to the post comment. Add
FIXME for it.

Differential Revision: https://reviews.llvm.org/D130625
2022-07-27 23:37:55 +08:00
Peixin Qiao 7ac2500eb0 [NFC][flang] Remove the unused header in Bridge.cpp
The header file OpenMPDialect.h is added in Bridge.cpp in D130027,
but it is unused. Remove it.

Differential Revision: https://reviews.llvm.org/D130625
2022-07-27 23:20:13 +08:00
David Spickett 52a3855fe7 [flang] Disable pipefail for tests for stdin input
We have seen the llvm test fail every so often on our bots:
https://lab.llvm.org/buildbot/#/builders/173/builds/6711

This happens because `flang-new -fc1 -S` does not wait for the
pipe to finish being written to/does not read out all the content.
You can see this in the output, cat comes after flang:
+ /home/tcwg-buildbot/worker/flang-aarch64-release/build/bin/not /home/tcwg-buildbot/worker/flang-aarch64-release/build/bin/flang-new -fc1 -S - -o -
+ cat /home/tcwg-buildbot/worker/flang-aarch64-release/llvm-project/flang/test/Driver/input-from-stdin-llvm.ll
error: Invalid input type - expecting a Fortran file

This means that cat gets SIGPIPE which causes it to exit with
code 141 and that's the final result due to pipefail.

flang isn't wrong to exit early (I think some modes of grep also do this)
and we only care about flang's exit code. So disable pipefail for
the stdin testing.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D130619
2022-07-27 10:31:02 +00:00
Diana Picus eb7a02ea00 [flang] Single entry point for GET_COMMAND_ARGUMENT
This patch refactors the runtime support for GET_COMMAND_ARGUMENT to
have a single entry point instead of 2. It also updates lowering
accordingly.

This makes it easier to handle dynamically optional arguments. See also
https://reviews.llvm.org/D118777

Differential Revision: https://reviews.llvm.org/D130475
2022-07-27 10:27:25 +00:00
Daniil Dudkin fefa36a864 [flang][NFC] Unify check prefixes in `abstract-results.fir` test
Now the prefixes have the same length
and they'll be easier to distinguish when
`GlobalOp` tests will be added

Depends on D129778

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D130087
2022-07-27 11:57:51 +03:00
Daniil Dudkin cb33e4ab14 [flang] Generalize `AbstractResultOpt` pass
This change decouples common functionality for convering abstract
results, so it can be reused later.

Depends on D129485

Reviewed By: clementval, jeanPerier

Differential Revision: https://reviews.llvm.org/D129778
2022-07-27 11:55:17 +03:00
Shraiysh Vaishay f2b7f18e63 Revert "[flang][OpenMP] Lowering support for default clause"
This reverts commit 05e6fce84f.
2022-07-26 19:18:27 +05:30
Peixin Qiao 418d2338f9 [flang] Remove fp128 support for llvm.round and llvm.trunc
The fp128 in llvm.round and llvm.trunc is not supported in X86_64 for
now. Revert the support. To support quad precision for llvm.round and
llvm.trunc, it may should be supported using runtime.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D130556
2022-07-26 20:21:51 +08:00
Sebastian Neubauer ae222dae56 [CMake] Fix add_subdirectory llvm builds
Fixes a regression from D117973, that used CMAKE_BINARY_DIR instead of
LLVM_BINARY_DIR in some places.

Differential Revision: https://reviews.llvm.org/D130555
2022-07-26 11:24:23 +02:00
Nimish Mishra 05e6fce84f [flang][OpenMP] Lowering support for default clause
This patch adds lowering support for default clause.

1. During symbol resolution in semantics, should the enclosing context have
a default data sharing clause defined and a `parser::Name` is not attached
to an explicit data sharing clause, the
`semantics::Symbol::Flag::OmpPrivate` flag (in case of `default(private)`)
and `semantics::Symbol::Flag::OmpFirstprivate` flag (in case of
`default(firstprivate)`) is added to the symbol.

2. During lowering, all symbols having either
   `semantics::Symbol::Flag::OmpPrivate` or
   `semantics::Symbol::Flag::OmpFirstprivate` flag are collected and
   privatised appropriately.

Co-authored-by: Peixin Qiao <qiaopeixin@huawei.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D123930
2022-07-26 14:11:43 +05:30
Diana Picus 05a948e67d [flang] Rename variables in test. NFCI
Use pertinent names instead of numbered values, to make it easier to
update the test in future patches.

Differential Revision: https://reviews.llvm.org/D130474
2022-07-26 07:33:24 +00:00
Kazu Hirata 3356d72a5f [flang] Use value or * instead of getValue (NFC)
This patch replaces x.getValue() with *x if the reference is obviously
protected by a presence check.  Otherwise, it replaces x.getValue()
with x.value().
2022-07-25 23:01:01 -07:00
Kazu Hirata 2aab797d01 [flang] Remove unused variable lastPrivBlock (NFC)
This fixes the warning:

  llvm-project/flang/lib/Lower/OpenMP.cpp:94:10: error: unused
  variable 'lastPrivBlock' [-Werror,-Wunused-variable]
2022-07-25 20:52:22 -07:00
Arnamoy Bhattacharyya 17d9bdf460 [Flang][OpenMP] Add support for lastprivate clause for worksharing loop.
This patch adds an initial support to the lastprivate clause for worksharing loop.  The patch creates necessary control flow to guarantee the store of the value from the logical last iteration of the workshare loop.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D130027
2022-07-25 20:31:23 -04:00
John Ericson ac0d1d5c7b [cmake] Support custom package install paths
Firstly, we we make an additional GNUInstallDirs-style variable. With
NixOS, for example, this is crucial as we want those to go in
`${dev}/lib/cmake` not `${out}/lib/cmake` as that would a cmake subdir
of the "regular" libdir, which is installed even when no one needs to do
any development.

Secondly, we make *Config.cmake robust to absolute package install
paths. We for NixOS will in fact be passing them absolute paths to make
the `${dev}` vs `${out}` distinction mentioned above, and the
GNUInstallDirs-style variables are suposed to support absolute paths in
general so it's good practice besides the NixOS use-case.

Thirdly, we make `${project}_INSTALL_PACKAGE_DIR` CACHE PATHs like other
install dirs are.

Reviewed By: sebastian-ne

Differential Revision: https://reviews.llvm.org/D117973
2022-07-25 21:02:53 +00:00
Peter Klausler 95f4ca7f5d [flang] Allow restricted specific intrinsic functions as implicitly-interfaced procedure pointer targets
The predicate "CanBeCalledViaImplicitInterface()" was returning false for
restricted specific intrinsic functions (e.g., SIN) because their procedure
characteristics have the elemental attribute; this leads to a bogus semantic
error when one attempts to use them as proc-targets in procedure pointer
assignment statements when the left-hand side of the assignment is a procedure
pointer with an implicit interface.  However, these restricted specific intrinsic
functions have always been allowed as special cases for such usage -- it is
as if they are elemental when it is necessary for them to be so, but not
when it's a problem.

Differential Revision: https://reviews.llvm.org/D130386
2022-07-25 12:19:49 -07:00
Peter Klausler ae1d5f4d9d [flang][runtime] Reset unit frame buffer when re-opening
An OPEN statement that implies closing a connection must invalidate
the unit's frame buffer so as to prevent stale data from the old
connection from being read into the newly-connected unit.

Differential Revision: https://reviews.llvm.org/D130430
2022-07-25 12:18:14 -07:00
Kiran Chandramohan 7bb1151ba2 [Flang][OpenMP] Initial support for integer reduction in worksharing-loop
Lower the Flang parse-tree containing OpenMP reductions to the OpenMP
dialect. The OpenMP dialect models reductions with,
1) A reduction declaration operation that specifies how to initialize, combine,
and atomically combine private reduction variables.
2) The OpenMP operation (like wsloop) that supports reductions has an array of
reduction accumulator variables (operands) and an array attribute of the same
size that points to the reduction declaration to be used for the reduction
accumulation.
3) The OpenMP reduction operation that takes a value and an accumulator.
This operation replaces the original reduction operation in the source.

(1) is implemented by the `createReductionDecl` in OpenMP.cpp,
(2) is implemented while creating the OpenMP operation,
(3) is implemented by the `genOpenMPReduction` function in OpenMP.cpp, and
called from Bridge.cpp. The implementation of (3) is not very robust.

NOTE 1: The patch currently supports only reductions for integer type addition.
NOTE 2: Only supports reduction in the worksharing loop.
NOTE 3: Does not generate atomic combination region.
NOTE 4: Other options for creating the reduction operation include
a) having the reduction operation as a construct containing an assignment
and then handling it appropriately in the Bridge.
b) we can modify `genAssignment` or `genFIR(AssignmentStmt)` in the Bridge to
handle OpenMP reduction but so far we have tried not to mix OpenMP
and non-OpenMP code and this will break that.
I will try (b) in a separate patch.
NOTE 5: OpenMP dialect gained support for reduction with the patches:
D105358, D107343. See https://discourse.llvm.org/t/rfc-openmp-reduction-support/3367
for more details.

Reviewed By: awarzynski

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

Co-authored-by: Peixin-Qiao <qiaopeixin@huawei.com>
2022-07-25 18:47:07 +00:00
Peter Klausler 90c4eda3d2 [flang] Dial some errors down to warnings for ASSOCIATED()
When a procedure pointer is associated with a procedure target, f18
will emit hard error messages if the pointer is incompatible with the
target in a way that would cause the program to not work if the
procedure pointer were actually called.  However, in the context of
the ASSOCIATED() intrinsic, the compiler should not consider a query
to be a compilation-time error if the pointer and the target are
incompatible.  The standard gives us sufficient wiggle room here
to treat these cases as warnings.

Attempts to use ASSOCIATED to test whether a procedure pointer is
associated with a data object, or vice versa, remain errors.

Differential Revision: https://reviews.llvm.org/D130384
2022-07-25 11:06:30 -07:00
Jean Perier 244bd7cba7 [flang] Runs FIR SimplifyRegionLitePass pass after calling the inliner
In flang pipeline, the inliner calls createCanonicalizerPass with the region
simplification disabled. The inliner pass does canonicalization even if
no inlining happens. After canonicalization, FIR lite region simplification
must be called to get rid of unreachable regions.
This code exposes the need to run SimplifyRegionLitePass after the inliner is
called with FIR pipeline.

Differential Revision: https://reviews.llvm.org/D130484
2022-07-25 19:38:59 +02:00
Peter Klausler 85a40ce6dd [flang] Better error message for NULL() actual argument for dummy allocatable
f18 intentionally does not support the spottily-implemented language extension
in which one can pass NULL() for an allocatable dummy argument.  This is perhaps
a sanctioned side effect in other compilers of the fact that they pass distinct
"base address" and "descriptor address" physical arguments.

Make the error message in this case more specific to the circumstances, and
add a note to Extensions.md to clarify that this behavior is intended.

(We could, with some effort in lowering, support passing NULL for an INTENT(IN)
allocatable dummy, but let's see whether such nonconforming usage appears
in a real application before spending any more time on it.)

Differential Revision: https://reviews.llvm.org/D130380
2022-07-25 10:09:55 -07:00
Peixin Qiao f532c07211 [flang] Support intrinsic `selected_int_kind` for variables
As Fortran 2018 16.9.169, the argument of selected_int_kind is integer
scalar, and result is default integer scalar. The constant expression in
this intrinsic has been supported by folding the constant expression.
This supports lowering and runtime for variables in this intrinsic.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D129959
2022-07-26 00:33:27 +08:00
Andrzej Warzynski 640c0ad0d5 [flang][nfc] Add missing `REQUIRES: asserts` in a test
This change is required for release builds - see
https://reviews.llvm.org/D130185 for more context.

I'm sending this without a review as this is rather straightforward and
identical to the changes from https://reviews.llvm.org/D130185 (the test
updated in this patch wasn't yet in-tree when D130185 landed).
2022-07-25 16:30:21 +00:00
Peixin Qiao 57e3fa3815 [flang] Support lowering intrinsic `selected_real_kind` for variables
As Fortran 2018 16.9.170, the argument of `selected_real_kind` is integer
scalar, and result is default integer scalar. The constant expression in
this intrinsic has been supported by folding the constant expression.
This supports lowering this intrinsic for variables using runtime.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D130183
2022-07-25 19:36:14 +08:00
Kazu Hirata fac0fb4d96 [flang] Use X->foo() instead of X.getValue().foo() (NFC)
Flang C++ Style Guide tells us to use *X when the reference is
protected by a presense test.  However, (*X).foo() is a little harder
to read, especially when X is a complicated expression.

This patch slightly deviates from the guide (but retains the spirit)
by using X->foo() instead.

Differential Revision: https://reviews.llvm.org/D130413
2022-07-25 00:55:06 -07:00
Kazu Hirata a010d32abb [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 a failure in EXPECT_TRUE
doesn't terminate a given test, I don't count it as "protection" here.

Differential Revision: https://reviews.llvm.org/D130410
2022-07-25 00:55:05 -07:00
Peter Klausler a9782fead3 [flang] Correct IsHostAssociated() to be true for BLOCK constructs
The predicate IsHostAssocited() was implemented in a way that would
return true only for cases of host association into a module or inner
subprogram.  Technically, the use of a name in a BLOCK construct
that is not declared therein is considered in the Fortran standard
to also be a form of host association, and this matters when doing
error checking on DATA statements.

Differential Revision: https://reviews.llvm.org/D130388
2022-07-23 10:46:54 -07:00
Peter Klausler b09c890510 [flang] Clean up bogus semantic error on procedure pointer assignment
When a procedure pointer with no interface is associated with
an EXTERNAL name with no interface information, but it is later
inferred that the procedure pointer must be a subroutine because it
appears in a CALL statement, don't complain that the EXTERNAL name
is not also known to be a subroutine.

Subroutine vs. function errors are still caught in procedure pointer
assignment compatibility checking; this fix simply ensures that those
more nuanced tests are not overridded by the attribute set equality test.

Also, leave in some code for dumping the differing attributes in legitimate
error cases that was added in the coures of debugging the specific problem.

Differential Revision: https://reviews.llvm.org/D130385
2022-07-23 10:18:28 -07:00
Peter Klausler 3096b85696 [flang] Don't fold zero-length substring references
In some contexts the code looks cleaner if we fold zero-length substring
references into empty character constants, but those don't work in
variable definition contexts and can lead to bogus semantic error
messages.

Differential Revision: https://reviews.llvm.org/D130383
2022-07-23 10:08:09 -07:00
Peter Klausler cbfc223920 [flang] Fix name of dummy argument to intrinsic NEW_LINE(A='')
It should be A= but I misspelled it in the intrinsics table as X=.

Differential Revision: https://reviews.llvm.org/D130382
2022-07-23 09:30:56 -07:00
Peixin Qiao 3ccd4ce29c [flang] Support aint/anint for 80/128 bit in lowering
For aint/anint, LLVM conversion operations llvm.trunc and llvm.round
can support the edge case of aint(-0.) and anint(-0.). The output is -0.
and it is the same of `gfortran` and `classic flang`, while the output
of `ifort` is 0.. The `real(10)/real(16)` is not supported before.
Support it and remove the runtime functions for aint/anint.

For nint, `gfortran`, `ifort`, and LLVM Flang using llvm.lround have
different results when the magnitude of argument is more than the max of
result value range. So delay its support in lowering after more
investigations.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D130024
2022-07-23 14:44:20 +08:00
Peter Klausler baec06a9d4 [flang] Fold calls to ISHFTC()
The integer arithmetic template supports ISHFTC() but the
integer intrinsic folding code had yet to call it; finish
the job.

Differential Revision: https://reviews.llvm.org/D130379
2022-07-22 18:21:57 -07:00
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