Commit Graph

3215 Commits

Author SHA1 Message Date
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 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 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 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
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
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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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 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
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
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
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 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
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
Valentin Clement 6d892987bc
[flang][NFC] Remove out of date IO helper
Functionality in IO.h and IO.cpp have been upstreamed together with the frontend
when flang landed upstream. Those files are out of date compared with fir-dev.
These functionality will be upstreamed again when needed in the lowering process
with an up to date code and a proper review.

These files (and the functions it contains) are not currently used. Hence
removing it is NFC.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118593
2022-01-31 16:33:47 +01:00
Andrzej Warzynski 4606f838b2 [flang][driver][nfc] Fix capitalisation
As pointed out in https://reviews.llvm.org/D93401, some methods in the
Flang driver are named inconsistently. The driver strives to follow
Flang's C++ style [1] and this patch updates these methods accordingly.

[1]
https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md

Differential Revision: https://reviews.llvm.org/D118381
2022-01-31 10:36:18 +00:00
Valentin Clement e1a12767ee
[flang] Initial lowering for empty program
This patch enable lowering from Fortran to FIR for a basic empty
program. It brings all the infrastructure needed for that. As discussed
previously, this is the first patch for lowering and follow up patches
should be smaller.

With this patch we can lower the following code:

```
program basic
end program
```

To a the FIR equivalent:

```
func @_QQmain() {
  return
}
```

Follow up patch will add lowering of more complex constructs.

Reviewed By: kiranchandramohan, schweitz, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D118436
2022-01-28 22:39:58 +01:00
Valentin Clement b62e5928e4
[flang][NFC] Remove obsolete IntrinsicCall helper
Remove obsolete code that has moved to the
`flang/Optimizer/Builder/Intrinsic` directory.

`genMin` is inlined in the code since it's not available
in the builder.

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118465
2022-01-28 22:37:56 +01:00
Valentin Clement 944dca758f
[flang][NFC] Remove obsolete ComplexExpr helper
Functionality present in `flang/include/flang/Lower/ComplexExpr.h` are
available in `flang/include/flang/Optimizer/Builder/Complex.h`. This patch removes
the obsolete files.

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118462
2022-01-28 21:02:14 +01:00
Valentin Clement 6277b90992
[flang] Add missing FIRBuilder library
Fix buildbot failure https://lab.llvm.org/buildbot/#/builders/160
2022-01-28 14:46:24 +01:00
Valentin Clement 47a66f1c5a
[flang][NFC] Remove obsolete DoLoopHelper
During the upstreaming process from fir-dev some
new builder have been introduced in the `flang/Optimizer/Builder`
directory. This patch removes the obsolete DoLoopHelper still present
in the lowering directories and makes use of the new one where needed.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118442
2022-01-28 11:30:11 +01:00
Valentin Clement 8a0d0a3a54
[flang][NFC] Remove obsolete FIRBuilder and BoxValue
This patch removes some files made obsolete by newer version
of them available in the Optimizer directory.
`flang/include/flang/Lower/FIRBuilder.h` and `flang/lib/Lower/FIRBuilder.cpp` are
removed and replace by the newer version present in
`flang/include/flang/Optimizer/Builder/FIRBuilder.h` and
`flang/lib/Optimizer/Builder/FIRBuilder.cpp`.
`flang/include/flang/Lower/Support/BoxValue.h` and `flang/lib/Lower/ConvertExpr.cpp` are removed and replace by the newer
version present in `flang/include/flang/Optimizer/Builder/BoxValue.h`

This patch is a preparation to be able to upstream the lowering from
fir-dev.

Reviewed By: jeanPerier, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D118404
2022-01-28 11:25:35 +01:00
Jean Perier 416e503adf [flang] split character procedure arguments in target-rewrite pass
When passing a character procedure as a dummy procedure, the result
length must be passed along the function address. This is to cover
the cases where the dummy procedure is declared with assumed length
inside the scope that will call it (it will need the length to allocate
the result on the caller side).

To be compatible with other Fortran compiler, this length must be
appended after all other argument just like character objects
(fir.boxchar).

A fir.boxchar cannot be used to implement this feature because it
is meant to take an object address, not a function address.

Instead, argument like `tuple<function type, integer type> {fir.char_proc}`
will be recognized as being character dummy procedure in FIR. That way
lowering does not have to do the argument split.

This patch adds tools in Character.h to create this type and tuple
values as well as to recognize them and extract its tuple members.

It also updates the target rewrite pass to split these arguments like
fir.boxchar.

This part is part of fir-dev upstreaming. It was reviwed previously
in: https://github.com/flang-compiler/f18-llvm-project/pull/1393

Differential Revision: https://reviews.llvm.org/D118108
2022-01-27 16:29:37 +01:00
River Riddle 9f85c198db [mlir] Finish replacing OwningRewritePatternList with RewritePatternSet
OwningRewritePatternList has been deprecated for ~10 months now, we can remove
the leftover using directives at this point.

Differential Revision: https://reviews.llvm.org/D118287
2022-01-26 23:11:02 -08:00
Yury Gribov d3f5ef241a Add ieee_is_normal/ieee_is_negative to ieee_arithmetic module. 2022-01-26 11:33:23 +03:00
Valentin Clement 74acd744d3
[flang] Change getLoweredName to translateNameToFrontendMangledName()
getLoweredName() is not a well suited name change it to
translateNameToFrontendMangledName()

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D118140
2022-01-26 08:52:39 +01:00
Valentin Clement 4d53f88d1a
[flang] Add MemoryAllocation pass to the pipeline
Add the MemoryAllocation pass into the pipeline. Add
the possibilty to pass the options directly within the tool (tco).

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

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D117886
2022-01-24 16:32:39 +01:00
Valentin Clement 853e79d8d8
[flang] Update tco tool pipline and add translation to LLVM IR
tco is a tool to test the FIR to LLVM IR pipeline of the Flang compiler.

This patch update tco pipelines and adds the translation to LLVM IR.

A simple test is added to make sure the tool is working with a simple
FIR program.
More tests will be upstream in follow up patch from the fir-dev branch.

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

Reviewed By: kiranchandramohan, awarzynski, schweitz, mehdi_amini

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2022-01-24 14:16:27 +01:00
Nimish Mishra 3519dcfec2 Added OpenMP 5.0 specification based semantic checks for atomic update construct 2022-01-24 13:24:00 +05:30
Peter Klausler 3726626a26 [flang] Fix crash from USE-associated defined I/O subprograms
User-defined derived type I/O implementation subroutines and
generic interfaces may be USE-associated, but the code that builds
the type description table wasn't allowing for that possibility.
Add a call to GetUltimate() to cope.

Differential Revision: https://reviews.llvm.org/D117902
2022-01-21 17:49:09 -08:00
Valentin Clement 3c90ae5d0b
Revert "[flang] Update tco tool pipline and add translation to LLVM IR"
This reverts commit 68db0e25df.
2022-01-21 20:34:17 +01:00
serge-sans-paille 5597ec2dc4 Include missing "llvm/Support/Path.h" in "flang/lib/Frontend/CompilerInvocation.cpp" 2022-01-21 17:05:49 +01:00
Valentin Clement 68db0e25df
[flang] Update tco tool pipline and add translation to LLVM IR
tco is a tool to test the FIR to LLVM IR pipeline of the Flang compiler.

This patch update tco pipelines and adds the translation to LLVM IR.

A simple test is added to make sure the tool is working with a simple
FIR program.
More tests will be upstream in follow up patch from the fir-dev branch.

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

Reviewed By: schweitz, mehdi_amini

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2022-01-21 13:15:28 +01:00
Valentin Clement 81cbbe3e17
[flang][NFC] Remove unused/duplicated kStridePosInDim
kStridePosInDim is a duplicate of kDimStridePos and is not used. Just
remove it.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D117784
2022-01-20 18:30:29 +01:00
Valentin Clement 010a10b738
[flang][NFC] Remove extra braces
Noticed during the upstreaming process.
2022-01-20 15:18:59 +01:00
Valentin Clement ccaaeca910
[flang][NFC] Move current inliner files in Dialect directory
This patch just move the files from the Transforms directory to
the Dialect directory.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D117661
2022-01-20 13:34:44 +01:00
Peter Klausler 78649a8499 [flang] Accept INDEX(..., BACK=array)
The intrinsic table entry for INDEX mistakenly required
the optional BACK= argument to be scalar, but it's an
elemental intrinsic that can accept a conforming array.

Differential Revision: https://reviews.llvm.org/D117700
2022-01-19 17:37:24 -08:00
Peter Klausler bddfb81a31 [flang] Accept sparse argument keyword names for MAX/MIN
Accept any keyword argument names of the form "An" for
values of n >= 3 in calls to the intrinsic functions MAX, MIN,
and their variants, so long as "n" has no leading zero and
all the keywords are distinct.  Previously, f18 was needlessly
requiring the names to be contiguous.  When synthesizing keywords
to characterize the procedure's interface, don't conflict with
the program's keywords.

