Commit Graph

176 Commits

Author SHA1 Message Date
Diana Picus 9df0ba599c [flang] Implement GET_ENVIRONMENT_VARIABLE(VALUE)
Implement the second entry point for GET_ENVIRONMENT_VARIABLE. Reuse
existing bits and pieces wherever possible.

This patch also increases CFI_* error codes in order to avoid conflicts.
GET_ENVIRONMENT_VARIABLE is required to return a status of 1 if an
environment variable does not exist and 2 if environment variables are
not supported. However, if we add status codes for that they will
conflict with CFI_ERROR_BASE_ADDR_NULL and CFI_ERROR_BASE_ADDR_NOT_NULL,
which are also 1 and 2 at the moment. We therefore move all CFI error
codes up (an arbitrary) 10 spots to make room. Hopefully this isn't
a problem, since we weren't matching the CFI error codes that gfortran
uses anyway. It may still be an issue if any other runtime functions
will need to return a status of 1 or 2, but we should probably deal with
that when/if it occurs.

Differential Revision: https://reviews.llvm.org/D112698
2021-11-01 09:19:20 +00:00
Diana Picus 824bf90819 [flang] runtime: Read environment variables directly
Add support for reading environment variables directly, via std::getenv.
This needs to allocate a C-style string to pass into std::getenv. If the
memory allocation for that fails, we terminate.

This also changes the interface for EnvVariableLength to receive the
source file and line so we can crash gracefully.

Note that we are now completely ignoring the envp pointer passed into
ProgramStart, since that could go stale if the environment is modified
during execution.

Differential Revision: https://reviews.llvm.org/D111785
2021-10-28 07:49:30 +00:00
peter klausler b83242e20e [flang] Support legacy usage of 'A' edit descriptors for integer & real
The 'A' edit descriptor once served as a form of raw I/O of bytes
to/from variables that weren't of type CHARACTER (which itself
didn't exist until F'77).  This usage was especially common for
output of numeric variables that had been initialized with Hollerith.

Differential Revision: https://reviews.llvm.org/D112346
2021-10-22 16:02:33 -07:00
peter klausler b8452dba28 [flang] Support NAMELIST input of short arrays
NAMELIST array input does not need to fully define an array.
If another input item begins after at least one element,
it ends input into the array and the remaining items are
not modified.

The tricky part of supporting this feature is that it's not
always easy to determine whether the next non-blank thing in
the input is a value or the next item's name, esp. in the case
of logical data where T and F can be names.  E.g.,

  &group logicalArray = t f f t
      = 1 /

should read three elements into "logicalArray" and then read
an integer or real variable named "t".

So the I/O runtime has to do some look-ahead to determine whether
the next thing in the input is a name followed by '=', '(', or '%'.
Since the '=' may be on a later record, possibly with intervening
NAMELIST comments, the runtime has to support a general form of
saving and restoring its current position.  The infrastructure
in the I/O runtime already has to support repositioning for
list-directed repetition, even on non-positionable input sources
like terminals and sockets; this patch adds an internal RAII API
to make it easier to save a position and then do arbitrary
look-ahead.

Differential Revision: https://reviews.llvm.org/D112245
2021-10-22 13:38:11 -07:00
Valentin Clement a2e7af7516
[fir] Add utility function to FIRBuilder and MutableBox
This patch is extracted from D111337 to make is smaller.
It introduce utility functions to the FIRBuilder and add the MutableBox
files.

- genShape
- readCharLen
- getExtents

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-22 10:00:34 +02:00
Valentin Clement 0bf230d422
[fir] Remove unused function in CharacterTest 2021-10-22 00:25:59 +02:00
Valentin Clement 2ba572a82a
[fir] Remove createConcatenate test temporarily
This test is makeing one buildbot fail for unknown reason. Remove
it until we can investifate further.
2021-10-21 22:40:19 +02:00
Valentin Clement 13c31539f7
[fir] Add Character helper
This patch is extracted from D111337. It introduce the
CharacterExprHelper that helps dealing with character in FIR.

Reviewed By: schweitz, awarzynski

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

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-10-21 18:45:32 +02:00
Valentin Clement 7bbd7e9c1d
Revert "[fir] Add Character helper"
This reverts commit e4ce92245c.

Buildbots not happy with the tests.
2021-10-21 11:36:10 +02:00
Valentin Clement e4ce92245c
[fir] Add Character helper
This patch is extracted from D111337. It introduce the
CharacterExprHelper that helps dealing with character in FIR.

