/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp
Line | Count | Source (jump to first uncovered line) |
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/BinaryFormat/Dwarf.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/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 | 1.74k | ARMException::ARMException(AsmPrinter *A) : DwarfCFIExceptionBase(A) {} |
38 | | |
39 | 1.72k | ARMException::~ARMException() {} |
40 | | |
41 | 18.6k | ARMTargetStreamer &ARMException::getTargetStreamer() { |
42 | 18.6k | MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer(); |
43 | 18.6k | return static_cast<ARMTargetStreamer &>(TS); |
44 | 18.6k | } |
45 | | |
46 | 9.31k | void ARMException::beginFunction(const MachineFunction *MF) { |
47 | 9.31k | if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM) |
48 | 9.31k | getTargetStreamer().emitFnStart(); |
49 | 9.31k | // See if we need call frame info. |
50 | 9.31k | AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves(); |
51 | 9.31k | assert(MoveType != AsmPrinter::CFI_M_EH && |
52 | 9.31k | "non-EH CFI not yet supported in prologue with EHABI lowering"); |
53 | 9.31k | |
54 | 9.31k | if (MoveType == AsmPrinter::CFI_M_Debug9.31k ) { |
55 | 59 | if (!hasEmittedCFISections59 ) { |
56 | 31 | if (Asm->needsOnlyDebugCFIMoves()) |
57 | 31 | Asm->OutStreamer->EmitCFISections(false, true); |
58 | 31 | hasEmittedCFISections = true; |
59 | 31 | } |
60 | 59 | |
61 | 59 | shouldEmitCFI = true; |
62 | 59 | Asm->OutStreamer->EmitCFIStartProc(false); |
63 | 59 | } |
64 | 9.31k | } |
65 | | |
66 | | /// endFunction - Gather and emit post-function exception information. |
67 | | /// |
68 | 9.31k | void ARMException::endFunction(const MachineFunction *MF) { |
69 | 9.31k | ARMTargetStreamer &ATS = getTargetStreamer(); |
70 | 9.31k | const Function *F = MF->getFunction(); |
71 | 9.31k | const Function *Per = nullptr; |
72 | 9.31k | if (F->hasPersonalityFn()) |
73 | 30 | Per = dyn_cast<Function>(F->getPersonalityFn()->stripPointerCasts()); |
74 | 9.31k | bool forceEmitPersonality = |
75 | 30 | F->hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) && |
76 | 0 | F->needsUnwindTableEntry(); |
77 | 9.31k | bool shouldEmitPersonality = forceEmitPersonality || |
78 | 9.31k | !MF->getLandingPads().empty(); |
79 | 9.31k | if (!Asm->MF->getFunction()->needsUnwindTableEntry() && |
80 | 3.66k | !shouldEmitPersonality) |
81 | 3.65k | ATS.emitCantUnwind(); |
82 | 5.66k | else if (5.66k shouldEmitPersonality5.66k ) { |
83 | 30 | // Emit references to personality. |
84 | 30 | if (Per30 ) { |
85 | 30 | MCSymbol *PerSym = Asm->getSymbol(Per); |
86 | 30 | Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global); |
87 | 30 | ATS.emitPersonality(PerSym); |
88 | 30 | } |
89 | 5.66k | |
90 | 5.66k | // Emit .handlerdata directive. |
91 | 5.66k | ATS.emitHandlerData(); |
92 | 5.66k | |
93 | 5.66k | // Emit actual exception table |
94 | 5.66k | emitExceptionTable(); |
95 | 5.66k | } |
96 | 9.31k | |
97 | 9.31k | if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM) |
98 | 9.31k | ATS.emitFnEnd(); |
99 | 9.31k | } |
100 | | |
101 | 30 | void ARMException::emitTypeInfos(unsigned TTypeEncoding) { |
102 | 30 | const MachineFunction *MF = Asm->MF; |
103 | 30 | const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos(); |
104 | 30 | const std::vector<unsigned> &FilterIds = MF->getFilterIds(); |
105 | 30 | |
106 | 30 | bool VerboseAsm = Asm->OutStreamer->isVerboseAsm(); |
107 | 30 | |
108 | 30 | int Entry = 0; |
109 | 30 | // Emit the Catch TypeInfos. |
110 | 30 | if (VerboseAsm && 30 !TypeInfos.empty()29 ) { |
111 | 29 | Asm->OutStreamer->AddComment(">> Catch TypeInfos <<"); |
112 | 29 | Asm->OutStreamer->AddBlankLine(); |
113 | 29 | Entry = TypeInfos.size(); |
114 | 29 | } |
115 | 30 | |
116 | 30 | for (const GlobalValue *GV : reverse(TypeInfos)) { |
117 | 30 | if (VerboseAsm) |
118 | 29 | Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--)); |
119 | 30 | Asm->EmitTTypeReference(GV, TTypeEncoding); |
120 | 30 | } |
121 | 30 | |
122 | 30 | // Emit the Exception Specifications. |
123 | 30 | if (VerboseAsm && 30 !FilterIds.empty()29 ) { |
124 | 1 | Asm->OutStreamer->AddComment(">> Filter TypeInfos <<"); |
125 | 1 | Asm->OutStreamer->AddBlankLine(); |
126 | 1 | Entry = 0; |
127 | 1 | } |
128 | 30 | for (std::vector<unsigned>::const_iterator |
129 | 32 | I = FilterIds.begin(), E = FilterIds.end(); I < E32 ; ++I2 ) { |
130 | 2 | unsigned TypeID = *I; |
131 | 2 | if (VerboseAsm2 ) { |
132 | 2 | --Entry; |
133 | 2 | if (TypeID != 0) |
134 | 1 | Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry)); |
135 | 2 | } |
136 | 2 | |
137 | 2 | Asm->EmitTTypeReference((TypeID == 0 ? nullptr1 : TypeInfos[TypeID - 1]1 ), |
138 | 2 | TTypeEncoding); |
139 | 2 | } |
140 | 30 | } |