Commit graph

933 commits

Author SHA1 Message Date
Shraiysh Vaishay f2b7f18e63 Revert "[flang][OpenMP] Lowering support for default clause"
This reverts commit 05e6fce84f.
2022-07-26 19:18:27 +05:30
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
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
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
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
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
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
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
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
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 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 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 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
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
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
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
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
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
Peter Klausler 62d874f203 [flang] Refine semantic checks for procedure pointer assignment
Some procedure pointers and EXTERNAL procedures have neither
explicit interfaces nor result types; these procedures are obviously
not known to be functions, but they could be, so semantics must not
assume that they are necessarily subroutines.  Refine the procedure
pointer / dummy procedure compatibility check to handle these more
ambiguous cases and not elicit inappropriate error messages.

Differential Revision: https://reviews.llvm.org/D129674
2022-07-13 14:56:50 -07:00
Kazu Hirata c82fb16f58 [flang] Use has_value instead of hasValue (NFC)
This patch replaces hasValue with has_value in an effort to deprecate
Optional<X>::hasValue.

Differential Revision: https://reviews.llvm.org/D129458
2022-07-11 20:41:12 -07:00
Kazu Hirata 86b8c1d9c4 [flang] Don't use Optional::hasValue (NFC)
Flang C++ Style Guide tells us to avoid .has_value() in the predicate
expressions of control flow statements.  I am treating ternary
expressions as control flow statements for the purpose of this patch.

Differential Revision: https://reviews.llvm.org/D128622
2022-07-10 15:01:06 -07:00
Slava Zakharin 73026a4fbf [flang] Changed lowering for allocatable assignment to make array-value-copy correct.
Array-value-copy fails to generate a temporary array for case like this:
subroutine bug(b)
  real, allocatable :: b(:)
  b = b(2:1:-1)
end subroutine

Since LHS may need to be reallocated, lowering produces the following FIR:
%rhs_load = fir.array_load %b %slice

%lhs_mem = fir.if %b_is_allocated_with_right_shape {
   fir.result %b
} else {
   %new_storage = fir.allocmem %rhs_shape
   fir.result %new_storage
}

%lhs = fir.array_load %lhs_mem
%loop = fir.do_loop {
 ....
}
fir.array_merge_store %lhs, %loop to %lhs_mem
// deallocate old storage if reallocation occured,
// and update b descriptor if needed.

Since %b in array_load and %lhs_mem in array_merge_store are not the same SSA
values, array-value-copy does not detect the conflict and does not produce
a temporary array. This causes incorrect result in runtime.

The suggested change in lowering is to generate this:
%rhs_load = fir.array_load %b %slice
%lhs_mem = fir.if %b_is_allocated_with_right_shape {
   %lhs = fir.array_load %b
   %loop = fir.do_loop {
      ....
   }
   fir.array_merge_store %lhs, %loop to %b
   fir.result %b
} else {
   %new_storage = fir.allocmem %rhs_shape
   %lhs = fir.array_load %new_storage
   %loop = fir.do_loop {
      ....
   }
   fir.array_merge_store %lhs, %loop to %new_storage
   fir.result %new_storage
}
// deallocate old storage if reallocation occured,
// and update b descriptor if needed.

Note that there are actually 3 branches in FIR, so the assignment loops
are currently produced in three copies, which is a code-size issue.
It is possible to generate just two branches with two copies of the loops,
but it is not addressed in this change-set.

Differential Revision: https://reviews.llvm.org/D129314
2022-07-08 09:41:34 -07:00
Valentin Clement 015834e455
[flang][openacc][NFC] Extract device_type parser to its own
Move the device_type parser to a separate parser AccDeviceTypeExprList. Preparatory work for D106968.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106967
2022-07-08 16:02:04 +02:00
Valentin Clement 53804e426d
[flang][NFC] Make LEN parameters homogenous
This patch is part of the upstreaming effort from fir-dev branch.
This is the last patch for the upstreaming effort.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-07-07 18:29:28 +02:00
Peter Klausler 6052025b58 [flang] Add IsElementalProcedure() predicate
Replace most tests of the explicit Attr::ELEMENTAL symbol flag with
a new predicate IsElementalProcedure() that works correctly for alternate
ENTRY points and does the right thing for procedure interfaces that
reference elemental intrinsic functions like SIN() whose elemental
nature does not propagate.