Reviewed By: schweitz, awarzynski

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

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-10-21 09:48:37 +02:00
Valentin Clement 676d091c63
Revert "[fir] Add Character helper"
This reverts commit 02d7089c23.
2021-10-20 22:43:13 +02:00
Valentin Clement 02d7089c23
[fir] Add Character helper
This patch is extracted from D111337. It introduce the
CharacterExprHelper that helps dealing with character in FIR.

Reviewed By: schweitz, awarzynski

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

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-10-20 21:35:02 +02:00
Valentin Clement c983aeddcf
[fir] Add character utility functions in FIRBuilder
Extract part of D111337 in order to mke it smaller
and easier to review. This patch add some utility
functions to the FIRBuilder.

Add the following utility functions:
- getCharacterLengthType
- createStringLiteral
- locationToFilename
- characterWithDynamicLen
- sequenceWithNonConstantShape
- hasDynamicSize

These bring up the BoxValue implementation together with it.

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

Reviewed By: AlexisPerry

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-19 22:34:21 +02:00
Valentin Clement 45503fc044
[fir] Add FIRBuilder utility functions
Extract some code from the big ptach D111337. This patch
contains some utility functions from the FIRBuidler.

List of utility functions added:
- getRegion
- getModule
- getKindMap
- getRefType
- getVarLenSeqTy
- getRealType
- createNullConstant
- createRealConstant
- createRealZeroConstant
- createGlobal
- createGlobalConstant
- createStringLitOp
- getNamedFunction
- getNamedGlobal
- createFunction
- addNamedFunction
- createBool

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-19 14:19:45 +02:00
Valentin Clement f17f694a0f
[fir] Add IfBuilder and utility functions
In order to reduct the size of D111337. The IfBuilder and the two
utility functions genIsNotNull and genIsNull have been extracted in
a separate patch with dedicated unittests.

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

Reviewed By: Leporacanthicus

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-17 20:55:41 +02:00
Eric Schweitz bde89ac7f1
[fir] Add the DoLoopHelper
Add the DoLoopHelper. Some helpers functions
to create fir.do_loop operations.

This code was part of D111337 and was extracted in order to
make the patch easier to review.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
Co-authored-by: Jean Perier <jperier@nvidia.com>
2021-10-13 21:48:45 +02:00
Diana Picus fc2ba5e53d [flang] Implement GET_ENVIRONMENT_VARIABLE(LENGTH)
Search for the environment variable in the envp string passed to
ProgramStart. This doesn't work if the main program isn't Fortran.

Differential Revision: https://reviews.llvm.org/D111394
2021-10-13 08:42:03 +00:00
peter klausler f65f830e5f [flang] runtime: fix output B/O/Z editing of "negative" values
B/O/Z integer output editing must not reflect any sign extension
of scalar output values.  Add more size-dependent OutputInteger
I/O APIs and kind instantiations of EditIntegerOutput.

Differential Revision: https://reviews.llvm.org/D111678
2021-10-12 16:02:07 -07:00
peter klausler f05c95f10f [flang] More work on SYSTEM_CLOCK runtime API and implementation
To get proper wrap-around behavior for the various kind parameter
values of the optional COUNT= and COUNT_MAX= dummy arguments to
the intrinsic subroutine SYSTEM_CLOCK, add an extra argument to
the APIs for lowering to pass the integer kind of the actual argument.
Avoid confusion by requiring that both actual arguments have the same
kind when both are present.  The results of the runtime functions
remain std::int64_t and lowering should still convert them before
storing to the actual argument variables.

Rework the implementation a bit to accomodate the dynamic
specification of the kind parameter, and to clean up some coding
issues with preprocessing and templates.

Use the kind of the COUNT=/COUNT_MAX= actual arguments to determine
the clock's resolution, where possible, in conformance with other
Fortran implementations.

Differential Revision: https://reviews.llvm.org/D111281
2021-10-12 09:24:24 -07:00
Valentin Clement 5371968e48
[fir][NFC] Add two negative tests for needExternalNameMangling
Add two test for needExternalNameMangling.
- One varibale in a function
- One namelist in a module

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111544
2021-10-12 09:25:23 +02:00
Valentin Clement fc66dbba1f
[fir] Add external name interop pass
Add the external name conversion pass needed for compiler
interoperability. This pass convert the Flang internal symbol name to
the common gfortran convention.

