1 //===-- LowLevelIntrinsics.cpp --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
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(),
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(),
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(),
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
);
62 fir::factory::getLlvmGetRounding(fir::FirOpBuilder
&builder
) {
63 auto int32Ty
= builder
.getIntegerType(32);
65 mlir::FunctionType::get(builder
.getContext(), std::nullopt
, {int32Ty
});
66 return builder
.createFunction(builder
.getUnknownLoc(), "llvm.get.rounding",
71 fir::factory::getLlvmSetRounding(fir::FirOpBuilder
&builder
) {
72 auto int32Ty
= builder
.getIntegerType(32);
74 mlir::FunctionType::get(builder
.getContext(), {int32Ty
}, std::nullopt
);
75 return builder
.createFunction(builder
.getUnknownLoc(), "llvm.set.rounding",
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",
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);
99 mlir::FunctionType::get(builder
.getContext(), {int32Ty
}, {int32Ty
});
100 return builder
.createFunction(builder
.getUnknownLoc(), "feclearexcept",
105 fir::factory::getFedisableexcept(fir::FirOpBuilder
&builder
) {
106 auto int32Ty
= builder
.getIntegerType(32);
108 mlir::FunctionType::get(builder
.getContext(), {int32Ty
}, {int32Ty
});
109 return builder
.createFunction(builder
.getUnknownLoc(), "fedisableexcept",
113 mlir::func::FuncOp
fir::factory::getFeenableexcept(fir::FirOpBuilder
&builder
) {
114 auto int32Ty
= builder
.getIntegerType(32);
116 mlir::FunctionType::get(builder
.getContext(), {int32Ty
}, {int32Ty
});
117 return builder
.createFunction(builder
.getUnknownLoc(), "feenableexcept",
121 mlir::func::FuncOp
fir::factory::getFegetexcept(fir::FirOpBuilder
&builder
) {
122 auto int32Ty
= builder
.getIntegerType(32);
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);
131 mlir::FunctionType::get(builder
.getContext(), {int32Ty
}, {int32Ty
});
132 return builder
.createFunction(builder
.getUnknownLoc(), "feraiseexcept",
136 mlir::func::FuncOp
fir::factory::getFetestexcept(fir::FirOpBuilder
&builder
) {
137 auto int32Ty
= builder
.getIntegerType(32);
139 mlir::FunctionType::get(builder
.getContext(), {int32Ty
}, {int32Ty
});
140 return builder
.createFunction(builder
.getUnknownLoc(), "fetestexcept",