Differential Revision: https://reviews.llvm.org/D129022
2022-07-06 18:08:45 -07:00
Peter Klausler 23c2bedfd9 [flang] Establish a single source of target information for semantics
Create a TargetCharacteristics class to centralize the few items of
target specific information that are relevant to semantics.  Use the
new class for all target queries, including derived type component layout
modeling.

Future work will initialize this class with target information
provided or forwarded by the drivers, and use it to fold layout-dependent
intrinsic functions like TRANSFER().

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

Updates: Attempts to work around build issues on Windows.
2022-07-06 10:25:34 -07:00
Peixin Qiao 13f9089ac9 [flang] Fix one corner case in reshape intrinsic
As Fortran 2018 16.9.163, the reshape is the only intrinsic which
requires the shape argument to be rank-one integer array and the SIZE
of it to be one constant expression. The current expression lowering
converts the shape expression with slice in intrinsic into one box value
with the box element type of unknown extent. However, the genReshape
requires the box element type to be constant size. So, convert the box
value into one with box element type of sequence of 1 x constant. This
corner case is found in cam4 in SPEC 2017
https://github.com/llvm/llvm-project/issues/56140.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D128597
2022-06-30 23:52:44 +08:00
Valentin Clement 1e55ec6666
[flang] SELECT CASE constructs with character selectors that require a temp
Here is a character SELECT CASE construct that requires a temp to hold the
result of the TRIM intrinsic call:

```
module m
      character(len=6) :: s
    contains
      subroutine sc
        n = 0
        if (lge(s,'00')) then
          select case(trim(s))
          case('11')
             n = 1
          case default
             continue
          case('22')
             n = 2
          case('33')
             n = 3
          case('44':'55','66':'77','88':)
             n = 4
          end select
        end if
        print*, n
      end subroutine
    end module m
```

This SELECT CASE construct is implemented as an IF/ELSE-IF/ELSE comparison
sequence.  The temp must be retained until some comparison is successful.
At that point the temp may be freed.  Generalize statement context processing
to allow multiple finalize calls to do this, such that the program always
executes exactly one freemem call.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: klausler, vdonaldson

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-06-30 09:04:27 +02:00
Valentin Clement be80c6d1b1
[flang][NFC] Cosmetic changes to make the file more homogenous
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D128799
2022-06-29 14:21:19 +02:00
Valentin Clement 7c65e62a51
[flang] Switch attr name to bindc_name
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-29 14:20:35 +02:00
Valentin Clement feb44ccc91
[flang][NFC] Fix some typos 2022-06-29 12:35:58 +02:00
Slava Zakharin 9f35657983 [flang] Lower Fortran math intrinsic operations into MLIR ops or libm calls.
Added new -lower-math-early option that defaults to 'true' that matches
the current math lowering scheme. If set to 'false', the intrinsic math
operations will be lowered to MLIR operations, which should potentially
enable more MLIR optimizations, or libm calls, if there is no corresponding
MLIR operation exists or if "precise" mode is requested.
The generated math MLIR operations are then converted to LLVM dialect
during codegen phase.

The -lower-math-early option is not exposed to users currently. I plan to
get rid of the "early" lowering completely, when "late" lowering
is robust enough to support all math intrinsics that are currently
supported via pgmath. So "late" mode will become default and -lower-math-early
option will not be needed. This will effectively eliminate the mandatory
dependency on pgmath in Fortran lowering, but this is WIP.

Differential Revision: https://reviews.llvm.org/D128385
2022-06-28 13:32:19 -07:00
Valentin Clement e2f313df8f
[flang] Make sure that conversions are applied in FORALL degenerate contexts
For the rapid triage push, just add a TODO for the degenerate POINTER
assignment case. The LHD ought to be a variable of type !fir.box, but it
is currently returning a shadow variable for the raw data pointer. More
investigation is needed there.
Make sure that conversions are applied in FORALL degenerate contexts.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-28 15:24:55 +02:00
Andrzej Warzynski 869385b11c [flang][driver] Add support for -O{0|1|2|3}
This patch adds support for most common optimisation compiler flags:
`-O{0|1|2|3}`. This is implemented in both the compiler and frontend
drivers. At this point, these options are only used to configure the
LLVM optimisation pipelines (aka middle-end). LLVM backend or MLIR/FIR
optimisations are not supported yet.

