Commit Graph

3616 Commits

Author SHA1 Message Date
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
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
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
peter klausler d0ca0595b9 [flang] Fix crash on "call system_clock(count_max=j)"
An erroneous entry in the intrinsics table causes semantics to
crash on a call to system_clock if the optional "count_max="
argument appears and "count=" does not.

Differential Revision: https://reviews.llvm.org/D112738
2021-10-29 10:51:28 -07:00
Nimish Mishra 9faed889cf Fixed erring semantic errors arising from D108904 2021-10-30 03:44:59 +05:30
peter klausler a94b721d26 [flang] Improve error message for misuse of NULL(mold) as data statement constant
While "null()" is accepted as a data statement constant when it
corresponds to a pointer object, "null(mold=p)" and "null(p)"
are not allowed.  The current error messages simply complain
that null is not an array.  This patch adds a context-sensitive
message to the effect that a data statement constant followed
by non-empty parentheses must be an array or structure constructor.

(Note that f18 can't simply special-case the name "null" when parsing
data statement constants, since programs are free to repurpose that
name as an array or derived type.)

Differential Revision: https://reviews.llvm.org/D112740
2021-10-28 15:20:41 -07:00
Peter Klausler 8b5b38eb24 [flang] Revert new unintended runtime behavior
A recent change caused some variable-length sequential formatted
output statements with record positioning at the end of a FORMAT
(e.g., FORMAT('hi',10X) to append blanks at the end of the completed
record when emitting it.

Differential Revision: https://reviews.llvm.org/D112742
2021-10-28 14:11:06 -07:00
peter klausler d48236a51c [flang] Fold SPREAD
Implements constant folding of the transformational intrinsic
function SPREAD().

Differential Revision: https://reviews.llvm.org/D112739
2021-10-28 14:10:16 -07:00
Emil Kieri 848cca6c5b [flang] Checks for pointers to intrinsic functions
Check that when a procedure pointer is initialised or assigned with an intrinsic
function, or when its interface is being defined by one, that intrinsic function
is unrestricted specific (listed in Table 16.2 of F'2018).

Mark intrinsics LGE, LGT, LLE, and LLT as restricted specific. Getting their
classifications right helps in designing the tests.

Differential Revision: https://reviews.llvm.org/D112381
2021-10-28 12:30:29 +02: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
Shraiysh Vaishay 9fb52cb3f1 [MLIR][OpenMP] Added omp.atomic.read and omp.atomic.write
This patch supports the atomic construct (read and write) following
section 2.17.7 of OpenMP 5.0 standard. Also added tests and
verifier for the same.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D111992
2021-10-27 14:05:44 +05:30
River Riddle 4283168603 Fix AffineDemotion pass after the DialectConversion change in D111620 2021-10-27 04:13:18 +00:00
Valentin Clement 9daec09551
[fir] Avoid slice with substr in fir.array_load, fir.array_coor and fir.array_merge_store
Substring information on slice operation has been added in D112441.
The operations fir.array_load, fir.array_coor and fir.array_merge_store can take
a slice but not with a substring. This patch add this check in their verifier.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D112568
2021-10-26 21:44:25 +02:00
Valentin Clement d43f779f82
[fir][NFC] Move RewritePatterns.td to CanonicalizationPatterns.td in Dialect
RewritePatterns.td/RewritePatterns.inc is used only by the
FIROps.cpp file. This patch move this file logically in the Dialect
folder together with FIRDialet, FIROps, FIRTypes ...
It also rename it to CanonicalizationPatterns.td.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D112522
2021-10-26 21:12:54 +02:00
Valentin Clement 1189d97d12
[fir][NFC] Fix indentation for fir.alloca builders 2021-10-26 14:55:47 +02:00
Valentin Clement 7812f510d2
[fir] Add substring to fir.slice operation
This patch adds the substriing information to the fir.slice
operation. This will be used by character operations in later
upstreaming patches.

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

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-26 10:33:40 +02:00
Mike Rice d8699391a4 [OPENMP51]Initial parsing/sema for append_args clause for 'declare variant'
Adds initial parsing and sema for the 'append_args' clause.

Note that an AST clause is not created as it instead adds its values
to the OMPDeclareVariantAttr.

Differential Revision: https://reviews.llvm.org/D111854
2021-10-25 09:38:50 -07:00
Valentin Clement 608eb3d9c2
[fir][NFC] Format and make FIROps.td homogenous
This patch has couple of small changes to clean-up FIROps.td.
- Wrap lines that are longer than 80.
- All parser, verifier and printer that are single line are wrapped with double
  quotes.
- Couple of small typos.

Reviewed By: AlexisPerry

Differential Revision: https://reviews.llvm.org/D112436
2021-10-25 18:36:38 +02:00
Valentin Clement 84486cb222
[fir][NFC] Move MLIR includes to FIRDialect.td
The fir_Dialect definition was coming silently through FIRTypes.td.
Make the include of flang/Optimizer/Dialect/FIRDialect.td explicit in
FIROps.td and move MLIR includes to FIRDialect.td.

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

Reviewed By: AlexisPerry

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-25 18:33:46 +02:00
peter klausler fc3f92a8f4 [flang] Fix buildbot (new warnings on old code)
The clang-aarch64-full-2stage buildbot is complaining about a
warning with three instances in f18 code (none modified recently).
The warning is for using the | bitwise OR operator on bool operands.

In one instance, the bitwise operator was being used instead of the
logical || operator in order to avoid short-circuting.  The fix
requires using some temporary variables.  In the other two instances,
the bitwise operator seemed more idiomatic in context, but can be
replaced without harm with the logical operator.

Pushing without review as confidence is high and nobody wants
a buildbot to stay sad for long.
2021-10-22 17:52:32 -07: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 89a927c678 [flang] Fix NAMELIST input bug with multiple subscript triplets
NAMELIST input can contain array subscripts with triplet notation.
The calculation of the default effective stride for the constructed
array descriptor was simply incorrect after the first dimension.

Differential Revision: https://reviews.llvm.org/D112347
2021-10-22 15:59:28 -07:00
peter klausler f6aac0dd4d [flang] Fix DOT_PRODUCT for logical
A build-time check in a template class instantiation was applying
a test that's meaningful only for numeric types.

Differential Revision: https://reviews.llvm.org/D112345
2021-10-22 15:56:20 -07:00
peter klausler fbb020fb48 [flang] Extension: allow tabs in output format strings
A CHARACTER variable used as an output format may contain
unquoted tab characters, which are treated as if they had
been quoted.  This is an extension supported by all other
Fortran compilers to which I have access.

Differential Revision: https://reviews.llvm.org/D112350
2021-10-22 15:53:29 -07:00
peter klausler ce71f8e017 [flang] Fix crash on empty formatted external READs
ExternalFileUnit::BeginReadingRecord() must be called at least once
during an external formatted READ statement before FinishReadingRecord().
In the case of a formatted external READ with no data items, the call
to finish processing of the format (which might have lingering control
items that need doing) was taking place before the call to BeginReadingRecord
from ExternalIoStatementState::EndIoStatement.  Add a call to
BeginReadingRecord on this path.

Differential Revision: https://reviews.llvm.org/D112351
2021-10-22 15:48:45 -07:00
Peter Klausler a5a493e192 [flang] Speed common runtime cases of DOT_PRODUCT & MATMUL
Look for contiguous numeric argument arrays at runtime and
use specialized code for them.

Differential Revision: https://reviews.llvm.org/D112239
2021-10-22 14:36:13 -07:00
peter klausler 14b90d1fe0 [flang] Fix generic resolution case
Don't try to convert INTEGER argument expressions to the kind of
the dummy argument when performing generic resolution; specific
procedures may be distinguished only by their kinds.

Differential Revision: https://reviews.llvm.org/D112240
2021-10-22 13:38:47 -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
peter klausler c4ba1108dd [flang] Extension to distinguish specific procedures
Allocatable dummy arguments can be used to distinguish
two specific procedures in a generic interface when
it is the case that exactly one of them is polymorphic
or exactly one of them is unlimited polymorphic.  The
standard requires that an actual argument corresponding
to an (unlimited) polymorphic allocatable dummy argument
must also be an (unlimited) polymorphic allocatable, so an
actual argument that's acceptable to one procedure must
necessarily be a bad match for the other.

Differential Revision: https://reviews.llvm.org/D112237
2021-10-22 12:38:21 -07:00
peter klausler f2360e1156 [flang] Enforce rest of semantic constraint C919
A reference to an allocatable or pointer component must be applied
to a scalar base object.  (This is the second part of constraint C919;
the first part is already checked.)

Differential Revision: https://reviews.llvm.org/D112241
2021-10-22 11:35:58 -07:00
peter klausler b03628d986 [flang] Emit unformatted headers & footers even with RECL=
The runtime library was emitting unformatted record headers and
footers when an external unit had no fixed RECL=.  This is wrong
for sequential files, which should have headers & footers even
with RECL.  Change to omit headers & footers from unformatted
I/O only for direct access files.

Differential Revision: https://reviews.llvm.org/D112243
2021-10-22 11:07:01 -07:00
peter klausler d5074c7166 [flang] Fix bogus folding error for ISHFT(x, negative)
Negative shift counts are of course valid for ISHFT when
shifting to the right.  This patch decouples the folding of
ISHFT from that of SHIFTA/L/R and adds tests.

Differential Revision: https://reviews.llvm.org/D112244
2021-10-22 10:38:27 -07:00
Andrzej Warzynski 3085e67851 [Flang][docs] Remove an out-dated section on the new driver
This section of the documentation should've been deleted in:
https://reviews.llvm.org/D105811

I am submitting this without a review as it's an obvious omission.
2021-10-22 14:44:24 +00: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
Josh Mottley e9fe8ef4b0 [flang] flang-omp-report replace std::map with llvm::DenseMap
This patch replaces the uses of std::map with llvm::DenseMap in the
flang-omp-report plugin. It also removed the 'constructClauseCount' map
due to no longer being needed after the plugin was stripped down.
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D111977
2021-10-20 07:57:04 +00:00
Josh Mottley 660c511e5b [Flang][flang-omp-report] Switch from std::string to StringRef (where possible)
This patch makes the following changes to flang-omp-report:
 - Update 'normalize_clause_name' parameter to use llvm::StringRef instead of
   std::sting.
 - Change usages of std::tolower to llvm::toLower from
   "ADT/StringExtras.h".
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: Leporacanthicus, clementval

Differential Revision: https://reviews.llvm.org/D111980
2021-10-20 07:55:44 +00: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