Differential Revision: https://reviews.llvm.org/D117701
2022-01-19 17:36:24 -08:00
River Riddle e084679f96 [mlir] Make locations required when adding/creating block arguments
BlockArguments gained the ability to have locations attached a while ago, but they
have always been optional. This goes against the core tenant of MLIR where location
information is a requirement, so this commit updates the API to require locations.

Fixes #53279

Differential Revision: https://reviews.llvm.org/D117633
2022-01-19 17:35:35 -08:00
Peter Klausler 028477758d [flang] Accept BOZ literals for some actual arguments
Consistent with previously documented policy, in which
BOZ literals are accepted in non-standard-conforming circumstances
where they can be converted to an unambiguous known numeric type,
allow BOZ literals to be passed as an actual argument in a reference
to a procedure whose explicit interface has a corresponding dummy
argument with a numeric type to which the BOZ literal may be
converted.  Improve error messages associated with BOZ literal
actual arguments, too: don't emit multiple errors.

Differential Revision: https://reviews.llvm.org/D117698
2022-01-19 17:28:21 -08:00
Peter Klausler 2985d5623c [flang] Improve error message (initialized variable in pure subprogram)
When variable with the SAVE attribute appears in a pure subprogram,
emit a more specialized error message if the SAVE attribute was acquired
from static initialization.

