Commit Graph

3703 Commits

Author SHA1 Message Date
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
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
peter klausler 2f80b73e0c [flang] Fold BTEST
Implements constant folding for BTEST intrinsic function.

Differential Revision: https://reviews.llvm.org/D111849
2021-10-18 13:46:46 -07: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
PeixinQiao dd8c8d4b7c This patch supports the following checks for THREADPRIVATE Directive:
```
[5.1] 2.21.2 THREADPRIVATE Directive
A variable that appears in a threadprivate directive must be declared in
the scope of a module or have the SAVE attribute, either explicitly or
implicitly.
A variable that appears in a threadprivate directive must not be an
element of a common block or appear in an EQUIVALENCE statement.
```

This patch supports the following checks for DECLARE TARGET Directive:
```
[5.1] 2.14.7 Declare Target Directive
A variable that is part of another variable (as an array, structure
element or type parameter inquiry) cannot appear in a declare
target directive.
A variable that appears in a declare target directive must be declared
in the scope of a module or have the SAVE attribute, either explicitly
or implicitly.
A variable that appears in a declare target directive must not be an
element of a common block or appear in an EQUIVALENCE statement.
```

As Fortran 2018 standard [8.5.16] states, a variable, common block, or
procedure pointer declared in the scoping unit of a main program,
module, or submodule implicitly has the SAVE attribute, which may be
confirmed by explicit specification.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109864
2021-10-17 22:08:02 +08:00
peter klausler 0fcda9ae57 [flang] Admit NULL() in generic procedure resolution cases
Semantics is rejecting valid programs with NULL() actual arguments
to generic interfaces, including user-defined operators.  Subclause
16.9.144(para 6) makes clear that NULL() can be a valid actual
argument to a generic interface so long as it does not produce
ambiguity.  This patch handles those cases, revises existing
tests, and adjust an error message about NULL() operands to
appear less like a blanket prohibition.

Differential Revision: https://reviews.llvm.org/D111850
2021-10-14 16:02:17 -07:00
peter klausler 6965a776ee [flang] Fold LGE/LGT/LLE/LLT intrinsic functions
Fold the legacy intrinsic functions LGE, LGT, LLE, & LLT
by rewriting them into character relational expressions and
then folding those.  Also fix folding of comparisons of
character values of distinct lengths: the shorter value must
be padded with blanks.  (This fix exposed some bad test cases,
which are also fixed.)

Differential Revision: https://reviews.llvm.org/D111843
2021-10-14 15:24:03 -07:00
peter klausler 1062f989af [flang] Expunge bogus semantic check for ELEMENTAL without dummies
Semantics refuses valid ELEMENTAL subprograms without dummy arguments,
but there's no such constraint in the standard; indeed, subclause
15.8.2 discusses the meaning of calls to ELEMENTAL functions with
arguments.  Remove the check and its test.

Differential Revision: https://reviews.llvm.org/D111832
2021-10-14 14:33:30 -07:00
Mogball cb3aa49ec0 [MLIR][arith] fix references to std.constant in comments
Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D111820
2021-10-14 20:38:47 +00:00
Josh Mottley 0b48b015b5 [Flang] flang-omp-report replace std::vector's with llvm::SmallVector
This patch replaces all uses of std::vector with llvm::SmallVector in the flang-omp-report plugin.
This is a one of several patches focusing on switching containers from STL to LLVM's ADT library.

Reviewed By: Leporacanthicus

Differential Revision: https://reviews.llvm.org/D111709
2021-10-14 11:05:24 +01:00
Valentin Clement 0fbd3aad75
[fir] Remove unused variable in FIRBuilder.h
Remove unsused variable that break Werror on some buildbots
2021-10-14 07:11: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
Mike Rice fb4c451001 [OPENMP51]Initial parsing/sema for adjust_args clause for 'declare variant'
Adds initial parsing and sema for the 'adjust_args' clause.

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

