2017-11-29 04:39:17 +08:00
|
|
|
//===- Memory.cpp ---------------------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-11-29 04:39:17 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lld/Common/Memory.h"
|
2022-01-21 03:53:18 +08:00
|
|
|
#include "lld/Common/CommonLinkerContext.h"
|
2017-11-29 04:39:17 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace lld;
|
|
|
|
|
2022-01-21 03:53:18 +08:00
|
|
|
SpecificAllocBase *
|
|
|
|
lld::SpecificAllocBase::getOrCreate(void *tag, size_t size, size_t align,
|
|
|
|
SpecificAllocBase *(&creator)(void *)) {
|
|
|
|
auto &instances = context().instances;
|
|
|
|
auto &instance = instances[tag];
|
|
|
|
if (instance == nullptr) {
|
|
|
|
void *storage = context().bAlloc.Allocate(size, align);
|
|
|
|
instance = creator(storage);
|
|
|
|
}
|
|
|
|
return instance;
|
2017-11-29 04:39:17 +08:00
|
|
|
}
|