]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
Don't pre-populate the set of keys in the map with variable locations history.
[opencl/llvm.git] / lib / CodeGen / AsmPrinter / DwarfCFIException.cpp
1 //===-- CodeGen/AsmPrinter/DwarfException.cpp - Dwarf 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 //===----------------------------------------------------------------------===//
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/MC/MachineLocation.h"
32 #include "llvm/Support/Dwarf.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/FormattedStream.h"
35 #include "llvm/Target/TargetFrameLowering.h"
36 #include "llvm/Target/TargetLoweringObjectFile.h"
37 #include "llvm/Target/TargetMachine.h"
38 #include "llvm/Target/TargetOptions.h"
39 #include "llvm/Target/TargetRegisterInfo.h"
40 using namespace llvm;
42 DwarfCFIException::DwarfCFIException(AsmPrinter *A)
43   : DwarfException(A),
44     shouldEmitPersonality(false), shouldEmitLSDA(false), shouldEmitMoves(false),
45     moveTypeModule(AsmPrinter::CFI_M_None) {}
47 DwarfCFIException::~DwarfCFIException() {}
49 /// endModule - Emit all exception information that should come after the
50 /// content.
51 void DwarfCFIException::endModule() {
52   if (moveTypeModule == AsmPrinter::CFI_M_Debug)
53     Asm->OutStreamer.EmitCFISections(false, true);
55   if (!Asm->MAI->isExceptionHandlingDwarf())
56     return;
58   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
60   unsigned PerEncoding = TLOF.getPersonalityEncoding();
62   if ((PerEncoding & 0x70) != dwarf::DW_EH_PE_pcrel)
63     return;
65   // Emit references to all used personality functions
66   bool AtLeastOne = false;
67   const std::vector<const Function*> &Personalities = MMI->getPersonalities();
68   for (size_t i = 0, e = Personalities.size(); i != e; ++i) {
69     if (!Personalities[i])
70       continue;
71     MCSymbol *Sym = Asm->getSymbol(Personalities[i]);
72     TLOF.emitPersonalityValue(Asm->OutStreamer, Asm->TM, Sym);
73     AtLeastOne = true;
74   }
76   if (AtLeastOne && !TLOF.isFunctionEHFrameSymbolPrivate()) {
77     // This is a temporary hack to keep sections in the same order they
78     // were before. This lets us produce bit identical outputs while
79     // transitioning to CFI.
80     Asm->OutStreamer.SwitchSection(
81                const_cast<TargetLoweringObjectFile&>(TLOF).getEHFrameSection());
82   }
83 }
85 /// beginFunction - Gather pre-function exception information. Assumes it's
86 /// being emitted immediately after the function entry point.
87 void DwarfCFIException::beginFunction(const MachineFunction *MF) {
88   shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
90   // If any landing pads survive, we need an EH table.
91   bool hasLandingPads = !MMI->getLandingPads().empty();
93   // See if we need frame move info.
94   AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
95   if (MoveType == AsmPrinter::CFI_M_EH ||
96       (MoveType == AsmPrinter::CFI_M_Debug &&
97        moveTypeModule == AsmPrinter::CFI_M_None))
98     moveTypeModule = MoveType;
100   shouldEmitMoves = MoveType != AsmPrinter::CFI_M_None;
102   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
103   unsigned PerEncoding = TLOF.getPersonalityEncoding();
104   const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()];
106   shouldEmitPersonality = hasLandingPads &&
107     PerEncoding != dwarf::DW_EH_PE_omit && Per;
109   unsigned LSDAEncoding = TLOF.getLSDAEncoding();
110   shouldEmitLSDA = shouldEmitPersonality &&
111     LSDAEncoding != dwarf::DW_EH_PE_omit;
113   if (!shouldEmitPersonality && !shouldEmitMoves)
114     return;
116   Asm->OutStreamer.EmitCFIStartProc(/*IsSimple=*/false);
118   // Indicate personality routine, if any.
119   if (!shouldEmitPersonality)
120     return;
122   const MCSymbol *Sym =
123       TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, Asm->TM, MMI);
124   Asm->OutStreamer.EmitCFIPersonality(Sym, PerEncoding);
126   Asm->OutStreamer.EmitDebugLabel
127     (Asm->GetTempSymbol("eh_func_begin",
128                         Asm->getFunctionNumber()));
130   // Provide LSDA information.
131   if (!shouldEmitLSDA)
132     return;
134   Asm->OutStreamer.EmitCFILsda(Asm->GetTempSymbol("exception",
135                                                   Asm->getFunctionNumber()),
136                                LSDAEncoding);
139 /// endFunction - Gather and emit post-function exception information.
140 ///
141 void DwarfCFIException::endFunction(const MachineFunction *) {
142   if (!shouldEmitPersonality && !shouldEmitMoves)
143     return;
145   Asm->OutStreamer.EmitCFIEndProc();
147   if (!shouldEmitPersonality)
148     return;
150   Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
151                                                 Asm->getFunctionNumber()));
153   // Map all labels and get rid of any dead landing pads.
154   MMI->TidyLandingPads();
156   EmitExceptionTable();