Differential Revision: https://reviews.llvm.org/D99905
2021-10-13 09:34:09 -07:00
Valentin Clement b2169992aa
[fir][NFC] Add disclaimer to affine promotion/demotion passes
AffinePromotion and AffineDemotion passes where upstreamed
in their current status from fir-dev. In order to make sure everybody
is on the same page, this patch add some comments to state that.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111629
2021-10-13 17:47:14 +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
Valentin Clement 665970d421
[fir][NFC] Remove unused variable 2021-10-13 10:40:38 +02:00
Valentin Clement 80bdf9c180
Revert "[fir] Update clang-tidy for the Optimizer directory"
This reverts commit edec659f48.
2021-10-13 09:29:54 +02:00
Mogball a54f4eae0e [MLIR] Replace std ops with arith dialect ops
Precursor: https://reviews.llvm.org/D110200

Removed redundant ops from the standard dialect that were moved to the
`arith` or `math` dialects.

Renamed all instances of operations in the codebase and in tests.

Reviewed By: rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D110797
2021-10-13 03:07:03 +00:00
peter klausler c5a5517be4 [flang] Fixing Windows build (take 3)
Add explicit casts to replace implicit conversions and
recently deleted assignment operators from uint128.h
used in runtime/edit-output.cpp.
2021-10-12 18:59:33 -07:00
peter klausler ecc7f8ab74 [flang] Fix Windows build (take 2)
Remove the offending "operator=()" member functions.  This should
silence the MSVC warnings that persist in uint128.h.
2021-10-12 18:32:16 -07:00
peter klausler bc1a0c2c01 [flang] Fix "latest-clang" build warnings
A recent patch to fix warnings from a Windows build regarding
inconsistent "struct" vs "class" usage missed a few code sites
and now the "latest-clang" build bot is also failing.  This
patch should resolve those failing builds.
2021-10-12 17:42:59 -07:00
peter klausler 02410df530 [flang] Fix Windows build
A recently added class constructor needs to be "explicit" to
prevent it from being available for use as a conversion, which
is breaking the MSVC build of flang.
2021-10-12 17:16:00 -07: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 6ee2aa126c [flang][NFC] Document extension: scalars are trivially contiguous
The Fortran 2018 standard defines the concept of simple contiguity
in subclause 9.5.4 as a characteristic of arrays.  So that scalars
may also be used in contexts where simply contiguous arrays are
allowed, f18 treats them as single-element arrays that are trivially
contiguous.  This patch documents this semantic extension and
also adds comments to the predicate that implements the concept.

Differential Revision: https://reviews.llvm.org/D111679
2021-10-12 16:00:54 -07:00
peter klausler 49142dd4a5 [flang][NFC] Address warnings from Windows build
An LLVM Flang build bot for Windows recently failed with a
bunch of warning messages.  None were from recent changes to
the Fortran compiler; I suspect that a newer (or maybe older)
version of MSVC was being used, or perhaps a different set of
compiler options were temporarily applied to the build, since
the buildbot status went back to green shortly thereafter.

Most of the warnings looked bogus to me, but some are legitimate
concerns and we might as well clean them up.  This patch does so.

Differential Revision: https://reviews.llvm.org/D111677
2021-10-12 16:00:09 -07:00
Jean Perier 68d692375c
[fir] Add cfg conversion pass
This patch upstream the cfg conversion pass. This pass
rewrite FIR loop-like operation to a CFG.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111095
2021-10-12 23:01:54 +02:00
peter klausler f7858e7582 [flang] Fix build on FreeBSD (need size_t)
Add #include <cstddef> to time-intrinsic.h so std::size_t is
guaranteed to be available.
2021-10-12 13:00:00 -07:00
Nimish Mishra fe2d053c45 Added OpenMP 5.0 specification based semantic checks for CRITICAL construct name resolution
As reported in https://bugs.llvm.org/show_bug.cgi?id=48145, name resolution for omp critical construct was failing. This patch adds functionality to help that name resolution as well as implementation to catch name mismatches.

The following semantic restrictions are therefore handled here:

- If a name is specified on a critical directive, the same name must also be specified on the end critical directive

