Commit Graph

4778 Commits

Author SHA1 Message Date
Valentin Clement f372142740
[flang] Add dump-symbols option to bbc
Restore the `--dump-symbols` option in the `bbc`
tool.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D129850
2022-07-18 13:40:25 +02:00
Valentin Clement 048aaab194
[flang][openacc] Use TableGen to generate the clause parser
This patch introduce an automatic generation of the clause parser from the TableGen
information.

New information can be stored directly in the TableGen file:
- The different aliases that a clause support.
- prefix before a value.
- whether a prefix is optional or not.

Makes it easier to add new clauses and also avoid some error (`write` clause incorrect until now).

This patch is updating only the OpenACC part. A patch with a modification of the OpenMP clause parser will follow.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106968
2022-07-18 09:26:57 +02:00
Kazu Hirata 8b3ed1fa98 Remove redundant return statements (NFC)
Identified with readability-redundant-control-flow.
2022-07-17 15:37:46 -07:00
Kazu Hirata c715e2ff92 [flang] Use value_or (NFC) 2022-07-16 00:51:54 -07:00
Kazu Hirata 009ab1728d [flang] Use *X instead of X.getValue() (NFC)
Per Flang C++ Style Guide, this patch replaces X.getValue() with *X
where *X is protected by a presence test.
2022-07-16 00:24:02 -07:00
Nimish Mishra 58753dea15 [flang][OpenMP] Fix warning due to uninitialized pointer dereference during atomic update lowering
Reviewed By: kiranchandramohan, kazu

Differential Revision: https://reviews.llvm.org/D129914
2022-07-16 12:23:37 +05:30
Naje George 42129b66d7 [flang] Add semantics test for EVENT POST statement
Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D129515
2022-07-15 16:03:29 -07:00
Jonathon Penix a560eea8bb [Flang] Set constructExit for Where and Forall constructs
Evaluations for the Where and Forall constructs previously did
not have their constructExit field fixed up. This could lead to
falling through to subsequent case blocks in select case
statements if either a Where or Forall construct was the final part
of one case block. Setting the constructExit field results in the
proper branching behavior.

Fixes issue: https://github.com/llvm/llvm-project/issues/56500

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

Change-Id: Ia868df12084520a935f087524e118bcdf47f6d7a
2022-07-15 12:34:28 -07:00
Katherine Rasmussen ebf3dbbe15 Revert "[flang] Add co_sum to the list of intrinsics and update test"
This reverts commit d2460d9008.

Reverting this commit because after pushing to main it caused
unexpected test failures.
2022-07-14 14:44:34 -07:00
Katherine Rasmussen d2460d9008 [flang] Add co_sum to the list of intrinsics and update test
Add the collective subroutine, co_sum, to the list of intrinsics.
In accordance with 16.9.50 and 16.9.137, add a check for and an
error if coindexed objects are being passed to certain arguments
in co_sum and in move_alloc. Add a semantics test to check that
this error is successfully caught in calls to move_alloc. Remove
the XFAIL directive, update the ERROR directives and add both
standard-conforming and non-standard conforming calls to the
semantics test for co_sum.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D114134
2022-07-14 13:49:38 -07:00
Nimish Mishra 7dc18a62e4 [flang][OpenMP] Added semantic checks for hint clause
This patch improves semantic checks for hint clause.
It checks "hint-expression is a constant expression
that evaluates to a scalar value with kind
`omp_sync_hint_kind` and a value that is a valid
synchronization hint."

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D127615
2022-07-14 18:24:57 +05:30
Nimish Mishra a56b76d9ca [flang][OpenMP] Lowering support for atomic update construct
This patch adds lowering support for atomic update construct. A region
is associated with every `omp.atomic.update` operation wherein resides:
(1) the evaluation of the expression on the RHS of the atomic assignment
statement, and (2) a `omp.yield` operation that yields the extended value
of expression evaluated in (1).

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D125668
2022-07-14 18:22:12 +05:30
Peter Klausler b7f8314270 [flang] Avoid crash from forward referenced derived type
Fortran permits forward references to derived types in contexts that don't
require knowledge of the derived type definition for semantic analysis,
such as in the declaration of a pointer or allocatable variable or component.
But when the forward-referenced derived type is used later for a component
reference, it is possible for the DerivedTypeSpec in he base variable or component
declaration to still have a null scope pointer even if the type has been defined,
since DerivedTypeSpec and TypeSpec objects are created in scopes of use
rather than in scopes of definition.  The fix is to call
DerivedTypeSpec::Instantiate() in the name resolution of each component
name so that the scope gets filled in if it is still null.

