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" 15*fcaf7f86SDimitry Andric #include "llvm/ADT/Twine.h" 16fe6060f1SDimitry Andric 17fe6060f1SDimitry Andric using namespace llvm; 18fe6060f1SDimitry Andric 19fe6060f1SDimitry Andric LLVM_INSTANTIATE_REGISTRY(GCRegistry) 20fe6060f1SDimitry Andric 21fe6060f1SDimitry Andric GCStrategy::GCStrategy() = default; 22349cc55cSDimitry Andric 23349cc55cSDimitry Andric std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) { 24349cc55cSDimitry Andric for (auto &S : GCRegistry::entries()) 25349cc55cSDimitry Andric if (S.getName() == Name) 26349cc55cSDimitry Andric return S.instantiate(); 27349cc55cSDimitry Andric 28349cc55cSDimitry Andric if (GCRegistry::begin() == GCRegistry::end()) { 29349cc55cSDimitry Andric // In normal operation, the registry should not be empty. There should 30349cc55cSDimitry Andric // be the builtin GCs if nothing else. The most likely scenario here is 31349cc55cSDimitry Andric // that we got here without running the initializers used by the Registry 32349cc55cSDimitry Andric // itself and it's registration mechanism. 33349cc55cSDimitry Andric const std::string error = 34349cc55cSDimitry Andric std::string("unsupported GC: ") + Name.str() + 35349cc55cSDimitry Andric " (did you remember to link and initialize the library?)"; 36*fcaf7f86SDimitry Andric report_fatal_error(Twine(error)); 37349cc55cSDimitry Andric } else 38*fcaf7f86SDimitry Andric report_fatal_error(Twine(std::string("unsupported GC: ") + Name.str())); 39349cc55cSDimitry Andric } 40