brintos

brintos / llvm-project-archived public Read only

0
0
Text · 884 B · 7c90ff1 Raw
26 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "lld/Common/Memory.h"10#include "lld/Common/CommonLinkerContext.h"11 12using namespace llvm;13using namespace lld;14 15SpecificAllocBase *16lld::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