Differential Revision: https://reviews.llvm.org/D129681
2022-07-13 16:58:26 -07:00
Peter Klausler be68a6adfb [flang] Error detection/avoidance for TRANSFER with empty MOLD= type
When MOLD= is an array and there is no SIZE= in a call to TRANSFER(),
the size of an element of the MOLD= is used as the denominator in a
division to establish the extent of the vector result.  When the
total storage size of the SOURCE= is known to be zero, the result is
empty and no division is needed.

To avoid a division by zero at runtime, we need to check for a zero-sized
MOLD= element type when the storage size of SOURCE= is nonzero and there
is no SIZE=.  Further, in the compilation-time rewriting of calls to
SHAPE(TRANSFER(...)) and SIZE(TRANSFER(...)) for constant folding and
simplification purposes, we can't replace the call with an arithmetic
element count expression when the storage size of SOURCE= is not known
to be zero and the element size of MOLD= is not known to be nonzero at
compilation time.

These changes mostly affect tests using a MOLD= argument that is an
assumed-length character.

Differential Revision: https://reviews.llvm.org/D129680
2022-07-13 16:50:57 -07:00
Peter Klausler cb193931fa [flang][runtime] Complete list-directed character input with DECIMAL='COMMA'
Most of the infrastructure for DECIMAL='COMMA' mode was in place
in the I/O runtime support library, but I dropped the ball for
list-directed character input, which has its own detection of
input separators.  Finish the job.

Differential Revision: https://reviews.llvm.org/D129679
2022-07-13 16:37:44 -07:00
Peter Klausler 0406c0cda6 [flang] Ensure name resolution visits "=>NULL()" in entity-decl
Most modern Fortran programs declare procedure pointers with a
procedure-declaration-stmt, but it's also possible to declare one
with a type-declaration-stmt with a POINTER attribute.  In this
case, e.g. "real, external, pointer :: p => null()" the initializer
is required to be a null-init.  The parse tree traversal in name
resolution would visit the null-init if the symbol were an object
pointer only, leading to a crash in the case of a procedure pointer.

That explanation of the bug is longer than the fix.  In short,
ensure that a null-init in an entity-decl is visited for both
species of pointers.

Differential Revision: https://reviews.llvm.org/D129676
2022-07-13 16:36:25 -07:00
Peter Klausler 1a65d09dcf [flang][runtime] Keep frame buffer in sync with file when truncating
When the I/O runtime is truncating an external file due to an
implied ENDFILE or explicit ENDFILE, ensure that the unit's frame
buffer for the file discards any data that have become obsolete.

This bug caused trouble with ACCESS='STREAM' I/O using POS= on
a WRITE, but it may have not been limited to that scenario.

Differential Revision: https://reviews.llvm.org/D129673
2022-07-13 16:12:12 -07:00
Peter Klausler faffcc3a46 [flang][runtime] Refine list-directed REAL(2) output
The rule used by list-directed REAL output editing to select
between Ew.d and Fw.d output editing breaks down for 16-bit
floating-point data, since the number of significant decimal
digits is so low that Ew,d output editing is nearly always selected.
Cap the test so that five-digit values will be output with Fw.d
editing.

Differential Revision: https://reviews.llvm.org/D129672
2022-07-13 16:10:46 -07:00
Peter Klausler ae93d8ea42 [flang] Fold TRANSFER()
Fold usage of the raw data reinterpretation intrinsic function TRANSFER().

Differential Revision: https://reviews.llvm.org/D129671
2022-07-13 15:34:48 -07:00
Peter Klausler 62d874f203 [flang] Refine semantic checks for procedure pointer assignment
Some procedure pointers and EXTERNAL procedures have neither
explicit interfaces nor result types; these procedures are obviously
not known to be functions, but they could be, so semantics must not
assume that they are necessarily subroutines.  Refine the procedure
pointer / dummy procedure compatibility check to handle these more
ambiguous cases and not elicit inappropriate error messages.

Differential Revision: https://reviews.llvm.org/D129674
2022-07-13 14:56:50 -07:00
Steve Scalpone 9d24eba04d [flang] Document the Intrinsic Types
Describe the built-in integer, real, complex and logical
types implemented in flang, capturing the as-implemented
characteristics.

