xref: /freebsd/contrib/llvm-project/llvm/lib/IR/GCStrategy.cpp (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
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 
16 using namespace llvm;
17 
18 LLVM_INSTANTIATE_REGISTRY(GCRegistry)
19 
20 GCStrategy::GCStrategy() = default;
21 
22 std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) {
23   for (auto &S : GCRegistry::entries())
24     if (S.getName() == Name)
25       return S.instantiate();
26 
27   if (GCRegistry::begin() == GCRegistry::end()) {
28     // In normal operation, the registry should not be empty.  There should
29     // be the builtin GCs if nothing else.  The most likely scenario here is
30     // that we got here without running the initializers used by the Registry
31     // itself and it's registration mechanism.
32     const std::string error =
33         std::string("unsupported GC: ") + Name.str() +
34         " (did you remember to link and initialize the library?)";
35     report_fatal_error(error);
36   } else
37     report_fatal_error(std::string("unsupported GC: ") + Name.str());
38 }
39