- If no name appears on the critical directive, no name can appear on the end critical directive

- If a name appears on either the start critical directive or the end critical directive

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110502
2021-10-12 22:18:24 +05:30
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
Nimish Mishra d4717b9b9d [flang][OpenMP] Added test case for OpenMP 5.0 specification based semantic checks for parallel sections construct
Parallel sections directive borrows the semantic checks from both sections directive and parallel directive. Semantic checks for both are merged in main branch; this test case is added to make sure correct semantic checks upon merging the two.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D111438
2021-10-12 15:12:24 +05:30
Diana Picus 02602c02a3 [flang] Add runtime interface for GET_ENVIRONMENT_VARIABLE
Split into 2 entry points, one for the length and one for the value.

Differential Revision: https://reviews.llvm.org/D111392
2021-10-12 08:11:47 +00: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
peter klausler ef44cad53d [flang][NFC] Document behavior for nonspecified/ambiguous cases
Add explicit documentation for a couple of cases where the Fortran
standard has been observed to be ambiguous or nonspecific and we've
had to choose the behavior of the implementation from some possible
alternatives (and may be distinct from other implementations).

Differential Revision: https://reviews.llvm.org/D111446
2021-10-11 11:06:07 -07:00
Eric Schweitz c3abfe4207
[fir] Add fir.convert canonicalization patterns
Add rewrite patterns for fir.convert op canonicalization.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-11 16:27:48 +02:00
Eric Schweitz 31a2ccc0b5
[fir] Clean up InitFIR.h
Clean up InitFIR.h file.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-11 15:41:50 +02:00
Eric Schweitz edec659f48
[fir] Update clang-tidy for the Optimizer directory
Update .clang-tidy file with the value used in fir-dev.

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

Reviewed By: rovka

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-11 14:06:39 +02:00
Andrzej Warzynski 6f8ef1d6e8 [flang][driver] Add actions that execute despite semantic errors
This patch adds a new abstract class for frontend actions:
`PrescanAndSemaDebugAction`. It's almost identical to
`PrescanAndSemaAction`, but in the presence of semantic errors it does
not skip the corresponding `ExecuteAction` specialisation. Instead, it
runs it as if there were no semantic errors. This class is for developer
actions only (i.e.  front-end driver options).

The new behaviour does not affect the return code from `flang-new -fc1`
when the input file is semantically incorrect. The return code is
inferred from the number of driver diagnostics generated in
`CompilerInstance::ExecuteAction` and this patch does not change that.
More specifically, the semantic errors are still reported and hence the
driver is able to correctly report that the compilation has failed (with
a non-zero return code).

This new base class is meant for debug actions only and
`DebugDumpAllAction` is updated to demonstrate the new behaviour. With
this change, `flang-new -fc1 -fdebug-dump-all` dumps the parse tree and
symbols for all input files, regardless of whether any semantic errors
were found.

This patch addresses https://bugs.llvm.org/show_bug.cgi?id=52097.

Differential Revision: https://reviews.llvm.org/D111308
2021-10-11 11:52:05 +00:00
Valentin Clement b0eef1eef0
[fir] Add the abstract result conversion pass
Add pass that convert abstract result to function argument.
This pass is needed before the conversion to LLVM IR.

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

Reviewed By: schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-10-11 10:10:41 +02:00
Jean Perier 6eb7634f30
[fir] Add character conversion pass
Upstream the character conversion pass.
Translates entities of one CHARACTER KIND to another.
By default the translation is to naively zero-extend or truncate a code
point to fit the destination size.

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111405
2021-10-10 20:20:09 +02:00
Peter Steinfeld 0620b12209 [flang] Fix capitalization of "ishft"
We weren't recognizing the ISHFT intrinsic because the code had
incorrectly capitalized it.

Differential Revision: https://reviews.llvm.org/D111449
2021-10-08 13:44:23 -07:00
Andrzej Warzynski b41e86642e [flang][driver] Fix erroneous `&`
As pointed out by Valentin Clement in PR [1], we should be using `&&`
instead of `&`.

