2017-02-27 22:45:06 +00:00
|
|
|
//===- GCStrategy.cpp - Garbage Collector Description ---------------------===//
|
Collector is the base class for garbage collection code generators.
This version enhances the previous patch to add root initialization
as discussed here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070910/053455.html
Collector gives its subclasses control over generic algorithms:
unsigned NeededSafePoints; //< Bitmask of required safe points.
bool CustomReadBarriers; //< Default is to insert loads.
bool CustomWriteBarriers; //< Default is to insert stores.
bool CustomRoots; //< Default is to pass through to backend.
bool InitRoots; //< If set, roots are nulled during lowering.
It also has callbacks which collectors can hook:
/// If any of the actions are set to Custom, this is expected to
/// be overriden to create a transform to lower those actions to
/// LLVM IR.
virtual Pass *createCustomLoweringPass() const;
/// beginAssembly/finishAssembly - Emit module metadata as
/// assembly code.
virtual void beginAssembly(Module &M, std::ostream &OS,
AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
virtual void finishAssembly(Module &M,
CollectorModuleMetadata &CMM,
std::ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
Various other independent algorithms could be implemented, but were
not necessary for the initial two collectors. Some examples are
listed here:
http://llvm.org/docs/GarbageCollection.html#collector-algos
llvm-svn: 42466
2007-09-29 02:13:43 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
Collector is the base class for garbage collection code generators.
This version enhances the previous patch to add root initialization
as discussed here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070910/053455.html
Collector gives its subclasses control over generic algorithms:
unsigned NeededSafePoints; //< Bitmask of required safe points.
bool CustomReadBarriers; //< Default is to insert loads.
bool CustomWriteBarriers; //< Default is to insert stores.
bool CustomRoots; //< Default is to pass through to backend.
bool InitRoots; //< If set, roots are nulled during lowering.
It also has callbacks which collectors can hook:
/// If any of the actions are set to Custom, this is expected to
/// be overriden to create a transform to lower those actions to
/// LLVM IR.
virtual Pass *createCustomLoweringPass() const;
/// beginAssembly/finishAssembly - Emit module metadata as
/// assembly code.
virtual void beginAssembly(Module &M, std::ostream &OS,
AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
virtual void finishAssembly(Module &M,
CollectorModuleMetadata &CMM,
std::ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
Various other independent algorithms could be implemented, but were
not necessary for the initial two collectors. Some examples are
listed here:
http://llvm.org/docs/GarbageCollection.html#collector-algos
llvm-svn: 42466
2007-09-29 02:13:43 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2015-01-15 19:29:42 +00:00
|
|
|
// This file implements the policy object GCStrategy which describes the
|
|
|
|
// behavior of a given garbage collector.
|
2008-08-17 18:44:35 +00:00
|
|
|
//
|
Collector is the base class for garbage collection code generators.
This version enhances the previous patch to add root initialization
as discussed here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070910/053455.html
Collector gives its subclasses control over generic algorithms:
unsigned NeededSafePoints; //< Bitmask of required safe points.
bool CustomReadBarriers; //< Default is to insert loads.
bool CustomWriteBarriers; //< Default is to insert stores.
bool CustomRoots; //< Default is to pass through to backend.
bool InitRoots; //< If set, roots are nulled during lowering.
It also has callbacks which collectors can hook:
/// If any of the actions are set to Custom, this is expected to
/// be overriden to create a transform to lower those actions to
/// LLVM IR.
virtual Pass *createCustomLoweringPass() const;
/// beginAssembly/finishAssembly - Emit module metadata as
/// assembly code.
virtual void beginAssembly(Module &M, std::ostream &OS,
AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
virtual void finishAssembly(Module &M,
CollectorModuleMetadata &CMM,
std::ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
Various other independent algorithms could be implemented, but were
not necessary for the initial two collectors. Some examples are
listed here:
http://llvm.org/docs/GarbageCollection.html#collector-algos
llvm-svn: 42466
2007-09-29 02:13:43 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-05-12 14:36:24 +07:00
|
|
|
#include "llvm/IR/GCStrategy.h"
|
2022-07-23 16:28:18 +02:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2022-12-22 21:29:58 +07:00
|
|
|
#include "llvm/IR/BuiltinGCs.h"
|
2015-01-25 15:05:36 +00:00
|
|
|
|
Collector is the base class for garbage collection code generators.
This version enhances the previous patch to add root initialization
as discussed here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070910/053455.html
Collector gives its subclasses control over generic algorithms:
unsigned NeededSafePoints; //< Bitmask of required safe points.
bool CustomReadBarriers; //< Default is to insert loads.
bool CustomWriteBarriers; //< Default is to insert stores.
bool CustomRoots; //< Default is to pass through to backend.
bool InitRoots; //< If set, roots are nulled during lowering.
It also has callbacks which collectors can hook:
/// If any of the actions are set to Custom, this is expected to
/// be overriden to create a transform to lower those actions to
/// LLVM IR.
virtual Pass *createCustomLoweringPass() const;
/// beginAssembly/finishAssembly - Emit module metadata as
/// assembly code.
virtual void beginAssembly(Module &M, std::ostream &OS,
AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
virtual void finishAssembly(Module &M,
CollectorModuleMetadata &CMM,
std::ostream &OS, AsmPrinter &AP,
const TargetAsmInfo &TAI) const;
Various other independent algorithms could be implemented, but were
not necessary for the initial two collectors. Some examples are
listed here:
http://llvm.org/docs/GarbageCollection.html#collector-algos
llvm-svn: 42466
2007-09-29 02:13:43 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2016-08-05 11:01:08 +00:00
|
|
|
LLVM_INSTANTIATE_REGISTRY(GCRegistry)
|
|
|
|
|
2017-02-27 22:45:06 +00:00
|
|
|
GCStrategy::GCStrategy() = default;
|
2021-08-02 12:00:56 +07:00
|
|
|
|
|
|
|
std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) {
|
|
|
|
for (auto &S : GCRegistry::entries())
|
|
|
|
if (S.getName() == Name)
|
|
|
|
return S.instantiate();
|
|
|
|
|
2022-12-22 21:29:58 +07:00
|
|
|
// We need to link all the builtin GCs when LLVM is used as a static library.
|
|
|
|
// The linker will quite happily remove the static constructors that register
|
|
|
|
// the builtin GCs if we don't use a function from that object. This function
|
|
|
|
// does nothing but we need to make sure it is (or at least could be, even
|
|
|
|
// with all optimisations enabled) called *somewhere*, and this is a good
|
|
|
|
// place to do that: if the GC strategies are being used then this function
|
|
|
|
// obviously can't be removed by the linker, and here it won't affect
|
|
|
|
// performance, since there's about to be a fatal error anyway.
|
|
|
|
llvm::linkAllBuiltinGCs();
|
|
|
|
|
2021-08-02 12:00:56 +07:00
|
|
|
if (GCRegistry::begin() == GCRegistry::end()) {
|
|
|
|
// In normal operation, the registry should not be empty. There should
|
|
|
|
// be the builtin GCs if nothing else. The most likely scenario here is
|
|
|
|
// that we got here without running the initializers used by the Registry
|
|
|
|
// itself and it's registration mechanism.
|
|
|
|
const std::string error =
|
|
|
|
std::string("unsupported GC: ") + Name.str() +
|
|
|
|
" (did you remember to link and initialize the library?)";
|
2022-07-23 16:28:18 +02:00
|
|
|
report_fatal_error(Twine(error));
|
2021-08-02 12:00:56 +07:00
|
|
|
} else
|
2022-07-23 16:28:18 +02:00
|
|
|
report_fatal_error(Twine(std::string("unsupported GC: ") + Name.str()));
|
2021-08-02 12:00:56 +07:00
|
|
|
}
|