1 //===-- ConvertCall.h -- lowering of calls ----------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ 10 // 11 //===----------------------------------------------------------------------===// 12 /// 13 /// Implements the conversion from evaluate::ProcedureRef to FIR. 14 /// 15 //===----------------------------------------------------------------------===// 16 17 #ifndef FORTRAN_LOWER_CONVERTCALL_H 18 #define FORTRAN_LOWER_CONVERTCALL_H 19 20 #include "flang/Lower/AbstractConverter.h" 21 #include "flang/Lower/CallInterface.h" 22 #include "flang/Optimizer/Builder/HLFIRTools.h" 23 #include <optional> 24 25 namespace Fortran::lower { 26 27 /// Data structure packaging the SSA value(s) produced for the result of lowered 28 /// function calls. 29 using LoweredResult = 30 std::variant<fir::ExtendedValue, hlfir::EntityWithAttributes>; 31 32 /// Given a call site for which the arguments were already lowered, generate 33 /// the call and return the result. This function deals with explicit result 34 /// allocation and lowering if needed. It also deals with passing the host 35 /// link to internal procedures. 36 /// \p isElemental must be set to true if elemental call is being produced. 37 /// It is only used for HLFIR. 38 /// The returned boolean indicates if finalization has been emitted in 39 /// \p stmtCtx for the result. 40 std::pair<LoweredResult, bool> genCallOpAndResult( 41 mlir::Location loc, Fortran::lower::AbstractConverter &converter, 42 Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx, 43 Fortran::lower::CallerInterface &caller, mlir::FunctionType callSiteType, 44 std::optional<mlir::Type> resultType, bool isElemental = false); 45 46 /// If \p arg is the address of a function with a denoted host-association tuple 47 /// argument, then return the host-associations tuple value of the current 48 /// procedure. Otherwise, return nullptr. 49 mlir::Value argumentHostAssocs(Fortran::lower::AbstractConverter &converter, 50 mlir::Value arg); 51 52 /// Is \p procRef an intrinsic module procedure that should be lowered as 53 /// intrinsic procedures (with Optimizer/Builder/IntrinsicCall.h)? 54 bool isIntrinsicModuleProcRef(const Fortran::evaluate::ProcedureRef &procRef); 55 56 /// Lower a ProcedureRef to HLFIR. If this is a function call, return the 57 /// lowered result value. Return nothing otherwise. 58 std::optional<hlfir::EntityWithAttributes> convertCallToHLFIR( 59 mlir::Location loc, Fortran::lower::AbstractConverter &converter, 60 const evaluate::ProcedureRef &procRef, std::optional<mlir::Type> resultType, 61 Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx); 62 63 void convertUserDefinedAssignmentToHLFIR( 64 mlir::Location loc, Fortran::lower::AbstractConverter &converter, 65 const evaluate::ProcedureRef &procRef, hlfir::Entity lhs, hlfir::Entity rhs, 66 Fortran::lower::SymMap &symMap); 67 } // namespace Fortran::lower 68 #endif // FORTRAN_LOWER_CONVERTCALL_H 69