blob: 9a16e15ecf774f5f9ae5be6b4cb1dd801a970698 [file] [log] [blame]
Anton Korobeynikova7ec2dc2011-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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/SmallString.h"
16#include "llvm/ADT/StringExtras.h"
17#include "llvm/ADT/Twine.h"
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000018#include "llvm/CodeGen/AsmPrinter.h"
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000022#include "llvm/IR/DataLayout.h"
Rafael Espindola894843c2014-01-07 21:19:40 +000023#include "llvm/IR/Mangler.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/Module.h"
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000025#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"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/Support/CommandLine.h"
32#include "llvm/Support/Dwarf.h"
33#include "llvm/Support/FormattedStream.h"
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000034#include "llvm/Target/TargetFrameLowering.h"
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000035#include "llvm/Target/TargetOptions.h"
36#include "llvm/Target/TargetRegisterInfo.h"
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000037using namespace llvm;
38
Rafael Espindolaa6001792015-03-09 18:29:12 +000039ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {}
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000040
41ARMException::~ARMException() {}
42
Rafael Espindolaa17151a2013-10-08 13:08:17 +000043ARMTargetStreamer &ARMException::getTargetStreamer() {
Rafael Espindola4a1a3602014-01-14 01:21:46 +000044 MCTargetStreamer &TS = *Asm->OutStreamer.getTargetStreamer();
Rafael Espindolaa17151a2013-10-08 13:08:17 +000045 return static_cast<ARMTargetStreamer &>(TS);
46}
47
Artyom Skrobovf6830f42014-02-14 17:19:07 +000048/// endModule - Emit all exception information that should come after the
49/// content.
Timur Iskhodzhanov119f3072013-11-26 13:34:55 +000050void ARMException::endModule() {
Artyom Skrobovf6830f42014-02-14 17:19:07 +000051 if (shouldEmitCFI)
52 Asm->OutStreamer.EmitCFISections(false, true);
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000053}
54
Timur Iskhodzhanov119f3072013-11-26 13:34:55 +000055void ARMException::beginFunction(const MachineFunction *MF) {
Joerg Sonnenberger3c108172014-04-30 22:43:13 +000056 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
57 getTargetStreamer().emitFnStart();
Artyom Skrobovf6830f42014-02-14 17:19:07 +000058 // 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) {
63 shouldEmitCFI = true;
Oliver Stannardcf6bfb12014-11-03 12:19:03 +000064 Asm->OutStreamer.EmitCFIStartProc(false);
Artyom Skrobovf6830f42014-02-14 17:19:07 +000065 }
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000066}
67
Timur Iskhodzhanov119f3072013-11-26 13:34:55 +000068/// endFunction - Gather and emit post-function exception information.
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000069///
Rafael Espindolaa6001792015-03-09 18:29:12 +000070void ARMException::endFunction(const MachineFunction *MF) {
Rafael Espindolaa17151a2013-10-08 13:08:17 +000071 ARMTargetStreamer &ATS = getTargetStreamer();
Logan Chien95188b92014-05-14 16:38:30 +000072 if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
73 MMI->getLandingPads().empty())
Rafael Espindolaa17151a2013-10-08 13:08:17 +000074 ATS.emitCantUnwind();
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000075 else {
Renato Golin8cea6e82014-01-29 11:50:56 +000076 if (!MMI->getLandingPads().empty()) {
77 // Emit references to personality.
Reid Klecknere80a0a72015-01-14 22:47:54 +000078 if (const Function *Personality = MMI->getPersonality()) {
Renato Golin8cea6e82014-01-29 11:50:56 +000079 MCSymbol *PerSym = Asm->getSymbol(Personality);
80 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
81 ATS.emitPersonality(PerSym);
Anton Korobeynikovb619a412012-11-14 19:13:30 +000082 }
Renato Golin8cea6e82014-01-29 11:50:56 +000083
84 // Emit .handlerdata directive.
85 ATS.emitHandlerData();
86
87 // Emit actual exception table
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000088 emitExceptionTable();
Evgeniy Stepanov33a7e2f2012-01-24 13:05:33 +000089 }
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000090 }
91
Joerg Sonnenberger3c108172014-04-30 22:43:13 +000092 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
93 ATS.emitFnEnd();
Anton Korobeynikova7ec2dc2011-03-05 18:43:15 +000094}
Anton Korobeynikovf65a6382012-11-19 21:06:26 +000095
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000096void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
Reid Kleckner283bc2e2014-11-14 00:35:50 +000097 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
Anton Korobeynikovf65a6382012-11-19 21:06:26 +000098 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
99
100 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
101
102 int Entry = 0;
103 // Emit the Catch TypeInfos.
104 if (VerboseAsm && !TypeInfos.empty()) {
105 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
106 Asm->OutStreamer.AddBlankLine();
107 Entry = TypeInfos.size();
108 }
109
Reid Kleckner283bc2e2014-11-14 00:35:50 +0000110 for (std::vector<const GlobalValue *>::const_reverse_iterator
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000111 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
Reid Kleckner283bc2e2014-11-14 00:35:50 +0000112 const GlobalValue *GV = *I;
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000113 if (VerboseAsm)
114 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000115 Asm->EmitTTypeReference(GV, TTypeEncoding);
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000116 }
117
118 // Emit the Exception Specifications.
119 if (VerboseAsm && !FilterIds.empty()) {
120 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
121 Asm->OutStreamer.AddBlankLine();
122 Entry = 0;
123 }
124 for (std::vector<unsigned>::const_iterator
125 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
126 unsigned TypeID = *I;
127 if (VerboseAsm) {
128 --Entry;
129 if (TypeID != 0)
130 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
131 }
132
Craig Topper353eda42014-04-24 06:44:33 +0000133 Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000134 TTypeEncoding);
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000135 }
136}