1 //===-- Lower/IntrinsicCall.h -- lowering of intrinsics ---------*- 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 #ifndef FORTRAN_LOWER_INTRINSICCALL_H 10 #define FORTRAN_LOWER_INTRINSICCALL_H 11 12 #include "flang/Lower/FIRBuilder.h" 13 14 namespace fir { 15 class ExtendedValue; 16 } 17 18 namespace Fortran::lower { 19 20 // TODO: Expose interface to get specific intrinsic function address. 21 // TODO: Handle intrinsic subroutine. 22 // TODO: Intrinsics that do not require their arguments to be defined 23 // (e.g shape inquiries) might not fit in the current interface that 24 // requires mlir::Value to be provided. 25 // TODO: Error handling interface ? 26 // TODO: Implementation is incomplete. Many intrinsics to tbd. 27 28 /// Helper for building calls to intrinsic functions in the runtime support 29 /// libraries. 30 31 /// Generate the FIR+MLIR operations for the generic intrinsic \p name 32 /// with arguments \p args and expected result type \p resultType. 33 /// Returned mlir::Value is the returned Fortran intrinsic value. 34 fir::ExtendedValue genIntrinsicCall(FirOpBuilder &, mlir::Location, 35 llvm::StringRef name, mlir::Type resultType, 36 llvm::ArrayRef<fir::ExtendedValue> args); 37 38 /// Get SymbolRefAttr of runtime (or wrapper function containing inlined 39 // implementation) of an unrestricted intrinsic (defined by its signature 40 // and generic name) 41 mlir::SymbolRefAttr 42 getUnrestrictedIntrinsicSymbolRefAttr(FirOpBuilder &, mlir::Location, 43 llvm::StringRef name, 44 mlir::FunctionType signature); 45 46 //===--------------------------------------------------------------------===// 47 // Direct access to intrinsics that may be used by lowering outside 48 // of intrinsic call lowering. 49 //===--------------------------------------------------------------------===// 50 51 /// Generate maximum. There must be at least one argument and all arguments 52 /// must have the same type. 53 mlir::Value genMax(FirOpBuilder &, mlir::Location, 54 llvm::ArrayRef<mlir::Value> args); 55 56 /// Generate minimum. Same constraints as genMax. 57 mlir::Value genMin(FirOpBuilder &, mlir::Location, 58 llvm::ArrayRef<mlir::Value> args); 59 60 /// Generate power function x**y with given the expected 61 /// result type. 62 mlir::Value genPow(FirOpBuilder &, mlir::Location, mlir::Type resultType, 63 mlir::Value x, mlir::Value y); 64 65 } // namespace Fortran::lower 66 67 #endif // FORTRAN_LOWER_INTRINSICCALL_H 68