Commit graph

4238 commits

Author SHA1 Message Date
Andrzej Warzynski 125a4d915e [flang] Remove deprecated fields from FIROps.td
This patch removes deprecated parser/printer/verifier fields from
FIROps.td. This is a follow-up of https://reviews.llvm.org/D119776 - it
takes care of operations deriving from `fir_IntegralSwitchTerminatorOp`
and `region_Op`.

No new functionality is added, hence no tests. This patch addresses:
https://github.com/llvm/llvm-project/issues/54314.

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

Some changes were extracted from D121090 (by River Riddle).

co-authored-by: River Riddle <riddleriver@gmail.com>
2022-03-11 11:29:20 +00:00
Jean Perier a7802a806d [flang] Do not return true for pointer sub-object in IsPointerObject
evaluate::IsPointerObject used to return true for pointer suboject like
`pointer(10)` while these object are not pointers. This prevented some
checks like 15.5.2.7 to be correctly enforced (e.g., it was possible to
pass `pointer(10)` to a non intent(in) dummy pointer).

After updating IsPointerObject behavior and adding a test for 15.5.2.7 in
call07.f90, a test in call03.f90 for 15.5.2.4(14) was failing.
It appeared the related semantics check was relying on IsPointerObject
to return true for `pointer(10)`. Adapt the code to detect pointer element
in another way.
While looking at the code, I also noticed that semantics was
rejecting `character(1)` pointer/assumed shape suboject when these are
allowed (the standard has a special case for character(1) in
15.5.2.4(14), and I verified that other compilers that enforce 15.5.2.4(14)
do accept this).

Differential Revision: https://reviews.llvm.org/D121377
2022-03-11 09:26:21 +01:00
Peixin-Qiao f2ac513812 [flang] Fix processing ModuleLikeUnit evaluationList
Push the ModuleLikeUnit evalutionList when entering module unit. Pop it
when exiting module unit if there is no module procedure. Otherwise, pop
it when entering the first module procedure.

Reviewed By: V Donaldson

Differential Revision: https://reviews.llvm.org/D120460
2022-03-11 15:20:23 +08:00
Peixin-Qiao b905864845 [flang] Support for dump OpenMP/OpenACC declarative directives PFT in module
OpenMP/OpenACC declarative directives can also be used in module unit.
Add support for dump them in module.

Reviewed By: kiranchandramohan, V Donaldson

Differential Revision: https://reviews.llvm.org/D120459
2022-03-11 14:33:17 +08:00
Valentin Clement 72276bdaff
[flang] Lower pointer component in derived type
This patch lowers pointer component part of derived types to
FIR.

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

Depends on D121383

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-10 20:20:55 +01:00
Valentin Clement 88ae0d61c3
[flang] Lower general forall statement
This patch lowers general forall statements. The forall
are lowered to nested loops.

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

Depends on D121385

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-10 19:43:50 +01:00
Valentin Clement 7a6a1655d8
[flang] Lower where statement
This patch lowers where statement to FIR.
The where statement is lowered to a conbination of
loops and if conditions.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-10 18:44:23 +01:00
Shraiysh Vaishay e0f549a43a [flang] Added basic connect to lower OpenMP constructs
Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D121382
2022-03-10 22:48:25 +05:30
Valentin Clement 589d51ea9f
[flang] Lower basic derived types
This patch lowers basic derived type to FIR.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-10 18:07:20 +01:00
Valentin Clement 1b3fd28c6e
[flang][NFC] Remove old RTBuilder.h
RTBuilder.h has been moved in `flang/Optimizer/Builder/Runtime/RTBuilder.h`.
This duplicate is not necessary anymore.

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

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D121317
2022-03-09 20:57:39 +01:00
Valentin Clement c3a7627cac
[flang] Lower more array character cases
This patch adds more lowering and tests for character array assignment/copy.

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

Depends on D121300

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-09 19:50:57 +01:00
Valentin Clement beeb86bd65
[flang] Update ArrayValueCopy to support array_amend and array_access
This patch update the array value copy pass to support fir-array_amend
and fir.array_access.

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-09 19:33:24 +01:00
Valentin Clement 140aabec43
[flang] Add OpenACC flag to bbc
Add `-fopenacc` flag to the `bbc` tool.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D121117
2022-03-09 18:37:15 +01:00
Valentin Clement b0f7dc2cf0
[flang] Add OpenMP flag to bbc
Add `-fopenmp` flag to the `bbc` tool.

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

Reviewed By: schweitz, awarzynski

Differential Revision: https://reviews.llvm.org/D121118
2022-03-09 18:34:04 +01:00
Peter Klausler 041080fc9b [flang] Fix extent computation in finalization
The code that computed the extent of a dimension of a
non-allocatable/non-automatic component array during
finalization had a reversed subtraction; fix, and
use variables to make the code a little more readable.

Differential Revision: https://reviews.llvm.org/D121163
2022-03-09 09:01:02 -08:00
Andrzej Warzynski 38101b4e95 [flang][driver] Add support for -S and implement -c/-emit-obj
This patch adds support for:
  * `-S` in Flang's compiler and frontend drivers,
and implements:
  * `-emit-obj` in Flang's frontend driver and `-c` in Flang's compiler
    driver (this is consistent with Clang).
(these options were already available before, but only as placeholders).
The semantics of these options in Clang and Flang are identical.

The `EmitObjAction` frontend action is renamed as `BackendAction`. This
new name more accurately reflects the fact that this action will
primarily run the code-gen/backend pipeline in LLVM. It also makes more
sense as an action implementing both `-emit-obj` and `-S` (originally,
it was just `-emit-obj`).

`tripleName` from FirContext.cpp is deleted and, when a target triple is
required, `mlir::LLVM::LLVMDialect::getTargetTripleAttrName()` is used
instead. In practice, this means that `fir.triple` is replaced with
`llvm.target_triple`. The former was effectively ignored. The latter is
used when lowering from the LLVM dialect in MLIR to LLVM IR (i.e. it's
embedded in the generated LLVM IR module). The driver can then re-use
it when configuring the backend. With this change, the LLVM IR files
generated by e.g. `tco` will from now on contain the correct target
triple.

The code-gen.f90 test is replaced with code-gen-x86.f90 and
code-gen-aarch64.f90. With 2 seperate files we can verify that
`--target` is correctly taken into account. LIT configuration is updated
to enable e.g.:
```
! REQUIRES: aarch64-registered-target
```

Differential Revision: https://reviews.llvm.org/D120568
2022-03-09 15:48:09 +00:00
Shraiysh Vaishay 7c385c4b2f [mlir][OpenMP] Generating enums in accordance with the guidelines
This patch changes the enums generated from `OMP.td` for MLIR according
to the enum naming guidelines in LLVM Coding Standards.

This also helps the issues we had with `static` being a C++ keyword and
also a value for the schedule clause.

Enumerator naming guidelines: https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D120825
2022-03-09 20:10:45 +05:30
Andrzej Warzynski 092601d4ba [flang] Remove 'using namespace mlir;` from header files
Currently, CGOps.h and FIROps.h contain `using namespace mlir;`. Every
file that includes one of these header files (directly and transitively)
will have the MLIR namespace enabled. With name-clashes within
sub-projects (LLVM and MLIR, MLIR and Flang), this is not desired. Also,
it is not possible to "un-use" a namespace once it is "used". Instead,
we should try to limit `using namespace` to implementation files (i.e.
*.cpp).

This patch removes `using namespace mlir;` from header files and adjusts
other files accordingly. In header and TableGen files, extra namespace
qualifier is added when referring to symbols defined in MLIR. Similar
approach is adopted in source files that didn't require many changes. In
files that would require a lot of changes, `using namespace mlir;` is
added instead.

Differential Revision: https://reviews.llvm.org/D120897
2022-03-09 10:19:51 +00:00
Jean Perier 3b7ec85a1e [flang] Use unix logical representation for fir.logical
The front-end and the runtime are currently using the unix logical
representation, but lowering was not. These inconsistencies could
caused issues.

The only place that defines what the logical representation is in
lowering is the translation from FIR to LLVM (FIR is agnostic to the
actual representation). More precisely, the LLVM implementation of
`fir.convert` between `i1` and `fir.logcial` is what defines the
representation:
- `fir.convert` from `i1` to `fir.logical` defines the `.true.` and `.false.`
canonical representations
- `fir.convert` from `fir.logical` to `i1` decides what the test for
truth is.

Unix representation is:
- .true. canonical integer representation is 1
- .false. canonical integer representation is 0
- the test for truth is "integer representation != 0"

For the record, the previous representation that was used was in
codegen was:
- .true. canonical integer representation is -1 (all bits 1)
- .false. canonical integer representation is 0
- the test for truth is "integer representation lowest bit == 1"

Differential Revision: https://reviews.llvm.org/D121200
2022-03-09 09:42:07 +01:00
Peter Klausler a53967cd55 [flang] Distinguish usage and portability warning messages
Using recently established message severity codes, upgrade
non-fatal messages to usage and portability warnings as
appropriate.

Differential Revision: https://reviews.llvm.org/D121246
2022-03-08 17:24:52 -08:00
Valentin Clement a49bf0ac38
[flang] Lower associate construct
This patch lowers the `associate` construct.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-03-08 22:09:26 +01:00
River Riddle f8d5c73c82 [mlir][NFC] Update the Builtin dialect to use "Both" accessors
Differential Revision: https://reviews.llvm.org/D121189
2022-03-08 12:25:32 -08:00
Peter Klausler 2895771faf [flang] Add nonfatal message classes
F18 presently has fatal and non-fatal diagnostic messages.  We'd like
to make non-fatal warnings stand out better in the output of the compiler.

This will turn out to be a large change that affects many files.
This patch is just the first part.  It converts a Boolean isFatal_ data
member of the message classes into a severity code, and defines four
of these codes (Error, Warning, Portability, and a catch-all Other).

Later patches will result from sweeping over the parser and semantics,
changing most non-fatal diagnostic messages into warnings and portability
notes.

Differential Revision: https://reviews.llvm.org/D121228
2022-03-08 11:40:45 -08:00
Andrzej Warzynski 8321579b28 [flang][driver] Add support for -debug-dump-pft
This patch adds support for dumping the pre-FIR tree in `flang-new
-fc1`, i.e. Flang's frontend driver. This flag is functionally identical
to `-pft-test` in `bbc` and semantically similar to
`-fdebug-dump-parse-tree` from `flang-new -fc1`.

Differential Revision: https://reviews.llvm.org/D121198
2022-03-08 19:21:58 +00:00
Valentin Clement 78a127a3ef
[flang] Lower computed and assigned goto
This patch lowers the computed and assigned goto statements.

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-08 20:19:18 +01:00
Valentin Clement b3eb0e113e
[flang] Lower sum intrinsic
This patch enables the lowering of the `sum` intrinsic. It adds
also infrastructure to deal with optional arguments in intrinsics and
implied loops.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
2022-03-08 18:50:34 +01:00
Andrzej Warzynski b383b17bf7 [flang][nfc] Update the CMake dependencies for flangFrontend
The "FrontendActions.cpp" file (which is one of the source files for the
`flangFrontend` library) includes "Passes.h.inc" (indirectly, via
"CLOptions.inc"). This file is generated alongside other TableGen
outputs from the `FIROptTransformsPassIncGen` CMake target. This patch
adds `FIROptTransformsPassIncGen` to the list of build dependencies for
`flangFrontend`.

