blob: e5a7d05f4c598a72cde1aeaebb5281120c9f8c11 [file] [log] [blame]
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +00001//===-- 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/Module.h"
16#include "llvm/CodeGen/AsmPrinter.h"
17#include "llvm/CodeGen/MachineModuleInfo.h"
18#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000020#include "llvm/MC/MCAsmInfo.h"
21#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCSection.h"
24#include "llvm/MC/MCStreamer.h"
25#include "llvm/MC/MCSymbol.h"
26#include "llvm/Target/Mangler.h"
27#include "llvm/Target/TargetData.h"
28#include "llvm/Target/TargetFrameLowering.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000029#include "llvm/Target/TargetMachine.h"
30#include "llvm/Target/TargetOptions.h"
31#include "llvm/Target/TargetRegisterInfo.h"
Evgeniy Stepanov79084802012-01-23 07:57:39 +000032#include "llvm/Support/CommandLine.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000033#include "llvm/Support/Dwarf.h"
34#include "llvm/Support/FormattedStream.h"
35#include "llvm/ADT/SmallString.h"
36#include "llvm/ADT/StringExtras.h"
37#include "llvm/ADT/Twine.h"
38using namespace llvm;
39
Evgeniy Stepanov79084802012-01-23 07:57:39 +000040cl::opt<ExceptionHandling::ARMEHABIMode>
41EnableARMEHABI("arm-enable-ehabi", cl::Hidden,
42 cl::desc("Generate ARM EHABI tables:"),
43 cl::values(clEnumValN(ExceptionHandling::ARMEHABIDisabled, "no",
44 "Do not generate ARM EHABI tables"),
45 clEnumValN(ExceptionHandling::ARMEHABIUnwind, "unwind",
46 "Emit unwinding instructions, but not descriptors"),
47 clEnumValN(ExceptionHandling::ARMEHABIFull, "full",
48 "Generate full ARM EHABI tables"),
49 clEnumValEnd));
50
51
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000052ARMException::ARMException(AsmPrinter *A)
53 : DwarfException(A),
54 shouldEmitTable(false), shouldEmitMoves(false), shouldEmitTableModule(false)
55 {}
56
57ARMException::~ARMException() {}
58
59void ARMException::EndModule() {
60}
61
62/// BeginFunction - Gather pre-function exception information. Assumes it's
63/// being emitted immediately after the function entry point.
64void ARMException::BeginFunction(const MachineFunction *MF) {
65 Asm->OutStreamer.EmitFnStart();
Rafael Espindolafc2bb8c2011-05-25 03:44:17 +000066 if (Asm->MF->getFunction()->needsUnwindTableEntry())
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000067 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
68 Asm->getFunctionNumber()));
69}
70
71/// EndFunction - Gather and emit post-function exception information.
72///
73void ARMException::EndFunction() {
Rafael Espindolafc2bb8c2011-05-25 03:44:17 +000074 if (!Asm->MF->getFunction()->needsUnwindTableEntry())
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000075 Asm->OutStreamer.EmitCantUnwind();
76 else {
77 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
78 Asm->getFunctionNumber()));
79
80 // Emit references to personality.
81 if (const Function * Personality =
82 MMI->getPersonalities()[MMI->getPersonalityIndex()]) {
83 MCSymbol *PerSym = Asm->Mang->getSymbol(Personality);
84 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
85 Asm->OutStreamer.EmitPersonality(PerSym);
86 }
87
Evgeniy Stepanov79084802012-01-23 07:57:39 +000088 if (EnableARMEHABI == ExceptionHandling::ARMEHABIFull) {
89 // Map all labels and get rid of any dead landing pads.
90 MMI->TidyLandingPads();
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000091
Evgeniy Stepanov79084802012-01-23 07:57:39 +000092 Asm->OutStreamer.EmitHandlerData();
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000093
Evgeniy Stepanov79084802012-01-23 07:57:39 +000094 // Emit actual exception table
95 EmitExceptionTable();
96 }
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000097 }
98
99 Asm->OutStreamer.EmitFnEnd();
100}