Clean up old passes without implementation in the Passes.ts file so
the project and fir-opt can build correctly.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111057
2021-10-05 20:33:41 +02:00
Valentin Clement b5a11a991e
[fir] Split FIROptimizer lib into several smaller libraries
Partition libFIROptimizer into smaller libraries that reflect the
structure. Adapt potential problems.

This patch is part of the upstreaming effort from fir-dev branch. It's a
building stone to upstreaming transformations.

Reviewed By: schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-05 14:02:32 +02:00
Valentin Clement 4755fb2e18
Revert "[fir] Split FIROptimizer lib into several smaller libraries"
This reverts commit c02a8cdda8.
2021-10-05 11:19:53 +02:00
Valentin Clement c02a8cdda8
[fir] Split FIROptimizer lib into several smaller libraries
Partition libFIROptimizer into smaller libraries that reflect the
structure. Adapt potential problems.

This patch is part of the upstreaming effort from fir-dev branch. It's a
building stone to upstreaming transformations.

Reviewed By: schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-05 11:08:51 +02:00
Valentin Clement bc02a3d428
Revert "[fir] Split FIROptimizer lib into several smaller libraries"
This reverts commit c2eff3d5b9.
2021-10-05 10:16:19 +02:00
Valentin Clement c2eff3d5b9
[fir] Split FIROptimizer lib into several smaller libraries
Partition libFIROptimizer into smaller libraries that reflect the
structure. Adapt potential problems.

This patch is part of the upstreaming effort from fir-dev branch. It's a
building stone to upstreaming transformations.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111055
2021-10-05 09:41:09 +02:00
Craig Rasmussen 18e6328935 [flang] Remove incorrect unit test
Any test of the team_number intrinsic function will apparently
fail because it doesn't have access to ISO_FORTRAN_ENV when
called.
2021-10-04 18:27:14 -07:00
Craig Rasmussen 9dd3965e96 [flang] Added tests for intrinsic function 'team_number()'
reviewers: klausler, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D100897
2021-10-04 12:35:45 -07:00
Jean Perier b7c07ce15f [flang] Improve runtime interface with C99 complex
Follow up of https://reviews.llvm.org/D83397.

In folding, make pgmath usage conditional to C99 complex
support in C++. Disable warning in such case.

In lowering, use an empty class type to indicate C99 complex
type in runtime interface.

Add a unit test enforcing C99 complex can be processed
by FIR runtime interface builder.

Differential Revision: https://reviews.llvm.org/D110860
2021-10-01 08:45:24 +02:00
peter klausler faa1842875 [flang] Front-end and runtime support for CALL EXIT and ABORT
Support the extension intrinsic subroutines EXIT([status]) and ABORT()
in the intrinsic table and runtime support library.  Lowering remains
to be done.

Differential Revision: https://reviews.llvm.org/D110741
2021-09-30 11:01:22 -07:00
Diana Picus 37089bae29 Reland "[flang] GET_COMMAND_ARGUMENT runtime implementation"
Recommit https://reviews.llvm.org/D109813 and
https://reviews.llvm.org/D109814.

This implements the second and final entry point for GET_COMMAND_ARGUMENT,
handling the VALUE, STATUS and ERRMSG parameters.

It has a small fix in that we're now using memcpy instead of strncpy
(which was a bad idea to begin with, since we're not actually interested
in a string copy).
2021-09-28 12:34:07 +00:00
Diana Picus 6359a4cdbf Revert "[flang] GET_COMMAND_ARGUMENT(VALUE) runtime implementation"
This reverts commit 0446f1299f and
df6302311f.

There's a warning on flang-aarch64-latest-gcc related to strncpy using
the result of strlen as a bound. I'll recommit with a fix.
2021-09-28 12:07:27 +00:00
Diana Picus 0446f1299f [flang] GET_COMMAND_ARGUMENT(ERRMSG) runtime implementation
Implement the final part of GET_COMMAND_ARGUMENT, i.e. the handling of
ERRMSG. This uses some of the infrastructure in stat.h and gets rid of
the magic numbers that we were using for return codes.

