Path: blob/main/contrib/llvm-project/llvm/lib/IR/GCStrategy.cpp
35234 views
//===- GCStrategy.cpp - Garbage Collector Description ---------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements the policy object GCStrategy which describes the9// behavior of a given garbage collector.10//11//===----------------------------------------------------------------------===//1213#include "llvm/IR/GCStrategy.h"14#include "llvm/ADT/Twine.h"15#include "llvm/IR/BuiltinGCs.h"1617using namespace llvm;1819LLVM_INSTANTIATE_REGISTRY(GCRegistry)2021GCStrategy::GCStrategy() = default;2223std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) {24for (auto &S : GCRegistry::entries())25if (S.getName() == Name)26return S.instantiate();2728// We need to link all the builtin GCs when LLVM is used as a static library.29// The linker will quite happily remove the static constructors that register30// the builtin GCs if we don't use a function from that object. This function31// does nothing but we need to make sure it is (or at least could be, even32// with all optimisations enabled) called *somewhere*, and this is a good33// place to do that: if the GC strategies are being used then this function34// obviously can't be removed by the linker, and here it won't affect35// performance, since there's about to be a fatal error anyway.36llvm::linkAllBuiltinGCs();3738if (GCRegistry::begin() == GCRegistry::end()) {39// In normal operation, the registry should not be empty. There should40// be the builtin GCs if nothing else. The most likely scenario here is41// that we got here without running the initializers used by the Registry42// itself and it's registration mechanism.43const std::string error =44std::string("unsupported GC: ") + Name.str() +45" (did you remember to link and initialize the library?)";46report_fatal_error(Twine(error));47} else48report_fatal_error(Twine(std::string("unsupported GC: ") + Name.str()));49}505152