The lack of this dependency might cause non-determinstic build failures,
e.g. https://lab.llvm.org/buildbot/#/builders/160/builds/6210.

Differential Revision: https://reviews.llvm.org/D121218
2022-03-08 17:19:32 +00:00
Valentin Clement 4730582d5d
[flang] Remove unused variable in Allocatable.cpp
Fix for buildbot failure: https://lab.llvm.org/buildbot/#/builders/180/builds/3532
2022-03-08 06:51:23 +01:00
Peter Klausler 665d41593f [flang] Fix module file missing USE for shadowed derived type
When a module uses a derived type that is shadowed by a generic
interface, the module file was missing a USE statement for the
name.  Detect and handle this situation.

Differential Revision: https://reviews.llvm.org/D121160
2022-03-07 17:12:51 -08:00
Peter Klausler 96aa48100c [flang] Make uninitialized allocatable components explicitly NULL() in structure constructors
When a structure constructor does not initialize an allocatable component,
ensure that the typed expression representation contains an explicit
NULL() for the component.  Expression semantics already copies default
initialized expressions for nonallocatable components into structure
constructors.  This change is expected to simplify lowering.

Differential Revision: https://reviews.llvm.org/D121162
2022-03-07 16:41:38 -08:00
Peter Klausler 764363368c [flang] Runtime validation of SPREAD(DIM=dim) argument
Crash when DIM= is not a valid dimension in the result.

Differential Revision: https://reviews.llvm.org/D121145
2022-03-07 13:49:39 -08:00
Peter Klausler ef7f6f7cd7 [flang] Use faster path for default formatted character input
Rather than reading default character variables in formatted
input one byte at a time via NextInField(), skip and read
them via blocks of available buffer data.  This eliminates
a bottleneck that affected reads of large character values.
(It also exposed a problem with sequential reads with RECL=
set on the OPEN statement, so that's fixed too.)

Differential Revision: https://reviews.llvm.org/D121144
2022-03-07 13:01:08 -08:00
Valentin Clement c5cf1b9034
[flang] Lower allocate and deallocate statements
This patch add the lowering for the allocate
and the deallocate statements.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-03-07 21:47:28 +01:00
Peter Klausler 89d5c31b78 [flang] Make per-argument intrinsic error messages more localized
A recent patch made it possible to emit more localized error messages
pertaining to actual arguments in non-intrinsic procedure references.
Use these new powers for good and make intrinsic error messages more
precise, too.

Differential Revision: https://reviews.llvm.org/D121126
2022-03-07 12:31:03 -08:00
Peter Klausler d7ea6068e5 [flang] Avoid crash case in provenance mapping
When a contiguous range of a cooked character stream is being
mapped to a range of source provenance, the code was assuming
that the "end()" position of the input range -- being the character
immediately after the range -- would also follow the range's
source provenance.  This isn't always the case.

Modify the code to work with the true last character of the
input range (at end()-1) and to also cope with cases when that
last position truly maps to an earlier provenance, which can happen
when the prescanner has inserted a space into the cooked character
stream.

Differential Revision: https://reviews.llvm.org/D121124
2022-03-07 11:40:50 -08:00
River Riddle 5a7b919409 [mlir][NFC] Rename StandardToLLVM to FuncToLLVM
The current StandardToLLVM conversion patterns only really handle
the Func dialect. The pass itself adds patterns for Arithmetic/CFToLLVM, but
those should be/will be split out in a followup. This commit focuses solely
on being an NFC rename.

Aside from the directory change, the pattern and pass creation API have been renamed:
 * populateStdToLLVMFuncOpConversionPattern -> populateFuncToLLVMFuncOpConversionPattern
 * populateStdToLLVMConversionPatterns -> populateFuncToLLVMConversionPatterns
 * createLowerToLLVMPass -> createConvertFuncToLLVMPass

Differential Revision: https://reviews.llvm.org/D120778
2022-03-07 11:25:23 -08:00
Valentin Clement 764f95a8c7
[flang] Add lowering for host association
This patches adds the code to handle host association for
inner subroutines and functions.

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-03-07 19:57:02 +01:00
Peter Klausler 4133a85c86 [flang] Accommodate arrays with a zero-extent dimension in location folding
The index incrementation code used for FINDLOC, MAXLOC, and MINLOC folding
would crash if the array had a zero extent on the dimension selected with
a DIM= argument since the subscript passed to IncrementSubscripts would
have a value less than the lower bound.  Fix, and add tests.

Differential Revision: https://reviews.llvm.org/D121125
2022-03-07 10:44:18 -08:00
Diana Picus af4ddd516f [flang] Update tco after 0dc66b76fe
Minor fix to appease the buildbots.
2022-03-07 12:55:43 +00:00
River Riddle 6b7d211a1b [mlir][NFC] Move MlirOptMain to the Tools/ directory
MlirOptMain is currently awkwardly shoved into mlir/Support. This commit
moves it to the Tools/ directory, which is intended for libraries used to
implement tools.

Differential Revision: https://reviews.llvm.org/D121025
2022-03-07 01:05:38 -08:00
River Riddle 9eaff42360 [mlir][NFC] Move Parser.h to Parser/
There is no reason for this file to be at the top-level, and
its current placement predates the Parser/ folder's existence.

Differential Revision: https://reviews.llvm.org/D121024
2022-03-07 01:05:38 -08:00
Stella Laurenzo 38151a08c2 Reapply "[cmake] Prefix gtest and gtest_main with "llvm_"."
This reverts commit 7cdda6b8ce.

Differential Revision: https://reviews.llvm.org/D121020
2022-03-04 13:45:43 -08:00
Andrzej Warzynski bbcc0f6006 [flang] Fix standalone builds
In dd875dd88b I added a missing MLIR
dependency in Flang. However, that particular CMake target is not
exported as something available to standalone builds. In this patch is
switch to `MLIRIR` instead, which depends on
`MLIRBuiltinAttributeInterfacesIncGen` - the missing dependency added
previously.

Differential Revision: https://reviews.llvm.org/D120986
2022-03-04 13:05:44 +00:00
Andrzej Warzynski 06be148843 [flang][nfc] Fix GCC 11 build
After merging https://reviews.llvm.org/D120801, Flang no longer builds
with GCC 11:
```
../llvm-project/flang/lib/Semantics/runtime-type-info.cpp:385:22: error: variable ‘lenParam’ set but not used [-Werror=unused-but-set-variable]
  385 |       for (SymbolRef lenParam : *lenParameters) {
      |                      ^~~~~~~~
```

I'm sending this without a review as a quick fix.
2022-03-03 17:06:54 +00:00
Andrzej Warzynski dd875dd88b [flang][nfc] Add missing build dependency
Two buildbots have started failing recently:
* https://lab.llvm.org/buildbot/#/builders/181/builds/3894
* https://lab.llvm.org/buildbot/#/builders/191/builds/3908

Build error:
```
In file included from /home/tcwg-buildbot/worker/flang-aarch64-rel-assert/llvm-project/flang/examples/FlangOmpReport/FlangOmpReport.cpp:21:
In file included from /home/tcwg-buildbot/worker/flang-aarch64-rel-assert/llvm-project/flang/include/flang/Frontend/FrontendActions.h:15:
In file included from /home/tcwg-buildbot/worker/flang-aarch64-rel-assert/llvm-project/llvm/../mlir/include/mlir/IR/BuiltinOps.h:16:
In file included from /home/tcwg-buildbot/worker/flang-aarch64-rel-assert/llvm-project/llvm/../mlir/include/mlir/IR/FunctionInterfaces.h:17:
In file included from /home/tcwg-buildbot/worker/flang-aarch64-rel-assert/llvm-project/llvm/../mlir/include/mlir/IR/BuiltinTypes.h:12:
/home/tcwg-buildbot/worker/flang-aarch64-rel-assert/llvm-project/llvm/../mlir/include/mlir/IR/BuiltinAttributeInterfaces.h:279:10: fatal error: 'mlir/IR/BuiltinAttributeInterfaces.h.inc' file not found
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```

I have not been able to reproduce locally, but from this log it is clear
that the rule for `flangFrontend` is missing the
`MLIRBuiltinAttributeInterfacesIncGen` dependency from MLIR.  I couldn't
identify a breaking commit. I suspect that until now we have simply been
"lucky" and that dependency just happened to be built before
`flangFrontend`.

I am sending this without a review - the change is rather
straightforward and the only way to verify it is to make the buildbots
test it.
2022-03-03 16:39:58 +00:00
Jean Perier f88a9497a2 [flang] Generate PDT runtime type info in the type definition scope
This patches modifies PDT runtime type info generation so that it is
easier to handle derived type descriptor in lowering. It changes three
aspects:

1. The symbol name suffix of runtime type info for PDT instantiation is
   changed from a serial number unrelated to the types to an encoding of
   the instantiated KIND parameters.
2. New runtime type info is not created for each instantiation of PDT without
   KIND parameters (only length parameters). Instead, the runtime type
   info of the type definition is always used. It is updated to contain
   the component descriptions.
3. Runtime type info of PDT instantiation is now always generated in the
   scope where the type is defined. If several PDT type instantiation
   are made in different scope with the same kind parameters, they will
   use the same runtime type info.

Rational of the change:

In lowering, derived type descriptors are not mapped when instantiating derived
type objects. They are mapped later when symbol knowledge is not available anymore.
This mapping is based on the FIR representation of derived types. For
PDT, the FIR type information does not allow deducing the instantiation
scope, it only allows retrieving the type name, the type _definition_
scope, and the kind parameter values. Therefore, in order to be able to
retrieve the derived type descriptor from a FIR type, the derived type
descriptor must be generated in the definition scope and must reflect
the kind parameters. This justifies the need for changes 1. and 3.
above (suffix and scope change). Changes 2. comes from the fact that
all runtime type info of type without kind parameters can be generated
from the type definition, and that because of the suffix change, the
symbol name for type definition and type instantiation are the same.

Although this change is first motivated by how lowering handles derived
types, I believe it is also an improvement from a functional point of
view since this change will allow reducing the number of generated
runtime type info for PDTs, since redundant information (different
instantiations with same kind parameters) will only be generated once.

Differential Revision: https://reviews.llvm.org/D120801
2022-03-03 10:15:21 +01:00
Jean Perier 392cba8603 [flang] Handle optional TARGET associate in ASSOCIATED runtime
The TARGET argument of ASSOCIATED may be dynamically optional, in which
case ASSOCIATED(POINTER, TARGET) is equal to ASSOCIATED(TARGET).

Make the runtime argument a pointer so that it can detect and handle
arguments that are dynamically optional.

Also fix the runtime to check if TARGET base address is not null and if
its element size is not null to match the requirement of ASSOCIATED
regarding TARGET:
- if TARGET is an object: true iff [..] TARGET is not a zerosized storage sequence
- if TARGET is a POINTER: true iff [..] POINTER and TARGET are associated

Not that ASSOCIATED will also returns false if TARGET is an unallocated allocatable.
This is not described in the standard, but is a unanimous behaviour of
existing compilers.

Differential Revision: https://reviews.llvm.org/D120835
2022-03-03 10:11:35 +01:00
Jean Perier 013160f6e2 [flang] Support PDT type descriptors in codegen
This change updates the mapping of derived types and type descriptor
object names to support kind parametrized derived types (PDT).
It moves the custom name mapping to the internal name utility.

To improve robustness and error reporting, type descriptors are also now
required to be generated in all compilation unit that manipulates
derived types. The previous codegen relied on the fact that descriptors
not defined in the current FIR module were available externally. Errors
with missing type descriptors were only caught at link time.

This patch makes derived type definition mandatory, except if the
derived types are expected to not have derived type descriptors (builtin
types), or if the newly added debug switch `--ignore-missing-type-desc`
is set. In those cases, a null pointer is used as type descriptor
pointer. The debug switch intends to help testing FIR to LLVM passes
without having to bother providing type descriptor data structures that
are normally built by the front-end.

Differential Revision: https://reviews.llvm.org/D120804
2022-03-03 10:08:18 +01:00
Peter Klausler 3bfe90748e [flang] Remove bogus messages for actual/dummy procedure argument compatibility
Add new IsCompatibleWith() member functions to many classes in evaluate::characteristics
that apply more nuanced compatibility checking for function results, dummy
arguments, and procedure interfaces than the previous tests for complete
equivalence.  Use IsCompatibleWith() in semantics for call checking.

Differential Revision: https://reviews.llvm.org/D120844
2022-03-02 16:00:36 -08:00
Peter Klausler 93f42491a5 [flang] Extend ProvenanceRange::Suffix() to handle crash case
Suffix() can be called from AllSources::IntersectionWithSourceFiles()
when a contiguous range of source provenance overlaps a macro expansion.
It skips over the macro expansion and recurses on the remainder of
the range, which might end with a bit that does overlap with a
source file.  However, in the case where the original range is
entirely within the expanded macro, Suffix() crashes when called
with a skip offset greater than the size of the range.

Rather than add logic around this and other calls to Suffix() to
avoid passing an out-of-range skip, it's better to accommodate it
in Suffix() and return an empty result.

Differential Revision: https://reviews.llvm.org/D120843
2022-03-02 15:24:35 -08:00
Peter Klausler 79f8e909ed [flang] Avoid bogus warning from MSVC build
And expand common::BitSet from 64 to 128 maximum elements.

Differential Revision: https://reviews.llvm.org/D120848
2022-03-02 15:23:45 -08:00
Peter Klausler 396865576f [flang] Accommodate module subprograms defined in the same module
The symbol table, name resolution, and semantic checks for module
subprograms -- esp. for MODULE FUNCTION and MODULE SUBROUTINE, but
also MODULE PROCEDURE -- essentially assumed that the subprogram
would be defined in a submodule of the (sub)module containing its
interface.  However, it is conforming to instead declare a module
subprogram in the *same* (sub)module as its interface, and we need
to handle that case.

Since this case involves two symbols in the same scope with the same
name, the symbol table details for subprograms have been extended
with a pointer to the original module interface, rather than relying
on searching in scopes.

Differential Revision: https://reviews.llvm.org/D120839
2022-03-02 13:07:16 -08:00
Peter Klausler 507f7317a0 [flang] Catch READ/WRITE on direct-access file without REC=
A data transfer statement must have REC= in its control list
if (and only if) the unit was opened with ACCESS='DIRECT'.
The runtime wasn't catching this error, but was just silently
advancing to the next record as if the access were sequential.

Differential Revision: https://reviews.llvm.org/D120838
2022-03-02 12:38:11 -08:00
Peter Klausler 3a96446d51 [flang] Honor RECL= in list-directed/namelist output
Advancement to new output lines was taking fixed-sized direct-access
and internal character array element lengths into account, but not
RECL= settings from OPEN statements.

Differential Revision: https://reviews.llvm.org/D120837
2022-03-02 12:07:18 -08:00
Stella Laurenzo 7cdda6b8ce Revert "[cmake] Prefix gtest and gtest_main with "llvm_"."
lldb buildbot failure. will investigate and roll forward.

This reverts commit 9f37775472.
2022-03-02 11:13:46 -08:00
Peter Klausler 1e082a4a9c [flang] Fix result type of "procedure(abs) :: f"
Name resolution was properly probing the table of unrestricted
specific intrinsics to find "abs", but failing to capture the
result type and save it in the created symbol table entry.

Differential Revision: https://reviews.llvm.org/D120749
2022-03-02 11:11:40 -08:00
Valentin Clement 859d4a18b5
[flang] Lower more cases of assignments on allocatable variables
This patch enables the lowering of various allocatable assignements
for character type and numeric types.

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

Depends on D120819

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-02 20:05:23 +01:00
Stella Laurenzo 9f37775472 [cmake] Prefix gtest and gtest_main with "llvm_".
The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).