[1] https://github.com/flang-compiler/f18-llvm-project/pull/1113#discussion_r724321121

Differential Revision: https://reviews.llvm.org/D111395
2021-10-08 14:44:44 +00:00
Rajan Walia 80c27abb2f
[fir] Add affine demotion pass
Add affine demotion pass.
Affine dialect's default lowering for loads and stores is different from
fir as it uses the `memref` type. The `memref` type is not compatible with
the Fortran runtime. Therefore, conversion of memory operations back to
`fir.load` and `fir.store` with `!fir.ref<?>` types is required.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Rajan Walia <walrajan@gmail.com>
Co-authored-by: Sourabh Singh Tomar <SourabhSingh.Tomar@amd.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111257
2021-10-08 14:03:27 +02:00
Jean Perier d70938bbad
[fir] Add affine promotion pass
Convert fir operations which satisfy affine constraints to the affine
dialect.

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

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
Co-authored-by: Rajan Walia <walrajan@gmail.com>
Co-authored-by: Sourabh Singh Tomar <SourabhSingh.Tomar@amd.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: schweitz, awarzynski

Differential Revision: https://reviews.llvm.org/D111155
2021-10-08 11:47:23 +02:00
peter klausler f4a5fb0c55 [flang] Error checking for IBCLR/IBSET and ISHFT/SHIFT[ALR]
Bit positions for the intrinsics IBCLR and IBSET and shift counts
for the intrinsics ISHFT/SHIFTA/SHIFTL/SHIFTR should be validated
when folding.

Differential Revision: https://reviews.llvm.org/D111327
2021-10-07 13:51:20 -07:00
peter klausler 094b380c21 [flang] Catch mismatched parentheses in prescanner
Source lines with mismatched parentheses are hard cases for error
recovery in parsing, and the best error message (viz.,
"here's an unmatched parenthesis") can be emitted from the
prescanner.

Differential Revision: https://reviews.llvm.org/D111254#3046173
2021-10-06 14:00:15 -07:00
peter klausler f5ab4bfb5b [flang] Define IEEE_SCALB, IEEE_NEXT_AFTER, IEEE_NEXT_DOWN, IEEE_NEXT_UP
These functions were missing from the standard intrinsic module
IEEE_ARITHMETIC.  IEEE_SCALB is an alias for the standard intrinsic
function SCALE(), and the others are defined as new builtin intrinsic
functions.

Differential Revision: https://reviews.llvm.org/D111253
2021-10-06 12:10:14 -07: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
peter klausler cc1d13f997 [flang] Fold MAXLOC and MINLOC
Generalize the code that folds FINDLOC to also handle
folding for MAXLOC and MINLOC.

Differential Revision: https://reviews.llvm.org/D110951
2021-10-05 11:22:02 -07: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
peter klausler f63dafebf4 [flang] runtime: fix formatted real input regression w/ spaces
Blank input fields must be interpreted as zero, including the case of
virutal space characters generated from record padding at the end of
an input record.  This stopped working sometime in the past few months
for real input (not sure when); here's a fix.

This bug was breaking FCVS test fm111.

Differential Revision: https://reviews.llvm.org/D110765
2021-10-04 16:46:42 -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 dc4d94e620
[fir] add fir.array_modify op
fir.array_update is only handling intrinsic assignments.
They are two big differences with user defined assignments:
1. The LHS and RHS types may not match, this does not play well
   with fir.array_update that relies on both the merge and the
   updated element to have the same type.
2. user defined assignment has a call semantics, with potential
   side effects. So if a fir.array_update can hide a call, it traits
   would need to be updated.

Instead of hiding more semantic in the fir.array_update, introduce
a new fir.array_modify op that allows de-correlating indicating that
an array value element is modified, and how it is modified.
This allow the ArrayValueCopy pass to still perform copy elision
while not having to implement the call itself, and could in general
be used for all kind of assignments (e.g. character assignment).

