[MemProf] Templatize CallStackRadixTreeBuilder (NFC) (#117014)
[llvm-project.git] / flang / lib / Optimizer / Builder / LowLevelIntrinsics.cpp
blob411a48614af6c874b99a536c48fc5ba929dec98f
1 //===-- LowLevelIntrinsics.cpp --------------------------------------------===//
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/
11 //===----------------------------------------------------------------------===//
13 // Low level intrinsic functions.
15 // These include LLVM intrinsic calls and standard C library calls.
16 // Target-specific calls, such as OS functions, should be factored in other
17 // file(s).
19 //===----------------------------------------------------------------------===//
21 #include "flang/Optimizer/Builder/LowLevelIntrinsics.h"
22 #include "flang/Optimizer/Builder/FIRBuilder.h"
24 mlir::func::FuncOp fir::factory::getLlvmMemcpy(fir::FirOpBuilder &builder) {
25 auto ptrTy = builder.getRefType(builder.getIntegerType(8));
26 llvm::SmallVector<mlir::Type> args = {ptrTy, ptrTy, builder.getI64Type(),
27 builder.getI1Type()};
28 auto memcpyTy =
29 mlir::FunctionType::get(builder.getContext(), args, std::nullopt);
30 return builder.createFunction(builder.getUnknownLoc(),
31 "llvm.memcpy.p0.p0.i64", memcpyTy);
34 mlir::func::FuncOp fir::factory::getLlvmMemmove(fir::FirOpBuilder &builder) {
35 auto ptrTy = builder.getRefType(builder.getIntegerType(8));
36 llvm::SmallVector<mlir::Type> args = {ptrTy, ptrTy, builder.getI64Type(),
37 builder.getI1Type()};
38 auto memmoveTy =
39 mlir::FunctionType::get(builder.getContext(), args, std::nullopt);
40 return builder.createFunction(builder.getUnknownLoc(),
41 "llvm.memmove.p0.p0.i64", memmoveTy);
44 mlir::func::FuncOp fir::factory::getLlvmMemset(fir::FirOpBuilder &builder) {
45 auto ptrTy = builder.getRefType(builder.getIntegerType(8));
46 llvm::SmallVector<mlir::Type> args = {ptrTy, ptrTy, builder.getI64Type(),
47 builder.getI1Type()};
48 auto memsetTy =
49 mlir::FunctionType::get(builder.getContext(), args, std::nullopt);
50 return builder.createFunction(builder.getUnknownLoc(),
51 "llvm.memset.p0.p0.i64", memsetTy);
54 mlir::func::FuncOp fir::factory::getRealloc(fir::FirOpBuilder &builder) {
55 auto ptrTy = builder.getRefType(builder.getIntegerType(8));
56 llvm::SmallVector<mlir::Type> args = {ptrTy, builder.getI64Type()};
57 auto reallocTy = mlir::FunctionType::get(builder.getContext(), args, {ptrTy});
58 return builder.createFunction(builder.getUnknownLoc(), "realloc", reallocTy);
61 mlir::func::FuncOp
62 fir::factory::getLlvmGetRounding(fir::FirOpBuilder &builder) {
63 auto int32Ty = builder.getIntegerType(32);
64 auto funcTy =
65 mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
66 return builder.createFunction(builder.getUnknownLoc(), "llvm.get.rounding",
67 funcTy);
70 mlir::func::FuncOp
71 fir::factory::getLlvmSetRounding(fir::FirOpBuilder &builder) {
72 auto int32Ty = builder.getIntegerType(32);
73 auto funcTy =
74 mlir::FunctionType::get(builder.getContext(), {int32Ty}, std::nullopt);
75 return builder.createFunction(builder.getUnknownLoc(), "llvm.set.rounding",
76 funcTy);
79 mlir::func::FuncOp
80 fir::factory::getLlvmInitTrampoline(fir::FirOpBuilder &builder) {
81 auto ptrTy = builder.getRefType(builder.getIntegerType(8));
82 auto funcTy = mlir::FunctionType::get(builder.getContext(),
83 {ptrTy, ptrTy, ptrTy}, std::nullopt);
84 return builder.createFunction(builder.getUnknownLoc(), "llvm.init.trampoline",
85 funcTy);
88 mlir::func::FuncOp
89 fir::factory::getLlvmAdjustTrampoline(fir::FirOpBuilder &builder) {
90 auto ptrTy = builder.getRefType(builder.getIntegerType(8));
91 auto funcTy = mlir::FunctionType::get(builder.getContext(), {ptrTy}, {ptrTy});
92 return builder.createFunction(builder.getUnknownLoc(),
93 "llvm.adjust.trampoline", funcTy);
96 mlir::func::FuncOp fir::factory::getFeclearexcept(fir::FirOpBuilder &builder) {
97 auto int32Ty = builder.getIntegerType(32);
98 auto funcTy =
99 mlir::FunctionType::get(builder.getContext(), {int32Ty}, {int32Ty});
100 return builder.createFunction(builder.getUnknownLoc(), "feclearexcept",
101 funcTy);
104 mlir::func::FuncOp
105 fir::factory::getFedisableexcept(fir::FirOpBuilder &builder) {
106 auto int32Ty = builder.getIntegerType(32);
107 auto funcTy =
108 mlir::FunctionType::get(builder.getContext(), {int32Ty}, {int32Ty});
109 return builder.createFunction(builder.getUnknownLoc(), "fedisableexcept",
110 funcTy);
113 mlir::func::FuncOp fir::factory::getFeenableexcept(fir::FirOpBuilder &builder) {
114 auto int32Ty = builder.getIntegerType(32);
115 auto funcTy =
116 mlir::FunctionType::get(builder.getContext(), {int32Ty}, {int32Ty});
117 return builder.createFunction(builder.getUnknownLoc(), "feenableexcept",
118 funcTy);
121 mlir::func::FuncOp fir::factory::getFegetexcept(fir::FirOpBuilder &builder) {
122 auto int32Ty = builder.getIntegerType(32);
123 auto funcTy =
124 mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
125 return builder.createFunction(builder.getUnknownLoc(), "fegetexcept", funcTy);
128 mlir::func::FuncOp fir::factory::getFeraiseexcept(fir::FirOpBuilder &builder) {
129 auto int32Ty = builder.getIntegerType(32);
130 auto funcTy =
131 mlir::FunctionType::get(builder.getContext(), {int32Ty}, {int32Ty});
132 return builder.createFunction(builder.getUnknownLoc(), "feraiseexcept",
133 funcTy);
136 mlir::func::FuncOp fir::factory::getFetestexcept(fir::FirOpBuilder &builder) {
137 auto int32Ty = builder.getIntegerType(32);
138 auto funcTy =
139 mlir::FunctionType::get(builder.getContext(), {int32Ty}, {int32Ty});
140 return builder.createFunction(builder.getUnknownLoc(), "fetestexcept",
141 funcTy);