[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / flang / runtime / allocator-registry.cpp
blobf5670331d6dbe2375b505379c7e4170f9ddc8688
1 //===-- runtime/allocator-registry.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 //===----------------------------------------------------------------------===//
9 #include "flang/Runtime/allocator-registry.h"
10 #include "terminator.h"
12 namespace Fortran::runtime {
14 #ifndef FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
15 RT_OFFLOAD_VAR_GROUP_BEGIN
16 RT_VAR_ATTRS AllocatorRegistry allocatorRegistry;
17 RT_OFFLOAD_VAR_GROUP_END
18 #endif // FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS
20 RT_OFFLOAD_API_GROUP_BEGIN
21 RT_API_ATTRS void AllocatorRegistry::Register(int pos, Allocator_t allocator) {
22 // pos 0 is reserved for the default allocator and is registered in the
23 // struct ctor.
24 INTERNAL_CHECK(pos > 0 && pos < MAX_ALLOCATOR);
25 allocators[pos] = allocator;
28 RT_API_ATTRS AllocFct AllocatorRegistry::GetAllocator(int pos) {
29 INTERNAL_CHECK(pos >= 0 && pos < MAX_ALLOCATOR);
30 AllocFct f{allocators[pos].alloc};
31 INTERNAL_CHECK(f != nullptr);
32 return f;
35 RT_API_ATTRS FreeFct AllocatorRegistry::GetDeallocator(int pos) {
36 INTERNAL_CHECK(pos >= 0 && pos < MAX_ALLOCATOR);
37 FreeFct f{allocators[pos].free};
38 INTERNAL_CHECK(f != nullptr);
39 return f;
41 RT_OFFLOAD_API_GROUP_END
42 } // namespace Fortran::runtime