1 //===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing DWARF exception info into asm files.
12 //===----------------------------------------------------------------------===//
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/Mangler.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCContext.h"
27 #include "llvm/MC/MCExpr.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCStreamer.h"
30 #include "llvm/MC/MCSymbol.h"
31 #include "llvm/Support/CommandLine.h"
32 #include "llvm/Support/Dwarf.h"
33 #include "llvm/Support/FormattedStream.h"
34 #include "llvm/Target/TargetFrameLowering.h"
35 #include "llvm/Target/TargetOptions.h"
36 #include "llvm/Target/TargetRegisterInfo.h"
39 ARMException::ARMException(AsmPrinter *A)
41 shouldEmitCFI(false) {}
43 ARMException::~ARMException() {}
45 ARMTargetStreamer &ARMException::getTargetStreamer() {
46 MCTargetStreamer &TS = *Asm->OutStreamer.getTargetStreamer();
47 return static_cast<ARMTargetStreamer &>(TS);
50 /// endModule - Emit all exception information that should come after the
52 void ARMException::endModule() {
54 Asm->OutStreamer.EmitCFISections(false, true);
57 /// beginFunction - Gather pre-function exception information. Assumes it's
58 /// being emitted immediately after the function entry point.
59 void ARMException::beginFunction(const MachineFunction *MF) {
60 getTargetStreamer().emitFnStart();
61 if (Asm->MF->getFunction()->needsUnwindTableEntry())
62 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
63 Asm->getFunctionNumber()));
64 // See if we need call frame info.
65 AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
66 assert(MoveType != AsmPrinter::CFI_M_EH &&
67 "non-EH CFI not yet supported in prologue with EHABI lowering");
68 if (MoveType == AsmPrinter::CFI_M_Debug) {
70 Asm->OutStreamer.EmitCFIStartProc(false);
74 /// endFunction - Gather and emit post-function exception information.
76 void ARMException::endFunction(const MachineFunction *) {
78 Asm->OutStreamer.EmitCFIEndProc();
80 ARMTargetStreamer &ATS = getTargetStreamer();
81 if (!Asm->MF->getFunction()->needsUnwindTableEntry())
84 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
85 Asm->getFunctionNumber()));
87 // Map all labels and get rid of any dead landing pads.
88 MMI->TidyLandingPads();
90 if (!MMI->getLandingPads().empty()) {
91 // Emit references to personality.
92 if (const Function * Personality =
93 MMI->getPersonalities()[MMI->getPersonalityIndex()]) {
94 MCSymbol *PerSym = Asm->getSymbol(Personality);
95 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
96 ATS.emitPersonality(PerSym);
99 // Emit .handlerdata directive.
100 ATS.emitHandlerData();
102 // Emit actual exception table
103 EmitExceptionTable();
110 void ARMException::EmitTypeInfos(unsigned TTypeEncoding) {
111 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
112 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
114 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
117 // Emit the Catch TypeInfos.
118 if (VerboseAsm && !TypeInfos.empty()) {
119 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
120 Asm->OutStreamer.AddBlankLine();
121 Entry = TypeInfos.size();
124 for (std::vector<const GlobalVariable *>::const_reverse_iterator
125 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
126 const GlobalVariable *GV = *I;
128 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
129 Asm->EmitTTypeReference(GV, TTypeEncoding);
132 // Emit the Exception Specifications.
133 if (VerboseAsm && !FilterIds.empty()) {
134 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
135 Asm->OutStreamer.AddBlankLine();
138 for (std::vector<unsigned>::const_iterator
139 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
140 unsigned TypeID = *I;
144 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
147 Asm->EmitTTypeReference((TypeID == 0 ? 0 : TypeInfos[TypeID - 1]),