Previously, the middle-end pass manager was only required when
generating LLVM bitcode (i.e. for `flang-new -c -emit-llvm <file>` or
`flang-new -fc1 -emit-llvm-bc <file>`). With this change, it becomes
required for all frontend actions that are represented as
`CodeGenAction` and `CodeGenAction::executeAction` is refactored
accordingly (in the spirit of better code re-use).

Additionally, the `-fdebug-pass-manager` option is enabled to facilitate
testing. This flag can be used to configure the pass manager to print
the middle-end passes that are being run. Similar option exists in Clang
and the semantics in Flang are identical. This option translates to
extra configuration when setting up the pass manager. This is
implemented in `CodeGenAction::runOptimizationPipeline`.

This patch also adds some bolier plate code to manage code-gen options
("code-gen" refers to generating machine code in LLVM in this context).
This was extracted from Clang. In Clang, it simplifies defining code-gen
options and enables option marshalling. In Flang, option marshalling is
not yet supported (we might do at some point), but being able to
auto-generate some code with macros is beneficial. This will become
particularly apparent when we start adding more options (at least in
Clang, the list of code-gen options is rather long).

Differential Revision: https://reviews.llvm.org/D128043
2022-06-27 10:06:14 +00:00
Kazu Hirata 3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3.
2022-06-25 11:56:50 -07:00
Kazu Hirata aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Kiran Chandramohan 703b1054e9 [Flang] enable fir.is_present and fir.absent with function types
Fortran dummy procedures and procedure pointer can be OPTIONAL, and
there is no technical reason to prevent fir.is_present and
fir.absent from accepting function types, so allow it and add test.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project. This patch is
basically upstreaming the following PR.
https://github.com/flang-compiler/f18-llvm-project/pull/1568

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-06-24 08:46:14 +00:00
Peixin-Qiao 27afb362b1 [flang][OpenMP] Initial support the lowering of copyin clause
This supports the lowering of copyin clause initially. The pointer,
allocatable, common block, polymorphic varaibles will be supported
later.

This also includes the following changes:

1. Resolve the COPYIN clause and make the entity as host associated.

2. Fix collectSymbolSet by adding one option to control collecting the
   symbol itself or ultimate symbol of it so that it can be used
   explicitly differentiate the host and associated variables in
   host-association.

3. Add one helper function `lookupOneLevelUpSymbol` to differentiate the
   usage of host and associated variables explicitly. The previous
   lowering of firstprivate depends on the order of
   `createHostAssociateVarClone` and `lookupSymbol` of host symbol. With
   this fix, this dependence is removed.

4. Reuse `copyHostAssociateVar` for copying operation of COPYIN clause.

Reviewed By: kiranchandramohan, NimishMishra

Differential Revision: https://reviews.llvm.org/D127468
2022-06-24 15:33:09 +08:00
Peter Klausler c078e464a0 [flang][runtime] FLUSH(bad or unconnected unit number) is an error
Some I/O control statements are no-ops when attempted on a bad or
unconnected UNIT=, but the standard says that FLUSH is an error
in that case.

Differential Revision: https://reviews.llvm.org/D128392
2022-06-23 11:08:53 -07:00
Peter Klausler b6fce8b92d [flang] Fix bogus errors from SIZE/SHAPE/UBOUND on assumed-shape
While it is indeed an error to use SIZE, SHAPE, or UBOUND on an
assumed-shape dummy argument without also supplying a DIM= argument
to the intrinsic function, it is *not* an error to use these intrinsic
functions on sections or expressions of such arrays.  Refine the test
used for the error message.

Differential Revision: https://reviews.llvm.org/D128391
2022-06-23 10:32:22 -07:00
Val Donaldson 124338dd80
[flang] Increase support for intrinsic module procedures
* Make Semantics test doconcurrent01.f90 an expected failure pending a fix
for a problem in recognizing a PURE prefix specifier for a specific procedure
that occurs in new intrinsic module source code,

* review update

* review update

* Increase support for intrinsic module procedures

The f18 standard defines 5 intrinsic modules that define varying numbers
of procedures, including several operators:

  2  iso_fortran_env
 55  ieee_arithmetic
 10  ieee_exceptions
  0  ieee_features
  6  iso_c_binding

