ARMException.cpp revision 320296a4cfe414ce59f406b8a5ce15272f563103
1//===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===// 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 contains support for writing DWARF exception info into asm files. 11// 12//===----------------------------------------------------------------------===// 13 14#include "DwarfException.h" 15#include "llvm/ADT/SmallString.h" 16#include "llvm/ADT/StringExtras.h" 17#include "llvm/ADT/Twine.h" 18#include "llvm/CodeGen/AsmPrinter.h" 19#include "llvm/CodeGen/MachineFrameInfo.h" 20#include "llvm/CodeGen/MachineFunction.h" 21#include "llvm/CodeGen/MachineModuleInfo.h" 22#include "llvm/IR/DataLayout.h" 23#include "llvm/IR/Module.h" 24#include "llvm/MC/MCAsmInfo.h" 25#include "llvm/MC/MCContext.h" 26#include "llvm/MC/MCExpr.h" 27#include "llvm/MC/MCSection.h" 28#include "llvm/MC/MCStreamer.h" 29#include "llvm/MC/MCSymbol.h" 30#include "llvm/Support/CommandLine.h" 31#include "llvm/Support/Dwarf.h" 32#include "llvm/Support/FormattedStream.h" 33#include "llvm/Target/Mangler.h" 34#include "llvm/Target/TargetFrameLowering.h" 35#include "llvm/Target/TargetOptions.h" 36#include "llvm/Target/TargetRegisterInfo.h" 37using namespace llvm; 38 39static cl::opt<bool> 40EnableARMEHABIDescriptors("arm-enable-ehabi-descriptors", cl::Hidden, 41 cl::desc("Generate ARM EHABI tables with unwinding descriptors"), 42 cl::init(false)); 43 44 45ARMException::ARMException(AsmPrinter *A) 46 : DwarfException(A) {} 47 48ARMException::~ARMException() {} 49 50ARMTargetStreamer &ARMException::getTargetStreamer() { 51 MCTargetStreamer &TS = Asm->OutStreamer.getTargetStreamer(); 52 return static_cast<ARMTargetStreamer &>(TS); 53} 54 55void ARMException::EndModule() { 56} 57 58/// BeginFunction - Gather pre-function exception information. Assumes it's 59/// being emitted immediately after the function entry point. 60void ARMException::BeginFunction(const MachineFunction *MF) { 61 getTargetStreamer().emitFnStart(); 62 if (Asm->MF->getFunction()->needsUnwindTableEntry()) 63 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin", 64 Asm->getFunctionNumber())); 65} 66 67/// EndFunction - Gather and emit post-function exception information. 68/// 69void ARMException::EndFunction() { 70 ARMTargetStreamer &ATS = getTargetStreamer(); 71 if (!Asm->MF->getFunction()->needsUnwindTableEntry()) 72 ATS.emitCantUnwind(); 73 else { 74 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end", 75 Asm->getFunctionNumber())); 76 77 if (EnableARMEHABIDescriptors) { 78 // Map all labels and get rid of any dead landing pads. 79 MMI->TidyLandingPads(); 80 81 if (!MMI->getLandingPads().empty()) { 82 // Emit references to personality. 83 if (const Function * Personality = 84 MMI->getPersonalities()[MMI->getPersonalityIndex()]) { 85 MCSymbol *PerSym = Asm->Mang->getSymbol(Personality); 86 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global); 87 ATS.emitPersonality(PerSym); 88 } 89 90 // Emit .handlerdata directive. 91 ATS.emitHandlerData(); 92 93 // Emit actual exception table 94 EmitExceptionTable(); 95 } 96 } 97 } 98 99 ATS.emitFnEnd(); 100} 101 102void ARMException::EmitTypeInfos(unsigned TTypeEncoding) { 103 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); 104 const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); 105 106 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm(); 107 108 int Entry = 0; 109 // Emit the Catch TypeInfos. 110 if (VerboseAsm && !TypeInfos.empty()) { 111 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<"); 112 Asm->OutStreamer.AddBlankLine(); 113 Entry = TypeInfos.size(); 114 } 115 116 for (std::vector<const GlobalVariable *>::const_reverse_iterator 117 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { 118 const GlobalVariable *GV = *I; 119 if (VerboseAsm) 120 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--)); 121 Asm->EmitTTypeReference(GV, TTypeEncoding); 122 } 123 124 // Emit the Exception Specifications. 125 if (VerboseAsm && !FilterIds.empty()) { 126 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<"); 127 Asm->OutStreamer.AddBlankLine(); 128 Entry = 0; 129 } 130 for (std::vector<unsigned>::const_iterator 131 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) { 132 unsigned TypeID = *I; 133 if (VerboseAsm) { 134 --Entry; 135 if (TypeID != 0) 136 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry)); 137 } 138 139 Asm->EmitTTypeReference((TypeID == 0 ? 0 : TypeInfos[TypeID - 1]), 140 TTypeEncoding); 141 } 142} 143