Update the alias analysis to not rely on the merge arguments (since
fir.array_modify has none).
Instead, analyze what is done with the element address.
This implies adding the ability to follow the users of fir.array_modify,
as well as being able to go through fir.store that may be generated to
store the RHS value in order to pass it to a user define routine.
This is done by adding a ReachCollector class to gather all array
accesses.

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

Reviewed By: schweitz

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-04 21:00:43 +02:00
Valentin Clement 1e96c4b508
[fir][NFC] Fix couple of clang-tidy warnings
Fix some clang-tidy wrning in flang/Optimizer/Support and
remove explicit number of inlined elements for SmallVector. This
is mostly to sync with the changes from fir-dev.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D111044
2021-10-04 20:55:06 +02:00
peter klausler 0061e681a3 [flang] Better error recovery for missing THEN in ELSE IF
The THEN keyword in the "ELSE IF (test) THEN" statement is useless
syntactically, and to omit it is a common error (at least for me!)
that has poor error recovery.  This patch changes the parser to
cough up a simple "expected 'THEN'" and still recognize the rest of
the IF construct.

Differential Revision: https://reviews.llvm.org/D110952
2021-10-04 09:37:53 -07:00
peter klausler 33c5264160 [flang][NFC] Fix first line of magic-numbers.h
The first line of flang/include/flang/Runtime/magic-numbers.h
got split into two somehow; join it back up.

Differential Revision: https://reviews.llvm.org/D110965
2021-10-04 09:36:48 -07:00
Nimish Mishra 063c5bc31b [flang][OpenMP] Added OpenMP 5.0 specification based semantic checks for sections construct and test case for simd construct
According to OpenMP 5.0 spec document, the following semantic restrictions have been dealt with in this patch.

1. [sections construct] Orphaned section directives are prohibited. That is, the section directives must appear within the sections construct and must not be encountered elsewhere in the sections region.

 Semantic checks for the following are not necessary, since use of orphaned section construct (i.e. without an enclosing sections directive) throws parser errors and control flow never reaches the semantic checking phase. Added a test case for the same.

2. [sections construct] Must be a structured block

Added test case and made changes to branching logic

3. [simd construct] Must be a structured block / A program that branches in or out of a function with declare simd is non conforming

4. Fixed !$omp do's handling of unlabeled CYCLEs

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D108904
2021-10-02 08:40:53 +05:30
Valentin Clement 3da95b68cd
[fir][NFC] Move fir.global printer to cpp file
All big enough parser, printer and verifier are moved to the cpp file.
This is one of the last one to be moved.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110929
2021-10-01 21:14:41 +02:00
Eric Schweitz 2372249d86
[fir] Remove obsolete fir.negf and fir.modf ops
fir.negf op is replaced by mlir.negf and
fir.modf is just deleted.

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-01 16:11:36 +02:00
Valentin Clement 067312d283
[fir][NFC] Remove explicit num of inlined element for SmallVectors
Remove explicit number of inlined elements for SmallVector.

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

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

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D110912
2021-10-01 14:41:50 +02:00
Eric Schweitz 15ea26de24
[fir] Add fir.char_convert op
Add the fir-char_convert op.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-10-01 14:40:11 +02:00
David Spickett 3780de4600 [flang][driver] Error if uuidgen is not installed
Ubuntu Bionic installs it by default, Focal does not.

Differential Revision: https://reviews.llvm.org/D110694
2021-10-01 09:42:58 +01:00
Valentin Clement a149b103ca
[fir][NFC] Move fir.select_type builder to cpp file
Move the big builder out of the td file to the cpp file.

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

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110820
2021-10-01 09:19:39 +02:00
Valentin Clement b04dd35f0e
[fir][NFC] Update doc for pinned attr in fir.alloca
Add descritpion for the attribute added in D110815.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110877
2021-10-01 09:18:09 +02:00
Jean Perier 7a6ab39e71 [flang] Revert 3 commits pushed by mistake along b7c07ce15f
Revert "[flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol"
This reverts commit b0e35fde21.

