xref: /freebsd/contrib/llvm-project/lld/Common/Memory.cpp (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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