Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/BuiltinGCs.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- BuiltinGCs.cpp - Boilerplate for our built in GC types -------------===//
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 contains the boilerplate required to define our various built in
10
// gc lowering strategies.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "llvm/CodeGen/BuiltinGCs.h"
15
#include "llvm/CodeGen/GCStrategy.h"
16
#include "llvm/IR/DerivedTypes.h"
17
#include "llvm/Support/Casting.h"
18
19
using namespace llvm;
20
21
namespace {
22
23
/// An example GC which attempts to be compatibile with Erlang/OTP garbage
24
/// collector.
25
///
26
/// The frametable emitter is in ErlangGCPrinter.cpp.
27
class ErlangGC : public GCStrategy {
28
public:
29
3
  ErlangGC() {
30
3
    NeededSafePoints = true;
31
3
    UsesMetadata = true;
32
3
  }
33
};
34
35
/// An example GC which attempts to be compatible with Objective Caml 3.10.0
36
///
37
/// The frametable emitter is in OcamlGCPrinter.cpp.
38
class OcamlGC : public GCStrategy {
39
public:
40
3
  OcamlGC() {
41
3
    NeededSafePoints = true;
42
3
    UsesMetadata = true;
43
3
  }
44
};
45
46
/// A GC strategy for uncooperative targets.  This implements lowering for the
47
/// llvm.gc* intrinsics for targets that do not natively support them (which
48
/// includes the C backend). Note that the code generated is not quite as
49
/// efficient as algorithms which generate stack maps to identify roots.
50
///
51
/// In order to support this particular transformation, all stack roots are
52
/// coallocated in the stack. This allows a fully target-independent stack map
53
/// while introducing only minor runtime overhead.
54
class ShadowStackGC : public GCStrategy {
55
public:
56
2
  ShadowStackGC() {}
57
};
58
59
/// A GCStrategy which serves as an example for the usage of a statepoint based
60
/// lowering strategy.  This GCStrategy is intended to suitable as a default
61
/// implementation usable with any collector which can consume the standard
62
/// stackmap format generated by statepoints, uses the default addrespace to
63
/// distinguish between gc managed and non-gc managed pointers, and has
64
/// reasonable relocation semantics.
65
class StatepointGC : public GCStrategy {
66
public:
67
16
  StatepointGC() {
68
16
    UseStatepoints = true;
69
16
    // These options are all gc.root specific, we specify them so that the
70
16
    // gc.root lowering code doesn't run.
71
16
    NeededSafePoints = false;
72
16
    UsesMetadata = false;
73
16
  }
74
75
0
  Optional<bool> isGCManagedPointer(const Type *Ty) const override {
76
0
    // Method is only valid on pointer typed values.
77
0
    const PointerType *PT = cast<PointerType>(Ty);
78
0
    // For the sake of this example GC, we arbitrarily pick addrspace(1) as our
79
0
    // GC managed heap.  We know that a pointer into this heap needs to be
80
0
    // updated and that no other pointer does.  Note that addrspace(1) is used
81
0
    // only as an example, it has no special meaning, and is not reserved for
82
0
    // GC usage.
83
0
    return (1 == PT->getAddressSpace());
84
0
  }
85
};
86
87
/// A GCStrategy for the CoreCLR Runtime. The strategy is similar to
88
/// Statepoint-example GC, but differs from it in certain aspects, such as:
89
/// 1) Base-pointers need not be explicitly tracked and reported for
90
///    interior pointers
91
/// 2) Uses a different format for encoding stack-maps
92
/// 3) Location of Safe-point polls: polls are only needed before loop-back
93
///    edges and before tail-calls (not needed at function-entry)
94
///
95
/// The above differences in behavior are to be implemented in upcoming
96
/// checkins.
97
class CoreCLRGC : public GCStrategy {
98
public:
99
2
  CoreCLRGC() {
100
2
    UseStatepoints = true;
101
2
    // These options are all gc.root specific, we specify them so that the
102
2
    // gc.root lowering code doesn't run.
103
2
    NeededSafePoints = false;
104
2
    UsesMetadata = false;
105
2
  }
106
107
0
  Optional<bool> isGCManagedPointer(const Type *Ty) const override {
108
0
    // Method is only valid on pointer typed values.
109
0
    const PointerType *PT = cast<PointerType>(Ty);
110
0
    // We pick addrspace(1) as our GC managed heap.
111
0
    return (1 == PT->getAddressSpace());
112
0
  }
113
};
114
115
} // end anonymous namespace
116
117
// Register all the above so that they can be found at runtime.  Note that
118
// these static initializers are important since the registration list is
119
// constructed from their storage.
120
static GCRegistry::Add<ErlangGC> A("erlang",
121
                                   "erlang-compatible garbage collector");
122
static GCRegistry::Add<OcamlGC> B("ocaml", "ocaml 3.10-compatible GC");
123
static GCRegistry::Add<ShadowStackGC>
124
    C("shadow-stack", "Very portable GC for uncooperative code generators");
125
static GCRegistry::Add<StatepointGC> D("statepoint-example",
126
                                       "an example strategy for statepoint");
127
static GCRegistry::Add<CoreCLRGC> E("coreclr", "CoreCLR-compatible GC");
128
129
// Provide hook to ensure the containing library is fully loaded.
130
0
void llvm::linkAllBuiltinGCs() {}