12017d52bSRui Ueyama //===- Memory.cpp ---------------------------------------------------------===// 22017d52bSRui Ueyama // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 62017d52bSRui Ueyama // 72017d52bSRui Ueyama //===----------------------------------------------------------------------===// 82017d52bSRui Ueyama 92017d52bSRui Ueyama #include "lld/Common/Memory.h" 10*83d59e05SAlexandre Ganea #include "lld/Common/CommonLinkerContext.h" 112017d52bSRui Ueyama 122017d52bSRui Ueyama using namespace llvm; 132017d52bSRui Ueyama using namespace lld; 142017d52bSRui Ueyama 15*83d59e05SAlexandre Ganea SpecificAllocBase * getOrCreate(void * tag,size_t size,size_t align,SpecificAllocBase * (& creator)(void *))16*83d59e05SAlexandre Ganealld::SpecificAllocBase::getOrCreate(void *tag, size_t size, size_t align, 17*83d59e05SAlexandre Ganea SpecificAllocBase *(&creator)(void *)) { 18*83d59e05SAlexandre Ganea auto &instances = context().instances; 19*83d59e05SAlexandre Ganea auto &instance = instances[tag]; 20*83d59e05SAlexandre Ganea if (instance == nullptr) { 21*83d59e05SAlexandre Ganea void *storage = context().bAlloc.Allocate(size, align); 22*83d59e05SAlexandre Ganea instance = creator(storage); 23*83d59e05SAlexandre Ganea } 24*83d59e05SAlexandre Ganea return instance; 252017d52bSRui Ueyama } 26