ErlangGC.cpp revision 249259
1249259Sdim//===-- ErlangGC.cpp - Erlang/OTP GC strategy -------------------*- C++ -*-===// 2249259Sdim// 3249259Sdim// The LLVM Compiler Infrastructure 4249259Sdim// 5249259Sdim// This file is distributed under the University of Illinois Open Source 6249259Sdim// License. See LICENSE.TXT for details. 7249259Sdim// 8249259Sdim//===----------------------------------------------------------------------===// 9249259Sdim// 10249259Sdim// This file implements the Erlang/OTP runtime-compatible garbage collector 11249259Sdim// (e.g. defines safe points, root initialization etc.) 12249259Sdim// 13249259Sdim// The frametable emitter is in ErlangGCPrinter.cpp. 14249259Sdim// 15249259Sdim//===----------------------------------------------------------------------===// 16249259Sdim 17249259Sdim#include "llvm/CodeGen/GCs.h" 18249259Sdim#include "llvm/CodeGen/GCStrategy.h" 19249259Sdim#include "llvm/CodeGen/MachineInstrBuilder.h" 20249259Sdim#include "llvm/MC/MCContext.h" 21249259Sdim#include "llvm/MC/MCSymbol.h" 22249259Sdim#include "llvm/Target/TargetInstrInfo.h" 23249259Sdim#include "llvm/Target/TargetMachine.h" 24249259Sdim 25249259Sdimusing namespace llvm; 26249259Sdim 27249259Sdimnamespace { 28249259Sdim 29249259Sdim class ErlangGC : public GCStrategy { 30249259Sdim MCSymbol *InsertLabel(MachineBasicBlock &MBB, 31249259Sdim MachineBasicBlock::iterator MI, 32249259Sdim DebugLoc DL) const; 33249259Sdim public: 34249259Sdim ErlangGC(); 35249259Sdim bool findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF); 36249259Sdim }; 37249259Sdim 38249259Sdim} 39249259Sdim 40249259Sdimstatic GCRegistry::Add<ErlangGC> 41249259SdimX("erlang", "erlang-compatible garbage collector"); 42249259Sdim 43249259Sdimvoid llvm::linkErlangGC() { } 44249259Sdim 45249259SdimErlangGC::ErlangGC() { 46249259Sdim InitRoots = false; 47249259Sdim NeededSafePoints = 1 << GC::PostCall; 48249259Sdim UsesMetadata = true; 49249259Sdim CustomRoots = false; 50249259Sdim CustomSafePoints = true; 51249259Sdim} 52249259Sdim 53249259SdimMCSymbol *ErlangGC::InsertLabel(MachineBasicBlock &MBB, 54249259Sdim MachineBasicBlock::iterator MI, 55249259Sdim DebugLoc DL) const { 56249259Sdim const TargetInstrInfo* TII = MBB.getParent()->getTarget().getInstrInfo(); 57249259Sdim MCSymbol *Label = MBB.getParent()->getContext().CreateTempSymbol(); 58249259Sdim BuildMI(MBB, MI, DL, TII->get(TargetOpcode::GC_LABEL)).addSym(Label); 59249259Sdim return Label; 60249259Sdim} 61249259Sdim 62249259Sdimbool ErlangGC::findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF) { 63249259Sdim for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); BBI != BBE; 64249259Sdim ++BBI) 65249259Sdim for (MachineBasicBlock::iterator MI = BBI->begin(), ME = BBI->end(); 66249259Sdim MI != ME; ++MI) 67249259Sdim 68249259Sdim if (MI->getDesc().isCall()) { 69249259Sdim 70249259Sdim // Do not treat tail call sites as safe points. 71249259Sdim if (MI->getDesc().isTerminator()) 72249259Sdim continue; 73249259Sdim 74249259Sdim /* Code copied from VisitCallPoint(...) */ 75249259Sdim MachineBasicBlock::iterator RAI = MI; ++RAI; 76249259Sdim MCSymbol* Label = InsertLabel(*MI->getParent(), RAI, MI->getDebugLoc()); 77249259Sdim FI.addSafePoint(GC::PostCall, Label, MI->getDebugLoc()); 78249259Sdim } 79249259Sdim 80249259Sdim return false; 81249259Sdim} 82