Commit Graph

3565 Commits

Author SHA1 Message Date
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