]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp
Update lldb to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / CodeGen / AsmPrinter / ARMException.cpp
1 //===-- 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/ADT/StringExtras.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/CodeGen/AsmPrinter.h"
18 #include "llvm/CodeGen/MachineFrameInfo.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineModuleInfo.h"
21 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/Mangler.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/MC/MCAsmInfo.h"
25 #include "llvm/MC/MCContext.h"
26 #include "llvm/MC/MCExpr.h"
27 #include "llvm/MC/MCSection.h"
28 #include "llvm/MC/MCStreamer.h"
29 #include "llvm/MC/MCSymbol.h"
30 #include "llvm/Support/Dwarf.h"
31 #include "llvm/Support/FormattedStream.h"
32 #include "llvm/Target/TargetFrameLowering.h"
33 #include "llvm/Target/TargetOptions.h"
34 #include "llvm/Target/TargetRegisterInfo.h"
35 using namespace llvm;
36
37 ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {}
38
39 ARMException::~ARMException() {}
40
41 ARMTargetStreamer &ARMException::getTargetStreamer() {
42   MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
43   return static_cast<ARMTargetStreamer &>(TS);
44 }
45
46 void ARMException::beginFunction(const MachineFunction *MF) {
47   if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
48     getTargetStreamer().emitFnStart();
49   // See if we need call frame info.
50   AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
51   assert(MoveType != AsmPrinter::CFI_M_EH &&
52          "non-EH CFI not yet supported in prologue with EHABI lowering");
53
54   if (MoveType == AsmPrinter::CFI_M_Debug) {
55     if (!hasEmittedCFISections) {
56       Asm->OutStreamer->EmitCFISections(false, true);
57       hasEmittedCFISections = true;
58     }
59
60     shouldEmitCFI = true;
61     Asm->OutStreamer->EmitCFIStartProc(false);
62   }
63 }
64
65 /// endFunction - Gather and emit post-function exception information.
66 ///
67 void ARMException::endFunction(const MachineFunction *MF) {
68   ARMTargetStreamer &ATS = getTargetStreamer();
69   const Function *F = MF->getFunction();
70   const Function *Per = nullptr;
71   if (F->hasPersonalityFn())
72     Per = dyn_cast<Function>(F->getPersonalityFn()->stripPointerCasts());
73   bool forceEmitPersonality =
74     F->hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) &&
75     F->needsUnwindTableEntry();
76   bool shouldEmitPersonality = forceEmitPersonality ||
77     !MF->getLandingPads().empty();
78   if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
79       !shouldEmitPersonality)
80     ATS.emitCantUnwind();
81   else if (shouldEmitPersonality) {
82     // Emit references to personality.
83     if (Per) {
84       MCSymbol *PerSym = Asm->getSymbol(Per);
85       Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global);
86       ATS.emitPersonality(PerSym);
87     }
88
89     // Emit .handlerdata directive.
90     ATS.emitHandlerData();
91
92     // Emit actual exception table
93     emitExceptionTable();
94   }
95
96   if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
97     ATS.emitFnEnd();
98 }
99
100 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
101   const MachineFunction *MF = Asm->MF;
102   const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
103   const std::vector<unsigned> &FilterIds = MF->getFilterIds();
104
105   bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
106
107   int Entry = 0;
108   // Emit the Catch TypeInfos.
109   if (VerboseAsm && !TypeInfos.empty()) {
110     Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
111     Asm->OutStreamer->AddBlankLine();
112     Entry = TypeInfos.size();
113   }
114
115   for (const GlobalValue *GV : reverse(TypeInfos)) {
116     if (VerboseAsm)
117       Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
118     Asm->EmitTTypeReference(GV, TTypeEncoding);
119   }
120
121   // Emit the Exception Specifications.
122   if (VerboseAsm && !FilterIds.empty()) {
123     Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
124     Asm->OutStreamer->AddBlankLine();
125     Entry = 0;
126   }
127   for (std::vector<unsigned>::const_iterator
128          I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
129     unsigned TypeID = *I;
130     if (VerboseAsm) {
131       --Entry;
132       if (TypeID != 0)
133         Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
134     }
135
136     Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
137                             TTypeEncoding);
138   }
139 }