• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// NOLINTNEXTLINE(readability-function-size)
17llvm::FunctionType *GetIntrinsicDeclaration(llvm::LLVMContext &ctx, ark::compiler::RuntimeInterface::IntrinsicId id)
18{
19    constexpr auto GC_SPACE = ark::llvmbackend::LLVMArkInterface::GC_ADDR_SPACE;
20    switch (id) {
21        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_FMOD:
22            return llvm::FunctionType::get(llvm::Type::getDoubleTy(ctx), {llvm::Type::getDoubleTy(ctx), llvm::Type::getDoubleTy(ctx)}, false);
23        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_FMODF:
24            return llvm::FunctionType::get(llvm::Type::getFloatTy(ctx), {llvm::Type::getFloatTy(ctx), llvm::Type::getFloatTy(ctx)}, false);
25        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_LDEXP:
26            return llvm::FunctionType::get(llvm::Type::getDoubleTy(ctx), {llvm::Type::getDoubleTy(ctx), llvm::Type::getInt32Ty(ctx)}, false);
27        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_LDEXPF:
28            return llvm::FunctionType::get(llvm::Type::getFloatTy(ctx), {llvm::Type::getFloatTy(ctx), llvm::Type::getInt32Ty(ctx)}, false);
29        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_EXP2:
30            return llvm::FunctionType::get(llvm::Type::getDoubleTy(ctx), {llvm::Type::getDoubleTy(ctx)}, false);
31        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_EXP2F:
32            return llvm::FunctionType::get(llvm::Type::getFloatTy(ctx), {llvm::Type::getFloatTy(ctx)}, false);
33        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEM_COPY:
34        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEM_MOVE:
35            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
36                {llvm::PointerType::get(ctx, 0), llvm::PointerType::get(ctx, 0), llvm::Type::getInt64Ty(ctx)}, false);
37        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEM_SET:
38            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
39                {llvm::PointerType::get(ctx, 0), llvm::Type::getInt8Ty(ctx), llvm::Type::getInt64Ty(ctx)}, false);
40        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEMSET_8:
41            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
42                {llvm::PointerType::get(ctx, GC_SPACE), llvm::Type::getInt8Ty(ctx), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx)}, false);
43        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEMSET_16:
44            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
45                {llvm::PointerType::get(ctx, GC_SPACE), llvm::Type::getInt16Ty(ctx), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx)}, false);
46        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEMSET_32:
47            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
48                {llvm::PointerType::get(ctx, GC_SPACE), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx)}, false);
49        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEMSET_64:
50            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
51                {llvm::PointerType::get(ctx, GC_SPACE), llvm::Type::getInt64Ty(ctx), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx)}, false);
52        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEMSET_F32:
53            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
54                {llvm::PointerType::get(ctx, GC_SPACE), llvm::Type::getFloatTy(ctx), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx)}, false);
55        case ark::compiler::RuntimeInterface::IntrinsicId::LIB_CALL_MEMSET_F64:
56            return llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
57                {llvm::PointerType::get(ctx, GC_SPACE), llvm::Type::getDoubleTy(ctx), llvm::Type::getInt32Ty(ctx), llvm::Type::getInt32Ty(ctx)}, false);
58% Runtime::intrinsics.each do |intrinsic|
59%   next unless intrinsic.respond_to?(:impl)
60        case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.enum_name %>:
61            return llvm::FunctionType::get(<%= llvm_type_getter(intrinsic.impl_signature.ret, 'GC_SPACE') %>,
62                       {<%= intrinsic.impl_signature.args.map { |t| llvm_type_getter(t, 'GC_SPACE') }.join(', ') %>}, false);
63% end
64        default:
65            ASSERT_DO(false, (std::cerr << "Cannot get intrinsic signature by IntrinsicId = " << static_cast<int>(id)
66                                        << std::endl));
67            UNREACHABLE();
68    }
69}
70