Commit graph

2480 commits

Author SHA1 Message Date
Sourabh Singh Tomar 3d0b76022d [flang][OpenMP] upstream OpenMP lowering
Summary:
This patch implements lowering of OpenMP barrier construct from
pft to OpenMPDialect.

Patch is carved out of following merged PR's from fir-dev branch
of https://github.com/flang-compiler/f18-llvm-project/

PR's:
https://github.com/flang-compiler/f18-llvm-project/pull/248
https://github.com/flang-compiler/f18-llvm-project/pull/251

Unfortunately primary tool `bbc` for functional validation is not
yet upstreamed. So this patch includes a unittest for lowering
`!OMP barrier` construct.

Some part of the these PR's still remains downstream(functional test
and dialect registration to legalizer) for obvious reasons.
Will upstream them when the dependencies are upstreamed.

Reviewed By: schweitz, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D83659
2020-07-14 18:01:15 +05:30
Valentin Clement f06ad91347 Revert "[flang][openacc] OpenACC 3.0 parser"
This reverts commit 65049d1610.

Buildbot failure clang-ppc64le-rhel
2020-07-13 22:35:19 -04:00
Valentin Clement 65049d1610 [flang][openacc] OpenACC 3.0 parser
Summary:
This patch introduce the parser for OpenACC 3.0 in Flang. It uses the same TableGen mechanism
than OpenMP.

Reviewers: nvdatian, sscalpone, tskeith, klausler, ichoyjx, jdoerfert, DavidTruby

Reviewed By: klausler

Subscribers: SouraVX, mgorny, hiraditya, jfb, sstefan1, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83649
2020-07-13 20:15:06 -04:00
AlexisPerry f630b8590f [flang] Extended the flang driver options to include gfortran equivalents to pgf90 specific options.
Summary: Added gfortran equivalents of pgf90's -Mfixed, -Mfree, -Mextend, -Mstandard, -Munlimited and also added -fdefault-double-8

Reviewers: sscalpone, richard.barton.arm, DavidTruby, clementval, jdoerfert

Reviewed By: sscalpone, richard.barton.arm

Subscribers: sstefan1, llvm-commits, flang-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83687
2020-07-13 14:26:28 -06:00
Tim Keith 3780d3eb10 [flang] Use octal escapes for character literals in modfiles
Character literals can be formatted using octal or hex escapes for
non-ascii characters. This is so that the program can be unparsed for
either pgf90 or gfortran to compile. But modfiles should not be affected
by that -- they should be consistent.

This changes causes modfiles to always have character literals formatted
with octal escapes.

