1ece8a530Spatrick //===- Memory.cpp ---------------------------------------------------------===// 2ece8a530Spatrick // 3ece8a530Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4ece8a530Spatrick // See https://llvm.org/LICENSE.txt for license information. 5ece8a530Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ece8a530Spatrick // 7ece8a530Spatrick //===----------------------------------------------------------------------===// 8ece8a530Spatrick 9ece8a530Spatrick #include "lld/Common/Memory.h" 10*dfe94b16Srobert #include "lld/Common/CommonLinkerContext.h" 11ece8a530Spatrick 12ece8a530Spatrick using namespace llvm; 13ece8a530Spatrick using namespace lld; 14ece8a530Spatrick 15*dfe94b16Srobert SpecificAllocBase * getOrCreate(void * tag,size_t size,size_t align,SpecificAllocBase * (& creator)(void *))16*dfe94b16Srobertlld::SpecificAllocBase::getOrCreate(void *tag, size_t size, size_t align, 17*dfe94b16Srobert SpecificAllocBase *(&creator)(void *)) { 18*dfe94b16Srobert auto &instances = context().instances; 19*dfe94b16Srobert auto &instance = instances[tag]; 20*dfe94b16Srobert if (instance == nullptr) { 21*dfe94b16Srobert void *storage = context().bAlloc.Allocate(size, align); 22*dfe94b16Srobert instance = creator(storage); 23*dfe94b16Srobert } 24*dfe94b16Srobert return instance; 25ece8a530Spatrick } 26