1 //===-- runtime/allocator-registry.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 #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
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);
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);
41 RT_OFFLOAD_API_GROUP_END
42 } // namespace Fortran::runtime