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)
40 : EHStreamer(A), shouldEmitCFI(false) {}
42 ARMException::~ARMException() {}
44 ARMTargetStreamer &ARMException::getTargetStreamer() {
45 MCTargetStreamer &TS = *Asm->OutStreamer.getTargetStreamer();
46 return static_cast<ARMTargetStreamer &>(TS);
49 /// endModule - Emit all exception information that should come after the
51 void ARMException::endModule() {
53 Asm->OutStreamer.EmitCFISections(false, true);
56 /// beginFunction - Gather pre-function exception information. Assumes it's
57 /// being emitted immediately after the function entry point.
58 void ARMException::beginFunction(const MachineFunction *MF) {
59 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
60 getTargetStreamer().emitFnStart();
61 // See if we need call frame info.
62 AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
63 assert(MoveType != AsmPrinter::CFI_M_EH &&
64 "non-EH CFI not yet supported in prologue with EHABI lowering");
65 if (MoveType == AsmPrinter::CFI_M_Debug) {
67 Asm->OutStreamer.EmitCFIStartProc(false);
71 /// endFunction - Gather and emit post-function exception information.
73 void ARMException::endFunction(const MachineFunction *) {
75 Asm->OutStreamer.EmitCFIEndProc();
77 // Map all labels and get rid of any dead landing pads.
78 MMI->TidyLandingPads();
80 ARMTargetStreamer &ATS = getTargetStreamer();
81 if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
82 MMI->getLandingPads().empty())
85 if (!MMI->getLandingPads().empty()) {
86 // Emit references to personality.
87 if (const Function *Personality = MMI->getPersonality()) {
88 MCSymbol *PerSym = Asm->getSymbol(Personality);
89 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
90 ATS.emitPersonality(PerSym);
93 // Emit .handlerdata directive.
94 ATS.emitHandlerData();
96 // Emit actual exception table
101 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
105 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
106 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
107 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
109 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
112 // Emit the Catch TypeInfos.
113 if (VerboseAsm && !TypeInfos.empty()) {
114 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
115 Asm->OutStreamer.AddBlankLine();
116 Entry = TypeInfos.size();
119 for (std::vector<const GlobalValue *>::const_reverse_iterator
120 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
121 const GlobalValue *GV = *I;
123 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
124 Asm->EmitTTypeReference(GV, TTypeEncoding);
127 // Emit the Exception Specifications.
128 if (VerboseAsm && !FilterIds.empty()) {
129 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
130 Asm->OutStreamer.AddBlankLine();
133 for (std::vector<unsigned>::const_iterator
134 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
135 unsigned TypeID = *I;
139 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
142 Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),