aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Lower/ConvertExprToHLFIR.cpp
AgeCommit message (Collapse)AuthorFilesLines
12 days[mlir][NFC] update `flang/Lower` create APIs (8/n) (#149912)Maksim Levental1-50/+50
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-17[flang] Migrate away from ArrayRef(std::nullopt_t) (#149337)Kazu Hirata1-1/+1
ArrayRef(std::nullopt_t) has been deprecated. This patch replaces std::nullopt with {}. A subsequence patch will address those places where we need to replace std::nullopt with mlir::TypeRange{} or mlir::ValueRange{}.
2025-07-09[flang] Add -fcomplex-arithmetic= option and select complex division ↵Shunsuke Watanabe1-2/+11
algorithm (#146641) This patch adds an option to select the method for computing complex number division. It uses `LoweringOptions` to determine whether to lower complex division to a runtime function call or to MLIR's `complex.div`, and `CodeGenOptions` to select the computation algorithm for `complex.div`. The available option values and their corresponding algorithms are as follows: - `full`: Lower to a runtime function call. (Default behavior) - `improved`: Lower to `complex.div` and expand to Smith's algorithm. - `basic`: Lower to `complex.div` and expand to the algebraic algorithm. See also the discussion in the following discourse post: https://discourse.llvm.org/t/optimization-of-complex-number-division/83468 --------- Co-authored-by: Tarun Prabhu <tarunprabhu@gmail.com>
2025-06-26[flang] Migrate away from std::nullopt (NFC) (#145928)Kazu Hirata1-7/+7
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. This patch replaces std::nullopt with {}. There are a couple of places where std::nullopt is replaced with TypeRange() to accommodate perfect forwarding.
2025-05-08[flang] Use box for components with non-default lower bounds (#138994)Asher Mancinelli1-3/+19
When designating an array component that has non-default lower bounds the bridge was producing hlfir designates yielding reference types, which did not preserve the bounds information. Then, when creating components, unadjusted indices were used when initializing the structure. We could look at the declaration to get the shape parameter, but this would not be preserved if the component were passed as a block argument. These results must be boxed, but we also must not lose the contiguity information either. To address contiguity, annotate these boxes with the `contiguous` attribute during designation. Note that other designated entities are handled inside the HlfirDesignatorBuilder while component designators are built in HlfirBuilder. I am not sure if this handling should be moved into the designator builder or left in the general builder, so feedback is welcome. Also, I wouldn't mind finding a test that demonstrates a box-designated component with the contiguous attribute really is determined to be contiguous by any passes down the line checking for that. I don't have a test like that yet.
2025-05-08[flang] Correctly prepare allocatable runtime call arguments (#138727)Asher Mancinelli1-6/+6
When lowering allocatables, the generated calls to runtime functions were not using the runtime::createArguments utility which handles the required conversions. createArguments is where I added the implicit volatile casts to handle converting volatile variables to the appropriate type based on their volatility in the callee. Because the calls to allocatable runtime functions were not using this function, their arguments were not casted to have the appropriate volatility. Add a test to demonstrate that volatile and allocatable class/box/reference types are appropriately casted before calling into the runtime library. Instead of using a recursive variadic template to perform the conversions in createArguments, map over the arguments directly so that createArguments can be called with an ArrayRef of arguments. Some cases in Allocatable.cpp already had a vector of values at the point where createArguments needed to be called - the new overload allows calling with a vector of args or the variadic version with each argument spelled out at the callsite. This change resulted in the allocatable runtime calls having their arguments converted left-to-right, which changed some of the test results. I used CHECK-DAG to ignore the order. Add some missing handling of volatile class entities, which I previously missed because I had not yet enabled volatile class entities in Lower.
2025-05-06[flang] Lower volatile class types (#138607)Asher Mancinelli1-11/+13
So far, only boxes and references have had their volatile attribute set during lowering. This patch enables the volatility of classes to be properly represented in the ir, same as box and ref. For simple cases, not much needs to change in the codegen or conversion patterns because the prior work on volatile refs/boxes propagates volatility already. I am running further testing with the strict verification enabled to find remaining cases of incorrect/missing volatile propagation.
2025-05-05[flang] Component references are volatile if their parent is (#138339)Asher Mancinelli1-6/+6
Component references inherit volatility from their base derived types. Moved the base type volatility check before the box type is built, and merge it (instead of overwrite it) with the volatility of the base type.
2025-04-30[flang] Add lowering of volatile references (#132486)Asher Mancinelli1-2/+30
[RFC on discourse](https://discourse.llvm.org/t/rfc-volatile-representation-in-flang/85404/1) Flang currently lacks support for volatile variables. For some cases, the compiler produces TODO error messages and others are ignored. Some of our tests are like the example from _C.4 Clause 8 notes: The VOLATILE attribute (8.5.20)_ and require volatile variables. Prior commits: ``` c9ec1bc753b0 [flang] Handle volatility in lowering and codegen (#135311) e42f8609858f [flang][nfc] Support volatility in Fir ops (#134858) b2711e1526f9 [flang][nfc] Support volatile on ref, box, and class types (#134386) ```
2025-04-28[flang][Lower][nfc] vector subscript lhs first element to helper (#137456)Tom Eccles1-0/+46
This encapsulates implementation details of hlfir.elemental_addr inside of ConvertExprToHLFIR instead of leaking to OpenMP code. Requested here: https://github.com/llvm/llvm-project/pull/133892#issuecomment-2821559394
2025-04-14[flang] Handle volatility in lowering and codegen (#135311)Asher Mancinelli1-4/+13
* Enable lowering and conversion patterns to pass volatility information from higher level operations to lower level ones. * Enable codegen to pass volatility to LLVM dialect ops by setting an attribute on loads, stores, and memory intrinsics. * Add utilities for passing along the volatility from an input type to an output type. To introduce volatile types into the IR, entities with the volatile attribute will be given a volatile type in the bridge; this is not enabled in this patch. User code should not result in IR with volatile types yet, so this patch contains no tests with Fortran source, only IR that already contains volatile types. Part 3 of #132486.
2025-04-09Reland "[flang][nfc] Support volatility in Fir ops" (#135039)Asher Mancinelli1-2/+7
#134858 had an extraneous include which caused the shared library builds to break.
2025-04-09Revert "[flang][nfc] Support volatility in Fir ops" (#135034)David Spickett1-7/+2
Reverts llvm/llvm-project#134858 Fails to build when shared libraries are enabled: https://lab.llvm.org/buildbot/#/builders/80/builds/12361 ``` : && /usr/local/bin/c++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -Wl,-z,defs -Wl,-z,nodelete -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/./lib -Wl,--gc-sections -shared -Wl,-soname,libFIRDialect.so.21.0git -o lib/libFIRDialect.so.21.0git tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIRAttr.cpp.o tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIRDialect.cpp.o tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIRType.cpp.o tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FirAliasTagOpInterface.cpp.o tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FortranVariableInterface.cpp.o tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/Inliner.cpp.o -Wl,-rpath,"\$ORIGIN/../lib:/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/lib:" lib/libCUFAttrs.so.21.0git lib/libFIRDialectSupport.so.21.0git lib/libLLVMAsmPrinter.so.21.0git lib/libMLIRBuiltinToLLVMIRTranslation.so.21.0git lib/libMLIROpenMPToLLVM.so.21.0git lib/libMLIRLLVMToLLVMIRTranslation.so.21.0git lib/libMLIRFuncToLLVM.so.21.0git lib/libMLIRArithToLLVM.so.21.0git lib/libMLIRArithAttrToLLVMConversion.so.21.0git lib/libMLIRArithTransforms.so.21.0git lib/libMLIRBufferizationTransforms.so.21.0git lib/libMLIRBufferizationDialect.so.21.0git lib/libMLIRSparseTensorDialect.so.21.0git lib/libMLIRSCFDialect.so.21.0git lib/libMLIRFuncTransforms.so.21.0git lib/libMLIRShardingInterface.so.21.0git lib/libMLIRMeshDialect.so.21.0git lib/libMLIRVectorDialect.so.21.0git lib/libMLIRTensorDialect.so.21.0git lib/libMLIRParallelCombiningOpInterface.so.21.0git lib/libMLIRMaskableOpInterface.so.21.0git lib/libMLIRMaskingOpInterface.so.21.0git lib/libMLIRVectorInterfaces.so.21.0git lib/libMLIRControlFlowToLLVM.so.21.0git lib/libMLIRControlFlowDialect.so.21.0git lib/libMLIRMemRefToLLVM.so.21.0git lib/libMLIRLLVMCommonConversion.so.21.0git lib/libMLIRMemRefUtils.so.21.0git lib/libMLIRAffineDialect.so.21.0git lib/libMLIRMemRefDialect.so.21.0git lib/libMLIRArithUtils.so.21.0git lib/libMLIRComplexDialect.so.21.0git lib/libMLIRArithDialect.so.21.0git lib/libMLIRCastInterfaces.so.21.0git lib/libMLIRInferIntRangeCommon.so.21.0git lib/libMLIRShapedOpInterfaces.so.21.0git lib/libMLIRDialect.so.21.0git lib/libMLIRDialectUtils.so.21.0git lib/libMLIROpenMPDialect.so.21.0git lib/libMLIROpenACCMPCommon.so.21.0git lib/libMLIRTargetLLVMIRExport.so.21.0git lib/libMLIRDLTIDialect.so.21.0git lib/libMLIRLLVMIRTransforms.so.21.0git lib/libMLIRTransforms.so.21.0git lib/libMLIRUBDialect.so.21.0git lib/libMLIRRuntimeVerifiableOpInterface.so.21.0git lib/libMLIRFuncDialect.so.21.0git lib/libMLIRNVVMDialect.so.21.0git lib/libMLIRTranslateLib.so.21.0git lib/libMLIRParser.so.21.0git lib/libMLIRBytecodeReader.so.21.0git lib/libMLIRAsmParser.so.21.0git lib/libMLIRTransformUtils.so.21.0git lib/libMLIRSubsetOpInterface.so.21.0git lib/libMLIRValueBoundsOpInterface.so.21.0git lib/libMLIRDestinationStyleOpInterface.so.21.0git lib/libMLIRRewrite.so.21.0git lib/libMLIRRewritePDL.so.21.0git lib/libMLIRPDLToPDLInterp.so.21.0git lib/libMLIRPass.so.21.0git lib/libMLIRAnalysis.so.21.0git lib/libMLIRInferIntRangeInterface.so.21.0git lib/libMLIRLoopLikeInterface.so.21.0git lib/libMLIRPresburger.so.21.0git lib/libMLIRViewLikeInterface.so.21.0git lib/libMLIRPDLInterpDialect.so.21.0git lib/libMLIRPDLDialect.so.21.0git lib/libLLVMFrontendOpenMP.so.21.0git lib/libLLVMTransformUtils.so.21.0git lib/libMLIRLLVMDialect.so.21.0git lib/libMLIRInferTypeOpInterface.so.21.0git lib/libMLIRControlFlowInterfaces.so.21.0git lib/libMLIRDataLayoutInterfaces.so.21.0git lib/libMLIRFunctionInterfaces.so.21.0git lib/libMLIRCallInterfaces.so.21.0git lib/libMLIRMemorySlotInterfaces.so.21.0git lib/libMLIRSideEffectInterfaces.so.21.0git lib/libMLIRIR.so.21.0git lib/libLLVMBitWriter.so.21.0git lib/libLLVMAnalysis.so.21.0git lib/libLLVMAsmParser.so.21.0git lib/libLLVMBitReader.so.21.0git lib/libMLIRSupport.so.21.0git lib/libLLVMCore.so.21.0git lib/libLLVMRemarks.so.21.0git lib/libLLVMBinaryFormat.so.21.0git lib/libLLVMTargetParser.so.21.0git lib/libLLVMSupport.so.21.0git -Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-sharedlibs/build/lib && : /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::CharBoxValue::dump() const': FIROps.cpp:(.text._ZNK3fir12CharBoxValue4dumpEv[_ZNK3fir12CharBoxValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::CharBoxValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::PolymorphicValue::dump() const': FIROps.cpp:(.text._ZNK3fir16PolymorphicValue4dumpEv[_ZNK3fir16PolymorphicValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::PolymorphicValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::ArrayBoxValue::dump() const': FIROps.cpp:(.text._ZNK3fir13ArrayBoxValue4dumpEv[_ZNK3fir13ArrayBoxValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::ArrayBoxValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::CharArrayBoxValue::dump() const': FIROps.cpp:(.text._ZNK3fir17CharArrayBoxValue4dumpEv[_ZNK3fir17CharArrayBoxValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::CharArrayBoxValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::ProcBoxValue::dump() const': FIROps.cpp:(.text._ZNK3fir12ProcBoxValue4dumpEv[_ZNK3fir12ProcBoxValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::ProcBoxValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::BoxValue::dump() const': FIROps.cpp:(.text._ZNK3fir8BoxValue4dumpEv[_ZNK3fir8BoxValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::BoxValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::MutableBoxValue::dump() const': FIROps.cpp:(.text._ZNK3fir15MutableBoxValue4dumpEv[_ZNK3fir15MutableBoxValue4dumpEv]+0x20): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::MutableBoxValue const&)' /usr/bin/ld: tools/flang/lib/Optimizer/Dialect/CMakeFiles/FIRDialect.dir/FIROps.cpp.o: in function `fir::ExtendedValue::dump() const': FIROps.cpp:(.text._ZNK3fir13ExtendedValue4dumpEv[_ZNK3fir13ExtendedValue4dumpEv]+0x18): undefined reference to `fir::operator<<(llvm::raw_ostream&, fir::ExtendedValue const&)' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ```
2025-04-09[flang][nfc] Support volatility in Fir ops (#134858)Asher Mancinelli1-2/+7
Part two of merging #132486. Support volatility in fir ops. * Introduce a new operation fir.volatile_cast, whose only purpose is to add or take away the volatility of an SSA value's type. The types must be otherwise identical, and any other type conversions must be handled by fir.convert. fir.convert will give an error if the volatility of the inputs does not match, such that all changes to volatility must be handled explicitly through fir.volatile_cast. * Add memory effects to ops that read from or write to memory. The precedent for this comes from the LLVM dialect (feb7beaf70) where llvm.load/store ops with the volatile attribute report read/write effects to a generic memory resource. This change is similar in spirit but different in two ways: the volatility of an operation is determined by the type of its memref, not an attribute on the op, and the memory effects of a load- or store-like operation on a volatile reference type are reported against a particular memory resource, `VolatileMemoryResource`. This is so MLIR optimizations are able to reorder operations that are not volatile around operations that are, which we believe more precisely models LLVM's volatile memory semantics. @vzakhari suggested this in #132486 citing LangRef. See https://llvm.org/docs/LangRef.html#volatile-memory-accesses Changes needed to generate IR with volatile types are not included in this change, so it should be non-functional, containing only the changes to Fir ops and op utilities that will be needed once we enable lowering to generate volatile types.
2025-03-29[Flang][OpenMP] Add PointerAssociateScalar to Cray Pointer used in the DSA ↵Thirumalai Shaktivel1-1/+2
(#133232) Issue: Cray Pointer is not associated to Cray Pointee, leading to Segmentation fault Fix: GetUltimate, retrieves the base symbol in the current scope, which gets passed all the references and returns the original symbol --------- Co-authored-by: Michael Klemm <michael.klemm@amd.com>
2025-03-03[flang] Move DumpEvaluateExpr from Lower to Semantics (#128723)Krzysztof Parzyszek1-1/+0
Since evaluate::Expr can show up in the parse tree in the semantic analysis step, make it possible to dump its structure in the Semantics module. The Lower module depends on Semantics, so the code is still accessible in it.
2025-02-05[flang] fix IsSimplyContiguous with expressions (#125708)jeanPerier1-1/+3
IsSymplyContiguous was visiting expressions and returning false on expressions like `x(::2) + y`, which triggered an assert in lowering when preparing arguments for copy-in/out. Update it to return false for everything that is not a variable, except when provided a flag to treat PARAMETER bases as variables. This flags is required for internal usages in lowering where lowering needs to now if the read-only memory is being addressed contiguously or not. Update call lowering to always copy parameter array section into contiguous writable memory when passing them. The rational here is that copy-out generated in nested calls using the dummy arguments will cause a segfault.
2024-12-18[flang] Add UNSIGNED (#113504)Peter Klausler1-5/+79
Implement the UNSIGNED extension type and operations under control of a language feature flag (-funsigned). This is nearly identical to the UNSIGNED feature that has been available in Sun Fortran for years, and now implemented in GNU Fortran for gfortran 15, and proposed for ISO standardization in J3/24-116.txt. See the new documentation for details; but in short, this is C's unsigned type, with guaranteed modular arithmetic for +, -, and *, and the related transformational intrinsic functions SUM & al.
2024-12-03[flang] Fix crash in HLFIR generation (#118399)Peter Klausler1-6/+5
Structure constructors with multiple components would crash when components were from parent types. The search for the right parent component must be done anew for each component. Fixes https://github.com/llvm/llvm-project/issues/118270, https://github.com/llvm/llvm-project/issues/96994, and https://github.com/llvm/llvm-project/issues/105848.
2024-10-18[flang] add getElementType() to fir::SquenceType and fir::VectorType (#112770)Scott Manley1-2/+3
getElementType() was missing from Sequence and Vector types. Did a replace of the obvious places getEleTy() was used for these two types and updated to use this name instead. Co-authored-by: Scott Manley <scmanley@nvidia.com>
2024-10-03[flang] replace fir.complex usages with mlir complex (#110850)jeanPerier1-1/+1
Core patch of https://discourse.llvm.org/t/rfc-flang-replace-usages-of-fir-complex-by-mlir-complex-type/82292. After that, the last step is to remove fir.complex from FIR types.
2024-10-03[flang] add nsw to operations in subscripts (#110060)Yusuke MINATO1-1/+13
This patch adds nsw to operations when lowering subscripts. See also the discussion in the following discourse post. https://discourse.llvm.org/t/rfc-add-nsw-flags-to-arithmetic-integer-operations-using-the-option-fno-wrapv/77584/9
2024-06-17[Flang] Switch to common::visit more call sites (#90018)Alexander Shaposhnikov1-11/+12
Switch to common::visit more call sites. Test plan: ninja check-all
2024-05-31[flang] improve and rename Entity::hasNonDefaultLowerBounds (#93848)jeanPerier1-4/+4
Improve hasNonDefaultLowerBounds to follow box fir.convert. This helps HLFIR helpers to generate less code when it can be easily deduced that the fir.box lower bounds were set to ones. It will help me for SELECT RANK lowering to avoid generating hlfir.declare with lower bounds inside the RANK CASE (Current situation would not be incorrect, the lower bounds would be SSA value ending-up being one, I just want simpler IR). Renamed to mayHaveNonDefaultLowerBounds since it may still answer yes when the lower bounds are ones.
2024-05-30[flang] lower RANK intrinsic (#93694)jeanPerier1-1/+1
First commit is reviewed in https://github.com/llvm/llvm-project/pull/93682. Lower RANK using fir.box_rank. This patches updates fir.box_rank to accept box reference, this avoids the need of generating an assumed-rank fir.load just for the sake of reading ALLOCATABLE/POINTER rank. The fir.load would generate a "dynamic" memcpy that is hard to optimize without further knowledge. A read effect is conditionally given to the operation.
2024-05-08[flang] Lowering changes for assigning dummy_scope to hlfir.declare. (#90989)Slava Zakharin1-1/+2
The lowering produces fir.dummy_scope operation if the current function has dummy arguments. Each hlfir.declare generated for a dummy argument is then using the result of fir.dummy_scope as its dummy_scope operand. This is only done for HLFIR. I was not able to find a reliable way to identify dummy symbols in `genDeclareSymbol`, so I added a set of registered dummy symbols that is alive during the variables instantiation for the current function. The set is initialized during the mapping of the dummy argument symbols to their MLIR values. It is reset right after all variables are instantiated - this is done to avoid generating hlfir.declare operations with dummy_scope for the clones of the dummy symbols (e.g. this happens with OpenMP privatization). If this can be done in a cleaner way, please advise.
2024-04-28Reapply "[mlir] Mark `isa/dyn_cast/cast/...` member functions depreca… ↵Christian Sigg1-14/+14
(#90406) …ted. (#89998)" (#90250) This partially reverts commit 7aedd7dc754c74a49fe84ed2640e269c25414087. This change removes calls to the deprecated member functions. It does not mark the functions deprecated yet and does not disable the deprecation warning in TypeSwitch. This seems to cause problems with MSVC.
2024-04-26Revert "[mlir] Mark `isa/dyn_cast/cast/...` member functions deprecated. ↵dyung1-14/+14
(#89998)" (#90250) This reverts commit 950b7ce0b88318f9099e9a7c9817d224ebdc6337. This change is causing build failures on a bot https://lab.llvm.org/buildbot/#/builders/216/builds/38157
2024-04-26[mlir] Mark `isa/dyn_cast/cast/...` member functions deprecated. (#89998)Christian Sigg1-14/+14
See https://mlir.llvm.org/deprecation and https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-03-26[Flang] Support for passing procedure pointer, reference to a function that ↵Daniel Chen1-3/+18
returns a procedure pointer to structure constructor. (#86533) This PR fixes `not yet implemented: procedure pointer component in structure constructor` as shown in the following test case. ``` MODULE M TYPE :: DT PROCEDURE(Fun), POINTER, NOPASS :: pp1 END TYPE CONTAINS INTEGER FUNCTION Fun(Arg) INTEGER :: Arg Fun = Arg END FUNCTION END MODULE PROGRAM MAIN USE M IMPLICIT NONE TYPE (DT) :: v2 PROCEDURE(FUN), POINTER :: pp2 v2 = DT(pp2) v2 = DT(bar()) CONTAINS FUNCTION BAR() RESULT(res) PROCEDURE(FUN), POINTER :: res END END ```
2024-03-22[flang] Fix lowering of host associated cray pointee symbols (#86121)jeanPerier1-1/+8
Cray pointee symbols can be host associated from a module or host procedure while the related cray pointer is not explicitly associated. This caused the "not yet implemented: lowering symbol to HLFIR" to fire when lowering a reference to the cray pointee and fetching the cray pointer. This patch: - Ensures cray pointers are always instantiated when instantiating a cray pointee. - Fix internal procedure lowering to deal with cray pointee host association like it does for pointers (the lowering strategy for cray pointee is to create a pointer that is updated with the cray pointer value before being fetched). This should fix the bug reported in https://github.com/llvm/llvm-project/issues/85420.
2024-03-12[flang] lower vector subscripted polymorphic designators (#84778)jeanPerier1-12/+15
A mold argument need to be added to the hlfir.element_addr and set in lowering so that when the hlfir.element_addr need to be turned into an hlfir.elemental operation because the designator must be turned into a value, the mold can be set on the hlfir.elemental to later allocate the temporary according the the dynamic type. This situation happens whenever the vector subscripted polymorphic designator does not appear as an assignment left-hand side, or as an IO-input item. I initially thought retrieving the mold would be tricky if the dynamic type of the designator was set by a part-ref of the right of the vector subscripts ("array(vector)%polymorphic_comp"), but this turned out to be impossible because: 1. A derived type component can be polymorphic only if it has the POINTER or ALLOCATABLE attribute (F2023 C708). 2. Vector-subscripted part are ranked and F2023 C919 prohibits any part-ref on the right of the rank part to have the POINTER or ALLOCATABLE attribute. => If a vector subscripted designator is polymorphic, the vector subscripted part is the rightmost part, and the mold is the base of the vector subscripted part. This makes the retrieval of the mold easy in lowering. The mold argument is always set to be the base of the vector subscripted part when lowering the vector subscripted part, and it is removed at the end of the designator lowering if the designator is not polymorphic. This way there is no need to find back the mold from the inside of the hlfir.element_addr body.
2024-03-05[flang] Deallocate structure constructor allocatable components (#83824)jeanPerier1-0/+10
Allocatable components of structure constructors were not deallocated. Deallocate them without calling final subroutines. This was already properly done for array constructors.
2024-02-02[flang] sanitize set_length in lowering (#80412)jeanPerier1-1/+4
In fortran, it is possible to give a negative "i" in "character(i)" in which case the standard says the length is zero. So the length must be sanitized as max(0, user_input) in lowering. This is already done when lowering specification parts, but was not done when "character(i)" appears in array constructors. Sanitize the length when lowering SetLength in lowering. Fixes https://github.com/llvm/llvm-project/issues/80270
2024-01-30[Flang]: Lowering reference to functions that return a procedure pointer ↵Daniel Chen1-3/+7
(#78194) This PR adds lowering the reference to a function that returns a procedure pointer. It also fixed intrinsic ASSOCIATED to take such argument. --------- Co-authored-by: jeanPerier <jperier@nvidia.com>
2024-01-26[flang] Lower passing non assumed-rank/size to assumed-ranks (#79145)jeanPerier1-2/+2
Start implementing assumed-rank support as described in https://github.com/llvm/llvm-project/blob/main/flang/docs/AssumedRank.md This commit holds the minimal support for lowering calls to procedure with assumed-rank arguments where the procedure implementation is done in C. The case for passing assumed-size to assumed-rank is left TODO since it will be done a change in assumed-size lowering that is better done in another patch. Care is taken to set the lower bounds to zero when passing non allocatable no pointer as descriptor to a BIND(C) procedure as required per 18.5.3 point 3. This was not done before while the requirements also applies to non assumed-rank descriptors. This change required special attention with IGNORE_TKR(t) to avoid emitting invalid fir.rebox operations (the actual argument type must be used in this case as the output type). Implementation of Fortran procedure with assumed-rank arguments is still TODO.
2024-01-25[flang] Lower struct ctor with character allocatable components (#79179)jeanPerier1-2/+14
There is no need to gather the length parameters from the parameter symbols when facing a deferred length allocatable components in a structure constructor, the length is set as part of the assignment given the value. Remove the checks for derived type runtime info symbols, this is not relevant for what is being tested here.
2023-12-19[flang] Lower procedure pointer components (#75453)jeanPerier1-0/+2
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-05[flang] Fix issue with lookup in the binding table (#74416)Valentin Clement (バレンタイン クレメン)1-7/+16
This patch is fixing two issue relative to the dynamic dispatch for polymorphic entities. 1. Fix the `requireDispatchCall` function. It was checking for the first symbol of the component but this is not the one to be checked. Instead the last symbol of the base of the component object is the one to check to know if it is polymorphic object with a dispatch call or not. This is demonstrated in the new added test in `flang/test/Lower/dispatch.f90` where the first symbol would point to `q` which is monomorphic and would result in a simple `fir.call` 2. Fix the pass object in a no pass situation. In a no pass situation the pass object is lowered anyway to be able to do the lookup in the binding table. It was previously lowered wrongly an lead to unresolved lookup. The base of the component is the passed object and should be lowered. To achieve this, the `gen(DataRef)` entry point is exposed form `ConvertExprToHLFIR` through a `convertDataRefToValue` function. The same test added in `flang/test/Lower/dispatch.f90` is checking for the correct passed object. In addition couple of tests were updated to HLFIR since the lowering used only works with it.
2023-11-23[Flang] Add partial support for lowering procedure pointer assignment. (#70461)Daniel Chen1-1/+3
**Scope of the PR:** 1. Lowering global and local procedure pointer declaration statement with explicit or implicit interface. The explicit interface can be from an interface block, a module procedure or an internal procedure. 2. Lowering procedure pointer assignment, where the target procedure could be external, module or internal procedures. 3. Lowering reference to procedure pointers so that it works end to end. **PR notes:** 1. The first commit of the PR does not include testing. I would like to collect some comments first, which may alter the output. Once I confirm the implementation, I will add some testing as a follow up commit to this PR. 2. No special handling of the host-associated entities when an internal procedure is the target of a procedure pointer assignment in this PR. **Implementation notes:** 1. The implementation is using the HLFIR path. 2. Flang currently uses `getUntypedBoxProcType` to get the `fir::BoxProcType` for `ProcedureDesignator` when getting the address of a procedure in order to pass it as an actual argument. This PR inherits the same design decision for procedure pointer as the `fir::StoreOp` requires the same memory type. Note: this commit is actually resubmitting the original commit from PR #70461 that was reverted. See PR #73221.
2023-11-23Revert "[Flang] Add partial support for lowering procedure pointer ↵Muhammad Omair Javaid1-3/+1
assignment. (#70461)" This reverts commit e07fec10ac208c2868a24c5c0be88e45778b297e. This change appears to have broken following buildbots: https://lab.llvm.org/buildbot/#/builders/176 https://lab.llvm.org/buildbot/#/builders/179 https://lab.llvm.org/buildbot/#/builders/184 https://lab.llvm.org/buildbot/#/builders/197 https://lab.llvm.org/buildbot/#/builders/198 All bots fails in testsuite where following tests seems broken: (eg: https://lab.llvm.org/buildbot/#/builders/176/builds/7131) test-suite::gfortran-regression-compile-regression__proc_ptr_46_f90.test test-suite::gfortran-regression-compile-regression__proc_ptr_37_f90.test
2023-11-22[Flang] Add partial support for lowering procedure pointer assignment. (#70461)Daniel Chen1-1/+3
**Scope of the PR:** 1. Lowering global and local procedure pointer declaration statement with explicit or implicit interface. The explicit interface can be from an interface block, a module procedure or an internal procedure. 2. Lowering procedure pointer assignment, where the target procedure could be external, module or internal procedures. 3. Lowering reference to procedure pointers so that it works end to end. **PR notes:** 1. The first commit of the PR does not include testing. I would like to collect some comments first, which may alter the output. Once I confirm the implementation, I will add some testing as a follow up commit to this PR. 2. No special handling of the host-associated entities when an internal procedure is the target of a procedure pointer assignment in this PR. **Implementation notes:** 1. The implementation is using the HLFIR path. 2. Flang currently uses `getUntypedBoxProcType` to get the `fir::BoxProcType` for `ProcedureDesignator` when getting the address of a procedure in order to pass it as an actual argument. This PR inherits the same design decision for procedure pointer as the `fir::StoreOp` requires the same memory type.
2023-10-27[flang] Move whole allocatable assignment implicit conversion to lowering ↵jeanPerier1-85/+36
(#70317) The front-end is making implicit conversions explicit in assignment and structure constructors. While this generally helps and is needed by semantics to fold structure constructors correctly, this is incorrect when the LHS or component is an allocatable. The RHS may have non default lower bounds that should be propagated to the LHS, and making the conversion explicit changes the semantics. In the structure constructor, the situation is even worse since Fortran 2018 7.5.10 point 7 allows the value to be a reference to an unallocated allocatable, and adding an explicit conversion in semantics will cause a segfault. This patch removes the explicit convert in semantics when the LHS/component is a whole allocatable, and update lowering to deal with the conversion insertion, dealing with preserving the lower bounds and the tricky structure constructor case.
2023-10-25[flang] Allow lowering of sub-expressions to be overridden (#69944)jeanPerier1-0/+11
OpenACC/OpenMP atomic lowering needs a finer control over expression lowering. This patch allows mapping evaluate::Expr<T> to mlir::Value so that any subsequent expression lowering will use these values when an operand is a mapped Expr<T>. This is an alternative to https://github.com/llvm/llvm-project/pull/69866 From which I took the test and some of the logic to extract the non-atomic sub-expression. --------- Co-authored-by: Nimish Mishra <neelam.nimish@gmail.com>
2023-10-20[flang][hlfir] Make the parent type the first component (#69348)jeanPerier1-78/+54
Type extension is currently handled in FIR by inlining the parents components as the first member of the record type. This is not correct from a memory layout point of view since the storage size of the parent type may be bigger than the sum of the size of its component (due to alignment requirement). To avoid making FIR types target dependent and fix this issue, make the parent component a single component with the parent type at the beginning of the record type. This also simplifies addressing since parent component is now a "normal" component that can be designated with hlfir.designate. StructureComponent lowering however is a bit more complex since the symbols in the structure component may refer to subcomponents of parent types. Notes: 1. The fix is only done in HLFIR for now, a similar fix should be done in ConvertExpr.cpp to fix the path without HLFIR (I will likely still do it in a new patch since it would be an annoying bug to investigate for people testing flang without HLFIR). 2. The private component extra mangling is useless after this patch. I will remove it after 1. 3. The "parent component" TODO in constant CTOR is free to implement for HLFIR after this patch, but I would rather remove it and test it in a different patch.
2023-10-16[flang] Regularize TODO messages for coarray related features (#69227)Pete Steinfeld1-2/+2
I want to make "not yet implemented" messages for features related to coarrays easy to identify and make them easy for users to read.
2023-10-09[flang][hlfir] address char_convert issues as mentioned in #64315 (#67570)Anthony Cabrera1-3/+6
As shown in #64315, there were issues when trying to lower two flavors of Fortran code that implicitly perform `CHARACTER` conversion. This PR addresses those issues.
2023-09-18[flang] Lower PRIVATE component names safely (#66076)jeanPerier1-2/+2
It is possible for a derived type extending a type with private components to define components with the same name as the private components. This was not properly handled by lowering where several fir.record type component names could end-up being the same, leading to bad generated code (only the first component was accessed via fir.field_index, leading to bad generated code). This patch handles the situation by adding the derived type mangled name to private component.
2023-09-07[flang][hlfir] Lower Cray pointee references. (#65563)Slava Zakharin1-1/+30
A Cray pointee reference must be done using the characteristics (bounds, type params) of the original pointee declaration, but using the actual address value of the associated Cray pointer. There might be multiple Cray pointees associated with the same Cray pointer. The proposed solution is to lower each Cray pointee into a POINTER variable with a descriptor. The descriptor is initialized at the point of declaration of the pointee, though its base_addr is set to null. Before each reference of the Cray pointee its descriptor's base_addr is updated to the current value of the Cray pointer. The update of the base_addr is done using PointerAssociateScalar runtime call, which just updates the base_addr of the descriptor. This is a temporary solution just to make Cray pointers work to the same extent they work with FIR lowering.
2023-08-29[flang] Support SELECT RANK on allocatables & pointersPeter Klausler1-4/+4
Unlike other executable constructs with associating selectors, the selector of a SELECT RANK construct can have the ALLOCATABLE or POINTER attribute, and will work as an allocatable or object pointer within each rank case, so long as there is no RANK(*) case. Getting this right exposed a correctness risk with the popular predicate IsAllocatableOrPointer() -- it will be true for procedure pointers as well as object pointers, and in many contexts, a procedure pointer should not be acceptable. So this patch adds the new predicate IsAllocatableOrObjectPointer(), and updates some call sites of the original function to use the new one. Differential Revision: https://reviews.llvm.org/D159043