10b57cec5SDimitry Andric //===- Memory.cpp ---------------------------------------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "lld/Common/Memory.h" 10*04eeddc0SDimitry Andric #include "lld/Common/CommonLinkerContext.h" 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric using namespace llvm; 130b57cec5SDimitry Andric using namespace lld; 140b57cec5SDimitry Andric 15*04eeddc0SDimitry Andric SpecificAllocBase * getOrCreate(void * tag,size_t size,size_t align,SpecificAllocBase * (& creator)(void *))16*04eeddc0SDimitry Andriclld::SpecificAllocBase::getOrCreate(void *tag, size_t size, size_t align, 17*04eeddc0SDimitry Andric SpecificAllocBase *(&creator)(void *)) { 18*04eeddc0SDimitry Andric auto &instances = context().instances; 19*04eeddc0SDimitry Andric auto &instance = instances[tag]; 20*04eeddc0SDimitry Andric if (instance == nullptr) { 21*04eeddc0SDimitry Andric void *storage = context().bAlloc.Allocate(size, align); 22*04eeddc0SDimitry Andric instance = creator(storage); 23*04eeddc0SDimitry Andric } 24*04eeddc0SDimitry Andric return instance; 250b57cec5SDimitry Andric } 26