Differential Revision: https://reviews.llvm.org/D109814
2021-09-28 08:32:19 +00:00
Diana Picus df6302311f [flang] GET_COMMAND_ARGUMENT(VALUE) runtime implementation
Partial implementation for the second entry point for
GET_COMMAND_ARGUMENT. It handles the VALUE and STATUS arguments, and
doesn't touch ERRMSG.

Differential Revision: https://reviews.llvm.org/D109813
2021-09-28 08:32:19 +00:00
Diana Picus af63d1791b [flang] GET_COMMAND_ARGUMENT(LENGTH) runtime implementation
Implement the ArgumentLength entry point of GET_COMMAND_ARGUMENT. Also
introduce a fixture for the tests.

Note that this also changes the interface for ArgumentLength from
returning a 4-byte integer to returning an 8-byte integer.

Differential Revision: https://reviews.llvm.org/D109227
2021-09-28 08:32:19 +00:00
Valentin Clement 62cc6b0da2
[flang][fir] Add support to mangle/deconstruct namelist group name
Add support to create unique name for namelist group and be able to
deconstruct them.

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

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-09-24 22:10:39 +02:00
Valentin Clement 321be24aa6
Revert "[flang][fir] Add support to mangle/deconstruct namelist group name"
This reverts commit 3593ae4312.
2021-09-24 18:49:40 +02:00
Valentin Clement 3593ae4312
[flang][fir] Add support to mangle/deconstruct namelist group name
Add support to create unique name for namelist group and be able to
deconstruct them.

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

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-09-24 14:06:08 +02:00
peter klausler 4393e3776b [flang] Implement READ(SIZE=) and INQUIRE(IOLENGTH=) in runtime
Count input characters corresponding to formatted edit descriptors
for READ(SIZE=); count output bytes for INQUIRE(IOLENGTH=).

The I/O APIs GetSize() and GetLength() were adjusted to return
std::size_t as function results.

Basic unit tests were added (and others fixed).

Differential Revision: https://reviews.llvm.org/D110291
2021-09-23 10:27:56 -07:00
peter klausler 5661317f86 [flang] Put intrinsic function table back into order
Some intrinsic functions weren't findable because the table
wasn't strictly in order of names.

And complete a missing generalization of the extension DCONJG
to accept any kind of complex argument, like DREAL and DIMAG
were.

Differential Revision: https://reviews.llvm.org/D110002
2021-09-20 08:40:28 -07:00
Jean Perier 05b4e49a17 [flang] Signal EOR in non advancing IO and move to next record
When an end of record is met in non advancing IO:
- Set IOSTAT if present according to 12.11.4 (5).
- Position the file to the next record (12.11.4 (4)).

The previous code was only signaling EOR for fixed record length IO.
Reading at 12.11.4, I do not find the rational for this condition, so I
removed it.
It also does not seem the presence of padding should prevent
the EOR signaling.

The positionning to the next record was block when EOR is signaling
in FinishReadingRecord because ErrorHandler.isError() is true in this
case.
EOR in input is not an error, but I am not confident to modify
ErrorHandler.isError() to cover that. However, In FinishReadingRecord,
the code should not bail if the error is simply an end of record.

I did not check the SIZE requirements here because GetSize runtime is
not yet implemented.

