LLVM API Documentation
00001 //===-- ErlangGC.cpp - Erlang/OTP GC strategy -------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the Erlang/OTP runtime-compatible garbage collector 00011 // (e.g. defines safe points, root initialization etc.) 00012 // 00013 // The frametable emitter is in ErlangGCPrinter.cpp. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #include "llvm/CodeGen/GCs.h" 00018 #include "llvm/CodeGen/GCStrategy.h" 00019 #include "llvm/CodeGen/MachineInstrBuilder.h" 00020 #include "llvm/MC/MCContext.h" 00021 #include "llvm/MC/MCSymbol.h" 00022 #include "llvm/Target/TargetInstrInfo.h" 00023 #include "llvm/Target/TargetMachine.h" 00024 #include "llvm/Target/TargetSubtargetInfo.h" 00025 00026 using namespace llvm; 00027 00028 namespace { 00029 00030 class ErlangGC : public GCStrategy { 00031 MCSymbol *InsertLabel(MachineBasicBlock &MBB, 00032 MachineBasicBlock::iterator MI, 00033 DebugLoc DL) const; 00034 public: 00035 ErlangGC(); 00036 bool findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF) override; 00037 }; 00038 00039 } 00040 00041 static GCRegistry::Add<ErlangGC> 00042 X("erlang", "erlang-compatible garbage collector"); 00043 00044 void llvm::linkErlangGC() { } 00045 00046 ErlangGC::ErlangGC() { 00047 InitRoots = false; 00048 NeededSafePoints = 1 << GC::PostCall; 00049 UsesMetadata = true; 00050 CustomRoots = false; 00051 CustomSafePoints = true; 00052 } 00053 00054 MCSymbol *ErlangGC::InsertLabel(MachineBasicBlock &MBB, 00055 MachineBasicBlock::iterator MI, 00056 DebugLoc DL) const { 00057 const TargetInstrInfo *TII = MBB.getParent()->getSubtarget().getInstrInfo(); 00058 MCSymbol *Label = MBB.getParent()->getContext().CreateTempSymbol(); 00059 BuildMI(MBB, MI, DL, TII->get(TargetOpcode::GC_LABEL)).addSym(Label); 00060 return Label; 00061 } 00062 00063 bool ErlangGC::findCustomSafePoints(GCFunctionInfo &FI, MachineFunction &MF) { 00064 for (MachineFunction::iterator BBI = MF.begin(), BBE = MF.end(); BBI != BBE; 00065 ++BBI) 00066 for (MachineBasicBlock::iterator MI = BBI->begin(), ME = BBI->end(); 00067 MI != ME; ++MI) 00068 00069 if (MI->getDesc().isCall()) { 00070 00071 // Do not treat tail call sites as safe points. 00072 if (MI->getDesc().isTerminator()) 00073 continue; 00074 00075 /* Code copied from VisitCallPoint(...) */ 00076 MachineBasicBlock::iterator RAI = MI; ++RAI; 00077 MCSymbol* Label = InsertLabel(*MI->getParent(), RAI, MI->getDebugLoc()); 00078 FI.addSafePoint(GC::PostCall, Label, MI->getDebugLoc()); 00079 } 00080 00081 return false; 00082 }