2015-01-08 03:13:28 +08:00
|
|
|
//===-- StatepointDefaultGC.cpp - The default statepoint GC strategy ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a GCStrategy which serves as an example for the usage
|
|
|
|
// of a statepoint based lowering strategy. This GCStrategy is intended to
|
|
|
|
// suitable as a default implementation usable with any collector which can
|
|
|
|
// consume the standard stackmap format generated by statepoints, uses the
|
|
|
|
// default addrespace to distinguish between gc managed and non-gc managed
|
2015-01-17 07:16:12 +08:00
|
|
|
// pointers, and has reasonable relocation semantics.
|
2015-01-08 03:13:28 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-01-27 02:26:35 +08:00
|
|
|
#include "llvm/CodeGen/GCStrategy.h"
|
2015-01-08 03:13:28 +08:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/IR/Value.h"
|
2015-01-08 03:13:28 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class StatepointGC : public GCStrategy {
|
|
|
|
public:
|
|
|
|
StatepointGC() {
|
|
|
|
UseStatepoints = true;
|
|
|
|
// These options are all gc.root specific, we specify them so that the
|
|
|
|
// gc.root lowering code doesn't run.
|
|
|
|
InitRoots = false;
|
|
|
|
NeededSafePoints = 0;
|
|
|
|
UsesMetadata = false;
|
|
|
|
CustomRoots = false;
|
|
|
|
}
|
|
|
|
Optional<bool> isGCManagedPointer(const Value *V) const override {
|
|
|
|
// Method is only valid on pointer typed values.
|
|
|
|
PointerType *PT = cast<PointerType>(V->getType());
|
|
|
|
// For the sake of this example GC, we arbitrarily pick addrspace(1) as our
|
|
|
|
// GC managed heap. We know that a pointer into this heap needs to be
|
2015-01-17 07:21:07 +08:00
|
|
|
// updated and that no other pointer does. Note that addrspace(1) is used
|
|
|
|
// only as an example, it has no special meaning, and is not reserved for
|
|
|
|
// GC usage.
|
2015-01-08 03:13:28 +08:00
|
|
|
return (1 == PT->getAddressSpace());
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2015-01-08 03:13:28 +08:00
|
|
|
|
2015-01-17 07:16:12 +08:00
|
|
|
static GCRegistry::Add<StatepointGC> X("statepoint-example",
|
|
|
|
"an example strategy for statepoint");
|
2015-01-08 03:13:28 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
void linkStatepointExampleGC() {}
|
|
|
|
}
|