There are existing fortran source files for each of these intrinsic modules.
This PR adds generic procedure declarations to these files for procedures
that do not already have them, together with associated specific procedure
declarations.  It also adds the capability of recognizing intrinsic module
procedures in lowering code, making it possible to use existing language
intrinsic code generation for intrinsic module procedures for both scalar
and elemental calls.  Code can then be generated for intrinsic module
procedures using existing options, including front end folding, direct
inlining, and calls to runtime support routines.  Detailed code generation
is provided for several procedures in this PR, with others left to future PRs.
Procedure calls that reach lowering and don't have detailed implementation
support will generate a "not yet implemented" message with a recognizable name.

The generic procedures in these modules may each have as many as 36 specific
procedures.  Most specific procedures are generated via macros that generate
type specific interface declarations.  These specific declarations provide
detailed argument information for each individual procedure call, similar
to what is done via other means for standard language intrinsics.  The
modules only provide interface declarations.  There are no procedure
definitions, again in keeping with how language intrinsics are processed.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier, PeteSteinfeld

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-06-23 18:03:48 +02:00
Kiran Chandramohan c995038c27 [Flang] Call the CSE pass in the pass pipeline
During the upstreaming process, it was decided to move contents
of the FIR CSE pass to the MLIR pass. Most of the FIR CSE changes
that are used are already moved to the MLIR pass. This patch calls
the MLIR CSE pass in places where the FIR CSE pass is called in the
pass pipeline.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.

Reviewed By: awarzynski, clementval

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2022-06-23 11:04:39 +00:00
Peixin Qiao 430841605d [flang][Driver] Refine _when_ driver diagnostics are formatted
This patch refines //when// driver diagnostics are formatted so that
`flang-new` and `flang-new -fc1` behave consistently with `clang` and
`clang -cc1`, respectively. This change only applies to driver diagnostics.
Scanning, parsing and semantic diagnostics are separate and not covered here.

**NEW BEHAVIOUR**
To illustrate the new behaviour, consider the following input file:
```! file.f90
program m
  integer :: i = k
end
```
In the following invocations, "error: Semantic errors in file.f90" _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
$ flang-new -fc1 -fcolor-diagnostics file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
```

However, in the following invocations, "error: Semantic errors in file.f90"
_will not be_ formatted:
```
$ flang-new -fno-color-diagnostics file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
$ flang-new -fc1 file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
```

Before this change, none of the above would be formatted. Note also that the
default behaviour in `flang-new` is different to `flang-new -fc1` (this is
consistent with Clang).

**NOTES ON IMPLEMENTATION**
Note that the diagnostic options are parsed in `createAndPopulateDiagOpt`s in
driver.cpp. That's where the driver's `DiagnosticEngine` options are set. Like
most command-line compiler driver options, these flags are "claimed" in
Flang.cpp (i.e.  when creating a frontend driver invocation) by calling
`getLastArg` rather than in driver.cpp.

In Clang's Options.td, `defm color_diagnostics` is replaced with two separate
definitions: `def fcolor_diagnostics` and def fno_color_diagnostics`. That's
because originally `color_diagnostics` derived from `OptInCC1FFlag`, which is a
multiclass for opt-in options in CC1. In order to preserve the current
behaviour in `clang -cc1` (i.e. to keep `-fno-color-diagnostics` unavailable in
`clang -cc1`) and to implement similar behaviour in `flang-new -fc1`, we can't
re-use `OptInCC1FFlag`.

Formatting is only available in consoles that support it and will normally mean that
the message is printed in bold + color.

Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>

Reviewed By: rovka

Differential Revision: https://reviews.llvm.org/D126164
2022-06-22 23:56:34 +08:00
Valentin Clement c67a87444f
[flang] Add more diagnostics to fir.coordinate_of
Add more diagnostics to fir.coordinate_of to provide better checking
that the IR is sane.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-21 20:43:22 +02:00
Kazu Hirata ed8fceaa09 Don't use Optional::getValue (NFC) 2022-06-20 23:35:53 -07:00
Kazu Hirata 064a08cd95 Don't use Optional::hasValue (NFC) 2022-06-20 20:05:16 -07:00
Kazu Hirata 5413bf1bac Don't use Optional::hasValue (NFC) 2022-06-20 11:33:56 -07:00