Differential Revision: https://reviews.llvm.org/D83703
2020-07-13 12:19:18 -07:00
David Truby 4121172239 [flang][openmp] libc++ unordered_map build fix in flang openmp static analysis
Simply move the include of unordered_map from the .cpp file to the .h file
2020-07-13 16:08:24 +01:00
Valentin Clement 6e42a417ba [flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.

Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert

Reviewed By: DavidTruby, ichoyjx

Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 12:45:12 -04:00
Eric Schweitz 9263e08251 [flang] ifdef to avoid warning about supposedly dead function 2020-07-09 16:10:08 -07:00
peter klausler 8a8bb078a3 [flang] Fix frontend build with -DBUILD_SHARED_LIBS=On
Fix fronted shared library builds by eliminating dependences of
the parser on other component libraries, moving some code around that
wasn't in the right library, and making some dependences
explicit in the CMakeLists.txt files.  The lowering library
does not yet build as a shared library due to some undefined
names.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83515
2020-07-09 15:54:19 -07:00
Pete Steinfeld 85d9745c83 [flang] Fix a crash when creating generics from a copy
Summary:
When a program unit creates a generic based on one defined in a module, the
function `CopyFrom()` is called to create the `GenericDetails`.  This function
copied the `specificProcs_` but failed to copy the `bindingNames_`.  If the
function `CheckGeneric()` then gets called, it tries to index into the empty
binding names and causes the crash.

I fixed this by adding code to `CopyFrom()` to copy the binding names.

I also added a test that causes the crash.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83491
2020-07-09 15:49:45 -07:00
Eric Schweitz 7cd1b0ff34 [flang] partially revert upstreamed code to support complex values in runtime support to avoid warnings. 2020-07-09 07:39:44 -07:00
peter klausler cffc603617 [flang] Fix negative unit number hashing
Ensure that external unit number hashing produces a valid
index for a negative unit number, viz. a NEWUNIT=.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83428
2020-07-08 17:59:00 -07:00
Pete Steinfeld 9520b6c8ab [flang] Fix a crash when cosubscript list is empty
Summary:
When there are errors in the evaluation of every cosubscript expression in a
coindexed object, the compiler would crash.  I fixed this by just checking to
see if there were errors in the evaluation of the cosubscripts before
constructing the `DataRef` for the coindexed object.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83410
2020-07-08 10:11:34 -07:00
Eric Schweitz c54a013e5a partial revert on RTBuilder.h to avoid warnings. 2020-07-08 08:47:13 -07:00
Eric Schweitz 24b62f28c5 [flang] Upstreaming intrinsic call lowering.
This module implements the lowering of Fortran intrinsics to the
corresponding calls in support libraries (the Fortran runtime, math
libraries, etc.)

This revision is a tad larger because there are a large number of Fortran
intrinsics and this adds lowering for a fair number of them.

Differential revision: https://reviews.llvm.org/D83355
2020-07-08 07:34:21 -07:00
Pete Steinfeld 15fa287b64 [flang] Support for image selectors
Summary:
This change implements support for image selectors and image selector
specifications as described in section 9.6.

In check-coarray[.h,cpp] I changed the `Leave()` function for
`parser::ImageSelectorSpec` to take a `parser::ImageSelector`, which
contains a list of image selector specifications.  This allows us to
detect when the same specification is used more than once.  I also added
code to analyze the expressions for the image selector specifications to
expression.cpp and a test for all of the conditions to check at
compile-time.

Note that we do not check at compile-time to see if the value of the
cosubscripts are within the specified cobounds.  We also do not check anything
related to selecting a valid team.  We also do not check that the denotation of
the `stat-variable` is not dependent on the evaluation of an entity in the
same statement.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83336
2020-07-08 07:31:54 -07:00
Isuru Fernando 2ebf4b6e4c [flang] Fix setting mxcsr on MSVC
Reviewers: sscalpone, jdoerfert, #flang, DavidTruby, jeanPerier

Reviewed By: jeanPerier

Subscribers: richard.barton.arm, jeanPerier, ro, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D77815
2020-07-08 07:25:25 -05:00
peter klausler 8f0f9eaddf [flang] Fix CHARACTER length folding problem
Do not rewrite LEN(x) or x%len to the expression that specifies
the length of x when that length is not a constant expression.
Its value may have changed since the value of the expression was
first captured in the definition of the object.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83352
2020-07-07 16:38:36 -07:00
Zachary Selk 4b9b64d561 [flang] Added missing runtime I/O definitions
Added runtime function definitions for 32-bit real I/O and 32-bit complex output

Differential Revision: https://reviews.llvm.org/D83112
2020-07-07 12:33:51 -07:00
Katherine Rasmussen c6a23df691 [flang] Make 'num_images()' intrinsic
I added 'num_images()' to the list of functions that are evaluated as intrinsic. I also added a test file in flang/test/Semantics to test calls to 'num_images()'. There was a call to 'num_images()' in flang/test/Semantics/call10.f90 that expected an error, now it no longer produces an error. So I edited that file accordingly. I also edited the intrinsics unit test to add further testing of 'num_images()'.

Differential Revision: https://reviews.llvm.org/D83142
2020-07-07 12:31:10 -07:00
Eric Schweitz 216a54a04b [flang] Add lowering of I/O statements.
The IO module is where I/O related statements are lowered to calls to the runtime library.

Differential revision: https://reviews.llvm.org/D83267
2020-07-07 07:31:50 -07:00
Kiran Kumar T P cd503166fb [flang][OpenMP] Enhance parser support for flush construct to OpenMP 5.0
Summary:
This patch enhances parser support for flush construct to OpenMP 5.0 by including memory-order-clause.

2.18.8 flush Construct
        !$omp flush [memory-order-clause] [(list)]
                where memory-order-clause is
                acq_rel
                release
                acquire

The patch includes code changes and testcase modifications.

Reviewed By: klausler, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D82177
2020-07-07 14:27:13 +05:30
Tim Keith 1b18391818 [flang] Add missing include for std::min
This was causing the build to fail on macos.

Differential Revision: https://reviews.llvm.org/D83237
2020-07-06 13:03:02 -07:00
Pete Steinfeld f9e24a563c [flang] Bug fix for ambiguous references to data and functions
Summary:
A program may erroneously reference the same name as both a data object
and as a function.  Some of these references were causing an internal
error in expression analysis.

It was already the case that a symbol referenced in a parse tree for a
call was changed from an `Entity` to a `ProcEntity`.  I added code to
detect when a symbol was referenced in a parse tree as an array element
gets changed from an `Entity` to an `ObjectEntity`.  Then, if an
`ObjectEntity` gets called as a function or a `ProcEntity` gets
referenced as a data object, errors get emitted.

This analysis was previously confined to the name resolution of the
specification part of a `ProgramTree`.  I added a pass to the execution
part of a `ProgramTree` to catch names declared in blocks.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D82903
2020-07-06 11:27:14 -07:00
peter klausler a39e9cf6be [flang] Basic tests of external I/O runtime (part 9/9)
Add new unit tests for external Fortran I/O that drive the
Fortran I/O runtime API from C++ and exercise basic writing
and read-back in the various combinations of access modes,
record length variability, and formatting.  Sequential modes
are tested with positioning.  More thorough tests written in
Fortran will follow when they can be compiled and run.

The Fortran runtime's error termination callback registration
was extended with source file and line number positions for
better failure messages in unit testing.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83164
2020-07-06 10:37:13 -07:00
peter klausler 5d5b968252 [flang] Add fixes and missing stmts to I/O runtime API handlers (ext. I/O part 8)
Complete the rework of the initial implementation of external I/O
to fix problems found in testing (tests to follow); add handlers
for hitherto unimplemented PAUSE, FLUSH, ENDFILE, BACKSPACE, and
REWIND statements.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83162
2020-07-04 12:53:31 -07:00
peter klausler 45b5c79a31 [flang] Extend & fix per-I/O-statement state (ext. I/O work part 7)
The per-I/O-statement state structures need to support missing
external I/O statements, and some bugs found in testing with
formatted input and record advancement are fixed.  The effects
of these changes will not be visible until further patches to
the I/O API handlers are pushed.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83151
2020-07-04 10:49:00 -07:00
peter klausler 0006354c3b [flang] Further implementation of external I/O unit operations (part 6)
Rework initial implementation of external I/O unit operations to
fix problems exposed in unit tests (in a later patch).  Add flushing.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83147
2020-07-03 17:31:01 -07:00
peter klausler 7926969afc [flang] Track known file size, add IsATerminal (ext. I/O work part 5)
Add a data member knownSize_ and an accessor to allow the size of
an external file to be tracked when known.  Also add a wrapper for
::isatty() here in the filesystem encapsulation module.  These
features are needed for the external I/O rework changes still
to come.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83141
2020-07-03 13:04:18 -07:00
peter klausler c7cabf9d60 [flang] Define new runtime error IOSTAT values (I/O runtime work part 4)
Add more IOSTAT= values for errors that can arise in external I/O.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83140
2020-07-03 12:41:33 -07:00
Eric Schweitz 35808ab8e1 [flang] Add FIRBuilder.cpp
The FIR builder is a helper class that manages the creation of MLIR
operations from the bridge. The focus of the builder is the creation of
Operations, Types, etc.

Differential revision: htps://reviews.llvm.org/D83107
2020-07-03 11:52:00 -07:00
peter klausler 98d576c78f [flang] Improve API for runtime allocator (I/O runtime work part 3)
New<A> used to return an A&; now it returns an OwningPtr<A>
to force better ownership tracking of allocations.  Its API
has also been split into New<A> and SizedNew<A> to allow
allocations with a size override.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83108
2020-07-03 08:37:40 -07:00
Jean Perier eb305631be [flang][NFC] Move and rework pgmath description used in folding
This change prepares usage of lipgmath description in lowering.
- Removes the static variable templates that were used to abstract
  libpgmath description
- Move the description to pgmath.h.inc header and rework the macros
  so that they can both be used to declare pgmath functions and use
  them.
  The way they are to be used is left to pgmath.h.inc user that
  must define PGMATH_USE_XX macros that will be called for all pgmath
  functions in pgmath.h.inc.
- In intrinsic-library.cpp define PGMATH_USE_XX macro callbacks in
  order to capture function pointers to pgmath functions as well as
  a description of their type. This will be used for constant folding
  using pgmath.
- Change atan/atan2 handling to use atan2 instead of atan when there are two
arguments  because it is easier to handle in the runtime description.

Also fixes lipgmath linking regression after D78215 cmake changes.

This change is motivated by the need to use a similar pgmath
description in lowering. The difference is that no function pointers will
be taken there, and instead only the function name and type are needed.

Reviewed By: schweitz, sscalpone

Differential Revision: https://reviews.llvm.org/D83051
2020-07-03 10:19:33 +02:00
peter klausler 4e958c1748 [flang] External I/O runtime work, repackaged (part 2)
Clean up the input editing path so external input works better
when combined with further changes.  List-directed input needed
to allow for advancement to following records.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83104
2020-07-02 17:44:51 -07:00
peter klausler 37f98f6f4c [flang] External I/O runtime work, repackaged (part 1)
Add a isFixedRecordLength flag member to Connection to
disambiguate the state of "record has known variable length"
from "record has fixed length".  Code that sets and tests this
flag will appear in later patches.  Rearrange data members to
reduce storage requirements, since Connection might indirectly
end up on a program stack frame.  Add a utility member function
BeginRecord(); use it in internal I/O processing.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83098
2020-07-02 15:17:26 -07:00
peter klausler 7cccd49a55 [flang] Clean up binary dependences of runtime libraries
There were dependences upon LLVM libraries in the Fortran
runtime support library binaries due to some indirect #includes
of llvm/Support/raw_ostream.h, which caused some kind of internal
ABI version consistency checking to get pulled in.  Fixed by
cleaning up some includes.

Reviewed By: tskeith, PeteSteinfeld, sscalpone

Differential Revision: https://reviews.llvm.org/D83060
2020-07-02 12:27:01 -07:00
Tim Keith 70f2bcc197 [flang] Fix bug determining alternate return
The arguments have been moved out of the analyzer so we can't get the
expected number there. Instead use the argument count from the newly
built callee.

Differential Revision: https://reviews.llvm.org/D83063
2020-07-02 12:24:35 -07:00
Eric Schweitz 5c02a2421b [flang] Add inliner pass.
This adds a minimalist inliner implementation. Along with the inliner, a
minimum number of support files are also included. These will pave the
way for future diffs to add more transformation passes to flang. A
future diff will add the inline test, which cannot be run successfully
quite yet as some components have not yet been upstreamed.

Differential revision:
2020-07-02 06:10:54 -07:00
Eric Schweitz ffa1f8198e [flang] Add changes to codegen to convert it to tablegen passes.
This upstreams changes to codegen to convert the passes to the new
tablegen pass support from MLIR.

Differential revision: https://reviews.llvm.org/D83018
2020-07-02 06:07:40 -07:00
Valentin Clement 2ddba3082c [flang][openmp] Use common Directive and Clause enum from llvm/Frontend
Summary:
This patch is removing the custom enumeration for OpenMP Directives and Clauses and replace them
with the newly tablegen generated one from llvm/Frontend. This is a first patch and some will follow to share the same
infrastructure where possible. The next patch should use the clauses allowance defined in the tablegen file.

Reviewers: jdoerfert, DavidTruby, sscalpone, kiranchandramohan, ichoyjx

Reviewed By: DavidTruby, ichoyjx

Subscribers: jholewinski, cfe-commits, dblaikie, MaskRay, ymandel, ichoyjx, mgorny, yaxunl, guansong, jfb, sstefan1, aaron.ballman, llvm-commits

Tags: #llvm, #flang, #clang

Differential Revision: https://reviews.llvm.org/D82906
2020-07-01 20:58:11 -04:00
Tim Keith 05756e6937 [flang] Add more support for alternate returns
Add `hasAlternateReturns` to `evaluate::ProcedureRef`.

Add `HasAlternateReturns` to test subprogram symbols.

Fix `label01.F90` test: It was checking that "error: " didn't appear in
the output. But that was erroneously matching a warning that ends
"would be in error:". So change it to check for ": error: " instead.

Differential Revision: https://reviews.llvm.org/D83007
2020-07-01 17:28:01 -07:00
Tim Keith dd90408262 [flang][NFC] Get formatting in sync with latest clang-format
flang/module only contains Fortran files and one is a .h so disable
formatting on that directory.

Differential Revision: https://reviews.llvm.org/D82989
2020-07-01 16:51:46 -07:00
clementval 5c37b2a5ee Revert "[flang][openmp] Use common Directive and Clause enum from llvm/Frontend"
This reverts commit 7f1e776795.
2020-07-01 18:49:07 -04:00
peter klausler 31e6cd28a5 [flang] Implement cross-set EQUIVALENCE impossibility checking
Implement cross-set EQUIVALENCE impossibility checking; fixes
an infinite loop on an erroneous test.  Also fix substring
reference offset calculations in EQUIVALENCE discovered to
be incorrect during testing.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D82993
2020-07-01 14:09:07 -07:00
Eric Schweitz 5a580bbb81 [flang] Add the Runtime.h to prepare for more code being upstreamed.
This is the header file for lowering Fortran statements that depend on
the Fortran runtime support library. The implementation of the lowering
of these constructs will follow in a subsequent diff.

Differential revision: https://reviews.llvm.org/D82991
2020-07-01 13:26:36 -07:00
Valentin Clement 7f1e776795 [flang][openmp] Use common Directive and Clause enum from llvm/Frontend
Summary:
This patch is removing the custom enumeration for OpenMP Directives and Clauses and replace them
with the newly tablegen generated one from llvm/Frontend. This is a first patch and some will follow to share the same
infrastructure where possible. The next patch should use the clauses allowance defined in the tablegen file.

Reviewers: jdoerfert, DavidTruby, sscalpone, kiranchandramohan, ichoyjx

Reviewed By: DavidTruby, ichoyjx

Subscribers: ichoyjx, mgorny, yaxunl, guansong, jfb, sstefan1, aaron.ballman, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D82906
2020-07-01 15:58:45 -04:00
River Riddle f625f5231a [mlir] Remove the default template parameters from AttrBase and TypeBase.
MSVC 2017 doesn't support the case where a trailing variadic template list comes after template types with default parameters. Until we upgrade to VS 2019, we can't use the simplified definitions.
2020-06-30 21:55:32 -07:00
Tim Keith 98202edacb [flang] Silence some warnings from clang-tidy
Disable some of the warnings from clang-tidy, in particular,
`readability-identifier-naming`. They add clutter to reviews.

Differential Revision: https://reviews.llvm.org/D82795
2020-06-30 10:15:12 -07:00
Eric Schweitz bd2c3014e1 [flang] Add coarray lowering hooks.
Differential review: https://reviews.llvm.org/D82790
2020-06-29 14:24:13 -07:00
peter klausler f45b41348b [flang] Defer stmt function body analysis until specification part complete
Expression analysis was being invoked on the bodies of statement functions
as they were being encountered during name resolution.  This led to failures
on some FCVS tests in cases where those expressions contained implicitly
typed objects.  Defer the analysis of statemet function bodies to the end
of the specification part, at which time the symbols of the enclosing scope
will have been typed.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D82796
2020-06-29 12:32:19 -07:00