Differential Revision: https://reviews.llvm.org/D129658
2022-07-13 11:21:01 -07:00
V Donaldson aba0d3cd94 [flang] Intrinsic module file update
Use symbolic iostat values in iso_fortran_env.f90.
Add generic names to the interfaces in __fortran_ieee_exceptions.f90.
2022-07-13 10:27:03 -07:00
Dylan Fleming d5fa11c4aa [Flang] Fix path strings in CreateFIRLangRef.py
In D129186, CreateFIRLangRef.py was created to help fix
formatting problems with FIRLangRef.md.

However, due to an error while rebasing, the last edit was lost,
as such the current path variables are Unix-style.

This patch addresses what was discussed in the previous patch and
now uses os.path.join instead.

Differential Revision: https://reviews.llvm.org/D129644
2022-07-13 15:29:14 +00:00
Slava Zakharin a280043b52 [flang] Lower TRANSPOSE without using runtime.
Calling runtime TRANSPOSE requires a temporary array for the result,
and, sometimes, a temporary array for the argument. Lowering it inline
should provide faster code.

I added -opt-transpose control just for debugging purposes temporary.
I am going to make driver changes that will disable inline lowering
for -O0. For the time being I would like to enable it by default
to expose the code to more tests.

Differential Revision: https://reviews.llvm.org/D129497
2022-07-12 08:33:39 -07:00
Peixin Qiao 13019955bf [NFC][flang][OpenMP] Add comment for handling the data race problem in copyin clause
The reference and description is missed before.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D129437
2022-07-12 19:54:24 +08:00
Jean Perier af40f99e2b [flang] Merge GEPs in substring fir.embox codegen
When computing the base addresses of an array slice to make a
descriptor, codegen generated two LLVM GEPs. The first to compute
the address of the base character element, and a second one to
compute the substring base inside that element.
The previous code did not care about getting the result of the first
GEP right: it used the base array LLVM type as the result type.
This used to work when opaque pointer were not enabled (the actual GEP
result type was probably applied in some later pass). But with opaque
pointers, the second GEP ends-up computing an offset of len*<LLVM array
type> instead of len*<character width>. A previous attempt to fix the
issue was done in D129079, but it does not cover the cases where the
array slice contains subcomponents before the substring
(e.g: array(:)%char_field(5:10)).

This patch fix the issue by computing the actual GEP result type in
codegen. There is also enough knowledge now so that a single GEP can be
generated instead of two.

Differential Revision: https://reviews.llvm.org/D129481
2022-07-12 09:27:51 +02:00
Jean Perier 906784a399 [flang] move getKindMapping() calls out of FIROpBuilder ctor calls
FirOpBuilder takes a fir::KindMapping reference. When the getKindMapping()
call is made inside the ctor call, the lifetime of this reference may
be as short as the ctor call (at least with when building flang in
release mode with clang 8). This can cause segfaults when later using
the FirOpBuilder.

Ensure the kindMap passed to the FirOpBuilder ctor is the same as the
FirOpBuilder.

Differential Revision: https://reviews.llvm.org/D129494
2022-07-12 09:22:59 +02:00
Kazu Hirata c82fb16f58 [flang] Use has_value instead of hasValue (NFC)
This patch replaces hasValue with has_value in an effort to deprecate
Optional<X>::hasValue.

Differential Revision: https://reviews.llvm.org/D129458
2022-07-11 20:41:12 -07:00
Dylan Fleming e7f05f2ad3 [Flang] Fix formatting for FIRLangRef.html
Previously, FIRLangRef.md was incorrectly formatted.
This was due to how FIRLangRef.md had no page header,
and so the first entry would render incorrectly.

This patch introduces a header file, which is prepended to the FIRLangRef
 before it becomes a HTML file. The header is currently brief
but can be expanded upon at a later date if required.

This formatting fix also means the index page
can correctly generate a link to FIRLangRef.html and as such,
this patch also removes FIRLangRef from the sidebar and adds it to the main list of links.

Depends on D128650

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D129186
2022-07-11 18:46:52 +00:00
Dylan Fleming b9f8a1ea84 [Flang] Add a link from the docs html page to the FIR html page
The Fortran Language Reference is currently generated via tablegen,
however isn't present on flang.llvm.org/docs/