This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120789
2022-03-02 10:53:32 -08:00
Valentin Clement 17d71347b2
[flang] Handle module in lowering pass
This patch enables the lowering of basic modules and functions/subroutines
in modules.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-02 18:26:43 +01:00
Valentin Clement 7e32cada01
[flang] Lower inquire statement
This patch adds the lowering of the `inquire` statement.

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

Depends on D120822

Reviewed By: schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-02 18:03:29 +01:00
Valentin Clement 46f46a3763
[flang] Lower basic IO file statements
This patches adds lowering for couple of basic io statements such as `flush`,
`endfile`, `backspace` and `rewind`

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

Depends on D120821

Reviewed By: schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-02 18:01:23 +01:00
Valentin Clement db48f7b2f7
[flang] Lower IO open and close statements
This patch adds the lowering of open and close statements

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

Reviewed By: schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-02 17:57:08 +01:00
Kiran Chandramohan dc48849fcc [Flang] NFC: Rearrange conversion patterns in Codegen.cpp
Minor rearrangment in the order of conversion patterns to identify
differences.

Reviewed By: clementval, schweitz

Differential Revision: https://reviews.llvm.org/D120721
2022-03-02 11:55:45 +00:00
Peter Klausler 44ff4df6de [flang] Extension: don't require commas between most edit descriptors in formats
The standard explicitly allows a comma to be omitted between a 'P'
edit descriptor and a following numeric edit descriptor (e.g., 1PE10.1),
and before and after a '/' edit descriptor, but otherwise requires them
between edit descriptors.  Most implementations, however, only require
commas where they prevent ambiguity, and accept things like 1XI10.
This extension is already assumed by the static FORMAT checker in
semantics.  Patch the runtime to behave accordingly.

Differential Revision: https://reviews.llvm.org/D120747
2022-03-01 15:15:59 -08:00
Peter Klausler df38f35acb [flang] Allow data transfer stmt control list errors to be caught
The runtime crashes on several fundamental I/O data transfer statement
control list errors, like list I/O on a direct-access unit, or
input from a write-only unit, &c.  These errors should not be fatal
when ERR= or IOSTAT= are present.

This patch creates a new ErroneousIoStatementState class and
uses it for the state of an I/O statement that is doomed to fail
from these errors.  If there is no ERR= label or IOSTAT= variable,
the error will be raised at the end of the statement.  Data transfer
operations along the way will be no-op failures.

Differential Revision: https://reviews.llvm.org/D120745
2022-03-01 14:39:30 -08:00
Valentin Clement bc274b854d
[flang] Add test for allocatable on the caller side
This patch adds test for allocatable on the caller side.
Lowering for missing features is added as well.

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

Depends on D120746

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-03-01 23:26:43 +01:00
Valentin Clement 96d9df4157
[flang] Add test for allocatable on the callee side
This patch adds couple of tests for allocatable
on the callee side. Lowering for some missing underlying features
is added as well.

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

Depends on D120744

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-03-01 22:58:34 +01:00
Valentin Clement d88dfd2b31
[flang] Handle dynamic array lowering
This patch enables dynamic array lowering
and use the funcationality inside some IO tests.

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

Depends on D120743

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-03-01 22:29:49 +01:00
Valentin Clement 8c22cb846f
[flang] Lower basic IO statement
This patch enables the lowering of the print, read and write
IO statements.

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2022-03-01 21:48:41 +01:00
Peter Klausler 59d38f1b56 [flang] Check constraint C711 correctly
An assumed-type actual argument that corresponds to an assumed-rank dummy
argument shall be assumed-shape or assumed-rank.

Differential Revision: https://reviews.llvm.org/D120750
2022-03-01 12:22:17 -08:00
River Riddle 1f971e23f0 [mlir] Trim a huge number of unnecessary dependencies on the Func dialect
The Func has a large number of legacy dependencies carried over from the old
Standard dialect, which was pervasive and contained a large number of varied
operations. With the split of the standard dialect and its demise, a lot of lingering
dead dependencies have survived to the Func dialect. This commit removes a
large majority of then, greatly reducing the dependence surface area of the
Func dialect.
2022-03-01 12:10:04 -08:00
River Riddle 23aa5a7446 [mlir] Rename the Standard dialect to the Func dialect
The last remaining operations in the standard dialect all revolve around
FuncOp/function related constructs. This patch simply handles the initial
renaming (which by itself is already huge), but there are a large number
of cleanups unlocked/necessary afterwards:

* Removing a bunch of unnecessary dependencies on Func
* Cleaning up the From/ToStandard conversion passes
* Preparing for the move of FuncOp to the Func dialect

See the discussion at https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061

Differential Revision: https://reviews.llvm.org/D120624
2022-03-01 12:10:04 -08:00
Peter Klausler 73b193aec2 [flang] Allow more concurrently open NEWUNIT= values, with recycling
Add a header-only implementation of Briggs & Torczon's fast small
integer set data structure to flang/include/flang/Common, and use
it in the runtime to manage a pool of Fortran unit numbers with
recycling.  This replaces the bit set previously used for that
purpose.  The set is initialized on demand with the negations of
all the NEWUNIT= unit numbers that can be returned to any kind
of integer variable.

For programs that require more concurrently open NEWUNIT= unit
numbers than the pool can hold, they are now allocated with a
non-recycling counter.  This allows as many open units as the
operating system provides.

Many of the top-line comments in flang/unittests/Runtime had the
wrong path name.  I noticed this while adding a unit test for the
fast integer set data structure, and cleaned them up.

Differential Revision: https://reviews.llvm.org/D120685
2022-02-28 16:13:22 -08:00
Kiran Chandramohan 4d5bcff3be [Flang] NFC: Changes to adhere to coding guidelines
This patch includes some changes which brings the code in line with
llvm coding guidelines.
-> Remove curlies for one line if statements.
-> Remove else after return.
-> Removes a few usage of auto.
-> Add Doxygen comments

Addresses post review comments in D120403 by @schweitz.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D120657
2022-02-28 23:50:39 +00:00
Peter Klausler 19d8642633 [flang] Catch I/O of bad derived type at compile time
Derived types with allocatable and pointer components cannot
be used in I/O data transfer statements unless they have defined
I/O procedures available (as type-bound or regular generics).
These cases are caught as errors by the I/O runtime library,
but it would be better if they were flagged during compilation.

