summaryrefslogtreecommitdiff
path: root/flang/lib/Optimizer/Support/InternalNames.cpp
AgeCommit message (Collapse)Author
2024-10-21[flang][debug] Don't generate debug for compiler-generated variables (#112423)Abid Qadeer
Flang generates many globals to handle derived types. There was a check in debug info to filter them based on the information that their names start with a period. This changed since PR#104859 where 'X' is being used instead of '.'. This PR fixes this issue by also adding 'X' in that list. As user variables gets lower cased by the NameUniquer, there is no risk that those will be filtered out. I added a test for that to be sure.
2024-08-21[RFC][flang] Replace special symbols in uniqued global names. (#104859)Slava Zakharin
This change addresses more "issues" as the one resolved in #71338. Some targets (e.g. NVPTX) do not accept global names containing `.`. In particular, the global variables created to represent the runtime information of derived types use `.` in their names. A derived type's descriptor object may be used in the device code, e.g. to initialize a descriptor of a variable of this type. Thus, the runtime type info objects may need to be compiled for the device. Moreover, at least the derived types' descriptor objects may need to be registered (think of `omp declare target`) for the host-device association so that the addendum pointer can be properly mapped to the device for descriptors using a derived type's descriptor as their addendum pointer. The registration implies knowing the name of the global variable in the device image so that proper host code can be created. So it is better to name the globals the same way for the host and the device. CompilerGeneratedNamesConversion pass renames all uniqued globals such that the special symbols (currently `.`) are replaced with `X`. The pass is supposed to be run for the host and the device. An option is added to FIR-to-LLVM conversion pass to indicate whether the new pass has been run before or not. This setting affects how the codegen computes the names of the derived types' descriptors for FIR derived types. fir::NameUniquer now allows `X` to be part of a name, because the name deconstruction may be applied to the mangled names after CompilerGeneratedNamesConversion pass.
2024-07-02Reland "[flang] add extra component information in fir.type_info" (#97404)jeanPerier
Reland #96746 with the proper Support/CMakelist.txt change. fir.type does not contain all Fortran level information about components. For instance, component lower bounds and default initial value are lost. For correctness purpose, this does not matter because this information is "applied" in lowering (e.g., when addressing the components, the lower bounds are reflected in the hlfir.designate). However, this "loss" of information will prevent the generation of correct debug info for the type (needs to know about lower bounds). The initial value could help building some optimization pass to get rid of initialization runtime calls. This patch adds lower bound and initial value information into fir.type_info via a new fir.dt_component operation. This operation is generated only for component that needs it, which helps keeping the IR small for "boring" types. In general, adding Fortran level info in fir.type_info will allow delaying the generation of "type descriptors" gobals that are very verbose in FIR and make it hard to work with FIR dumps from applications with many derived types.
2024-06-27Revert "[flang] add extra component information in fir.type_info" (#96937)jeanPerier
Reverts llvm/llvm-project#96746 Breaking shared library buillds: https://lab.llvm.org/buildbot/#/builders/89/builds/931
2024-06-27[flang] add extra component information in fir.type_info (#96746)jeanPerier
fir.type does not contain all Fortran level information about components. For instance, component lower bounds and default initial value are lost. For correctness purpose, this does not matter because this information is "applied" in lowering (e.g., when addressing the components, the lower bounds are reflected in the hlfir.designate). However, this "loss" of information will prevent the generation of correct debug info for the type (needs to know about lower bounds). The initial value could help building some optimization pass to get rid of initialization runtime calls. This patch adds lower bound and initial value information into fir.type_info via a new fir.dt_component operation. This operation is generated only for component that needs it, which helps keeping the IR small for "boring" types. In general, adding Fortran level info in fir.type_info will allow delaying the generation of "type descriptors" gobals that are very verbose in FIR and make it hard to work with FIR dumps from applications with many derived types.
2023-12-19[flang] Lower procedure pointer components (#75453)jeanPerier
Lower procedure pointer components, except in the context of structure constructor (left TODO). Procedure pointer components lowering share most of the lowering logic of procedure poionters with the following particularities: - They are components, so an hlfir.designate must be generated to retrieve the procedure pointer address from its derived type base. - They may have a PASS argument. While there is no dispatching as with type bound procedure, special care must be taken to retrieve the derived type component base in this case since semantics placed it in the argument list and not in the evaluate::ProcedureDesignator. These components also bring a new level of recursive MLIR types since a fir.type may now contain a component with an MLIR function type where one of the argument is the fir.type itself. This required moving the "derived type in construction" stackto the converter so that the object and function type lowering utilities share the same state (currently the function type utilty would end-up creating a new stack when lowering its arguments, leading to infinite loops). The BoxedProcedurePass also needed an update to deal with this recursive aspect.
2023-12-13[flang] Use StringRef::{starts,ends}_with (NFC)Kazu Hirata
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-05-17[flang] Non-type-bound defined IO loweringV Donaldson
Generate supporting data structures and calls to new runtime IO functions for defined IO that accesses non-type-bound procedures, such as `wft` in: module m1 type t integer n end type interface write(formatted) module procedure wft end interface contains subroutine wft(dtv, unit, iotype, v_list, iostat, iomsg) class(t), intent(in) :: dtv integer, intent(in) :: unit character(*), intent(in) :: iotype integer, intent(in) :: v_list(:) integer, intent(out) :: iostat character(*), intent(inout) :: iomsg iostat = 0 write(unit,*,iostat=iostat,iomsg=iomsg) 'wft was called: ', dtv%n end subroutine end module module m2 contains subroutine test1 use m1 print *, 'test1, should call wft: ', t(1) end subroutine subroutine test2 use m1, only: t print *, 'test2, should not call wft: ', t(2) end subroutine end module use m1 use m2 call test1 call test2 print *, 'main, should call wft: ', t(3) end
2023-02-28[flang] Block constructV Donaldson
A block construct is an execution control construct that supports declaration scopes contained within a parent subprogram scope or another block scope. (blocks may be nested.) This is implemented by applying basic scope processing to the block level. Name uniquing/mangling is extended to support this. The term "block" is heavily overloaded in Fortran standards. Prior name uniquing used tag `B` for common block objects. Existing tag choices were modified to free up `B` for block construct entities, and `C` for common blocks, and resolve additional issues with other tags. The "old tag -> new tag" changes can be summarized as: -> B -- block construct -> new B -> C -- common block C -> YI -- intrinsic type descriptor; not currently generated CT -> Y -- nonintrinsic type descriptor; not currently generated G -> N -- namelist group L -> -- block data; not needed -> deleted Existing name uniquing components consist of a tag followed by a name from user source code, such as a module, subprogram, or variable name. Block constructs are different in that they may be anonymous. (Like other constructs, a block may have a `block-construct-name` that can be used in exit statements, but this name is optional.) So blocks are given a numeric compiler-generated preorder index starting with `B1`, `B2`, and so on, on a per-procedure basis. Name uniquing is also modified to include component names for all containing procedures rather than for just the immediate host. This fixes an existing name clash bug with same-named entities in same-named host subprograms contained in different-named containing subprograms, and variations of the bug involving modules and submodules. F18 clause 9.7.3.1 (Deallocation of allocatable variables) paragraph 1 has a requirement that an allocated, unsaved allocatable local variable must be deallocated on procedure exit. The following paragraph 2 states: When a BLOCK construct terminates, any unsaved allocated allocatable local variable of the construct is deallocated. Similarly, F18 clause 7.5.6.3 (When finalization occurs) paragraph 3 has a requirement that a nonpointer, nonallocatable object must be finalized on procedure exit. The following paragraph 4 states: A nonpointer nonallocatable local variable of a BLOCK construct is finalized immediately before it would become undefined due to termination of the BLOCK construct. These deallocation and finalization requirements, along with stack restoration requirements, require knowledge of block exits. In addition to normal block termination at an end-block-stmt, a block may be terminated by executing a branching statement that targets a statement outside of the block. This includes Single-target branch statements: - goto - exit - cycle - return Bounded multiple-target branch statements: - arithmetic goto - IO statement with END, EOR, or ERR specifiers Unbounded multiple-target branch statements: - call with alternate return specs - computed goto - assigned goto Lowering code is extended to determine if one of these branches exits one or more relevant blocks or other constructs, and adds a mechanism to insert any necessary deallocation, finalization, or stack restoration code at the source of the branch. For a single-target branch it suffices to generate the exit code just prior to taking the indicated branch. Each target of a multiple-target branch must be analyzed individually. Where necessary, the code must first branch to an intermediate basic block that contains exit code, followed by a branch to the original target statement. This patch implements an `activeConstructStack` construct exit mechanism that queries a new `activeConstruct` PFT bit to insert stack restoration code at block exits. It ties in to existing code in ConvertVariable.cpp routine `instantiateLocal` which has code for finalization, making block exit finalization on par with subprogram exit finalization. Deallocation is as yet unimplemented for subprograms or blocks. This may result in memory leaks for affected objects at either the subprogram or block level. Deallocation cases can be addressed uniformly for both scopes in a future patch, presumably with code insertion in routine `instantiateLocal`. The exit code mechanism is not limited to block construct exits. It is also available for use with other constructs. In particular, it is used to replace custom deallocation code for a select case construct character selector expression where applicable. This functionality is also added to select type and associate constructs. It is available for use with other constructs, such as select rank and image control constructs, if that turns out to be necessary. Overlapping nonfunctional changes include eliminating "FIR" from some routine names and eliminating obsolete spaces in comments.
2023-01-07[flang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07[flang] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-07[flang] Support codegen of procedure pointer componentPeixin Qiao
This supports the codegen for procedure pointer component in BoxedProcedure pass. Also fix the FIR in ProcedurePointer.md so that all the cases can be run using `tco` to generate the LLVM IR. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D136842
2022-10-18[flang] Add getTypeDescriptorBindingTableName functionValentin Clement
Type descriptor and its binding table are defined as fir.global in FIR. Their names are derived from the derived-type name. This patch adds a new function `getTypeDescriptorBindingTableName` in the NameUniquer and refactor the `GetTypeDescriptorName` function to reuse the same code. This will be used in the fir.dispatch code generation. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D136167
2022-08-14[flang] Remove redundant string initialization (NFC)Kazu Hirata
Identified with readability-redundant-string-init.
2022-07-16[flang] Use *X instead of X.getValue() (NFC)Kazu Hirata
Per Flang C++ Style Guide, this patch replaces X.getValue() with *X where *X is protected by a presence test.
2022-07-10[flang] Don't use Optional::hasValue (NFC)Kazu Hirata
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-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata
2022-03-03[flang] Support PDT type descriptors in codegenJean Perier
This change updates the mapping of derived types and type descriptor object names to support kind parametrized derived types (PDT). It moves the custom name mapping to the internal name utility. To improve robustness and error reporting, type descriptors are also now required to be generated in all compilation unit that manipulates derived types. The previous codegen relied on the fact that descriptors not defined in the current FIR module were available externally. Errors with missing type descriptors were only caught at link time. This patch makes derived type definition mandatory, except if the derived types are expected to not have derived type descriptors (builtin types), or if the newly added debug switch `--ignore-missing-type-desc` is set. In those cases, a null pointer is used as type descriptor pointer. The debug switch intends to help testing FIR to LLVM passes without having to bother providing type descriptor data structures that are normally built by the front-end. Differential Revision: https://reviews.llvm.org/D120804
2022-02-14[flang] Fail at link time if derived type descriptors were not generatedJean Perier
Currently, code generation was creating weak symbols for derived type descriptor global it could not find in the current compilation unit. The rational is that: - the derived type descriptors of external module derived types are generated in the compilation unit that compiled the module so that the type descriptor address is uniquely associated with the type. - some types do not have derived type descriptors: the builtin derived types used to create derived type descriptors. The runtime knows about them and does not need them to accomplish the feat of describing themselves. Hence, all unresolved derived type descriptors in codegen cannot be assumed to be resolved at link time. However, this caused immense debugging pain when, for some reasons, derived type descriptor that should be generated were not. This caused random runtime failures instead of a much cleaner link time failure. Improve this situation by allowing codegen to detect the builtin derived types that have no derived type descriptors and requiring the other unresolved derived type descriptor to be resolved at link time. Also make derived type descriptor constant data since this was a TODO and makes the situation even cleaner. This requiring telling lowering which compiler created symbols can be placed in read only memory. I considered using PARAMETER, but I have mixed feeling using it since that would cause the initializer expressions of derived type descriptor to be invalid from a Fortran point of view since pointer targets cannot be parameters. I do not want to start misusing Fortran attributes, even if I think it is quite unlikely semantics would currently complain. I also do not want to rely on the fact that all object symbols with the CompilerCreated flags are currently constant data. This could easily change in the future and cause runtime bugs if lowering rely on this while the assumption is not loud and clear in semantics. Instead, add a ReadOnly symbol flag to tell lowering that a compiler generated symbol can be placed in read only memory. Differential Revision: https://reviews.llvm.org/D119555
2022-01-19[flang][NFC] Remove number of inlined elementsValentin Clement
Following the recommendation just remove the specified number of inlined elements since it is not well-motivated choice here.
2021-10-05[fir] Add external name interop passValentin Clement
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-04[fir][NFC] Fix couple of clang-tidy warningsValentin Clement
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-09-24[flang][fir] Add support to mangle/deconstruct namelist group nameValentin Clement
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-24Revert "[flang][fir] Add support to mangle/deconstruct namelist group name"Valentin Clement
This reverts commit 3593ae4312f6156c9ca50d46cdb55a8dfad782d0.
2021-09-24[flang][fir] Add support to mangle/deconstruct namelist group nameValentin Clement
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-02-19[flang][fir] Update flang test tool support classes.Eric Schweitz
This updates the various classes that support the compliation of Fortran. These classes are shared by the test tools. Authors: Eric Schweitz, Sameeran Joshi, et.al. Differential Revision: https://reviews.llvm.org/D97073
2021-02-09[flang][fir] Updates to internal name uniquer.Eric Schweitz
https://github.com/flang-compiler/f18-llvm-project/pull/474 Differential Revision: https://reviews.llvm.org/D96361
2020-06-16[flang] Upstream the Mangler module from lowering.Eric Schweitz
This upstreams the internal name mangling used in the bridge to generate unique names from symbols. Replace InternalNamesTest with the actual, functional unittest. Differential revision: https://reviews.llvm.org/D81764
2020-04-24[flang] Support for making unique internal names.Eric Schweitz
Differential Revision: https://reviews.llvm.org/D78838