1fe6060f1SDimitry Andric //===- GCStrategy.cpp - Garbage Collector Description ---------------------===// 2fe6060f1SDimitry Andric // 3fe6060f1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4fe6060f1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5fe6060f1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6fe6060f1SDimitry Andric // 7fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 8fe6060f1SDimitry Andric // 9fe6060f1SDimitry Andric // This file implements the policy object GCStrategy which describes the 10fe6060f1SDimitry Andric // behavior of a given garbage collector. 11fe6060f1SDimitry Andric // 12fe6060f1SDimitry Andric //===----------------------------------------------------------------------===// 13fe6060f1SDimitry Andric 14fe6060f1SDimitry Andric #include "llvm/IR/GCStrategy.h" 15fe6060f1SDimitry Andric 16fe6060f1SDimitry Andric using namespace llvm; 17fe6060f1SDimitry Andric 18fe6060f1SDimitry Andric LLVM_INSTANTIATE_REGISTRY(GCRegistry) 19fe6060f1SDimitry Andric 20fe6060f1SDimitry Andric GCStrategy::GCStrategy() = default; 21*349cc55cSDimitry Andric 22*349cc55cSDimitry Andric std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) { 23*349cc55cSDimitry Andric for (auto &S : GCRegistry::entries()) 24*349cc55cSDimitry Andric if (S.getName() == Name) 25*349cc55cSDimitry Andric return S.instantiate(); 26*349cc55cSDimitry Andric 27*349cc55cSDimitry Andric if (GCRegistry::begin() == GCRegistry::end()) { 28*349cc55cSDimitry Andric // In normal operation, the registry should not be empty. There should 29*349cc55cSDimitry Andric // be the builtin GCs if nothing else. The most likely scenario here is 30*349cc55cSDimitry Andric // that we got here without running the initializers used by the Registry 31*349cc55cSDimitry Andric // itself and it's registration mechanism. 32*349cc55cSDimitry Andric const std::string error = 33*349cc55cSDimitry Andric std::string("unsupported GC: ") + Name.str() + 34*349cc55cSDimitry Andric " (did you remember to link and initialize the library?)"; 35*349cc55cSDimitry Andric report_fatal_error(error); 36*349cc55cSDimitry Andric } else 37*349cc55cSDimitry Andric report_fatal_error(std::string("unsupported GC: ") + Name.str()); 38*349cc55cSDimitry Andric } 39