Revert "[flang] Add a wrapper for Fortran main program"
This reverts commit 2c1ce0755e.

Revert "[flang][NFC] Fix header comments in some runtime headers"
This reverts commit a63f57674d.
2021-10-01 09:01:31 +02: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
Jean Perier b0e35fde21 [flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol
Helps debugging when working with symbol/expression issue. The dump
method is easy to call in the debugger.
2021-10-01 08:45:20 +02:00
Jean Perier 2c1ce0755e [flang] Add a wrapper for Fortran main program
Add a C wrapper that calls the Fortran runtime initialization and
finalization routines as well as the compiled Fortran main program
_QQmain.

Place it in its own library to satisfy shared library builds since it
contains a C main function.

- cc7ac498f9 (diff-fa35a5efa62731fd2845e5e982eca9a2e36439783e11a4e4a463753c2160ec10R53)
- was created in flang/test/Examples/main.c in Eric's branch
2021-10-01 08:45:20 +02:00
Jean Perier a63f57674d [flang][NFC] Fix header comments in some runtime headers 2021-10-01 08:45:20 +02:00
Jean Perier fdcbb540fc [flang][NFC] Add debug dump method to evaluate::Expr and semantics::Symbol
Helps debugging when working with symbol/expression issue. The dump
method is easy to call in the debugger.

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

Differential Revision: https://reviews.llvm.org/D110856
2021-09-30 23:26:46 +02:00
Jean Perier 962e503cc8 [flang] Take into account SubprogramDetails in GetInterfaceSymbol
When the ProcRef is Symbol is a SubprogramDetails, the interface is
the SubprogramDetails. Do not return nullptr.

Differential Revision: https://reviews.llvm.org/D110853
2021-09-30 23:06:32 +02:00
Jean Perier cf1f5fbdfc [flang][NFC] Fix header comments in some runtime headers
Differential Revision: https://reviews.llvm.org/D110850
2021-09-30 23:04:23 +02:00
Peter Klausler 8256867508 [flang] Fold FINDLOC()
Fold the transformational intrinsic function FINDLOC() for
all combinations of optional arguments and data types.

Differential Revision: https://reviews.llvm.org/D110757
2021-09-30 12:08:10 -07:00
peter klausler 691814f9cc [flang] Fix test regression from SQRT folding
The algorithm used to fold SQRT has some holes that
led to test failures; debug and add more tests.

Differential Revision: https://reviews.llvm.org/D110744
2021-09-30 11:35:44 -07: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
Eric Schweitz 7362cc5ef5
[fir][NFC] Rename lenParams to typeparams in builders
Fine tuning after couple of upstreamed patches.
Rename the lenParams varaiables in buidlers to typeparams.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 17:56:32 +02:00
Kiran Chandramohan 4cab4f6b1c
[fir] Update fir.alloca op
Add pinned attributes and speicifc builders.

The pinned attribute helps mark those allocas in OpenMP regions that should not
be hoisted out by an alloca hoisting pass.

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

Coming from PR: https://github.com/flang-compiler/f18-llvm-project/pull/1065

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 17:02:32 +02:00
Valentin Clement 0781461959
[fir][NFC] Removed unused declaration from td file
Remove unused code from FIROps.td file after latest
patches.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110814
2021-09-30 16:46:13 +02:00
Valentin Clement a6fc555202
[fir][NFC] Move parser/printer for fir.global_len
Move parser and printer to the .cpp file.

Follow up to https://reviews.llvm.org/D110626.

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

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D110828
2021-09-30 16:27:30 +02:00
Valentin Clement afb30fcdf6
[fir][NFC] Move fir.shape verifier to cpp file
Move verifier code to the .cpp file.

Follow up to https://reviews.llvm.org/D110626.

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

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D110826
2021-09-30 16:26:44 +02:00
Valentin Clement ccc0f62d1b
[fir][NFC] Update and move fir.freemem and fir.store
Move fir.freemem and fir.store to the Memory SSA operations sections.
Move parser, printer and verifier of fir.store to the .cpp file.

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

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

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D110816
2021-09-30 16:25:50 +02:00
Valentin Clement 220f314f94
[fir] Update fir.field_index op
Move the parser, printer, verifier and builder out of the .td file.
Rename lenparams to typeparams to be in sync with fir-dev.

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

Reviewed By: rovka

Differential Revision: https://reviews.llvm.org/D110690
2021-09-30 12:51:57 +02:00
Valentin Clement 633f70f76e
[fir][NFC] Move parser/printer/builder to cpp file
Move the parsers, printers and builders from the TableGen file
to the .cpp file. Remaining parsers, printers and builders will be
moved when we update the operations.

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

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D110626
2021-09-30 11:18:23 +02:00
Eric Schweitz 8014b28dcf
[fir] Update fir.alloca op
Update the fir.alloca operation.

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

Reviewed By: mehdi_amini

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 11:05:13 +02:00
Valentin Clement 1f69dc0845
[fir] Update fir.allocmem op
Updatet the fir.allocmem operation.

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

Reviewed By: schweitz

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-09-30 10:58:35 +02:00
Eric Schweitz c8f03a7fe8
[fir] Update fir.extract_value and fir.insert_value ops
Move coor operand from variadic values to ArrayAttr.
Update assembly format.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 10:23:51 +02:00
Eric Schweitz 34d6c1822e
[fir] Update fir.array_update, fir.array_fetch and fir.array_merge_store
Add typeparams to fir.array_update, fir.array_fetch and
fir.array_merge_store operations. Add optional slice operands to
fir.array_merge_store op.
Move verifiers to cpp file.

Reviewed By: kiranchandramohan

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-30 09:56:50 +02:00
Andrzej Warzynski 3ccb473df3 [flang][docs] Remove the new driver sync-up calls 2021-09-30 07:52:27 +00:00
Chris Lattner fb093c8314 [ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser.
The former is redundant because the later carries it as part of
its builder.  Add a getContext() helper method to DialectAsmParser
to make this more convenient, and stop passing the context around
explicitly.  This simplifies ODS generated parser hooks for attrs
and types.

This resolves PR51985

Recommit 4b32f8bac4 after fixing a dependency.

Differential Revision: https://reviews.llvm.org/D110796
2021-09-30 05:10:28 +00:00
Mehdi Amini 3310e0020c Revert "[ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser."
This reverts commit 4b32f8bac4.

Seems like the build is broken with -DDBUILD_SHARED_LIBS=ON
2021-09-30 05:01:17 +00:00
Chris Lattner 4b32f8bac4 [ODS/AsmParser] Don't pass MLIRContext with DialectAsmParser.
The former is redundant because the later carries it as part of
its builder.  Add a getContext() helper method to DialectAsmParser
to make this more convenient, and stop passing the context around
explicitly.  This simplifies ODS generated parser hooks for attrs
and types.

This resolves PR51985

Differential Revision: https://reviews.llvm.org/D110796
2021-09-29 21:36:05 -07:00
peter klausler 52711fb8da [flang] Make builtin types more easily accessible; use them
Rearrange the contents of __builtin_* module files a little and
make sure that semantics implicitly USEs the module __Fortran_builtins
before processing each source file.  This ensures that the special derived
types for TEAM_TYPE, EVENT_TYPE, LOCK_TYPE, &c. exist in the symbol table
where they will be available for use in coarray intrinsic function
processing.

Update IsTeamType() to exploit access to the __Fortran_builtins
module rather than applying ad hoc name tests.  Move it and some
other utilities from Semantics/tools.* to Evaluate/tools.* to make
them available to intrinsics processing.

Add/correct the intrinsic table definitions for GET_TEAM, TEAM_NUMBER,
and THIS_IMAGE to exercise the built-in TEAM_TYPE as an argument and
as a result.

Add/correct/extend tests accordingly.

Differential Revision: https://reviews.llvm.org/D110356
2021-09-29 13:06:01 -07:00
Eric Schweitz a28896ae6a
[fir] Move parser/printer/verifier of fir.string_lit and add builders
Move the parser, printer and verifier to the .cpp file. Add builders
needed for lowering.

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

Reviewed By: schweitz, mehdi_amini

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-29 21:45:17 +02:00
Eric Schweitz 576301d922
[fir] Update fir.call op
Move builders to .cpp file and update accordingly.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-29 18:32:29 +02:00
Eric Schweitz 6e2afdb7f5
[fir][NFC] Update fir.iterate_while op
Add getFinalValueAttrName() and remove specified number of
inlined elements for SmallVector. This patch is mainly motivated
to help the upstreaming effort.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110710
2021-09-29 18:13:43 +02:00
Andrzej Warzynski 5c52753d9f [Flang] Fix failing plugin tests
The updated tests were originally added in
https://reviews.llvm.org/D109890 and are currently causing some
buildbots to fail.

This patch:
* adds missing items in the `REQUIRERS` list in tests
* adds `flangOmpReport` (the plugin library added in D109890) as a CMake
  dependency for tests (only when examples are enabled)

Differential Revision: https://reviews.llvm.org/D110682
2021-09-29 09:27:11 +00:00
Eric Schweitz 60527cee95
[fir][NFC] Rename operand of ArrayCoorOp
Rename `lenParams` to `typeparams` to be in sync with fir-dev.

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D110645
2021-09-29 10:31:38 +02:00
Stuart Ellis 38c42d42eb Flang OpenMP Report Plugin
This plugin parses Fortran files and creates a
YAML report with all the OpenMP constructs and
clauses seen in the file.

The following tests have been modified to be
compatible for testing the plugin, hence why
they are not reused from another directory:

- omp-atomic.f90
- omp-declarative-directive.f90
- omp-device-constructs.f90

The plugin outputs a single file in the same
directory as the source file in the following format:
`<source-file-name>.yaml`

Building the plugin:
`ninja flangOmpReport`

Running the plugin:
`./bin/flang-new -fc1 -load lib/flangOmpReport.so -plugin flang-omp-report -fopenmp <source_file.f90>`

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Stuart Ellis <stuart.ellis@arm.com>

Reviewed By: awarzynski, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109890
2021-09-28 22:57:17 +01:00
Valentin Clement b38c04ab7f
[fir][NFC] Rename operand of EmboxOp
Rename `lenParams` to `typeparams` to be in sync with fir-dev.

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

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-09-28 17:00:55 +02: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
Eric Schweitz 5b5ef2e265
[fir] Add fir.save_result op
Add the fir.save_result operation. It is use to save an
array, box, or record function result SSA-value to a memory location

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-28 11:58:42 +02:00
V Donaldson bd2623b9c2
[fir] Update fir.insert_on_range op
Update the fir.insert_on_range operation. Add a better description,
builder and verifier.

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

Reviewed By: jeanPerier

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-09-28 11:03:28 +02: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
peter klausler 9eab0da183 [flang] Catch branching into FORALL/WHERE constructs
Enforce constraints C1034 & C1038, which disallow the use
of otherwise valid statements as branch targets when they
appear in FORALL &/or WHERE constructs.  (And make the
diagnostic message somewhat more user-friendly.)

Differential Revision: https://reviews.llvm.org/D109936
2021-09-27 10:51:44 -07:00
peter klausler 1c2e5fd66e [flang] Enforce constraint: defined ass't in WHERE must be elemental
A defined assignment subroutine invoked in the context of a WHERE
statement or construct must necessarily be elemental (C1032).

Differential Revision: https://reviews.llvm.org/D109932
2021-09-27 10:12:53 -07:00
Valentin Clement 2c28e3f008
[fir] Add desc to fir.array_load op and update operand name
This patch is part of the upstreaming effort from fir-dev branch.

Add a description for the fir.array_load opeartion and rename lenParams to typeparams.

Reviewed By: kiranchandramohan

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2021-09-25 14:10:35 +02: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