(Address comment in review: don't use explicit name string lengths.)

Differential Revision: https://reviews.llvm.org/D120675
2022-02-28 15:40:12 -08:00
Valentin Clement 89080b8414
[flang][NFC] Add complex operations lowering tests
Just adds some lowering test for complex operations. These were not
added when the lowering landed.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D120672
2022-02-28 21:37:34 +01:00
Valentin Clement 43c071fa4c
[flang] Lower power operations
Lower the power operation for real, integer
and complex.

The power operation is lowered to library calls.

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

Depends on D120403

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D120556
2022-02-28 14:49:14 +01:00
Valentin Clement a7ac120a9a
[flang] Lower logical comparison and logical operations
This handles the lowering of the logical comparison
to `arith.cmpi` operation. The logical operations `.OR.`, `.AND.`
and `.NOT.` are lowered to `arith.ori`, `arith.andi` and `arith.xori`

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

Depends on D120559

Reviewed By: schweitz, rovka

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-25 21:05:44 +01:00
Valentin Clement 98813e365c
[flang] Lower real comparison operations
This patch handles the lowering of real
comparison operations. The real comparison operations
are lowered to `arith.cmpf` operation.

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-25 21:03:39 +01:00
Valentin Clement f1dcf3ae92
[flang] Lower integer comparison operation
This patch handles the lowering of comprison
operator between integers.
The comparison is lowered to a `arith.cmpi` operation.

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

Reviewed By: PeteSteinfeld, schweitz, rovka

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-25 21:01:27 +01:00
Kiran Chandramohan 7c0acc1a98 Lower Fortran intrinsic to a runtime call/llvm intrinsic
This patch brings in code which can lower a Fortran intrinsic to
a runtime call or an llvm intrinsic. For math intrinsics the
runtime call is to the `math` or `pgmath` library. Non-math
intrinsics are covered by the Flang runtime. A distance computation
mechanism is introduced to find the runtime function that closely
matches the types of the intrinsic call.

In this patch, the `abs` intrinsic is lowered in the following way,
-> Integer version is lowered as a group of MLIR/FIR operations
-> Real version is lowered to llvm intrinsics
-> Complex version is lowered to the `math_hypot` runtime function

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

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: zacharyselk <zrselk@gmail.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2022-02-25 17:41:48 +00:00
Valentin Clement 37e84d9be0
[flang] Lower simple character return
Handles function with character return.

Character scalar results are passed as arguments in lowering so
that an assumed length character function callee can access the result
length.

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-02-25 18:23:13 +01:00
Andrzej Warzynski 2e9439e489 [flang][driver] Add support for --target/--triple
This patch adds support for:
  * `--target` in the compiler driver (`flang-new`)
  * `--triple` in the frontend driver (`flang-new -fc1`)
The semantics of these flags are inherited from `clangDriver`, i.e.
consistent with `clang --target` and `clang -cc1 --triple`,
respectively.

A new structure is defined, `TargetOptions`, that will hold various
Frontend options related to the target. Currently, this is mostly a
placeholder that contains the target triple. In the future, it will be
used for storing e.g. the CPU to tune for or the target features to
enable.

Additionally, the following target/triple related options are enabled
[*]: `-print-effective-triple`, `-print-target-triple`. Definitions in
Options.td are updated accordingly and, to facilated testing,
`-emit-llvm` is added to the list of options available in `flang-new`
(previously it was only enabled in `flang-new -fc1`).

[*] These options were actually available before (like all other options
defined in `clangDriver`), but not included in `flang-new --help`.
Before this change, `flang-new` would just use `native` for defining the
target, so these options were of little value.

Differential Revision: https://reviews.llvm.org/D120246
2022-02-25 09:38:10 +00:00
Valentin Clement f9704f0cfb
[flang] Simple array assignment lowering
This patch handles lowering of simple array assignment.

```
a(:) = 10
```

or

```
a(1) = 1
```

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-24 21:23:30 +01:00
Damian Rouson f3c9a52519 [flang] add semantics tests for sync team
Test a range of acceptable forms of SYNC TEAM statements,
including combinations with and without the stat-variable
and errmsg-variable present.  Also test that several invalid
forms of SYNC TEAM call generate the correct error messages.

Differential Revision: https://reviews.llvm.org/D120099
2022-02-24 12:11:49 -08:00
Damian Rouson 95fd0dbaf0 [flang] add semantics test for sync memory
Test a range of acceptable forms of SYNC MEMORY statements,
including combinations with and without the stat-variable
and errmsg-variable present.  Also test that several invalid
forms of SYNC MEMORY call generate the correct error messages.

Differential Revision: https://reviews.llvm.org/D120097
2022-02-24 11:04:00 -08:00
Valentin Clement 2a59ead118
[flang] Lower allocatable assignment for scalar
Add lowering for simple assignement on allocatable
scalars.

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

Depends on D120483

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-24 18:13:18 +01:00
Valentin Clement 914061bbcf
[flang] Handle allocatable dummy arguments
This patch handles allocatable dummy argument lowering
in function and subroutines.

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

Reviewed By: schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-24 17:16:55 +01:00
Andrzej Warzynski 19b6e70554 [flang][docs] Update the top "doc" page
* Added a note about "Classic Flang"
* sorted entries in ToC

Differential Revision: https://reviews.llvm.org/D120067
2022-02-24 10:41:53 +00:00
V Donaldson 338b478e70 [flang] Do not print format tabs
As an extension, tabs are accepted in a format, but should be skipped,
not printed.
2022-02-23 20:03:10 -08:00
Valentin Clement d0b70a070a
[flang] Lower function and subroutine calls
This patch introduce basic function/subroutine calls.
Because of the state of lowering only simple scalar arguments
can be used in the calls. This will be enhanced in follow up
patches with arrays, allocatable, pointer ans so on.

```
subroutine sub1()
end

subroutine sub2()
  call sub1()
end
```

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

Reviewed By: schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-02-23 19:50:06 +01:00
Valentin Clement 307ccf4c0d
[flang][NFC] Clean up ConvertType
This patch removes unused or obsolete code in
the ConvertType.h and ConvertType.cpp files. These
files were landed together with the initial flang
upstreaming. This cleanup will help future upstreaming
effort from fir-dev and keep only used code.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D120405
2022-02-23 18:04:47 +01:00
Valentin Clement e9d2f17391
[flang] Lower complex constant
Add ability to lower complex constant.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-23 18:03:30 +01:00
Andrzej Warzynski 16a91a1cbe [flang][driver] Make flang-new always generate run-time type info
Currently, the driver generates the tables with "run-time type
information for derived types" only when specific actions are run.
However, the corresponding data might be required by the subsequent
compilation stages (e.g. lowering, code-gen) and should be generated
unconditionally. Note that this is only possible once the semantic
checks have been run.

Note that when generating these tables, extra semantic errors might be
generated. The driver will always report these and in most cases such
semantic errors will cause the driver to exit immediately. The only
exception are actions inheriting from `PrescanAndSemaDebugAction`.
Currently, there's only one such action: `DebugDumpAllAction`
(corresponds to `-fdebug-dump-all` command-line flag). I've updated the
comments for this action to clarify this.

This change will mostly affect lowering, which currently is only
available for most basic examples (e.g. empty programs). I wasn't able
to find a working case that would demonstrate the new behaviour. I
hope that this change is straightforward enough and am submitting it
without a test.

Differential Revision: https://reviews.llvm.org/D120051
2022-02-23 10:08:03 +00:00
Valentin Clement b3d1f073de
[flang] Lower real constant
This patch handles lowering of real constant.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-23 08:27:54 +01:00
Valentin Clement 026a43f6cf
[flang] Update PFTBuilder
This patch update the PFTBuilder to be able to lower
the construct present in semantics.

This is a building block for other lowering patches that will be posted soon.

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

Reviewed By: PeteSteinfeld, schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2022-02-22 19:09:28 +01:00
Kiran Chandramohan f57627f544 [Flang] Initial patch to lower a Fortran intrinsic
This patch brings in some initial changes for lowering Fortran
intrinsics. Intrinsics are generally lowered to a mix of FIR and
MLIR operations, runtime calls or LLVM intrinsics. This patch
particularly brings in the lowering of the Fortran `andi` intrinsic
to `arith.andi` in MLIR.

The significant changes are in ConvertExpr.cpp and IntrinsicCall.cpp.
Intrinsic functions occur as part of expressions. Lowering deals with this
in ConvertExpr.cpp in `genval(const Fortran::evaluate::FunctionRef<A> &funcRef)`.
The code in the above mentioned function kicks of a sequence of calls
that ultimately results in a call to the `genIand ` function in
IntrinsicCall.cpp which creates the MLIR `arith.andi` operation.

A few tests are also included.

Note: Generally intrinsics like `iand` can occur in array (elemental)
context, but since that part is not fully supported in lowering, tests
are only added for the scalar context.

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

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: zacharyselk <zrselk@gmail.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2022-02-22 12:46:35 +00:00
Shraiysh Vaishay 5ee500acbb [mlir][OpenMP] Remove clauses that are not being handled
This patch removes the following clauses from OpenMP Dialect:

 - private
 - firstprivate
 - lastprivate
 - shared
 - default
 - copyin
 - copyprivate

The privatization clauses are being handled in the flang frontend. The
data copying clauses are not being handled anywhere for now. Once
we have a better picture of how to handle these clauses in OpenMP
Dialect, we can add these. For the time being, removing unneeded
clauses.

For detailed discussion about this refer to [[ https://discourse.llvm.org/t/rfc-privatisation-in-openmp-dialect/3526 | Privatisation in OpenMP dialect ]]

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D120029
2022-02-19 01:13:05 +05:30
Valentin Clement be3b40c059
[flang] Lower basic binary operation for scalars
Lower simple binary operation (+, -, *, /) for scalars.

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

Depends on D120058

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-18 15:50:31 +01:00
Valentin Clement eafafbae92
[flang] Lower scalar negation
Handle negation on scalar expression.

```
res = -a
```

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-18 08:09:09 +01:00
Kiran Chandramohan e217ebcc96 [NFC][Flang] Add colon to CHECK-LABEL to exercise the check
Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D119995
2022-02-17 22:01:16 +00:00
Valentin Clement e641c29f41
[flang] Lower simple scalar assignment
This patch hanlde lowering of simple scalar assignment.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-17 18:24:30 +01:00
Shao-Ce SUN f29f86b60b [NFC] Fix comment 2022-02-17 21:19:22 +08:00
Shao-Ce SUN 21ac474392 [NFC] Correct typo interger to integer 2022-02-17 21:17:47 +08:00
Andrzej Warzynski e993b20c04 [flang][driver] Add support for -emit-llvm
This patch adds support for the `-emit-llvm` option in the frontend
driver (i.e. `flang-new -fc1`). Similarly to Clang, `flang-new -fc1
-emit-llvm file.f` will generate a textual LLVM IR file.

Depends on D118985

Differential Revision: https://reviews.llvm.org/D119012
2022-02-17 12:13:03 +00:00
Damian Rouson d4332a8842 [flang] add semantics test for sync images
Test a range of acceptable forms of SYNC IMAGES statements,
including combinations with and without the stat-variable
and errmsg-variable present.  Also test that several invalid
forms of SYNC IMAGES call generate the correct error messages.

Differential Revision: https://reviews.llvm.org/D118933
2022-02-16 22:30:58 -08:00
Damian Rouson 99dd49cf97 [flang] add semantics test for sync all
Test a range of acceptable forms of SYNC ALL statements,
including combinations with and without the stat-variable
and errmsg-variable present.  Also test that several invalid
forms of SYNC ALL call generate the correct error messages.

Differential Revision: https://reviews.llvm.org/D114181
2022-02-16 20:43:01 -08:00
V Donaldson d8364e3ea4 [flang] Allow tabs as white space in formats
The fortran standard views blanks in IO formats as white space in
non-string contexts.  Other compilers extend this to also view horizontal
tabs as white space.  Some compilers additionally add other white space
characters to this group.

Add recognition of horizontal and vertical tabs to runtime format
validation code to match what the runtime code currently does.
2022-02-16 17:49:52 -08:00
Andrzej Warzynski b389fbd015 [flang] Add Win32 to the list of supported triples
This patch adds Win32 to the list of supported triples in
`fir::CodeGenSpecifics`. This change means that we can use the "native"
triple, even when running tests on Windows. Currently this affects only
1 test, but it will change once we start adding more tests for lowering
and code-generation.

Differential Revision: https://reviews.llvm.org/D119332
2022-02-16 21:43:13 +00:00
Valentin Clement da7c77b82c
[flang] Handle lowering arguments in subroutine and function
This patch adds infrsatrcutrue to be able to lower
arguments in functions and subroutines.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-16 20:28:07 +01:00
Andrzej Warzynski dda3c14fd7 [flang] Fix LoweringBridge::validModule
This patch updates `validModule` not to use `getModule`.  `getModule`
will dereference `module`, but that will lead to a seg-fault if `module`
is a `nullptr`.

Differential Revision: https://reviews.llvm.org/D119705
2022-02-16 10:41:57 +00:00
Jacques Pienaar b077ee9240 [mlir][ods] Allow type attribute/operand for 0 result ops prefixed
Without results, there is no getType injected and so generating one in prefixed form doesn't result in any failures during C++ compilation.

Differential Revision: https://reviews.llvm.org/D119871
2022-02-15 12:20:07 -08:00
Peter Klausler fa0443f2e7 [flang] Make source location more accurate for actual arguments
Track source location information when available for actual arguments
to procedure references, and use this information when checking constraints
on calls so that error messages refer to specific actual arguments
rather than to the entire call.

Differential Revision: https://reviews.llvm.org/D119849
2022-02-15 11:24:22 -08:00
Peter Klausler f6ded53fb0 [flang] Handle CALL C_F_POINTER(without SHAPE=)
Calls to C_F_POINTER() without the optional SHAPE= third argument
were failing to be recognized as proper calls to the intrinsic,
but the failure was not generating any error message.  This led to
a crash in lowering, which rightfully expects a typed expression
to be associated with the call.

So (1) catch silent failures to convert CALL statements as internal
errors, as is done for expressions and assignment statements; and
(2) clean up C_F_POINTER intrinsic handling to cope with only two
arguments and to emit an error for a FPTR= argument with no type.

Differential Revision: https://reviews.llvm.org/D119847
2022-02-15 10:58:11 -08:00
Peter Klausler 6bd72fa661 [flang] Allow extension cases of EQUIVALENCE with optional warnings
EQUIVALENCE storage association of objects whose types are not
both default-kind numeric storage sequences, or not both default-kind
character storage sequences, are not standard conformant.
However, most Fortran compilers admit such usage, with warnings
in strict conformance mode.  This patch allos EQUIVALENCE of objects
that have sequence types that are either identical, both numeric
sequences (of default kind or not), or both character sequences.
Non-sequence types, and sequences types that are not homogeneously
numeric or character, remain errors.

Differential Revision: https://reviews.llvm.org/D119848
2022-02-15 10:21:38 -08:00
Peter Klausler 7763c01401 [flang] Accept pointer assignment w/ remapping to function result
When a pointer assignment with bounds remapping has a function
reference as its right-hand side, don't check for array conformance.

Differential Revision: https://reviews.llvm.org/D119845
2022-02-15 09:39:34 -08:00
Jean Perier 5bde97b17e [flang][nfc] Update D119555 comments and use getVoidPtr
Minor comment updates and use getVoidPtr helper instead of
builiding `i8*` type manually in codegen.

Differential Revision: https://reviews.llvm.org/D119828
2022-02-15 18:24:04 +01:00
Shraiysh Vaishay 149ad3d554 [flang][mlir][NFC] Replace uses of raw accessors with prefixed accessors
`kEmitAccessorPrefix_Raw ` is being removed, and so updating the
accessors to `kEmitAccessorPrefix_Prefixed`.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D119812
2022-02-15 21:07:46 +05:30
Valentin Clement c807aa53ee
[flang] Handle lowering of ranked array
This patch adds lowering of ranked array as function return.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-15 16:01:02 +01:00
Valentin Clement 1ceb1d9b40
[flang] Enable complex type in function lowering
This patch enables complex type in lowering.
It is tested on function return types.

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

Depends on D119698

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-15 08:25:54 +01:00
Valentin Clement 0a0b3029de
[flang] Enable scalar real type in lowering
This patch enables scalar real type in lowering.
It is tested on function return types.

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

Depends on D119698

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-15 08:23:32 +01:00
Shraiysh Vaishay cc120e36c3 [flang][mlir][NFC] Remove deprecated parser/printer/verifier utilities
These have been replaced by `hasCustomAssemblyFormat` and `hasVerifier`
fields and aren't needed anymore.

Ops deriving from `fir_IntegralSwitchTerminatorOp` and `region_Op` are
not handled in this patch for ease of review.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D119776
2022-02-15 11:54:24 +05:30
Peter Klausler bca13174bc [flang] Accept structure constructor value for polymorphic component
Semantic analysis was emitting a bogus error message when a structure
constructor contains a monomorphic value for a (limited) polymorphic
component of a derived type.  The type compatibility test was too
strict; this patch relaxes it a little to allow values that could
be assigned or passed to a variable or dummy argument with that type.
Also add some quotes to an error message that was sometimes confusing
without them, and remove a repeated space character from another.

Differential Revision: https://reviews.llvm.org/D119744
2022-02-14 16:00:34 -08:00
Peter Klausler 882d5f14ad [flang] Ensure a characterized ENTRY in a PURE subprogram is also marked PURE
ENTRY point symbols aren't marked PURE in the symbol table, but must
instead inherit the attribute from their containing subprograms.
There's a predicate in semantics that does this, but it wasn't being
used in the context of actual procedure argument characterization.

Differential Revision: https://reviews.llvm.org/D119564
2022-02-14 15:34:45 -08:00
Peter Klausler 3632e9f852 [flang] Accept NULL(mold=x) as constant component value in constant structure constructor
The predicate IsInitialDataTarget() was failing to return a correct true
result in the case of a reference to the intrinsic function NULL() with a
MOLD= argument.  Fix, and improve tests for "NULL()" elsewhere in semantics,
checking for an attribute set by intrinsics.cpp rather than the actual name.

Differential Revision: https://reviews.llvm.org/D119452
2022-02-14 14:46:53 -08:00
Valentin Clement ad40cc14a8
[flang] Lower basic function with scalar integer/logical return value
This patch allows the lowring of simple empty function with a
scalar integer or logical return value.
The code in ConvertType.cpp is cleaned up as well. This file was landed
together with the initial flang push and lowering was still a prototype
at that time. Some more cleaning will come with follow up patches.

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

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-14 21:32:24 +01:00
Peter Klausler c4f67ea12e [flang] Allow DATA initialization of derived types w/ allocatable components
While one cannot of course statically initialize an allocatable component
of an instance of a derived type, its mere presence should not prevent
DATA initialization of the other nonallocatable components.  Semantics
was treating the existence of an allocatable component as a case of
"default initialization", which it is, but not one that should run
afoul of C877.  Add another Boolean argument to IsInitialized() to allow
for a more nuanced test.

Differential Revision: https://reviews.llvm.org/D119449
2022-02-14 10:43:49 -08:00
Peter Klausler 07b9a44515 [flang] Allow for deferred-length character in EstablishDescriptor
When the runtime is initializing an instance of a derived type,
don't crash if an allocatable character component has deferred length.

Differential Revision: https://reviews.llvm.org/D119731
2022-02-14 10:05:07 -08:00
Jean Perier 7dd7ccd224 [flang] Fail at link time if derived type descriptors were not generated
Currently, code generation was creating weak symbols for derived type
descriptor global it could not find in the current compilation unit.
The rational is that:
 - the derived type descriptors of external module derived types are
   generated in the compilation unit that compiled the module so that
   the type descriptor address is uniquely associated with the type.
 - some types do not have derived type descriptors: the builtin derived
   types used to create derived type descriptors. The runtime knows
   about them and does not need them to accomplish the feat of
   describing themselves. Hence, all unresolved derived type descriptors
   in codegen cannot be assumed to be resolved at link time.

However, this caused immense debugging pain when, for some reasons, derived
type descriptor that should be generated were not. This caused random
runtime failures instead of a much cleaner link time failure.

Improve this situation by allowing codegen to detect the builtin derived
types that have no derived type descriptors and requiring the other
unresolved derived type descriptor to be resolved at link time.

Also make derived type descriptor constant data since this was a TODO
and makes the situation even cleaner. This requiring telling lowering
which compiler created symbols can be placed in read only memory. I
considered using PARAMETER, but I have mixed feeling using it since that
would cause the initializer expressions of derived type descriptor to
be invalid from a Fortran point of view since pointer targets cannot be
parameters. I do not want to start misusing Fortran attributes, even if
I think it is quite unlikely semantics would currently complain. I also
do not want to rely on the fact that all object symbols with the
CompilerCreated flags are currently constant data. This could easily
change in the future and cause runtime bugs if lowering rely on this
while the assumption is not loud and clear in semantics.
Instead, add a ReadOnly symbol flag to tell lowering that a compiler
generated symbol can be placed in read only memory.

Differential Revision: https://reviews.llvm.org/D119555
2022-02-14 11:37:13 +01:00
Harshil Jain bea53eead1 The device expression must evaluate to a non-negative integer value.
Device clause when it occurs with **target enter data** and **target exit data** must be declared with some non negative value. So some changes were made to evaluate the device clause argument to non negative value and throw the expected error when it takes negative value as argument.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D119141
2022-02-13 16:51:19 +05:30
Peter Klausler fc510998f7 [flang] Fix edge case in USE-associated generics
It is generally an error when a USE-associated name clashes
with a name defined locally, but not in all cases; a generic
interface can be both USE-associated and locally defined.
This works, but not when there is also a local subprogram
with the same name, which is valid when that subprogram is
a specific of the local generic.  A bogus error issues at
the point of the USE because name resolution will have already
defined a symbol for the local subprogram.

The solution is to collect the names of local generics when
creating the program tree, and then create their symbols as
well if their names are also local subprograms, prior to any
USE association processing.

Differential Revision: https://reviews.llvm.org/D119566
2022-02-11 16:55:05 -08:00
Peter Klausler 7fbabe6ee4 [flang] Avoid bogus error for specification expression
When a scope's symbol has characteriztics whose specification
expressions depend on other non-constant symbols in the same scope,
f18 rightfully emits an error.  However, in the case of usage in
specification expressions involving host association, the program is not
invalid.  This can arise, for example, in the case of an internal
function whose result's attributes use host-associated variables.

Differential Revision: https://reviews.llvm.org/D119565
2022-02-11 15:57:06 -08:00
Peter Steinfeld bdf5736521 [flang] Change internal errors in RESHAPE runtime routine to user errors
There are several checks in the runtime routine for the RESHAPE
intrinsic.  Some checks verify things that should have been checked at
compile time while others represent user errors.

This update changes the checks for user errors into calls to "Crash"
which include information about the failing check.  This identifies them
as user errors rather than compiler errors.

I also verified that the checks that remain as internal errors are also
checked by the front end.  I added a test to the front end's RESHAPE
test to complete the checks.

Differential Revision: https://reviews.llvm.org/D119596
2022-02-11 15:51:21 -08:00
Eric Schweitz c45bd4b9e5 [flang] Upstream fix to allocmem codegen to deal with missing dimensions
for sequence of character types.

Upstream type test. Upstream test. Fix tests.

Do not run on windows, as that is not an implemented target.

Differential Revision: https://reviews.llvm.org/D119551
2022-02-11 11:12:49 -08:00
Peter Steinfeld 1341b5a0f5 [flang] Allow mixed association of procedure pointers and targets
Section 10.2.2.4, paragraph 3 states that a procedure pointer with an explicit
interface must have the same characteristics as its target.  Previously, we
interpreted this as disallowing such pointers to point to procedures with
implicit interfaces.  But several other compilers allow this.

We make an exception for the case where the explicit interface cannot be
called via an implicit interface.

This change makes us allow this, also

Differential Revision: https://reviews.llvm.org/D119404
2022-02-11 10:55:45 -08:00
Louis Dionne 4ae83bb2b1 Update all LLVM documentation mentioning runtimes in LLVM_ENABLE_PROJECTS
We are moving away from building the runtimes with LLVM_ENABLE_PROJECTS,
however the documentation was largely outdated. This commit updates all
the documentation I could find to use LLVM_ENABLE_RUNTIMES instead of
LLVM_ENABLE_PROJECTS for building runtimes.

Note that in the near future, libcxx, libcxxabi and libunwind will stop
supporting being built with LLVM_ENABLE_PROJECTS altogether. I don't know
what the plans are for other runtimes like libc, openmp and compiler-rt,
so I didn't make any changes to the documentation that would imply
something for those projects.

Once this lands, I will also cherry-pick this on the release/14.x branch
to make sure that LLVM's documentation is up-to-date and reflects what
we intend to support in the future.

Differential Revision: https://reviews.llvm.org/D119351
2022-02-10 15:05:23 -05:00
Peter Klausler 82dbe82585 [flang] Refine pointer/target test for ASSOCIATED intrinsic
The second argument to the ASSOCIATED intrinsic must be a valid pointer
or target. The test for this property only checked the last symbol
in a data-reference, but any symbol in the reference with the
POINTER or TARGET attribute will do.

Differential Revision: https://reviews.llvm.org/D119450
2022-02-10 11:32:21 -08:00
Peter Klausler 93b0638eff [flang] Handle "type(foo) function f" when foo is defined in f
Fortran allows forward references to derived types, including
function results that are typed in a prefix of a FUNCTION statement.
If a type is defined in the body of the function, a reference to
that type from a prefix on the FUNCTION statement must resolve to
the local symbol, even and especially when that type shadows one
from the host scope.

The solution is to defer the processing of that type until the
end of the function's specification part.  But the language doesn't
allow for forward references to other names in the prefix, so defer
the processing of the type only when it is not an intrinsic type.
The data structures in name resolution that track this information
for functions needed to become a stack in order to make this work,
since functions can contain interfaces that are functions.

Differential Revision: https://reviews.llvm.org/D119448
2022-02-10 10:29:36 -08:00
Valentin Clement 85b89ed213
[flang] Lower simple RETURN statement
This patch adds the lowering for the RETURN statement
without alternate returns in the main program or in subroutine
and functions.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-10 18:36:04 +01:00
Valentin Clement 2d4dc1cba0
[flang][NFC] Replace hardcoded attribute name
Replace the hardcoded attribute name with the constexpr StringRef
defined in the FIROps.td file.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D119422
2022-02-10 18:34:12 +01:00
Rainer Orth c2b9e9674d [fir] Fix FlangOptimizerTests link on Solaris
As reported in Issue #53690,
`tools/flang/unittests/Optimizer/FlangOptimizerTests` `FAIL`s to link on
Solaris:

  Undefined                       first referenced
   symbol                             in file
  _ZN3fir7runtimeL8getModelIcEEPFN4mlir4TypeEPNS2_11MLIRContextEEv lib/libFIRBuilder.a(Reduction.cpp.o)

which is `mlir::Type (*fir::runtime::getModel<char>())(mlir::MLIRContext*)`.

`clang++` warn's

  In file included from /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/flang/lib/Optimizer/Builder/Runtime/Reduction.cpp:14:
  /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h:60:34: warning: function 'fir::runtime::getModel<char>' has internal linkage but is not defined [-Wundefined-internal]
  static constexpr TypeBuilderFunc getModel();
                                   ^
  /var/llvm/llvm-14.0.0-rc1/rc1/llvm-project/flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h:289:29: note: used here
        TypeBuilderFunc ret = getModel<RT>();
                              ^

Fixed by adding an explicit template instantiation for `getModel<char>`.  I
suppose this is necessary because on Solaris `char` is `signed`.

Tested on `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D119438
2022-02-10 16:09:50 +01:00
Valentin Clement 6da728ad99
[flang] Add FIRInlinerInterface
This patch introduces the FIRInlinerInterface.
This class defines the interface for handling inlining of FIR calls.

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

Reviewed By: schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-10 11:38:34 +01:00
Uday Bondhugula 7d7ebf3cf0 Fix flang build breakage - trim dependency to AffineUtils
There wasn't a need for FIRTransforms to depend on AffineToStandard
conversoin for just an affine utility. The utility was moved to
AffineUtils recently. Fix flang build breakage.

Differential Revision: https://reviews.llvm.org/D119408
2022-02-10 11:33:55 +05:30
Eric Schweitz 3915789503 Folding in the front end was replacing calls to LEN and dropping
arguments even in situations where the arguments are required to compute
the LEN value at runtime.

Add tests.

Differential Revision: https://reviews.llvm.org/D119373
2022-02-09 16:50:28 -08:00
Peter Steinfeld 6cd417bfd8 [flang] Upstream runtime changes for inquiry intrinsics
This change adds runtime routines and tests for LBOUND when passed a DIM argument, SIZE, and UBOUND when not passed a DIM argument.

Associated changes for lowering have already been merged into fir-dev.

Differential Revision: https://reviews.llvm.org/D119360
2022-02-09 12:42:36 -08:00
Valentin Clement fd0417a3cf
[flang] Add type conversion for !fir.box<none>
`none` is used in `fir.box` type to specify a polymorphic type.
This patch add the conversion from `!fir.box<none>` to LLVM.

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

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-09 15:13:47 +01:00
Valentin Clement 0b626df1bc
[flang][NFC] Reorder conversions
During upstreaming the alphabetical order was not respected.
2022-02-09 11:27:23 +01:00
Diana Picus 50bccf2297 [flang] Add runtime interface for GET_COMMAND
Use a single entry point with several optional parameters.

Differential Revision: https://reviews.llvm.org/D118776
2022-02-09 09:49:03 +00:00
Kiran Chandramohan ae37bb9804 [Flang] Add support for lowering the goto statement
This patch adds support for lowering the Fortran goto statement from
parse-tree to MLIR. The goto statement in Fortran is a form of
unstructured control flow. The statement transfers control to the
code starting at the label specified in the statement. This can be
faithfully represented in MLIR by a branch instruction.

To assist the lowering of code with unstructured control flow, blocks
are created in advance and associated with the relevant pre-fir tree
evaluations.

This is part of the upstreaming effort from the fir-dev branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

Reviewed By: clementval, vdonaldson, schweitz, awarzynski

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-09 09:48:13 +00:00
Valentin Clement 903f6b7170
[flang] Add missing CFI case for REAL and COMPLEX
ISO_Fortran_binding.h was updated with missing entries for CFI
types for REAL and COMPLEX kinds 2,3,10,16. This patch updates TypeCode.h
to use these new types.

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

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D119283
2022-02-09 10:07:40 +01:00
Andrzej Warzynski 69c3309d45 [flang][driver] Add support for -emit-mlir
This patch adds support for generating MLIR files in Flang's frontend
driver (i.e. `flang-new -fc1`). `-emit-fir` is added as an alias for
`-emit-mlir`. We may want to decide to split the two in the future.

A new parent class for code-gen frontend actions is introduced:
`CodeGenAction`. We will be using this class to encapsulate logic shared
between all code-generation actions, but not required otherwise. For
now, it will:
 * run prescanning, parsing and semantic checks,
 * lower the input to MLIR.
`EmitObjAction` is updated to inherit from this class. This means that
the behaviour of `flang-new -fc1 -emit-obj` is also updated (previously,
it would just exit immediately). This change required
`flang/test/Driver/syntax-only.f90` to be updated.

For `-emit-fir`, a specialisation of `CodeGenAction` is introduced:
`EmitMLIRAction`. The key logic for this class is implemented in
`EmitMLIRAction::ExecuteAction`.

Differential Revision: https://reviews.llvm.org/D118985
2022-02-09 08:35:48 +00:00
Jean Perier 47995a0ec9 [flang] catch implicit interface incompatibility with global scope symbol
Previously, when calling a procedure implicitly for which a global scope
procedure symbol with the same name existed, semantics resolved the
procedure name in the call to the global symbol without checking that
the symbol interface was compatible with the implicit interface of the
call.
This could cause expression rewrite and lowering to later badly process
the implicit call assuming a different result type or an explicit
interface. This could lead to lowering crash in case the actual argument
were incompatible with the dummies from the explicit interface.

Emit errors in the following problematic cases:
- If the result type from the symbol did not match the one from the
  implicit interface.
- If the symbol requires an explicit interface.

This patch still allows calling an F77 like procedure with different
actual argument types than the one it was defined with because it is
correctly supported in lowering and is a feature in some program
(it is a pointer cast). The two cases that won't be accepted have
little chance to make much sense. Results returning ABIs may differ
depending on the return types, and function that requires explicit
interface usually requires descriptors or specific processing that
is incompatible with implicit interfaces.

Note that this patch is not making a deep analysis, and it will only
catch mistakes if a global symbol and an implicit interface are
involved. Cases where the user provided a conflicting explicit
interface would still require a pass after name resolution to study
conflicts more deeply. But these cases will not crash lowering or
trigger expression rewrite to do weird things.

Differential Revision: https://reviews.llvm.org/D119274
2022-02-09 09:30:32 +01:00
Valentin Clement 9b5bb511ad
[flang][codegen] Keep primitive type for extractvalue and insertvalue
llvm.insertvalue and llvm.extractvalue need LLVM primitive type
for the indexing operands. While upstreaming the TargetRewrite pass the change
was made from i32 to index without knowing this restriction. This patch reverts
back the types used for indexing in the two ops created in this pass.

the error you will receive when lowering to LLVM IR with the current code
is the following:

```
 'llvm.insertvalue' op operand #1 must be primitive LLVM type, but got 'index'
```

Reviewed By: jeanPerier, schweitz

Differential Revision: https://reviews.llvm.org/D119253
2022-02-08 21:26:38 +01:00
Josh Mottley 5ebbcfa01d [flang] Upstream partial lowering of GET_ENVIRONMENT_VARIABLE intrinsic
This patch adds partial lowering of the "GET_ENVIRONMENT_VARIABLE" intrinsic
to the backend runtime hook implemented in patches D111394 and D112698.
It also renames the `isPresent` lambda to `isAbsent` and moves it out to
its own function in `Command.cpp`. Corresponding comment fixes for this
are also modified. Lastly it adds the i1 type to
`RuntimeCallTestBash.h`.

Differential Revision: https://reviews.llvm.org/D118984
2022-02-08 17:42:53 +00:00
Andrzej Warzynski 8d248002a6 [flang][nfc] Add an assert to guard against nullptr dereferencing
Differential Revision: https://reviews.llvm.org/D119133
2022-02-08 10:46:57 +00:00
River Riddle 60cac0c081 [mlir][NFC] Remove deprecated/old build/fold/parser utilities from OpDefinition
These have generally been replaced by better ODS functionality, and do not
need to be explicitly provided anymore.

Differential Revision: https://reviews.llvm.org/D119065
2022-02-07 19:03:58 -08:00
Valentin Clement a8d48fe0fe
[flang] Handle character constant for error code in STOP stmt
Handle character constant ofr error code in the STOP statement.

Depends on D118992

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

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118993
2022-02-07 12:19:55 +01:00
Valentin Clement 74751f4b0c
[flang] Add lowering for ASCII character constant
Lower character constant of KIND = 1 with the
`createStringLiteral` helper function.

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

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118992
2022-02-07 12:17:41 +01:00
Valentin Clement b880455768
[flang] Remove unused converter for now
AbstractConverter private variable is currently not used
and triggers a buildbot failure.

https://lab.llvm.org/buildbot/#/builders/180/builds/3119

This fixes the buildbot.
2022-02-07 11:56:06 +01:00
Valentin Clement 6518c40931
[flang] Add test for quiet with local variable in STOP stmt
Depends on D118978.

Differential Revision: https://reviews.llvm.org/D118982
2022-02-07 09:17:28 +01:00
Valentin Clement 2c2e5a5d0f
[flang] Basic local variable lowering
This patch add lowering for simple local variable.

- The signatures in `ConvertType.h` have been simplified to take advantage of the `AbstractConverter`.
- The lowering make use of the `allocateLocal` from the `FirOpBuilder`.

This lowering is used in patch D118982

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

Reviewed By: kiranchandramohan, jeanPerier, schweitz

Differential Revision: https://reviews.llvm.org/D118978
2022-02-07 09:14:09 +01:00
River Riddle ace01605e0 [mlir] Split out a new ControlFlow dialect from Standard
This dialect is intended to model lower level/branch based control-flow constructs. The initial set
of operations are: AssertOp, BranchOp, CondBranchOp, SwitchOp; all split out from the current
standard dialect.

See https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061

Differential Revision: https://reviews.llvm.org/D118966
2022-02-06 14:51:16 -08:00
Peter Klausler 991696c2eb [flang] Debugging of ACCESS='STREAM' I/O (take 2)
Corrects the runtime implementation of I/O on files with
the access mode ACCESS='STREAM'.  This is a collection
of edge-case tweaks to ensure that the distinctions between
stream and direct/sequential files, unformatted or formatted,
are respected where appropriate.

Moves NextInField() from io-stmt.h to io-stmt.cpp --
it was getting too big to keep in a header.

This patch exposed a problem with the I/O runtime
on Windows and it was reverted.  This version also
fixes that problem; files are now opened on Windows
in binary mode to prevent inadvertent insertions of
carriage returns before line feeds, and those line
endings (CR+LF) are now explicitly generated.

Differential Revision: https://reviews.llvm.org/D119015
2022-02-04 18:02:34 -08:00
Josh Mottley 38073b0669 [flang] Upstream partial lowering of GET_COMMAND_ARGUMENT intrinsic
This patch adds partial lowering of the "GET_COMMAND_ARGUMENT"
intrinsic to the backend runtime hook implemented in patches D109227,
D109813, D109814.

Differential Revision: https://reviews.llvm.org/D118801
2022-02-04 10:25:01 +00:00
Valentin Clement cc306740cc
[flang] Handle logical constant value for quiet in STOP stmt
This patch handles the quiet argument in the STOP statement. It adds
ability to lower LOGICAL constant.

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

Reviewed By: kiranchandramohan, PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-04 10:12:25 +01:00
Andrzej Warzynski 4e53e28374 Revert "[flang] Debugging of ACCESS='STREAM' I/O"
This reverts commit be9946b877.

This change has caused Flang's Windows buildbot to start failing:
* https://lab.llvm.org/buildbot/#/builders/172/builds/7664
2022-02-03 15:19:42 +00:00
Valentin Clement e7361469bb
[fir] Add fir.array_amend operation definition
This patch adds the fir.array_amend operation. this op
is used later in upstreaming patches for the F95 compliance.

The `array_amend` operation marks an array value as having been changed via
a reference obtain by an `array_access`. It acts as a logical transaction
log that is used to merge the final result back with an `array_merge_store`
operation.

 ```mlir
  // fetch the value of one of the array value's elements
  %1 = fir.array_access %v, %i, %j : (!fir.array<?x?xT>, index, index) -> !fir.ref<T>
  // modify the element by storing data using %1 as a reference
  %2 = ... %1 ...
  // mark the array value
  %new_v = fir.array_amend %v, %2 : (!fir.array<?x?xT>, !fir.ref<T>) -> !fir.array<?x?xT>
```

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

Reviewed By: kiranchandramohan, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-03 15:04:35 +01:00
Valentin Clement 1bfbe315a7
[flang] Remove ununsed variable in ScalarExprLowering
Fix buildbot failure https://lab.llvm.org/buildbot/#/builders/180/builds/3066
2022-02-03 15:02:49 +01:00
Valentin Clement f254a8eff6
[fir] Add fir.array_access op
The `array_access` provides a reference to a single element from an array
value. This is *not* a view in the immutable array, otherwise it couldn't
be stored to. It can be see as a logical copy of the element and its
position in the array. This reference can be written to and modified without
changing the original array.

The `array_access` operation is used to fetch the memory reference of an
element in an array value.

```fortran
      real :: a(n,m)
      ...
      ... a ...
      ... a(r,s+1) ...
```

One can use `fir.array_access` to recover the implied memory reference to
the element `a(i,j)` in an array expression `a` as shown above. It can also
be used to recover the reference element `a(r,s+1)` in the second
expression.

```mlir
      %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
      // load the entire array 'a'
      %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
      // fetch the value of one of the array value's elements
      %1 = fir.array_access %v, %i, %j : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
```

More information about `array_access` and other array operations can be
found in flang/docs/FIRArrayOperations.md.

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

Reviewed By: kiranchandramohan, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-03 11:45:27 +01:00
Valentin Clement ca53e049e0
[flang] Lower integer constant code for STOP stmt
This patch lower the integer constant code in the STOP statement.

The code is lowered to `arith.constant`.

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

Reviewed By: schweitz, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118787
2022-02-03 11:31:12 +01:00
Valentin Clement dc6a344637
[flang] Add lowering for integer constant
This patch enables the lowering of integer constant.

The `ScalarExprLowering` class is introduced in `ConvertExpr.cpp` to help
the lowering of expression. This patch adds all the placeholder as well for future
expression lowering with the appropriate TODOs.

Integer constant expression are lowered to `arith.constant` with an integer type corresponding to the kind value.

This patch is in support of D118787

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

Reviewed By: schweitz, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118786
2022-02-03 11:10:30 +01:00
Jean Perier 575a6f819b [flang] add ExtendedValue type helpers and factory::genZeroValue
Add some helpers to get the base type and element type of
fir::ExtendedValue and to test if a fir::ExtendedValue is
a derived type with length parameters.

Add a new helper factory::genZeroValue to generate zero scalar value for
all the numerical types and false for logicals.

These helpers are used only in lowering for now, so add unit tests.

Differential Revision: https://reviews.llvm.org/D118795
2022-02-03 10:13:54 +01:00
Damian Rouson e76ccf2a0c [flang] Add a semantics test for co_broadcast
Test a range of acceptable forms of co_broadcast calls, including
combinations of keyword and non-keyword actual arguments of
intrinsic and derived type.  Also test that several invalid forms
of co_sum call generate the correct error messages.

Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D113084
2022-02-02 14:58:48 -08:00
River Riddle 8e123ca65f [mlir:Standard] Remove support for creating a unit ConstantOp
This is completely unused upstream, and does not really have well defined semantics
on what this is supposed to do/how this fits into the ecosystem. Given that, as part of
splitting up the standard dialect it's best to just remove this behavior, instead of try
to awkwardly fit it somewhere upstream. Downstream users are encouraged to
define their own operations that clearly can define the semantics of this.

This also uncovered several lingering uses of ConstantOp that weren't
updated to use arith::ConstantOp, and worked during conversions because
the constant was removed/converted into something else before
verification.

See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for more discussion.

Differential Revision: https://reviews.llvm.org/D118654
2022-02-02 14:45:12 -08:00
River Riddle dec8af701f [mlir] Move SelectOp from Standard to Arithmetic
This is part of splitting up the standard dialect. See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for discussion.

Differential Revision: https://reviews.llvm.org/D118648
2022-02-02 14:45:12 -08:00
Peter Klausler 2b0b9b2e83 [flang] Modify right modes for READ/WRITE vs OPEN
When a mode flag is modified (e.g., BLANK='ZERO') in an I/O data transfer
statement, ensure that the right set of mode flags is modified.
There's one set of mode flags that are captured by an OPEN
statement and maintained in the connection, and another that
is maintained in an I/O statement state record for local mutability.
Some I/O API routines were unconditionally modifying the persistent
set of flags.

Differential Revision: https://reviews.llvm.org/D118835
2022-02-02 13:47:46 -08:00
River Riddle 42e5f1d97b [mlir] Refactor how additional verification is specified in ODS
Currently if an operation requires additional verification, it specifies an inline
code block (`let verifier = "blah"`). This is quite problematic for various reasons, e.g.
it requires defining C++ inside of Tablegen which is discouraged when possible, but mainly because
nearly all usages simply forward to a static function `static LogicalResult verify(SomeOp op)`.
This commit adds support for a `hasVerifier` bit field that specifies if an additional verifier
is needed, and when set to `1` declares a `LogicalResult verify()` method for operations to
override. For migration purposes, the existing behavior is untouched. Upstream usages will
be replaced in a followup to keep this patch focused on the hasVerifier implementation.

One main user facing change is that what was one `MyOp::verify` is now `MyOp::verifyInvariants`.
This better matches the name this method is called everywhere else, and also frees up `verify` for
the user defined additional verification. The `verify` function when generated now (for additional
verification) is private to the operation class, which should also help avoid accidental usages after
this switch.

Differential Revision: https://reviews.llvm.org/D118742
2022-02-02 13:34:28 -08:00
Peter Klausler be9946b877 [flang] Debugging of ACCESS='STREAM' I/O
Corrects the runtime implementation of I/O on files with
the access mode ACCESS='STREAM'.  This is a collection
of edge-case tweaks to ensure that the distinctions between
stream and direct/sequential files, unformatted or formatted,
are respected where appropriate.
Moves NextInField() from io-stmt.h to io-stmt.cpp --
it was getting too big to keep in a header.

Differential Revision: https://reviews.llvm.org/D118834
2022-02-02 13:09:38 -08:00
Peter Klausler aee705661f [flang] Silence bogus error on use after IMPORT
When a scope uses an explicit IMPORT statement to import a
symbol from the scope's host, it should not emit a bogus error
message later if that symbol is used in a specification construct.
The code that checks for imports being hidden by local declarations
was not allowing for the presence of host association (or USE)
indirection symbols in the local scope.  Fix by using GetUltimate()
before checking for the hidden symbol.

Differential Revision: https://reviews.llvm.org/D118747
2022-02-02 11:15:58 -08:00
Jean Perier bc699ed0bf [flang] prevent rewrite of CMPLX with dynamically optional Y argument
CMPLX was always rewritten as a complex constructor, but the second operand
of a complex constructor cannot be dynamically absent (i.e., a
disassociated pointer, an unallocated allocatable or an absent OPTIONAL
dummy argument), while the second argument of CMPLX can be dynamically
absent.

To avoid having to generate branches in complex constructor lowering
when Y is a pointer, keep the distinction between CMPLX and a complex
constructor when Y is a pointer, an allocatable, or an OPTIONAL entity.

Differential Revision: https://reviews.llvm.org/D118784
2022-02-02 19:52:52 +01:00
Peter Klausler 73f21db537 [flang] Fix: use right symbol for parent component
When constructing the representation for a component reference
to an inherited component, expression semantics make the parent
component references explicit in the DataRef; e.g., base%component
becomes base%parent%grandparent%component if component was
inheritance-associated through two levels.  But expression semantics
was inserting references to the symbol table entries for the
intermediate types, not the symbols for the parent components in
the extended types.  (We didn't notice the distinction until
recently because both symbols have the same name; this only
affects lowering.)  Find and use the right symbols.

Differential Revision: https://reviews.llvm.org/D118746
2022-02-02 10:49:10 -08:00
Valentin Clement 415267407d
[flang] Switch return to ExtendedValue in AbstractConverter and Bridge
Change the signature of `genExprAddr`, `genExprValue` to return a `fir::ExtendedValue` instead of a simple `mlir::Value`

This patch is a preparation for more lowering to be upstream. It supports D118786 and D118787.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118785
2022-02-02 18:44:28 +01:00
Peter Klausler 9772dbba74 [flang] Set right "inNamelist" flag
NAMELIST I/O was inconsistent in its choice of which set of I/O modes
to set the "inNamelist" flag.  The wrong choice was in the set of modes
that are part of the persistent state of an I/O connection; the right
place is the set of modes that are reinitialized at the beginning of
each I/O statement so that they can be modified by READ/WRITE control
list specifiers and FORMAT control edit descriptors.  Fix.

Differential Revision: https://reviews.llvm.org/D118745
2022-02-02 09:33:19 -08:00
Jean Perier c099ca4e45 [flang][optimizer] support aggregate types inside tuple and record type
This patch allows:
 - fir.box type to be a member of tuple<> or fir.type<> types,
 - tuple<> type to be a member of tuple<> type.

When a fir.box types are nested in tuple<> or fir.type<>, it is translated
to the struct type of a Fortran runtime descriptor, and not a
pointer to a descriptor. This is because the fir.box is owned by the tuple
or fir.type.

FIR type translation was also flattening nested tuple while lowering to LLVM
dialect types. There does not seem to be a deep reason for doing that
and doing it causes issues in fir.coordinate_of generated on such tuple
(a fir.coordinate_of getting tuple<B, C> in tuple<A, tuple<B, C>>
ended-up lowered to an LLVM GEP getting B).

Differential Revision: https://reviews.llvm.org/D118701
2022-02-02 09:22:11 +01:00
Valentin Clement db01b123d0
[flang] Lower PAUSE statement
Lower the PAUSE statement to a runtime call.

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

Reviewed By: kiranchandramohan, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-02-02 08:16:12 +01:00
Peter Klausler 01b52f77c9 [flang] Fix argument keyword names in some specific intrinsics
Some entries in the specific intrinsic function table have the
wrong argument keyword names -- they should agree with the names
of the arguments on their corresponding generic intrinsic function.
Clean them up.

Differential Revision: https://reviews.llvm.org/D118721
2022-02-01 16:55:21 -08:00
Peter Klausler 0f5c60f151 [flang] Fix edge-case I/O regressions
A blank field in an input record that exists must be interpreted
as a zero value for numeric input editing, but advancing to a
next record that doesn't exist should leave an input variable
unmodified (and signal END=).  On internal output, blank fill
the "current record" array element even if nothing has been
written to it if it is the only record.

Differential Revision: https://reviews.llvm.org/D118720
2022-02-01 16:27:47 -08:00
Valentin Clement aab4263ad6
[flang] Lower basic STOP statement
This patch lowers STOP statement without arguments
and ERROR STOP. STOP statement with arguments lowering will
come in later patches ince it requires some expression lowering
to be added.
STOP statement is lowered to a runtime call.

Also makes sure we are creating a constant in the MLIR arith constant.

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

Reviewed By: kiranchandramohan, schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-02-01 20:54:45 +01:00
Peter Klausler 82cf35bc89 [flang] Fix/work around warnings from GCC 11
Apply part of a pending patch for GCC 11 warnings, and
rework a piece of code, to dodge warnings on flag from
GCC 11 build bots exposed by a recent patch.

Applying without review to get bots working again; changes
also tested against GCC 9.3.0.
2022-02-01 11:54:04 -08:00
Josh Mottley ce8022faa3 [flang] Upstream partial lowering of EXIT intrinsic
This patch adds partial lowering of the "EXIT" intrinsic to
the backend runtime hook implemented in patch D110741. It also adds a
helper function to the `RuntimeCallTestBase.h` for testing for an
intrinsic function call in a `mlir::Block`.

Differential Revision: https://reviews.llvm.org/D118141
2022-02-01 17:48:51 +00:00
Peter Steinfeld 93ee588232 [flang] Rename the runtime routine that reports a fatal user error
As per Steve Scalpone's suggestion, I've renamed the runtime routine to
better evoke its purpose.

I implemented a routine called "Crash" and added a test.

Differential Revision: https://reviews.llvm.org/D118703
2022-02-01 09:01:50 -08:00
Valentin Clement 89275300d8
[flang] Add lowering for basic empty SUBROUTINE
This patch adds the ability to lower an empty subroutine.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118695
2022-02-01 15:28:18 +01:00
Valentin Clement 990759136a
[flang] Add lowering placeholders
This patch puts in place the differents
function to lower the evaluation list. All functions
are just placholders with TODOs for now.
Follow up patches will bring the proper lowering in these
functions.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D118678
2022-02-01 13:50:09 +01:00
Peter Klausler c7f4c333af [flang] Make NEWUNIT= use a range suitable for INTEGER(KIND=1) and recycle unit numbers
Use a bit-set to manage runtime-generated I/O unit numbers, recycle
them after they're closed, and use a range of values that fits in
a minimal-sized integer.

Differential Revision: https://reviews.llvm.org/D118651
2022-01-31 15:20:21 -08:00
Peter Klausler 702c0cfa07 [flang] runtime perf: larger I/O buffer growth increments
When reallocating an I/O buffer to accommodate a large record,
ensure that the amount of growth is at least as large as the
minimum initial record size (64KiB).  The previous policy was
causing input buffer reallocation for each byte after the minimum
buffer size when scanning input data for record termination
newlines.

Differential Revision: https://reviews.llvm.org/D118649
2022-01-31 14:53:15 -08:00
Peter Klausler 52a1346b78 [flang] Distinguish intrinsic from non-intrinsic modules
For "USE, INTRINSIC", search only for intrinsic modules;
for "USE, NON_INTRINSIC", do not recognize intrinsic modules.
Allow modules of both kinds with the same name to be used in
the same source file (but not in the same scoping unit, a
constraint of the standard that is now enforced).

The symbol table's scope tree now has a single instance of
a scope with a new kind, IntrinsicModules, whose children are
the USE'd intrinsic modules (explicit or not).  This separate
"top-level" scope is a child of the single global scope and
it allows both intrinsic and non-intrinsic modules of the same
name to exist in the symbol table.  Intrinsic modules' scopes'
symbols now have the INTRINSIC attribute set.

The search path directories need to make a distinction between
regular directories and the one(s) that point(s) to intrinsic
modules.  I allow for multiple intrinsic module directories in
the second search path, although only one is needed today.

Differential Revision: https://reviews.llvm.org/D118631
2022-01-31 13:31:27 -08:00
Peter Klausler f651bbea06 [flang] Correct interpretation of RECL=
When RECL= is set on OPEN(), ensure that it:
  1) enforces a max output record payload size
     (not including header+footer or newline), and
  2) causes padding of short output records only
     for ACCESS='DIRECT'

The previous code was causing some false overrun errors
and applying padding to sequential/stream output files.

Differential Revision: https://reviews.llvm.org/D118630
2022-01-31 12:48:17 -08:00
Sanjoy Das 697a5036cd Remove OpTrait, AttrTrait and TypeTrait
- Remove the `{Op,Attr,Type}Trait` TableGen classes and replace with `Trait`
  - Rename `OpTraitList` to `TraitList` and use it in a few places

The bulk of this change is a mechanical s/OpTrait/Trait/ throughout the codebase.

Reviewed By: rriddle, jpienaar, herhut

Differential Revision: https://reviews.llvm.org/D118543
2022-01-31 11:04:00 -08:00
Valentin Clement 0a494d0623
[flang][NFC] Remove obsolete Character helper
During the upstreaming process from fir-dev some
new builder have been introduced in the `flang/Optimizer/Builder/Character.h`
and `flang/include/Builder/Runtime/Character.h` files.
This patch removes the obsolete Charachter helpers still present
in the lowering directories.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118594
2022-01-31 18:29:32 +01:00
Josh Mottley ddac11aee6 [flang] Upstream partial lowering of COMMAND_ARGUMENT_COUNT intrinsic
This patch adds partial lowering of the "COMMAND_ARGUMENT_COUNT" intrinsic
to the backend runtime hook implemented in patch D109048. Also adds a
"helper" function for retrieving the default integer type from
FIRBuilder, which will be used later when finishing the lowering of
intrinsic.

Differential Revision: https://reviews.llvm.org/D117869
2022-01-31 17:01:26 +00:00