1193323Sed//===-- ShadowStackGC.cpp - GC support for uncooperative targets ----------===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed// This file implements lowering for the llvm.gc* intrinsics for targets that do
11193323Sed// not natively support them (which includes the C backend). Note that the code
12193323Sed// generated is not quite as efficient as algorithms which generate stack maps
13193323Sed// to identify roots.
14193323Sed//
15193323Sed// This pass implements the code transformation described in this paper:
16193323Sed//   "Accurate Garbage Collection in an Uncooperative Environment"
17193323Sed//   Fergus Henderson, ISMM, 2002
18193323Sed//
19193323Sed// In runtime/GC/SemiSpace.cpp is a prototype runtime which is compatible with
20193323Sed// ShadowStackGC.
21193323Sed//
22193323Sed// In order to support this particular transformation, all stack roots are
23193323Sed// coallocated in the stack. This allows a fully target-independent stack map
24193323Sed// while introducing only minor runtime overhead.
25193323Sed//
26193323Sed//===----------------------------------------------------------------------===//
27193323Sed
28249423Sdim#include "llvm/CodeGen/GCs.h"
29193323Sed#include "llvm/ADT/StringExtras.h"
30193323Sed#include "llvm/CodeGen/GCStrategy.h"
31276479Sdim#include "llvm/IR/CallSite.h"
32249423Sdim#include "llvm/IR/IRBuilder.h"
33249423Sdim#include "llvm/IR/IntrinsicInst.h"
34249423Sdim#include "llvm/IR/Module.h"
35193323Sed
36193323Sedusing namespace llvm;
37193323Sed
38276479Sdim#define DEBUG_TYPE "shadowstackgc"
39276479Sdim
40193323Sednamespace {
41288943Sdimclass ShadowStackGC : public GCStrategy {
42288943Sdimpublic:
43288943Sdim  ShadowStackGC();
44288943Sdim};
45193323Sed}
46193323Sed
47193323Sedstatic GCRegistry::Add<ShadowStackGC>
48288943Sdim    X("shadow-stack", "Very portable GC for uncooperative code generators");
49193323Sed
50288943Sdimvoid llvm::linkShadowStackGC() {}
51193323Sed
52288943SdimShadowStackGC::ShadowStackGC() {
53193323Sed  InitRoots = true;
54193323Sed  CustomRoots = true;
55193323Sed}
56