This patch adds FIRLangRef.md to the flang/docs directoy,
and adds a link to the generated HTML file in sidebar
under the 'Documentation' heading.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D128650
2022-07-11 17:59:11 +00:00
Katherine Rasmussen 9bb18a983f [flang] Add semantics test for image_status and add a check
Add a semantics test for the intrinsic function image_status. Add
a check and restriction on the image argument in image_status,
ensuring that it is a positive value. Add same check on the
size argument of the intrinsic ishftc. Add another check on
the shift argument of ishftc, ensuring that it is less than or
equal to the size argument. Add a short semantics test checking
these restrictions in ishftc function calls.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D128009
2022-07-11 10:54:12 -07:00
Nimish Mishra 5cbe39ef88 [flang][OpenMP] Allow default(none) to access variables with PARAMETER attribute
This patch fixes https://github.com/flang-compiler/f18-llvm-project/issues/1351.
Concretely, data-sharing attributes on PARAMETER data used in a block
with DEFAULT(NONE) should be ignored.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D129444
2022-07-12 00:33:14 +05:30
Arnamoy Bhattacharyya d507e8b70e [flang][OpenMP] Fix firstprivate bug
In case where the bound(s) of a workshare loop use(s) firstprivate var(s), currently, that use is not updated with the created clone.  It still uses the shared variable.  This patch fixes that.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D127137
2022-07-11 09:01:15 -04:00
Kazu Hirata 86b8c1d9c4 [flang] Don't use Optional::hasValue (NFC)
Flang C++ Style Guide tells us to avoid .has_value() in the predicate
expressions of control flow statements.  I am treating ternary
expressions as control flow statements for the purpose of this patch.

Differential Revision: https://reviews.llvm.org/D128622
2022-07-10 15:01:06 -07:00
River Riddle fe4f512be7 [mlir:LSP] Add support for code completing attributes and types
This required changing a bit of how attributes/types are parsed. A new
`KeywordSwitch` class was added to AsmParser that provides a StringSwitch
like API for parsing keywords with a set of potential matches. It intends to
both provide a cleaner API, and enable injection for code completion. This
required changing the API of `generated(Attr|Type)Parser` to handle the
parsing of the keyword, instead of having the user do it. Most upstream
dialects use the autogenerated handling and didn't require a direct update.

Differential Revision: https://reviews.llvm.org/D129267
2022-07-08 16:24:55 -07:00
Leonard Chan 474c873148 Revert "[llvm] cmake config groundwork to have ZSTD in LLVM"
This reverts commit f07caf20b9 which seems to break upstream https://lab.llvm.org/buildbot/#/builders/109/builds/42253.
2022-07-08 13:48:05 -07:00
Cole Kissane f07caf20b9 [llvm] cmake config groundwork to have ZSTD in LLVM
- added `FindZSTD.cmake`
- added a CMake option `LLVM_ENABLE_ZSTD` with behavior mirroring that of `LLVM_ENABLE_ZLIB`
- likewise added have_zstd to compiler-rt/test/lit.common.cfg.py, clang-tools-extra/clangd/test/lit.cfg.py, and several lit.site.cfg.py.in files mirroring have_zlib behavior

Reviewed By: leonardchan, MaskRay

Differential Revision: https://reviews.llvm.org/D128465
2022-07-08 11:46:52 -07:00
Slava Zakharin 73026a4fbf [flang] Changed lowering for allocatable assignment to make array-value-copy correct.
Array-value-copy fails to generate a temporary array for case like this:
subroutine bug(b)
  real, allocatable :: b(:)
  b = b(2:1:-1)
end subroutine

Since LHS may need to be reallocated, lowering produces the following FIR:
%rhs_load = fir.array_load %b %slice

%lhs_mem = fir.if %b_is_allocated_with_right_shape {
   fir.result %b
} else {
   %new_storage = fir.allocmem %rhs_shape
   fir.result %new_storage
}

%lhs = fir.array_load %lhs_mem
%loop = fir.do_loop {
 ....
}
fir.array_merge_store %lhs, %loop to %lhs_mem
// deallocate old storage if reallocation occured,
// and update b descriptor if needed.

Since %b in array_load and %lhs_mem in array_merge_store are not the same SSA
values, array-value-copy does not detect the conflict and does not produce
a temporary array. This causes incorrect result in runtime.

The suggested change in lowering is to generate this:
%rhs_load = fir.array_load %b %slice
%lhs_mem = fir.if %b_is_allocated_with_right_shape {
   %lhs = fir.array_load %b
   %loop = fir.do_loop {
      ....
   }
   fir.array_merge_store %lhs, %loop to %b
   fir.result %b
} else {
   %new_storage = fir.allocmem %rhs_shape
   %lhs = fir.array_load %new_storage
   %loop = fir.do_loop {
      ....
   }
   fir.array_merge_store %lhs, %loop to %new_storage
   fir.result %new_storage
}
// deallocate old storage if reallocation occured,
// and update b descriptor if needed.

Note that there are actually 3 branches in FIR, so the assignment loops
are currently produced in three copies, which is a code-size issue.
It is possible to generate just two branches with two copies of the loops,
but it is not addressed in this change-set.

