MLIR  20.0.0git
FunctionCallUtils.h
Go to the documentation of this file.
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 
21 namespace mlir {
22 class Location;
23 class ModuleOp;
24 class OpBuilder;
25 class Operation;
26 class Type;
27 class ValueRange;
28 
29 namespace LLVM {
30 class 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).
36 LLVM::LLVMFuncOp lookupOrCreatePrintI64Fn(Operation *moduleOp);
37 LLVM::LLVMFuncOp lookupOrCreatePrintU64Fn(Operation *moduleOp);
38 LLVM::LLVMFuncOp lookupOrCreatePrintF16Fn(Operation *moduleOp);
39 LLVM::LLVMFuncOp lookupOrCreatePrintBF16Fn(Operation *moduleOp);
40 LLVM::LLVMFuncOp lookupOrCreatePrintF32Fn(Operation *moduleOp);
41 LLVM::LLVMFuncOp lookupOrCreatePrintF64Fn(Operation *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`.
45 LLVM::LLVMFuncOp
46 lookupOrCreatePrintStringFn(Operation *moduleOp,
47  std::optional<StringRef> runtimeFunctionName = {});
48 LLVM::LLVMFuncOp lookupOrCreatePrintOpenFn(Operation *moduleOp);
49 LLVM::LLVMFuncOp lookupOrCreatePrintCloseFn(Operation *moduleOp);
50 LLVM::LLVMFuncOp lookupOrCreatePrintCommaFn(Operation *moduleOp);
51 LLVM::LLVMFuncOp lookupOrCreatePrintNewlineFn(Operation *moduleOp);
52 LLVM::LLVMFuncOp lookupOrCreateMallocFn(Operation *moduleOp, Type indexType);
53 LLVM::LLVMFuncOp lookupOrCreateAlignedAllocFn(Operation *moduleOp,
54  Type indexType);
55 LLVM::LLVMFuncOp lookupOrCreateFreeFn(Operation *moduleOp);
56 LLVM::LLVMFuncOp lookupOrCreateGenericAllocFn(Operation *moduleOp,
57  Type indexType);
58 LLVM::LLVMFuncOp lookupOrCreateGenericAlignedAllocFn(Operation *moduleOp,
59  Type indexType);
60 LLVM::LLVMFuncOp lookupOrCreateGenericFreeFn(Operation *moduleOp);
61 LLVM::LLVMFuncOp lookupOrCreateMemRefCopyFn(Operation *moduleOp, Type indexType,
62  Type unrankedDescriptorType);
63 
64 /// Create a FuncOp with signature `resultType`(`paramTypes`)` and name `name`.
65 LLVM::LLVMFuncOp lookupOrCreateFn(Operation *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_
LLVM::LLVMFuncOp lookupOrCreateMemRefCopyFn(Operation *moduleOp, Type indexType, Type unrankedDescriptorType)
LLVM::LLVMFuncOp lookupOrCreatePrintNewlineFn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreateFreeFn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreateGenericFreeFn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreatePrintI64Fn(Operation *moduleOp)
Helper functions to lookup or create the declaration for commonly used external C function calls.
LLVM::LLVMFuncOp lookupOrCreatePrintOpenFn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreateAlignedAllocFn(Operation *moduleOp, Type indexType)
LLVM::LLVMFuncOp lookupOrCreateGenericAllocFn(Operation *moduleOp, Type indexType)
LLVM::LLVMFuncOp lookupOrCreateGenericAlignedAllocFn(Operation *moduleOp, Type indexType)
LLVM::LLVMFuncOp lookupOrCreatePrintStringFn(Operation *moduleOp, std::optional< StringRef > runtimeFunctionName={})
Declares a function to print a C-string.
LLVM::LLVMFuncOp lookupOrCreateFn(Operation *moduleOp, StringRef name, ArrayRef< Type > paramTypes={}, Type resultType={}, bool isVarArg=false)
Create a FuncOp with signature resultType(paramTypes)and namename`.
LLVM::LLVMFuncOp lookupOrCreatePrintBF16Fn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreatePrintF16Fn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreatePrintF32Fn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreatePrintCloseFn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreateMallocFn(Operation *moduleOp, Type indexType)
LLVM::LLVMFuncOp lookupOrCreatePrintF64Fn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreatePrintCommaFn(Operation *moduleOp)
LLVM::LLVMFuncOp lookupOrCreatePrintU64Fn(Operation *moduleOp)
@ Type
An inlay hint that for a type annotation.
Include the generated interface declarations.