1 //===- GCStrategy.cpp - Garbage Collector Description ---------------------===// 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 // This file implements the policy object GCStrategy which describes the 10 // behavior of a given garbage collector. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/IR/GCStrategy.h" 15 #include "llvm/ADT/Twine.h" 16 17 using namespace llvm; 18 19 LLVM_INSTANTIATE_REGISTRY(GCRegistry) 20 21 GCStrategy::GCStrategy() = default; 22 23 std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) { 24 for (auto &S : GCRegistry::entries()) 25 if (S.getName() == Name) 26 return S.instantiate(); 27 28 if (GCRegistry::begin() == GCRegistry::end()) { 29 // In normal operation, the registry should not be empty. There should 30 // be the builtin GCs if nothing else. The most likely scenario here is 31 // that we got here without running the initializers used by the Registry 32 // itself and it's registration mechanism. 33 const std::string error = 34 std::string("unsupported GC: ") + Name.str() + 35 " (did you remember to link and initialize the library?)"; 36 report_fatal_error(Twine(error)); 37 } else 38 report_fatal_error(Twine(std::string("unsupported GC: ") + Name.str())); 39 } 40