1 //===- Memory.cpp ---------------------------------------------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lld/Common/Memory.h"
10 #include "lld/Common/CommonLinkerContext.h"
11 
12 using namespace llvm;
13 using namespace lld;
14 
15 SpecificAllocBase *
16 lld::SpecificAllocBase::getOrCreate(void *tag, size_t size, size_t align,
17                                     SpecificAllocBase *(&creator)(void *)) {
18   auto &instances = context().instances;
19   auto &instance = instances[tag];
20   if (instance == nullptr) {
21     void *storage = context().bAlloc.Allocate(size, align);
22     instance = creator(storage);
23   }
24   return instance;
25 }
26