43 lines · cpp
1//===-- lib/runtime/allocator-registry.cpp ----------------------*- C++ -*-===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "flang-rt/runtime/allocator-registry.h"10#include "flang-rt/runtime/terminator.h"11 12namespace Fortran::runtime {13 14#ifndef FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS15RT_OFFLOAD_VAR_GROUP_BEGIN16RT_VAR_ATTRS AllocatorRegistry allocatorRegistry;17RT_OFFLOAD_VAR_GROUP_END18#endif // FLANG_RUNTIME_NO_GLOBAL_VAR_DEFS19 20RT_OFFLOAD_API_GROUP_BEGIN21RT_API_ATTRS void AllocatorRegistry::Register(int pos, Allocator_t allocator) {22 // pos 0 is reserved for the default allocator and is registered in the23 // struct ctor.24 INTERNAL_CHECK(pos > 0 && pos < MAX_ALLOCATOR);25 allocators[pos] = allocator;26}27 28RT_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;33}34 35RT_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;40}41RT_OFFLOAD_API_GROUP_END42} // namespace Fortran::runtime43