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) : DwarfCFIExceptionBase(A) {}
41 ARMException::~ARMException() {}
43 ARMTargetStreamer &ARMException::getTargetStreamer() {
44 MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
45 return static_cast<ARMTargetStreamer &>(TS);
48 /// endModule - Emit all exception information that should come after the
50 void ARMException::endModule() {
52 Asm->OutStreamer->EmitCFISections(false, true);
55 void ARMException::beginFunction(const MachineFunction *MF) {
56 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
57 getTargetStreamer().emitFnStart();
58 // See if we need call frame info.
59 AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
60 assert(MoveType != AsmPrinter::CFI_M_EH &&
61 "non-EH CFI not yet supported in prologue with EHABI lowering");
62 if (MoveType == AsmPrinter::CFI_M_Debug) {
64 Asm->OutStreamer->EmitCFIStartProc(false);
68 /// endFunction - Gather and emit post-function exception information.
70 void ARMException::endFunction(const MachineFunction *MF) {
71 ARMTargetStreamer &ATS = getTargetStreamer();
72 if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
73 MMI->getLandingPads().empty())
76 if (!MMI->getLandingPads().empty()) {
77 // Emit references to personality.
78 if (const Function *Personality = MMI->getPersonality()) {
79 MCSymbol *PerSym = Asm->getSymbol(Personality);
80 Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global);
81 ATS.emitPersonality(PerSym);
84 // Emit .handlerdata directive.
85 ATS.emitHandlerData();
87 // Emit actual exception table
92 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
96 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
97 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
98 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
100 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
103 // Emit the Catch TypeInfos.
104 if (VerboseAsm && !TypeInfos.empty()) {
105 Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
106 Asm->OutStreamer->AddBlankLine();
107 Entry = TypeInfos.size();
110 for (std::vector<const GlobalValue *>::const_reverse_iterator
111 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
112 const GlobalValue *GV = *I;
114 Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
115 Asm->EmitTTypeReference(GV, TTypeEncoding);
118 // Emit the Exception Specifications.
119 if (VerboseAsm && !FilterIds.empty()) {
120 Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
121 Asm->OutStreamer->AddBlankLine();
124 for (std::vector<unsigned>::const_iterator
125 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
126 unsigned TypeID = *I;
130 Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
133 Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),