Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / lld / Common / CommonLinkerContext.cpp
blob12f56bc10ec963153b760861b697d5345166f078
1 //===- CommonLinkerContext.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 //===----------------------------------------------------------------------===//
9 #include "lld/Common/CommonLinkerContext.h"
10 #include "lld/Common/ErrorHandler.h"
11 #include "lld/Common/Memory.h"
13 #include "llvm/CodeGen/CommandFlags.h"
15 using namespace llvm;
16 using namespace lld;
18 // Reference to the current LLD instance. This is a temporary situation, until
19 // we pass this context everywhere by reference, or we make it a thread_local,
20 // as in https://reviews.llvm.org/D108850?id=370678 where each thread can be
21 // associated with a LLD instance. Only then will LLD be free of global
22 // state.
23 static CommonLinkerContext *lctx;
25 CommonLinkerContext::CommonLinkerContext() {
26 lctx = this;
27 // Fire off the static initializations in CGF's constructor.
28 codegen::RegisterCodeGenFlags CGF;
31 CommonLinkerContext::~CommonLinkerContext() {
32 assert(lctx);
33 // Explicitly call the destructors since we created the objects with placement
34 // new in SpecificAlloc::create().
35 for (auto &it : instances)
36 it.second->~SpecificAllocBase();
37 lctx = nullptr;
40 CommonLinkerContext &lld::commonContext() {
41 assert(lctx);
42 return *lctx;
45 bool lld::hasContext() { return lctx != nullptr; }
47 void CommonLinkerContext::destroy() {
48 if (lctx == nullptr)
49 return;
50 delete lctx;