Differential Revision: https://reviews.llvm.org/D117699
2022-01-19 17:27:31 -08:00
Jean Perier 81c6693329 [flang] Prevent any non constant result extent to be inlined on caller side
UBOUND, SIZE, and SHAPE folding was still creating expressions that are
invalid on the caller side without the call expression context.
A previous patch intended to deal with this situation (https://reviews.llvm.org/D116933)
but it assumed the return expression would be a descriptor inquiry to
the result symbol, which is not the case if the extent expression is
"scope invariant" inside the called subroutine (e.g., referring to
intent(in) dummy arguments). Simply prevent folding from inlining non
constant extent expression on the caller side.

Folding could be later improved by having ad-hoc folding for UBOUND, SIZE, and
SHAPE on function references where it could try replacing the dummy symbols
by the actual expression, but this is left as a possible later improvement.

Differential Revision: https://reviews.llvm.org/D117686
2022-01-19 19:15:49 +01:00
Peter Klausler f2dac557f5 [flang] Intrinsic assignment of distinct but "same" derived types
Subclause 7.5.2.4 lists conditions under which two distinct derived
types are to be considered the same type for purposes of argument
association, assignment, and so on.  These conditions are implemented
in evaluate::IsTkCompatibleWith(), but assignment semantics doesn't
use it for testing for intrinsic assignment compatibility.  Fix that.

Differential Revision: https://reviews.llvm.org/D117621
2022-01-19 10:08:17 -08:00
Valentin Clement 64d7d5a597
[flang][NFC] Remove number of inlined elements
Following the recommendation just remove the specified number of
inlined elements since it is not well-motivated choice here.
2022-01-19 14:51:17 +01:00
Valentin Clement 367c4ed2f8
[flang][NFC] Fix includes order 2022-01-19 14:32:48 +01:00
River Riddle 196c4279c0 [flang] Convert uses of FunctionPass to OperationPass<FuncOp>
FunctionPass has been deprecated and is in the process of being removed.
2022-01-18 20:46:44 -08:00
Peter Klausler a567961574 [flang] Better messages for function vs. array errors
When a scalar-valued function with no distinct RESULT
is being called recursively in its own executable part,
emit a better message about the error.  Clean up the
code that resolves function vs. array ambiguities in
expression semantics.

Update to address review comment

Differential Revision: https://reviews.llvm.org/D117577
2022-01-18 15:42:08 -08:00
Mogball aae5125550 [mlir] Replace StrEnumAttr -> EnumAttr in core dialects
Removes uses of `StrEnumAttr` in core dialects

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D117514
2022-01-18 17:15:00 +00:00
Mogball 5c36ee8d57 [mlir] Drop the leading space when printing regions
The leading space that is always printed at the beginning of regions is not consistent with other parts of the printing API. Moreover, this leading space can lead to undesirable assembly formats:

```
attr-dict-with-keyword $region
```

Prints as:

```
// Two spaces between `}` and `{`
attributes {foo}  { ... }
```

Moreover, the leading space results in the odd generic op format:

```
"test.op"() ( {...}) : () -> ()
```

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D117411
2022-01-18 16:52:34 +00:00
Peter Klausler 5c5bde1bb6 [flang] Fold SCALE()
Fold references to the intrinsic function SCALE().

(Also work around some MSVC headaches somehow exposed by
this patch: disable a bogus MSVC warning that began to appear
in unrelated source files, and avoid the otherwise-necessary
use of the "template" keyword in a call to a template member
function of a class template.)

Differential Revision: https://reviews.llvm.org/D117150
2022-01-15 09:31:00 -08:00
Peter Klausler bd859cb4de [flasg] Debug folding of substring references
Character substrings weren't being folded correctly;
add tests and rework the implementation so that substrings
of literals and named constant character scalars & arrays
are properly folded for use in constant expressions.

Differential Revision: https://reviews.llvm.org/D117343
2022-01-14 16:09:06 -08:00
Peter Klausler bed947f708 [flang] Accept ENTRY names in generic interfaces
ENTRY statement names in module subprograms were not acceptable for
use as a "module procedure" in a generic interface, but should be.
ENTRY statements need to have symbols with place-holding
SubprogramNameDetails created for them in order to be visible in
generic interfaces.  Those symbols are created from the "program
tree" data structure.  This patch adds ENTRY statement names to the
program tree data structure and uses them to generate SubprogramNameDetails
symbols.

Differential Revision: https://reviews.llvm.org/D117345
2022-01-14 15:43:21 -08:00
Peter Klausler cadc07f01f [flang] Legacy extension: non-character formats
Very old (pre-'77 standard) codes would use arrays initialized
with Hollerith literals, typically in DATA, as modifiable
formats.

Differential Revision: https://reviews.llvm.org/D117344
2022-01-14 14:17:05 -08:00
Peter Klausler dc65c3f2ff [flang] Allow pointers to non-sequence types in sequence types
Derived types with SEQUENCE must have data components of sequence
types; but this rule is relaxed as common an extension in the case of
pointer components, whose targets' types are not really relevant
to the implementation requirements of sequence types.

Differential Revision: https://reviews.llvm.org/D117158
2022-01-14 10:49:49 -08:00
Peter Klausler d393ce3b3e [flang] Support extension intrinsic function variations on ABS
Accept the legacy specific intrinsic names BABS, IIABS, JIABS,
KIABS, and ZABS as well.

Differential Revision: https://reviews.llvm.org/D117155
2022-01-13 17:10:44 -08:00
Peter Klausler 0f500d3dae [flang] Downgrade benign error message to a warning
It's not conforming to specify the SAVE attribute more than
once for a variable, but it also doesn't hurt anything and
isn't fatal in other Fortran compilers.  Downgrade the
message to a warning for better portability.

Differential Revision: https://reviews.llvm.org/D117153
2022-01-13 16:27:40 -08:00
Peter Klausler 63a2987d51 [flang] Allow initialization in blank COMMON
This is nonconformant usage, but widely accepted as an extension.
Downgrade the error message to a warning.

Differential Revision: https://reviews.llvm.org/D117152
2022-01-13 15:07:37 -08:00
Peter Klausler 00e0de0572 [flang] Extension: initialization of LOGICAL with INTEGER & vice versa
We already accept assignments of INTEGER to LOGICAL (& vice versa)
as an extension, but not initialization.  Extend initialization
to cover those cases.

(Also fix misspelling in nearby comment as suggested by code reviewer.)

Decouple an inadvertent dependence cycle by moving two
one-line function definitions into a header file.

Differential Revision: https://reviews.llvm.org/D117159
2022-01-13 14:22:45 -08:00
Peter Klausler c14cf92b5a [flang] Implement semantics for DEC STRUCTURE/RECORD
Implements part of the legacy "DEC structures" feature from
VMS Fortran.  STRUCTUREs are processed as if they were derived
types with SEQUENCE.  DATA-like object entity initialization
is supported as well (e.g., INTEGER FOO/666/) since it was used
for default component initialization in structures.  Anonymous
components (named %FILL) are also supported.

These features, and UNION/MAP, were already being parsed.
An omission in the collection of structure field names in the
case of nested structures with entity declarations was fixed
in the parser.

Structures are supported in modules, but this is mostly for
testing purposes.  The names of fields in structures accessed
via USE association cannot appear with dot notation in client
code (at least not yet).  DEC structures antedate Fortran 90,
so their actual use in applications should not involve modules.

This patch does not implement UNION/MAP, since that feature
would impose difficulties later in lowering them to MLIR types.
In the meantime, if they appear, semantics will issue a
"not yet implemented" error message.

Differential Revision: https://reviews.llvm.org/D117151
2022-01-13 13:17:13 -08:00
Peter Klausler bb59b38e87 [flang] Any type can appear in a structure constructor for an unlimited polymorphic allocatable component
A bogus error message is appearing for structure constructors containing
values that correspond to unlimited polymorphic allocatable components.
A value of any type can actually be used.

Differential Revision: https://reviews.llvm.org/D117154
2022-01-13 10:37:42 -08:00
Peter Klausler aea27c3100 [flang] RESHAPE(PAD=) can be arbitrary array rank
The "pad=" argument in the intrinsic function table entry for RESHAPE
has a Rank::Array constraint, and that would be fine if not for RESHAPE
already having an earlier argument that's Rank::Array.  It's the only
intrinsic that has multiple Rank::Array arguments.  The checking for
the Rank::Array constraint was enforcing that multiple occurrences
of it have the same rank in a call, and that's not appropriate.

Differential Revision: https://reviews.llvm.org/D117149
2022-01-12 17:30:27 -08:00
Peter Klausler 0e811d3b66 [flang] Fix handling of space between # and name in preprocessor stringification
When preprocessing "# ARG" in function-like macro expansion,
the preprocessor needs to pop the previously-pushed '#' token
from the end of the resulting token sequence after detecting the
argument name.  The code to do this was just wrong in a couple of
ways.

Differential Revision: https://reviews.llvm.org/D117148
2022-01-12 16:02:17 -08:00
River Riddle 56f62fbf73 [mlir] Finish removing Identifier from the C++ API
There have been a few API pieces remaining to allow for a smooth transition for
downstream users, but these have been up for a few months now. After this only
the C API will have reference to "Identifier", but those will be reworked in a followup.

The main updates are:
* Identifier -> StringAttr
* StringAttr::get requires the context as the first parameter
  - i.e. `Identifier::get("...", ctx)` -> `StringAttr::get(ctx, "...")`

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D116626
2022-01-12 11:58:23 -08:00
Diana Picus 776d0ed632 [flang] Fix overallocation by fir-to-llvm-ir pass
When converting a fir.alloca of an array to the LLVM dialect, we used to
multiply the allocated size by all the constant factors encoded in the
array type. This is fine when the array type is converted to the element
type for the purposes of the allocation, but if it's converted to an
array type, then we might be allocating too much space. For example, for
`%2 = fir.alloca !fir.array<8x16x32xf32>, %0, %1` we would allocate
%0 * %1 * 8 * 16 * 32 x llvm.array<32 x array<16 * array<8 x f32>>>. We
really only need to allocate %0 * %1 such arrays.

This patch fixes the issue by taking note of the array type that we're
trying to allocate. It tries to match the behaviour of
LLVMTypeConverter::convertPointerLike, which returns a pointer to the
element type only when the array type doesn't have a constant interior.
We consequently only multiply with the constant factors in the array
type if the array type doesn't have a constant interior.

This has the nice side effect that it gets rid of some redundant
multiplications with the constant 1 in some cases.

Differential Revision: https://reviews.llvm.org/D116926
2022-01-12 10:08:50 +00:00
Jennifer Yu 140a6b1e5c [clang][OpenMP5.1] Initial parsing/sema for 'indirect' clause
Differential Revision: https://reviews.llvm.org/D116764
2022-01-10 16:58:56 -08:00
Jean Perier fb3faa8b32 [flang] Do not lose call in shape inquiry on function reference
Currently, something like `print *, size(foo(n,m))` was rewritten
to `print *, size(foo_result_symbol)` when foo result is a non constant
shape array. This cannot be processed by lowering or reprocessed by a
Fortran compiler since the syntax is wrong (`foo_result_symbol` is
unknown on the caller side) and the arguments are lost when they might
be required to compute the result shape.

It is not possible (and probably not desired) to make GetShape fail in
general in such case since returning nullopt seems only expected for
scalars or assumed rank (see GetRank usage in lib/Semantics/check-call.cpp),
and returning a vector with nullopt extent may trigger some checks to
believe they are facing an assumed size (like here in intrinsic argument
checks: 196204c72c/flang/lib/Evaluate/intrinsics.cpp (L1530)).

Hence, I went for a solution that limits the rewrite change to folding
(where the original expression is returned if the shape depends on a non
constant shape from a call).

I added a non default option to GetShapeHelper that prevents the rewrite
of shape inquiry on calls to descriptor inquiries. At first I wanted to
avoid touching GetShapeHelper, but it would require to re-implement all
its logic to determine if the shape comes from a function call or not
(the expression could be `size(1+foo(n,m))`). So added an alternate
entry point to GetShapeHelper seemed the cleanest solution to me.

Differential Revision: https://reviews.llvm.org/D116933
2022-01-10 19:10:48 +01:00
Alex Zinenko 301226562b [flang] update to reflect MLIR LLVM::GEPOp changes 2022-01-07 12:50:42 +01:00
Peixin-Qiao 8eb74626fa [flang][OpenMP] Add some semantic checks for threadprivate and declare target directives
This supports the following checks for THREADPRIVATE Directive:
```
[5.1] 2.21.2 THREADPRIVATE Directive
A threadprivate variable must not appear in any clause except the
copyin, copyprivate, schedule, num_threads, thread_limit, and if clauses.
```

This supports the following checks for DECLARE TARGET Directive:
```
[5.1] 2.14.7 Declare Target Directive
A threadprivate variable cannot appear in the directive.
```

Besides, procedure name and the entity with PARAMETER attribute cannot
be in the threadprivate directive. The main program name and module name
cannot be in the threadprivate directive and declare target directive.
There is no clear description or restriction about the entity with
PARAMETER attribute in OpenMP 5.1 Specification, and a warning is given.

Reviewed By: kiranchandramohan, shraiysh, NimishMishra

Differential Revision: https://reviews.llvm.org/D114941
2022-01-06 20:00:16 +08:00
Benjamin Kramer 32c9208750 [flang][openacc] Remove unused variable. NFC. 2022-01-04 21:47:28 +01:00
Kiran Chandramohan 21d299172e [Flang] Enable support for conversion of recursive record types
Uses the recursive type conversion implemented in D113579, D113580.
Tests check for recursive and mutually recursive types.

Note: The downstream implementation for recursive types is a bit old
and is based on a static map. This was removed while upstreaming
(https://reviews.llvm.org/D112961) based on review comments. Since
the recursive type conversion is now available in MLIR we are using
that. If this patch is accepted we can use the same in the downstream
implementation.
Part of upstreaming flang from fir-dev branch of https://github.com/flang-compiler/f18-llvm-project.

Reviewed By: ftynse

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-01-04 13:53:58 +00:00
Shilei Tian c7a589a2c4 [Clang][OpenMP] Add the support for atomic compare in parser
This patch adds the support for `atomic compare` in parser. The support
in Sema and CodeGen will come soon. For now, it simply eimits an error when it
is encountered.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D115561
2021-12-24 08:16:51 -05:00
Andrzej Warzynski 6d655ad011 [flang][codegen] Add a conversion for `fir.coordinate_of` - part 2
This patch extends the `FIRToLLVMLowering` pass in Flang by extending
the hook to transform `fir.coordinate_of` into a sequence of LLVM MLIR
instructions (i.e. `CoordinateOpConversion::doRewrite`). The following
case is added:
  3.1 the input object is inside `!fir.ref` (e.g. `!fir.ref<!fir.array>` or
      `!fir.ref<!fir.type>`).
  3.2 the input object is inside `!fir.ptr` (e.g. `!fir.ptr<!fir.array>` or
      `!fir.ptr<!fir.type>`).
From the point of view of the conversion, 3.1 and 3.2 are currently identical.

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

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

Originally written by:
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>

Depends on: D114159

Differential Revision: https://reviews.llvm.org/D115333
2021-12-17 10:34:57 +00:00
Andrzej Warzynski d18a9aeae9 [flang] Make the frontend driver error out when requesting multiple actions
With this change, the following invocations will be treated as errors
(multiple actions are specified):
```
$ flang-new -fc1 -E -fsyntax-only file.95
$ flang-new -fc1 -fsyntax-only -fdebug-dump-symbols file.95
```
In the examples above it is not clear whether it is `-fsyntax-only` or
the other action that is run (i.e. `-E` or `-fdebug-dump-symbols`). It
makes sense to disallow such usage. This should also lead to cleaner and
clearer tests (the `RUN` lines using `%flang_fc1` will only allow one
action).

This change means that `flang-new -fc1` and `clang -cc1` will behave
differently when multiple action options are specified. As frontend
drivers are mostly used by compiler developers, this shouldn't affect or
confuse the compiler end-users. Also, `flang-new` and `clang` remain
consistent.

Tests are updated accordingly. More specifically, I've made sure that
every test specifies only one action. I've also taken the opportunity to
simplify "multiple-input-files.f90" a bit.

Differential Revision: https://reviews.llvm.org/D111781
2021-12-17 10:05:28 +00:00
Valentin Clement 3ab67c3d62
[fir] Move Factory.h to flang/Optimizer/Builder
Move the Factory.h header file to flang/Optimizer/Builder.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D115801
2021-12-16 16:08:34 +01:00
Eric Schweitz 3d092e31c1 Add a new memory allocation rewrite pass.
This pass can reclassify memory allocations (fir.alloca, fir.allocmem)
based on heuristics and settings. The intention is to allow better
performance and workarounds for conditions such as environments with
limited stack space.

Currently, implements two conversions from stack to heap allocation.
  1. If a stack allocation is an array larger than some threshold value
     make it a heap allocation.
  2. If a stack allocation is an array with a runtime evaluated size make
     it a heap allocation.

Add a lit test for both suboptions.

Reviewed By: PeteSteinfeld, vdonaldson

Differential Revision: https://reviews.llvm.org/D115763
2021-12-15 15:45:08 -08:00
Peter Klausler cea3638812 [flang] Avoid code duplication in mixed expressions
Rather than represent the mixed real/complex subexpression x*(a,b)
as (x*a,x*b), use (x,0)*(a,b) to avoid a potential code duplication
in current lowering code.  Same for mixed division, and for mixed
integer*complex and integer/complex cases.

Differential Review: https://reviews.llvm.org/D115732
2021-12-15 13:23:50 -08:00
Kiran Chandramohan 135d5d4a6d [Flang][NFC] Convert static to static inline for a function
Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D115619
2021-12-14 13:49:58 +00:00
Jacques Pienaar feeee78afc [mlir] Flip dialects to _Prefixed
Following
https://llvm.discourse.group/t/psa-ods-generated-accessors-will-change-to-have-a-get-prefix-update-you-apis/4476
these have been flipped to both for ~4 weeks, flipping to _Prefixed.

Differential Revision: https://reviews.llvm.org/D115585
2021-12-11 14:21:20 -08:00
Andrzej Warzynski e6e7da5515 [flang][nfc] Fix formatting 2021-12-10 08:56:57 +00:00
Andrzej Warzynski 75db341d5a [flang][codegen] Add a conversion for `!fir.coordinate_of` - part 1
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `!fir.coordinate_of` into a sequence of LLVM MLIR
instructions.

The following cases are currently supported:
  1.  the input object is a `!fir.complex` (wrapped in e.g. `!fir.ref` or
      `!fir.box`)
  2.  the input object is wrapped in a `!fir.box` (including e.g.
      `!fir.array`).
Note that `!fir.complex` inside a `!fir.box` falls under case 1. above
(i.e. it's a special case regardless of the wrapping type).

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

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-12-10 08:34:26 +00:00
Peter Klausler c4360b4547 [flang] Fix folding of ac-implied-do indices in structure c'tors
Array constructors with implied DO loops that oversee structure
constructors were being prematurely folded into invalid constants
containing symbolic references to the ac-implied-do indices,
because they are indeed "constant expressions" as that term is
used in the Fortran standard and implemented as IsConstantExpr().
What's actually needed in structure constructor folding is a
test for actual constant values, which is what results from
folding them later with repetition in the context of folding
an ac-implied-do.

Differential Revision: https://reviews.llvm.org/D115470
2021-12-09 18:03:04 -08:00
Jacques Pienaar 3012f35f87 [flang] Updated FIR dialect to _Both
Change dialect (and remove now redundant accessors) to generate both
form of accessors of being generated. Tried to keep this change
reasonably minimal (this also includes keeping note about not generating
getType accessor to avoid shadowing).

Differential Revision: https://reviews.llvm.org/D115420
2021-12-09 15:05:13 -08:00
Valentin Clement ad3bb7c7da
[flang] Simplify RaggedArrayHeader and make it plain C struct
- Join indirection and rank into a single value `flags`
- Make the struct a plain C struct.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D115464
2021-12-09 22:28:06 +01:00
Valentin Clement 70638d997c
[fir] Keep runtime function name in comment
Some of the function name in the comment didn't match
their actual name in the runtime. This patch fixes that.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D115076
2021-12-09 18:29:41 +01:00
Valentin Clement de467afe18
[fir] Add fir ragged array builder
This patch introduces a bunch of builder functions
to create function calls to runtime ragged arrays functions.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-12-08 17:28:43 +01:00
AlexisPerry c2acd45393 Convert fir.allocmem and fir.freemem operations to calls to malloc and free, respectively
This patch is part of the upstreaming effort from the fir-dev branch.

Address review comments
- move CHECK blocks to after the mlir code in the test file
- fix style with respect to anonymous namespaces: only include class definitions in the namespace and make functions static and outside the namespace
- fix a few nits
- remove TODO in favor of notifyMatchFailure
- removed unnecessary CHECK line from convert-to-llvm.fir
- rebase on main - add TODO back in
- get successfull test of TODO in AllocMemOp converion of derived type with LEN params
- clearer comments and reduced use of auto
- move defintion of computeDerivedTypeSize to fix build error

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>

Reviewed By: awarzynski, clementval, kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D114104
2021-12-07 15:59:10 -07:00
Kiran Chandramohan fa51755542 [Flang] Upstream conversion of the XRebox Op
The XRebox Op is formed by the codegen rewrite which makes it easier to
convert the operation to LLVM. The XRebox op includes the information
from the rebox op and the associated slice, shift, and shape ops.

During the conversion process a new descriptor is created for reboxing.

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Val Donaldson <vdonaldson@nvidia.com>

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D114709
2021-12-07 22:22:39 +00:00
Valentin Clement 5d27abe629
[fir] Add fircg.ext_array_coor conversion
This patch adds the conversion pattern for the fircg.ext_array_coor
operation. It applies the address arithmetic on a dynamically shaped, shifted
and/or sliced array.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-12-06 15:52:45 +01:00
Valentin Clement d59a0f58f4
[fir] Add fir character builder
This patch adds the FIR builder to generate the numeric intrinsic
runtime call.

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

Reviewed By: rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
2021-12-03 14:58:17 +01:00
Valentin Clement c32421c925
[fir] Add fir derived type runtime builder
This patch adds the builder to generate derived type runtime API calls.

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

Reviewed By: rovka

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

Co-authored-by: Peter Klausler <pklausler@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-12-03 14:51:59 +01:00
Diana Picus 3fd250d258 [fir] TargetRewrite: Rewrite fir.address_of(func)
Rewrite AddrOfOp if taking the address of a function.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-12-03 10:56:24 +00:00
Valentin Clement 1f55103263
[fir] Add fircg.ext_embox conversion
Convert a fircg.ext_embox operation to LLVM IR dialect.
A fircg.ext_embox is converted to a sequence of operation that
create, allocate if needed, and populate a descriptor.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-12-03 11:45:36 +01:00
Kiran Chandramohan 7ce8c6fcf1 [Flang] Replace notifyMatchFailure with TODO hard failures
For unimplemented patterns we revert to using TODO hard failures instead of
notifyMatchFailure.

For fir.select_type revert to using mlir::emiterror.
For the fir.embox TODO on a type with len params we cannot add a test since the type cannot be converted to llvm.

Adding negative tests using not and checking for the error message.
TODO exits with an error in a build without assertion but aborts in a
build with assertions. Abort requires using not with the --crash
option. The two different usages of not is handled by using a custom
command %not_todo_cmd which is converted to not or not --crash
depending on the presence or absence of assertions. Using llvm-config
to check the presence of assertions.

Reviewed By: clementval, awarzynski

Differential Revision: https://reviews.llvm.org/D114371
2021-12-02 10:25:02 +00:00
Valentin Clement 529d0942da
[fir] Add fir numeric intrinsic runtime call builder
This patch adds the FIR builder to generate the numeric intrinsic
runtime call.

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

Reviewed By: rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
2021-12-02 10:22:26 +01:00
Peter Klausler 44bc97c834 [flang] Adjust names in Semantics that imply too much (NFC)
Some kinds of Fortran arrays are declared with the same syntax,
and it is impossible to tell from a shape (:, :) or (*) whether
the object is assumed shape, deferred shape, assumed size, implied
shape, or whatever without recourse to more information about the
symbol in question.  This patch softens the names of some predicate
functions (IsAssumedShape to CanBeAssumedShape) and makes others
more reflective of the syntax they represent (isAssumed to isStar)
in an attempt to encourage coders to seek and find definitive
predicate functions whose names deliver what they seem to mean.

Address TODO comments in IsSimplyContiguous() by using the
updated IsAssumedShape() predicate.

Differential Revision: https://reviews.llvm.org/D114829
2021-12-01 11:19:19 -08:00
Kiran Chandramohan 003c9c7457 Revert "[Flang] Replace notifyMatchFailure with TODO hard failures"
This reverts commit 46fd7fd7b3.
2021-12-01 14:23:48 +00:00
Kiran Chandramohan 46fd7fd7b3 [Flang] Replace notifyMatchFailure with TODO hard failures
For unimplemented patterns we revert to using TODO hard failures instead of
notifyMatchFailure.

For fir.select_type revert to using mlir::emiterror.
For the fir.embox TODO on a type with len params we cannot add a test since the type cannot be converted to llvm.

Adding negative tests using not and checking for the error message.
TODO exits with an error in a build without assertion but aborts in a
build with assertions. Abort requires using not with the --crash
option. The two different usages of not is handled by using a custom
command %not_todo_cmd which is converted to not or not --crash
depending on the presence or absence of assertions. Using llvm-config
to check the presence of assertions.

Reviewed By: clementval, awarzynski

Differential Revision: https://reviews.llvm.org/D114371
2021-12-01 08:19:44 +00:00
Valentin Clement f6ae8e8cc7
[fir] Add fir reduction builder
This patch introduces a bunch of builder functions
to create function calls to runtime reduction functions.

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

This patch failed previously because a macro was missing.

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
2021-12-01 09:01:12 +01:00
Peter Klausler 1ee6f7add1 [flang] Rearrange prototype & code placement of IsCoarray()
A quick fix last week to the shared library build caused
the predicate IsCoarray(const Symbol &) to be moved from
Semantics to Evaluate.  This patch completes that move in
a way that properly combines the existing IsCoarray() tests
for expressions and other object with the test for a symbol.

Differential Revision: https://reviews.llvm.org/D114806
2021-11-30 15:26:34 -08:00
Peter Klausler cbd445e4a3 [flang] Re-fold bounds expressions in DATA implied DO loops
To accommodate triangular implied DO loops in DATA statements, in which
the bounds of nested implied DO loops might depend on the values of the
indices of outer implied DO loops in the same DATA statement set, it
is necessary to run them through constant folding each time they are
encountered.

Differential Revision: https://reviews.llvm.org/D114754
2021-11-30 13:28:31 -08:00
Peter Klausler 196204c72c [flang] Fix usage & catch errors for MAX/MIN with keyword= arguments
Max(), MIN(), and their specific variants are defined with an unlimited
number of dummy arguments named A1=, A2=, &c. whose names are almost never
used in practice but should be allowed for and properly checked for the
usual errors when they do appear.  The intrinsic table's entries otherwise
have fixed numbers of dummy argument definitions, so add some special
case handling in a few spots for MAX/MIN/&c. checking and procedure
characteristics construction.

Differential Revision: https://reviews.llvm.org/D114750
2021-11-30 12:53:47 -08:00
Peter Klausler 8bc593cbbb [flang] Address TODO from previous changes to IsSaved()
An earlier fix to evaluate::IsSaved() needed to preserve its
treatment of named constants in modules and main programs -- i.e.
they would appear to be saved -- until a correction was added
to the lowering code.  This TODO can now be resolved.

Differential Revision: https://reviews.llvm.org/D114756
2021-11-30 10:39:51 -08:00
Valentin Clement 3cc21ee6b9
Revert "[fir] Add fir reduction builder"
This reverts commit cf3422d3df.

This fails on some buildbots
2021-11-30 17:15:42 +01:00
Valentin Clement eb97c89cac
[fir] Remove unused fct recordTypeCanBeMemCopied
Remove unused fct added with 47f759309e
2021-11-30 17:02:25 +01:00
Valentin Clement cf3422d3df
[fir] Add fir reduction builder
This patch introduces a bunch of builder functions
to create function calls to runtime reduction functions.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>

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

Reviewed By: awarzynski
2021-11-30 15:52:30 +01:00
Valentin Clement 47f759309e
[fir] Add array value copy pass
This patch upstream the array value copy pass.

Transform the set of array value primitives to a memory-based array
representation.

The Ops `array_load`, `array_store`, `array_fetch`, and `array_update` are
used to manage abstract aggregate array values. A simple analysis is done
to determine if there are potential dependences between these operations.
If not, these array operations can be lowered to work directly on the memory
representation. If there is a potential conflict, a temporary is created
along with appropriate copy-in/copy-out operations. Here, a more refined
analysis might be deployed, such as using the affine framework.

This pass is required before code gen to the LLVM IR dialect.

This patch is part of the upstreaming effort from fir-dev branch. The
pass is bringing quite a lot of file with it.

Reviewed By: kiranchandramohan, schweitz

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-11-30 13:51:08 +01:00
Valentin Clement 1cc3b135aa
[fir] Get rid of the global option in FIRBuilder
Replace the global option `nameLengthHashSize` with a constexpr
with the same name. The option was not used in fir-dev so switching
to a constexpr is fine.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D114630
2021-11-29 17:08:09 +01:00
Valentin Clement 2e7202b008
[fir] Add data flow optimization pass
Add pass to perform store/load forwarding and potentially removing dead
stores.

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

Reviewed By: kiranchandramohan, schweitz, mehdi_amini, awarzynski

Differential Revision: https://reviews.llvm.org/D111288
2021-11-29 11:00:09 +01:00
Valentin Clement 51e2c8c9bf
[fir] Add assignment runtime API builder
This patch adds the builder that generate assignment runtime API calls.

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

Reviewed By: rovka, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-29 10:23:06 +01:00
Valentin Clement 18452d1f12
[fir] Add fir transformational intrinsic builder
This patch adds the builder to generate transformational
intrinsic runtime API calls.

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

Reviewed By: rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: mleair <leairmark@gmail.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Peter Steinfeld <psteinfeld@nvidia.com>
2021-11-29 10:09:36 +01:00
Jean Perier 9d1938fd14 [flang] Return true in IsSymplyContiguous for allocatables
The current code was relying on the fact that allocatables are deferred
shape and that isAssumedShape() should therefore return true for them.

This is not true, because the current parsing/semantic analysis always
builds a semantics::ArraySpec for `x(:)` that returns true to both
isDeferredShape()/isAssumedShape(), whether x is allocatable/pointer or
not.

It proved tricky to change this behavior, so this is a simple fix for
IsSymplyContiguous where it currently matters, but we most likely want
to investigate more and fix the isDeferredShape()/isAssumedShape() in
a second time.

Differential Revision: https://reviews.llvm.org/D114599
2021-11-29 08:28:26 +01:00
Mehdi Amini 8ec0f22184 Update fir.insert_on_range syntax to make the range more explicit (NFC)
Also replace ArrayAttr with IndexElementsAttr to model subscript dimensions.
An array of attribute is a sparse inefficient storage, with an API that
requires to unpack/repack integers at every call site.
Instead we can store dense array of integer as IndexElementsAttr.

Reviewed By: clementval, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D112899
2021-11-24 02:06:17 +00:00
Diana Picus cdc476ab2f [fir] Set !fir.len_param_index conversion to unimplemented
This patch is part of the upstreaming effort from fir-dev.

The conversion of len_param_index in fir-dev is incomplete, so for now
we're marking this as unimplemented until we can settle on a design for
the runtime support of LEN parameters.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-23 12:14:28 +00:00
Peter Klausler bb0d8e4bd9 [flang] Correct the argument keyword for AIMAG(Z=...)
It was X= in the intrinsics table.

Differential Revision: https://reviews.llvm.org/D114296
2021-11-22 16:13:21 -08:00
Peter Klausler 42bfd059bf [flang] Move IsCoarray() to fix shared library build
The predicate IsCoarray() needs to be in libFortranEvaluate so that
IsSaved() can call it without breaking the shared library build.

Pushed without pre-commit review as I'm moving code around and
the fix to the shared build is confirmed.
2021-11-22 12:46:15 -08:00
Peter Klausler 996ef895cd [flang] Add -fno-automatic, refine IsSaved()
This legacy option (available in other Fortran compilers with various
spellings) implies the SAVE attribute for local variables on subprograms
that are not explicitly RECURSIVE.  The SAVE attribute essentially implies
static rather than stack storage.  This was the default setting in Fortran
until surprisingly recently, so explicit SAVE statements & attributes
could be and often were omitted from older codes.  Note that initialized
objects already have an implied SAVE attribute, and objects in COMMON
effectively do too, as data overlays are extinct; and since objects that are
expected to survive from one invocation of a procedure to the next in static
storage should probably be explicit initialized in the first place, so the
use cases for this option are somewhat rare, and all of them could be
handled with explicit SAVE statements or attributes.

This implicit SAVE attribute must not apply to automatic (in the Fortran sense)
local objects, whose sizes cannot be known at compilation time.  To get the
semantics of IsSaved() right, the IsAutomatic() predicate was moved into
Evaluate/tools.cpp to allow for dynamic linking of the compiler.  The
redundant predicate IsAutomatic() was noticed, removed, and its uses replaced.

GNU Fortran's spelling of the option (-fno-automatic) was added to
the clang-based driver and used for basic sanity testing.

Differential Revision: https://reviews.llvm.org/D114209
2021-11-22 10:06:38 -08:00
Valentin Clement b8207db700
[fir] Add fir.no_reassoc conversion
Currently `fir.no_reassoc` is just removed in the conversion.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-19 11:38:24 +01:00
Diana Picus ca3795541f [flang] Fix printing of constc and parsing of #fir.real
Printing and parsing of constc didn't agree with each other. This patch
treats the parsing of constc as the final word and fixes the printing
accordingly.

More concretely, this patch prints the RealAttrs that make up the
ConstcOp directly instead of casting to mlir::FloatAttr (which blows
up). It also fixes parseFirRealAttr to invoke APFloat's method for
getting the size of a floating point type instead of computing it as
8 * kind (which blows up for BFloat, with kind == 3 and size == 16).

Kudos to Kiran Chandramohan <kiran.chandramohan@arm.com> for noticing
that we were missing tests for constc in fir-ops.fir.

Differential Revision: https://reviews.llvm.org/D114081
2021-11-19 09:28:02 +00:00
Kiran Chandramohan a1f9bd32c5 [Flang] Add a factory class for creating Complex Ops
Use the factory class in the FIRBuilder.
Add unit tests for the factory class function and the convert function
of the Complex class.

Reviewed By: clementval, rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-18 16:55:35 +00:00
Andrzej Warzynski e6c66ef55e [flang][CodeGen] Transform `fir.field_index` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.field_index` to a sequence of LLVM MLIR
instructions.

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

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-18 16:35:16 +00:00
Andrzej Warzynski 22d332a0a2 [flang][codegen] Add `fir.end` conversion placeholder
This patch extends the FIRToLLVMLowering pass in Flang by adding a hook
to transform fir.end. This is just a placeholder for now as fir.end is
not required yet.

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

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

Differential Revision: https://reviews.llvm.org/D113295
2021-11-18 14:19:26 +00:00
Kiran Chandramohan cc505c0bb7 [Flang] Notify conversion failure for Proc ops, types
Add the FIR to LLVM conversion patterns for the BoxProcHostOp, EmboxProcOp,
and UnboxProcOp ops and the boxproc type. These are currently unimplemented.
Implementation will come at a later time when support for Fortran 2003
procedure pointer feature is added.

Reviewed By: clementval, rovka

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-18 12:27:25 +00:00
Valentin Clement af6ee58092
[fir] Add fir.embox conversion
Convert a `fir.embox` operation to LLVM IR dialect.
A `fir.embox` is converted to a sequence of operation that
create, allocate if needed, and populate a descriptor.

Current limitiation: alignment is set by default but should be retrieved in the specific target.

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

Reviewed By: kiranchandramohan, awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-18 11:06:39 +01:00
Diana Picus e81d73ed92 [fir] Add fir.constc conversion
Add the codegen for fir.constc.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-18 08:46:10 +00:00
River Riddle 0c7890c844 [mlir] Convert NamedAttribute to be a class
NamedAttribute is currently represented as an std::pair, but this
creates an extremely clunky .first/.second API. This commit
converts it to a class, with better accessors (getName/getValue)
and also opens the door for more convenient API in the future.

Differential Revision: https://reviews.llvm.org/D113956
2021-11-18 05:39:29 +00:00
Peter Klausler 78d60094c7 [flang] Deal with negative character lengths in semantics
Fortran defines LEN(X) = 0 after CHARACTER(LEN=-1)::X so
apply MAX(0, ...) to character length expressions.

Differential Revision: https://reviews.llvm.org/D114030
2021-11-17 09:49:15 -08:00
Jean Perier 394d6fcf3e [flang] Check ArrayRef base for contiguity in IsSimplyContiguousHelper
Previous code was returning true for `x(:)` where x is a pointer without
the contiguous attribute.
In case the array ref is a whole array section, check the base for contiguity
to solve the issue.

Differential Revision: https://reviews.llvm.org/D114084
2021-11-17 18:18:58 +01:00
Valentin Clement 964536cf04
[fir] !fir.tdesc type conversion
Add !fir.tdesc type conversion.
!fir.tdesc is converted to a llvm.ptr<i8>.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-17 13:31:14 +01:00
Valentin Clement e38ef2ff71
[fir] Add fir.box_tdesc conversion
This patch adds the conversion pattern for
`fir.box_tdes`.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-17 12:02:48 +01:00
Valentin Clement 1ed5a90f70
[fir] Add conversion patterns for slice, shape, shapeshift and shift ops
The information in these perations is used by other operation.
At this point they should not have anymore uses.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-17 10:35:56 +01:00
Valentin Clement 1a2ec6670a
[fir] Add fir.string_lit conversion
This patch adds the conversion pattern for
the fir.string_lit operation.

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

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-16 21:13:45 +01:00
Andrzej Warzynski 6c3d7fd4c5 [flang][CodeGen] Transform `fir.boxchar_len` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.boxchar_len` to a sequence of LLVM MLIR
instructions.

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

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

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

Originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-16 13:49:23 +00:00
Valentin Clement 3124618704
[fir] Add fir.gentypedesc conversion
Add conversion pattern for the GenTypeDescOp.
Convert to a global constant with an addressof.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-16 14:41:00 +01:00
Diana Picus f1dfc0275c [fir] Add fir.cmpc conversion
This patch adds the codegen for fir.cmpc. The real and imaginary parts
are extracted and compared separately. For the .EQ. predicate the
results are AND'd, for the .NE. predicate the results are OR'd, and for
other predicates we keep only the result on the real parts.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-16 12:26:27 +00:00
Peter Steinfeld 4f11944652 [flang] Allow implicit procedure pointers to associate with explicit procedures
Section 10.2.2.4, paragraph 3 states that, for procedure pointer assignment:
  If the pointer object has an explicit interface, its characteristics shall be
  the same as the pointer target ...

Thus, it's illegal for a procedure pointer with an explicit interface to be
associated with a procedure whose interface is implicit.  However, there's no
prohibition that disallows a procedure pointer with an implicit interface from
being associated with a procedure whose interface is explicit.

We were incorrectly emitting an error message for this latter case.

We were also not covering the case of procedures with explicit
interfaces where calling them requires the use of a descriptor.  Such
procedures cannot be associated with procedure pointers with implicit
interfaces.

Differential Revision: https://reviews.llvm.org/D113706
2021-11-15 09:51:25 -08:00
Kiran Chandramohan 49c08a22ed [Flang] Add the FIR LLVMPointer Type
Add a fir.llvm_ptr type to allow any level of indirections

Currently, fir pointer types (fir.ref, fir.ptr, and fir.heap) carry
a special Fortran semantics, and cannot be freely combined/nested.

When implementing some features, lowering sometimes needs more liberty
regarding the number of indirection levels. Add a fir.llvm_ptr that has
no constraints.

Allow its usage in fir.coordinate_op, fir.load, and fir.store.

Convert the FIR LLVMPointer to an LLVMPointer in the LLVM dialect.

Reviewed By: clementval

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-15 15:57:59 +00:00
Valentin Clement 677df8c709
[fir] Add fir.global_len conversion placeholder
As for D113662, this patch just add a place holder for
the fir.global_len operation conversion. This operation
is part of F20xx and is not implemented yet.

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

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D113887
2021-11-15 16:47:20 +01:00
Andrzej Warzynski 14867ffc7c [flang][CodeGen] Transform `fir.unboxchar` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.unboxchar` to a sequence of LLVM MLIR
instructions.

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

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

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

Originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-15 15:34:55 +00:00
Valentin Clement 37c7211f11
[fir] Remove extra return in SelectTypeOpConversion
Extra commit after D113878
2021-11-15 16:20:53 +01:00
Valentin Clement 2a299e4f06
[fir] Add fir.select_type conversion placeholder
As for D113662, this patch just add a place holder for
the `fir.select_type` operation conversion. This operation
is part of F20xx and is not implemented yet.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113878
2021-11-15 14:35:57 +01:00
Andrzej Warzynski 1e77b09538 [flang][CodeGen] Transform `fir.emboxchar` to a sequence of LLVM MLIR
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.emboxchar` to a sequence of LLVM MLIR
instructions.

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

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

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-15 11:09:12 +00:00
Valentin Clement 6c8eecd676
[fir] Add !fir.len type conversion
This patch adds the !fir.len type conversion. The type is converted
to the a 32 bits integer.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113658
2021-11-15 10:18:23 +01:00
Diana Picus faf869dc65 [Flang] Fixup some comments. NFC
Clarify some comments as discussed here:
https://github.com/flang-compiler/f18-llvm-project/pull/1210
2021-11-15 09:03:37 +00:00
Peter Klausler ece17064b5 [flang] Handle ENTRY names in IsPureProcedure() predicate
Fortran defines an ENTRY point name as being pure if its enclosing
subprogram scope defines a pure procedure.

Differential Revision: https://reviews.llvm.org/D113711
2021-11-12 13:21:18 -08:00
Peter Klausler da25f968a9 [flang] Runtime performance improvements to real formatted input
Profiling a basic internal real input read benchmark shows some
hot spots in the code used to prepare input for decimal-to-binary
conversion, which is of course where the time should be spent.
The library that implements decimal to/from binary conversions has
been optimized, but not the code in the Fortran runtime that calls it,
and there are some obvious light changes worth making here.

Move some member functions from *.cpp files into the class definitions
of Descriptor and IoStatementState to enable inlining and specialization.

Make GetNextInputBytes() the new basic input API within the
runtime, replacing GetCurrentChar() -- which is rewritten in terms of
GetNextInputBytes -- so that input routines can have the
ability to acquire more than one input character at a time
and amortize overhead.

These changes speed up the time to read 1M random reals
using internal I/O from a character array from 1.29s to 0.54s
on my machine, which on par with Intel Fortran and much faster than
GNU Fortran.

Differential Revision: https://reviews.llvm.org/D113697
2021-11-12 11:40:02 -08:00
Peter Klausler 85ec449352 [flang] Fix ORDER= argument to RESHAPE
The ORDER= argument to the transformational intrinsic function RESHAPE
was being misinterpreted in an inverted way that could be detected only
with 3-d or higher rank array.  Fix in both folding and the runtime, and
extend tests.

Differential Revision: https://reviews.llvm.org/D113699
2021-11-12 10:25:00 -08:00
Kiran Chandramohan aa26119b82 [Flang] Add type conversion for FIR integer kind
Convert fir.int<kind> to their llvm equivalent type

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

Reviewed By: clementval, awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-12 10:15:21 +00:00
Kiran Chandramohan 2b247941ca [Flang] Add type conversion for FIR heap type
Convert fir.heap type to its llvm equivalent type (llvm.ptr)

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

Reviewed By: clementval

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-12 09:49:54 +00:00
Peter Klausler c3dddeeafb [flang] Allow exterior branch to outermost WHERE construct statement
The labels of WHERE constructs were being created within the scope of
the construct, not the scope of its parent, leading to incorrect error
messages for branches to that label.

Differential Revision: https://reviews.llvm.org/D113696
2021-11-11 13:14:42 -08:00
Andrzej Warzynski 420ad7ce7d [flang][CodeGen] Transform `IsPresentOpConversion` and `AbsentOpConversion`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding
hooks to transform `fir.is_present` and `fir.absent` to the LLVM dialect
of MLIR.

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

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

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

Originally written by:
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 18:07:51 +00:00
Valentin Clement b67be52054
[fir] Add !fir.field type conversion
This patch adds conversion for !fir.field types.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 15:40:15 +01:00
Valentin Clement 39f4ef8146
[fir] Add fir.select_case conversion
The `fir.select_case` operation is converted to a if-then-else ladder.

Conversion of `fir.select_case` operation with character is not
implemented yet.

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

Reviewed By: kiranchandramohan, mehdi_amini

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 15:00:51 +01:00
Valentin Clement 9534e361ea
[fir] Add placeholder conversion pattern for disptach operations
`fir.dispatch`, `fir.dispatch_table` and `fir.dt_entry` are operations
for type-bound procedures. This patch just adds placeholder conversion
pattern that currently fails since F2003 is not implemented yet.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D113662
2021-11-11 13:58:59 +01:00
Diana Picus 1e6d9c06a5 [fir] Add !fir.alloca conversion
Convert !fir.alloca into !llvm.alloca.

This also contains a fix for verifyInType in FIROps.cpp, to make sure we
can handle a !fir.ptr<!fir.array<?xN>>.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-11 11:26:33 +00:00
Andrzej Warzynski bb2018261e [flang][codegen] Add type conversion for `fir.boxchar`
This is part of the upstreaming effort from the `fir-dev` branch in [1].

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

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-11 10:28:40 +00:00
Valentin Clement afcacccd5a
[fir] Add !fir.vector type conversion
This patch adds the !fir.vector type conversion. The type is converted
to the builtin vector type.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 11:21:55 +01:00
Andrzej Warzynski f1a2b50789 [flang][nfc] Tidy up in CodeGen.cpp and TypeConverter.h
Some header `#include`s that belong in TypeConverter.h rather than in
CodeGen.cpp are moved accordingly. As TypeConverter.h is currently only
used in CodeGen.cpp, this wouldn't cause any build issues (ultimately,
all the required headers are included). However, this would become a problem
when including TypeConverter.h elsewhere.

Also, from [1], "(...) include all of the header files that you are
using ". This is currently not the case in TypeConverter.h and hence the
`#include`s should be moved.

I've also added missing namespace qualifiers in a few places in
TypeConverter.h

[1] https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible

Differential Revision: https://reviews.llvm.org/D113569
2021-11-11 10:08:55 +00:00
Valentin Clement b6e44ecd6e
[fir] Add fir.box_isarray, fir.box_isptr and fir.box_isalloc conversion.
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-11 10:41:06 +01:00
Mehdi Amini f97e72aaca Use base class AsmParser/AsmPrinter in Types and Attribute print/parse method (NFC)
This decouples the printing/parsing from the "context" in which the parsing occurs.
This will allow to invoke these methods directly using an OpAsmParser/OpAsmPrinter.

Differential Revision: https://reviews.llvm.org/D113637
2021-11-11 06:26:33 +00:00
Valentin Clement df3b9810c7
[fir] Add fir.box_rank, fir.box_addr, fir.box_dims and fir.box_elesize conversion
This patch adds conversion for basic box operations that extract
information from the box.

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

Reviewed By: awarzynski

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-10 15:35:19 +01:00
Valentin Clement 5eca6ad752
[fir] Use contralized values for indexing box
Add constant to index the different values in a box so that
they can be reused for the codegen part as well.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D113553
2021-11-10 15:35:19 +01:00
Diana Picus 81c99c5404 [fir] Fixup comment. NFC
Fixed comment as requested in https://reviews.llvm.org/D113560.
2021-11-10 12:49:31 +00:00
Diana Picus a343b74f85 [fir] Add !fir.char type conversion
This patch is part of the upstreaming effort from fir-dev.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-10 12:27:58 +00:00
Diana Picus deafc6fc6d [fir] Add !fir.ptr type conversion
This patch is part of the upstreaming effort for fir-dev.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-10 12:27:39 +00:00
Mehdi Amini 18334a1c1a Fix flang following MLIR API change in f30a8a6f67
The printer for Attribute/Type does not need to include the mnemonic
anymore.
2021-11-10 01:25:36 +00:00
Andrzej Warzynski e3349fa1a3 [flang][CodeGen] Transform `fir.{store|load}` to `llvm.{store|load}`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.store`/`fir.load` to `llvm.store`/`fir.load`,
respectively.

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

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

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-09 20:22:45 +00:00
Emil Kieri 384b4e0d33 [flang] Fix error in characteristics check at procedure pointer assignment
If the procedure pointer has an explicit interface, its characteristics must
equal the characteristics of its target, except that the target may be pure or
elemental also when the pointer is not (cf. F2018 10.2.2.4(3)). In the semantics
check for assignment of procedure pointers, the attributes of the procedures
were not checked correctly due to a typo. This caused some illegal
pointer-target-combinations to pass without raising an error. Fix this, and
expand the test case to improve the coverage of procedure pointer assignment
checks.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D113368
2021-11-09 18:46:54 +01:00
Valentin Clement 092cee5f7f
[fir] Add fir.convert op conversion from FIR to LLVM IR
Add conversion pattern for the `fir.convert` operation.

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

This patch was previously landed with a truncated version that
was failing the windows buildbot.

Reviewed By: rovka, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 15:38:50 +01:00
Valentin Clement 9d9019c77c
Revert "[fir] Add fir.convert op conversion from FIR to LLVM IR"
This reverts commit 165879ec31.

Windows buildbot failure
2021-11-09 15:03:51 +01:00
Valentin Clement 165879ec31
[fir] Add fir.convert op conversion from FIR to LLVM IR
Add conversion pattern for the `fir.convert` operation.

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

Reviewed By: rovka, awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 14:55:24 +01:00
Valentin Clement 7b5132dae8
[fir] Add complex operations conversion from FIR LLVM IR
This patch add conversion for primitive operations on complex types.
- fir.addc
- fir.subc
- fir.mulc
- fir.divc
- fir.negc

This adds also the type conversion for !fir.complex<KIND> type.

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

This patch was updated to avoid failure on windows buildbot.
Flang codegen does not support windows target so we force the test
to use a known target instead.

Reviewed By: kiranchandramohan, rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 14:17:34 +01:00
David Pagan b0de656bdf Initial parsing/sema for 'align' clause
Added basic parsing/sema/serialization support for 'align' clause for use with
'allocate' directive.
2021-11-09 07:34:18 -05:00
Valentin Clement 9b7c584ed8
Revert "[fir] Add complex operations conversion from FIR LLVM IR"
This reverts commit b9bc64ba14.

flang-x86_64-windows is failing with this patch
2021-11-09 13:07:36 +01:00
Valentin Clement b9bc64ba14
[fir] Add complex operations conversion from FIR LLVM IR
This patch add conversion for primitive operations on complex types.
- fir.addc
- fir.subc
- fir.mulc
- fir.divc
- fir.negc

This adds also the type conversion for !fir.complex<KIND> type.

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

Reviewed By: rovka

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-09 11:05:29 +01:00
Diana Picus 65431d3aeb [fir] TargetRewrite: Rewrite COMPLEX values
Rewrite function signatures and calls to functions that accept or return
COMPLEX values.

Also teach insert_value and extract_value about the MLIR ComplexType, by
adding AnyComplex to AnyCompositeLike.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Tim Keith <tkeith@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-11-09 09:26:10 +00:00
Diana Picus 4c263ede54 [flang] Add TargetRewrite pass
This patch adds the basic infrastructure for the TargetRewrite pass,
which rewrites certain FIR dialect operations into target specific
forms. In particular, it converts boxchar function parameters, call
arguments and return values. Other convertions will be included in
future patches.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Tim Keith <tkeith@nvidia.com>
2021-11-09 07:57:31 +00:00
Peter Klausler ca47447952 [flang] Don't reference non-invariant symbols in shape expressions
When an array's shape involves references to symbols that are not
invariant in a scope -- the classic example being a dummy array
with an explicit shape involving other dummy arguments -- the
compiler was creating shape expressions that referenced those
symbols.  This might be valid if those symbols are somehow
captured and copied at each entry point to a subprogram, and
the copies referenced in the shapes instead, but that's not
the case.

This patch introduces a new expression predicate IsScopeInvariantExpr(),
which defines a class of expressions that contains constant expressions
(in the sense that the standard uses that term) as well as references
to items that may be safely accessed in a context-free way throughout
their scopes.   This includes dummy arguments that are INTENT(IN)
and not VALUE, descriptor inquiries into descriptors that cannot
change, and bare LEN type parameters within the definitions of
derived types.  The new predicate is then used in shape analysis
to winnow out results that would have otherwise been contextual.

Differential Revision: https://reviews.llvm.org/D113309
2021-11-08 12:48:47 -08:00
Peter Klausler 80f0bb5971 [flang] Distinguish error/warning cases for bad jumps into constructs
Previously, jumps to labels in constructs from exterior statements
would elicit only a warning.  Upgrade these to errors unless the
branch into the construct would enter into only DO, IF, and SELECT CASE
constructs, whose interiors don't scope variables or have other
set-up/tear-down semantics.  Branches into these "safe" constructs
are still errors if they're nested in an unsafe construct that doesn't
also enclose the exterior branch statement.

Differential Revision: https://reviews.llvm.org/D113310
2021-11-08 11:52:01 -08:00
Peter Klausler f411c1dd95 [flang] Fix crash in semantic error recovery situation
A CHECK() in semantics is triggering when analyzing a program
with an undefined derived type pointer because the CHECK is
expecting a new error message to have been issued in a function
but not allowing for the case that a diagnostic could have been
produced earlier.  Adjust the predicate.

Differential Revision: https://reviews.llvm.org/D113307
2021-11-08 11:19:20 -08:00
Valentin Clement 59a4bbe26c
[fir] Add !fir.logical type conversion
Add conversion from !fir.logical types to LLVM IR Dialect types.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-08 17:54:55 +01:00
Valentin Clement 7e92b759ed
[fir] Add fir.box type conversion
This patch add the `!fir.box` type conversion to llvm.
`fir.box` is converted to the descriptor as defined in the ISO_Fortran_binding.h
and the addendum defined in descriptor.h.

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

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
2021-11-08 14:18:11 +01:00
Andrzej Warzynski ddd11b9a4b [flang][CodeGen] Transform `fir.call` to `llvm.call`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.call` to `llvm.call`.

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

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>

Differential Revision: https://reviews.llvm.org/D113278
2021-11-08 11:43:54 +00:00
Valentin Clement 54c563474a
[fir] Add fir.extract_value and fir.insert_value conversion
This patch add the conversion pattern for fir.extract_value
and fir.insert_value. fir.extract_value is lowered to llvm.extractvalue
anf fir.insert_value is lowered to llvm.insertvalue.
This patch also adds the type conversion for the BoxType and RecordType
needed to have some comprehensive tests.

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

This patch was landed and reverted once.
TypeBuilderFunc getModel<Fortran::ISO::CFI_index_t>() was clashing
with getModel<long long> on windows since they both are 64 bits
signed interger. On linux CFI_index_t is long. Change CFI_index_t
to getModel<long>.

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-07 21:59:01 +01:00
Valentin Clement 7a189fb267
Revert "[fir] Add fir.extract_value and fir.insert_value conversion"
This reverts commit ea55503d7c.
2021-11-05 22:16:37 +01:00
Valentin Clement d75ab7d548
[fir] Remove getModel<Fortran::ISO::CFI_dim_t> in DescriptorModel.h
A windows buildbot complains about previous definiton after D112961.

Remove the extra definition until we can figure out if really needed.
2021-11-05 20:49:17 +01:00
Valentin Clement ea55503d7c
[fir] Add fir.extract_value and fir.insert_value conversion
This patch add the conversion pattern for fir.extract_value
and fir.insert_value. fir.extract_value is lowered to llvm.extractvalue
anf fir.insert_value is lowered to llvm.insertvalue.
This patch also adds the type conversion for the BoxType and RecordType
needed to have some comprehensive tests.

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

Reviewed By: awarzynski

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-05 15:53:42 +01:00
Valentin Clement 8c23990949
[fir] Add fir.select and fir.select_rank FIR to LLVM IR conversion patterns
The `fir.select` and `fir.select_rank` are lowered to llvm.switch.

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

Reviewed By: mehdi_amini

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-05 12:54:51 +01:00
Mike Rice 4eac7bcf1a [OpenMP] Add parsing/sema/serialization for 'bind' clause.
Differential Revision: https://reviews.llvm.org/D113154
2021-11-04 14:40:30 -07:00
Kiran Chandramohan 48dc5c8e73 [Flang][OpenMP] Use the ultimate symbol in a call to the IsPointer function
The IsPointer check currently fails for host-associated symbols in OpenMP
regions. This causes some failures in semantic checks for pointer association
in an OpenMP region. Fix is to use the ultimate symbol in the call to the
IsPointer function in CheckPointerAssignment function in
lib/Semantics/pointer-assignment.cpp.

Reviewed By: klausler, peixin

Differential Revision: https://reviews.llvm.org/D112876
2021-11-04 19:53:58 +00:00
Valentin Clement 3ae8e44215
[fir] Add fir.insert_on_range conversion
Convert fir.insert_on_range operation to corresponding
llvm.insertvalue operations.

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

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D112896
2021-11-04 10:36:20 +01:00
Valentin Clement c86b4503a9
[fir] Restrict array type on fir.insert_on_range
Sequence type had no restriction on the insert_on_range operation.
This patch adds a restriction for the type to have constant shape
and size.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D113092
2021-11-04 08:54:09 +01:00
Valentin Clement 52d813edcc
[fir] Use notifyMatchFailure in fir.zero_bits conversion
Change emitOpError to notifyMatchFailure in conversion pattern.

Post-commit change after D113014

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D113091
2021-11-03 20:45:24 +01:00
Valentin Clement 3c7ff45cbb
[fir] Add substr information to fircg.ext_embox and fircg.ext_rebox operations
This patch adds the substring information to the fircg.ext_embox and
fircg.ext_rebox operations.

Substring is used for CHARACTER types.

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

Reviewed By: mehdi_amini

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-03 10:15:10 +01:00
Mehdi Amini ca0ed40e00 Remove builder that takes SSA value instead of Attribute on ExtractValueOp, InsetValueOp, and InsertOnRangeOp
This builder exposed a somehow "unsafe" API: it pretends we can
construct an InsertOnRangeOp from a range of SSA values, even though
this will crash if these aren't the result of `arith.constant` since
the operation actually needs attribute values (a build method can't
fail gracefully).
That means that the caller must check for the producer, at which
point they can just assemble the attribute array directly and call
the existing builder.

The existing call-sites were even in a worse state here: they would
actually create a constant operation that wouldn't be used and only
serve to carry the attribute through the builder API.

Differential Revision: https://reviews.llvm.org/D112946
2021-11-02 22:35:47 +00:00
Andrzej Warzynski 32e08248aa [flang][CodeGen] Transform `fir.unreachable` to `llvm.unreachable`
This patch extends the `FIRToLLVMLowering` pass in Flang by adding a
hook to transform `fir.unreachable` to `llvm.unreachable`.

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

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>

Differential Revision: https://reviews.llvm.org/D113023
2021-11-02 18:22:51 +00:00
Valentin Clement a7a6135925
[fir] Add fir.zero_bits conversion pattern to LLVM IR dialect
This patch adds the ZeroOpConversion pattern to LLVM IR dialect.
Conversion of aggregate types is not implemented yet and will trigger a
failure to legalize the operation. This is tested in the
convert-to-llvm-invalid.fir test file.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-11-02 16:54:34 +01:00
Valentin Clement 0c4a7a5263
[fir][NFC] Address post commit comments on D112845
Address some of the comments on D112845 after
it was committed.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D112918
2021-11-01 17:56:55 +01:00
Valentin Clement 044d5b5dd1
[fir] Add base of the FIR to LLVM IR pass
This patch adds the base of the FIR to LLVM IR Dialect conversion pass.
It currently can convert the following operations:
 - fir.global
 - fir.has_value
 - fir.address_of
 - fir.undefined

This patch is part of the upstreaming effort from fir-dev branch. It does not
cover all FIR operations in order to have small patches. Several patches will
follow to convert other operations.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D112845
2021-10-29 23:21:43 +02:00
peter klausler f70343d926 [flang] Fix combined folding of FINDLOC/MAXLOC/MINLOC
The tests for folding these intrinsics neglected to name the
logical scalars with a leading "test_", so test failures caused
by recent work to implement a combined constant folding facility
for these intrinsics wasn't catching some bugs.  This patch fixes
the tests and the bugs.

Differential Revision: https://reviews.llvm.org/D112741
2021-10-29 11:00:11 -07:00