Differential Revision: https://reviews.llvm.org/D129314
2022-07-08 09:41:34 -07:00
Valentin Clement 015834e455
[flang][openacc][NFC] Extract device_type parser to its own
Move the device_type parser to a separate parser AccDeviceTypeExprList. Preparatory work for D106968.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106967
2022-07-08 16:02:04 +02:00
Valentin Clement 36e24da8eb
[flang][openacc][NFC] Make self clause value optional in ACC.td and extract the parser
Set the isOptional flag for the self clause. Move the optional and parenthesis part of the parser. Update the rest of the code to deal with the optional value.

Preparatory work for D106968.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106965
2022-07-08 15:45:12 +02:00
Peter Steinfeld e3611f82fc [flang] Fix typo in runtime message
The title says it.

Differential Revision: https://reviews.llvm.org/D129329
2022-07-07 14:10:25 -07:00
Peter Steinfeld 9f9e9d9cfc [flang] SET_EXPONENT(-0.0) should return -0.0
Section 16.9.171 says:

If X has the value zero, the result has the same value as X

So if X is -0.0, SET_EXPONENT should return -0.0.

Differential Revision: https://reviews.llvm.org/D129309
2022-07-07 12:43:30 -07:00
Valentin Clement 53804e426d
[flang][NFC] Make LEN parameters homogenous
This patch is part of the upstreaming effort from fir-dev branch.
This is the last patch for the upstreaming effort.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-07-07 18:29:28 +02:00
Peter Klausler 7c708adb4a [flang][runtime] Trim FORMATs echoed to error messages
Since dynamic FORMAT strings usually come from blank-padded fixed-length
CHARACTER variables, trim leading and trailing blanks from them when they
are echoed to error messages for better readability.

Differential Revision: https://reviews.llvm.org/D129024
2022-07-06 18:55:03 -07:00
Peter Klausler ac77649951 [flang] Avoid spurious warnings in pedantic mode from FORMAT items
In free form source, pedantic mode will elicit portability warnings
about missing spaces when a token string ends with a character that
can be in an identifier and there is no space between that last token
character and a following character that can also be part of an identifier.

This behavior doesn't really work well for the token strings that are
parsed for edit descriptors in FORMAT statements.  For example, the
'F' in FORMAT(F7.3) is followed by a digit, but obviously no space is
necessary.  Free form or not, FORMATs are their own odd little world.

This patch adds trailing blanks to these FORMAT edit descriptor token
parsers to disable the missing space check, and extends the documentation
for token string parsing to explain why this technique works.

Differential Revision: https://reviews.llvm.org/D129023
2022-07-06 18:54:11 -07:00
Peter Klausler 6052025b58 [flang] Add IsElementalProcedure() predicate
Replace most tests of the explicit Attr::ELEMENTAL symbol flag with
a new predicate IsElementalProcedure() that works correctly for alternate
ENTRY points and does the right thing for procedure interfaces that
reference elemental intrinsic functions like SIN() whose elemental
nature does not propagate.

Differential Revision: https://reviews.llvm.org/D129022
2022-07-06 18:08:45 -07:00
Peter Klausler 061df07389 [flang][runtime] Fix directed UP/DOWN rounding edge case for Fw.d output
When Fw.d output editing takes place with directed rounding, make sure that
nonzero values that would normally be converted to zero round up (or down,
depending on the sign) to a scaled 1.

Differential Revision: https://reviews.llvm.org/D129021
2022-07-06 17:35:34 -07:00
Peter Klausler 715283aa17 [flang] Cope with overflow in real MOD/MODULO
In folding and in the runtime library for real MOD/MODULO(A,P),
detect overflow from the division A/P and return a properly signed
zero result.  (When A/P overflows and both A and P are finite numbers
with nonzero P, the quotient would be a large integer when rounded to
the precision of the floating-point representation.)

Differential Revision: https://reviews.llvm.org/D129020
2022-07-06 17:31:11 -07:00
Peter Klausler 0508fd5935 [flang][runtime] Make ENDFILE work after non-advancing READ
An ENDFILE statement executed when a non-advancing READ has
left the unit in the middle of a record must truncate the file
at that position.

Differential Revision: https://reviews.llvm.org/D129019
2022-07-06 17:30:33 -07:00
Naje George 9ad64cf020 [flang] Add semantics test for coshape function
Reviewed By: ktras

Differential Revision: https://reviews.llvm.org/D128957
2022-07-06 14:27:08 -07:00