LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ErlangGC.cpp
Go to the documentation of this file.
1 //===-- ErlangGC.cpp - Erlang/OTP GC strategy -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Erlang/OTP runtime-compatible garbage collector
11 // (e.g. defines safe points, root initialization etc.)
12 //
13 // The frametable emitter is in ErlangGCPrinter.cpp.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #include "llvm/CodeGen/GCs.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCSymbol.h"
24 
25 using namespace llvm;
26 
27 namespace {
28 
29  class ErlangGC : public GCStrategy {
30  MCSymbol *InsertLabel(MachineBasicBlock &MBB,
32  DebugLoc DL) const;
33  public:
34  ErlangGC();
35  bool findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF);
36  };
37 
38 }
39 
41 X("erlang", "erlang-compatible garbage collector");
42 
44 
45 ErlangGC::ErlangGC() {
46  InitRoots = false;
47  NeededSafePoints = 1 << GC::PostCall;
48  UsesMetadata = true;
49  CustomRoots = false;
50  CustomSafePoints = true;
51 }
52 
53 MCSymbol *ErlangGC::InsertLabel(MachineBasicBlock &MBB,
55  DebugLoc DL) const {
57  MCSymbol *Label = MBB.getParent()->getContext().CreateTempSymbol();
58  BuildMI(MBB, MI, DL, TII->get(TargetOpcode::GC_LABEL)).addSym(Label);
59  return Label;
60 }
61 
62 bool ErlangGC::findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF) {
63  for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); BBI != BBE;
64  ++BBI)
65  for (MachineBasicBlock::iterator MI = BBI->begin(), ME = BBI->end();
66  MI != ME; ++MI)
67 
68  if (MI->getDesc().isCall()) {
69 
70  // Do not treat tail call sites as safe points.
71  if (MI->getDesc().isTerminator())
72  continue;
73 
74  /* Code copied from VisitCallPoint(...) */
75  MachineBasicBlock::iterator RAI = MI; ++RAI;
76  MCSymbol* Label = InsertLabel(*MI->getParent(), RAI, MI->getDebugLoc());
77  FI.addSafePoint(GC::PostCall, Label, MI->getDebugLoc());
78  }
79 
80  return false;
81 }
const MachineFunction * getParent() const
void linkErlangGC()
Creates an erlang-compatible garbage collector.
Definition: ErlangGC.cpp:43
MCSymbol * CreateTempSymbol()
Definition: MCContext.cpp:165
const HexagonInstrInfo * TII
MCContext & getContext() const
bundle_iterator< MachineInstr, instr_iterator > iterator
Instr is the return address of a call.
Definition: GCMetadata.h:54
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
const MCInstrDesc & get(unsigned Opcode) const
Definition: MCInstrInfo.h:48
virtual const TargetInstrInfo * getInstrInfo() const
const TargetMachine & getTarget() const
BasicBlockListType::iterator iterator
void addSafePoint(GC::PointKind Kind, MCSymbol *Label, DebugLoc DL)
Definition: GCMetadata.h:133
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")