1//===- FunctionCallUtils.h - Utilities for C function 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// This file declares helper functions to call common simple C functions in
10// LLVMIR (e.g. among others to support printing and debugging).
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_LLVMIR_FUNCTIONCALLUTILS_H_
15#define MLIR_DIALECT_LLVMIR_FUNCTIONCALLUTILS_H_
16
17#include "mlir/IR/Operation.h"
18#include "mlir/Support/LLVM.h"
19#include <optional>
20
21namespace mlir {
22class Location;
23class ModuleOp;
24class OpBuilder;
25class Operation;
26class Type;
27class ValueRange;
28
29namespace LLVM {
30class LLVMFuncOp;
31
32/// Helper functions to lookup or create the declaration for commonly used
33/// external C function calls. The list of functions provided here must be
34/// implemented separately (e.g. as part of a support runtime library or as part
35/// of the libc).
36LLVM::LLVMFuncOp lookupOrCreatePrintI64Fn(ModuleOp moduleOp);
37LLVM::LLVMFuncOp lookupOrCreatePrintU64Fn(ModuleOp moduleOp);
38LLVM::LLVMFuncOp lookupOrCreatePrintF16Fn(ModuleOp moduleOp);
39LLVM::LLVMFuncOp lookupOrCreatePrintBF16Fn(ModuleOp moduleOp);
40LLVM::LLVMFuncOp lookupOrCreatePrintF32Fn(ModuleOp moduleOp);
41LLVM::LLVMFuncOp lookupOrCreatePrintF64Fn(ModuleOp moduleOp);
42/// Declares a function to print a C-string.
43/// If a custom runtime function is defined via `runtimeFunctionName`, it must
44/// have the signature void(char const*). The default function is `printString`.
45LLVM::LLVMFuncOp
46lookupOrCreatePrintStringFn(ModuleOp moduleOp,
47 std::optional<StringRef> runtimeFunctionName = {});
48LLVM::LLVMFuncOp lookupOrCreatePrintOpenFn(ModuleOp moduleOp);
49LLVM::LLVMFuncOp lookupOrCreatePrintCloseFn(ModuleOp moduleOp);
50LLVM::LLVMFuncOp lookupOrCreatePrintCommaFn(ModuleOp moduleOp);
51LLVM::LLVMFuncOp lookupOrCreatePrintNewlineFn(ModuleOp moduleOp);
52LLVM::LLVMFuncOp lookupOrCreateMallocFn(ModuleOp moduleOp, Type indexType);
53LLVM::LLVMFuncOp lookupOrCreateAlignedAllocFn(ModuleOp moduleOp,
54 Type indexType);
55LLVM::LLVMFuncOp lookupOrCreateFreeFn(ModuleOp moduleOp);
56LLVM::LLVMFuncOp lookupOrCreateGenericAllocFn(ModuleOp moduleOp,
57 Type indexType);
58LLVM::LLVMFuncOp lookupOrCreateGenericAlignedAllocFn(ModuleOp moduleOp,
59 Type indexType);
60LLVM::LLVMFuncOp lookupOrCreateGenericFreeFn(ModuleOp moduleOp);
61LLVM::LLVMFuncOp lookupOrCreateMemRefCopyFn(ModuleOp moduleOp, Type indexType,
62 Type unrankedDescriptorType);
63
64/// Create a FuncOp with signature `resultType`(`paramTypes`)` and name `name`.
65LLVM::LLVMFuncOp lookupOrCreateFn(ModuleOp moduleOp, StringRef name,
66 ArrayRef<Type> paramTypes = {},
67 Type resultType = {}, bool isVarArg = false);
68
69} // namespace LLVM
70} // namespace mlir
71
72#endif // MLIR_DIALECT_LLVMIR_FUNCTIONCALLUTILS_H_
73

source code of mlir/include/mlir/Dialect/LLVMIR/FunctionCallUtils.h