Differential Revision: https://reviews.llvm.org/D109505
2021-09-10 13:08:02 +02:00
Peter Klausler 830c0b9023 [flang] Move runtime API headers to flang/include/flang/Runtime
Move the closure of the subset of flang/runtime/*.h header files that
are referenced by source files outside flang/runtime (apart from unit tests)
into a new directory (flang/include/flang/Runtime) so that relative
include paths into ../runtime need not be used.

flang/runtime/pgmath.h.inc is moved to flang/include/flang/Evaluate;
it's not used by the runtime.

Differential Revision: https://reviews.llvm.org/D109107
2021-09-03 11:08:34 -07:00
V Donaldson 29c3ef5a0e Remove blank from NaN string representation
Flang front end function DumpHexadecimal generates a string
representation of a REAL value.  When the value is a NaN, the string
contains a blank, as in "NaN 0x7fc00000".  This function is used by
lowering to generate a string that is then passed to llvm Support
function convertFromStringSpecials, which does not expect a blank
in the string.  Remove the blank to allow correct recognition of a
NaN by this llvm function.

Note that function DumpHexadecimal is not exercised by the front end
itself.  This functionality is only exercised by code that is not yet
present in llvm.
2021-09-03 08:09:55 -07:00
Diana Picus 0c375296cc [flang] COMMAND_ARGUMENT_COUNT runtime implementation
Grab whatever ProgramStart has stored in executionEnvironment.argc and
subtract 1 (based on the assumption that ProgramStart is called with
a C-style argc that counts the command name as an argument).

Spoiler alert: The tests will evolve into fixtures when we implement
GET_COMMAND_ARGUMENT etc.

Differential Revision: https://reviews.llvm.org/D109048
2021-09-03 07:29:39 +00:00
Jean Perier b3e392c081 [flang] Implement Posix version of DATE_AND_TIME runtime
Use gettimeofday and localtime_r to implement DATE_AND_TIME intrinsic.
The Windows version fallbacks to the "no date and time information
available" defined by the standard (strings set to blanks and values to
-HUGE).

The implementation uses an ifdef between windows and the rest because
from my tests, the SFINAE approach leads to undeclared name bogus errors
with clang 8 that seems to ignore failure to instantiate is not an error
for the function names (i.e., it understands it should not instantiate
the version using gettimeofday if it is not there, but still yields an
error that it is not declared on the spot where it is called in the
uninstantiated version).

Differential Revision: https://reviews.llvm.org/D108622
2021-08-25 11:16:52 +02:00
Diana Picus 0104cc85b1 [flang] Add default implementation for SYSTEM_CLOCK
Add an implementation for the runtime functions related to SYSTEM_CLOCK.
As with CPU_TIME, this is based on std::clock(), which should be
available everywhere, but it is highly recommended to add
platform-specific implementations for systems where std::clock() behaves
poorly (e.g. POSIX).

The documentation for std::clock() doesn't specify a maximum value and
in fact wrap around behaviour is non-conforming.  Therefore, this
implementation of SYSTEM_CLOCK is not guaranteed to wrap around either,
and after std::clock reaches its maximum value we will likely just
return failure rather than wrap around. If this happens often on your
system, please add a new platform-specific implementation.

We define COUNT_MAX as either the maximum value that can be stored in
a std::clock_t or in a 64-bit integer (whichever is smaller), and
COUNT_RATE as CLOCKS_PER_SEC. For POSIX systems, the value of
CLOCKS_PER_SEC is hardcoded to 10^6 and irrelevant for the values
returned by std::clock.

Differential Revision: https://reviews.llvm.org/D105969
2021-08-18 07:39:13 +00:00
Peter Steinfeld b8ecdcdd81 [flang] Fix the vector version of EOSHIFT with a BOUNDARY argument
When the vector version of EOSHIFT was called, the BOUNDARY argument was being
ignored.  I fixed that and added a test that would not pass without this fix.

Differential Revision: https://reviews.llvm.org/D108249
2021-08-17 15:20:15 -07:00
peter klausler a05bae6163 [flang] Correct off-by-one error in SET_EXPONENT
SET_EXPONENT is returning values that are too large by a factor
of two.

Differential Revision: https://reviews.llvm.org/D107986
2021-08-12 12:50:16 -07:00
peter klausler 39c38c2152 [flang] Fix list-directed plural repeated null values at end of record
A repeated null value at the end of an input record with a count > 1
would incorrectly advance to the next record when resumed.  Fix.

Improve some poor naming and code flow noticed while debugging, so
next time will be easier.

Extend a unit test to check this case.

Differential Revision: https://reviews.llvm.org/D107917
2021-08-11 13:14:07 -07:00
Andrzej Warzynski 7b73ca3043 [flang][driver] Delete `f18` (i.e. the old Flang driver)
This patch removes `f18`, a.k.a. the old driver. It is being replaced
with the new driver, `flang-new`, which has reached feature parity with
`f18` a while ago. This was discussed in [1] and also in [2].

With this change, `FLANG_BUILD_NEW_DRIVER` is no longer needed and is
also deleted. This means that we are making the dependency on Clang permanent
(i.e. it cannot be disabled with a CMake flag).

LIT set-up is updated accordingly. All references to `f18` or `f18.cpp`
are either updated or removed.

The `F18_FC` variable from the `flang` bash script is replaced with
`FLANG_FC`. The former is still supported for backwards compatibility.

[1] https://lists.llvm.org/pipermail/flang-dev/2021-June/000742.html
[2] https://reviews.llvm.org/D103177

Differential Revision: https://reviews.llvm.org/D105811
2021-08-05 12:57:15 +00:00