llvm.org GIT mirror llvm / b5dd669
Revert r196270, "Generalize debug info / EH emission in AsmPrinter" It broke CodeGen/R600 tests with +Asserts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196272 91177308-0d34-0410-b5e6-96231b3b80d8 NAKAMURA Takumi 5 years ago
7 changed file(s) with 79 addition(s) and 167 deletion(s). Raw diff Collapse all Expand all
2121 #include "llvm/Support/ErrorHandling.h"
2222
2323 namespace llvm {
24 class AsmPrinterHandler;
2524 class BlockAddress;
2625 class GCStrategy;
2726 class Constant;
110109 /// function.
111110 MachineLoopInfo *LI;
112111
113 struct HandlerInfo {
114 AsmPrinterHandler *Handler;
115 const char *TimerName, *TimerGroupName;
116 HandlerInfo(AsmPrinterHandler *Handler, const char *TimerName,
117 const char *TimerGroupName)
118 : Handler(Handler), TimerName(TimerName),
119 TimerGroupName(TimerGroupName) {}
120 };
121 /// Handlers - a vector of all debug/EH info emitters we should use.
122 /// This vector maintains ownership of the emitters.
123 SmallVector Handlers;
124
125112 /// DD - If the target supports dwarf debug info, this pointer is non-null.
126113 DwarfDebug *DD;
114
115 /// DE - If the target supports dwarf exception info, this pointer is
116 /// non-null.
117 DwarfException *DE;
127118
128119 protected:
129120 explicit AsmPrinter(TargetMachine &TM, MCStreamer &Streamer);
9898 OutContext(Streamer.getContext()),
9999 OutStreamer(Streamer),
100100 LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) {
101 DD = 0; MMI = 0; LI = 0; MF = 0;
101 DD = 0; DE = 0; MMI = 0; LI = 0; MF = 0;
102102 CurrentFnSym = CurrentFnSymForSize = 0;
103103 GCMetadataPrinters = 0;
104104 VerboseAsm = Streamer.isVerboseAsm();
105105 }
106106
107107 AsmPrinter::~AsmPrinter() {
108 assert(DD == 0 && Handlers.empty() && "Debug/EH info didn't get finalized");
108 assert(DD == 0 && DE == 0 && "Debug/EH info didn't get finalized");
109109
110110 if (GCMetadataPrinters != 0) {
111111 gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
191191 OutStreamer.AddBlankLine();
192192 }
193193
194 if (MAI->doesSupportDebugInformation()) {
194 if (MAI->doesSupportDebugInformation())
195195 DD = new DwarfDebug(this, &M);
196 Handlers.push_back(HandlerInfo(DD, DbgTimerName, DWARFGroupName));
197 }
198
199 DwarfException *DE = 0;
196
200197 switch (MAI->getExceptionHandlingType()) {
201198 case ExceptionHandling::None:
202 break;
199 return false;
203200 case ExceptionHandling::SjLj:
204201 case ExceptionHandling::DwarfCFI:
205202 DE = new DwarfCFIException(this);
206 break;
203 return false;
207204 case ExceptionHandling::ARM:
208205 DE = new ARMException(this);
209 break;
206 return false;
210207 case ExceptionHandling::Win64:
211208 DE = new Win64Exception(this);
212 break;
213 }
214 if (DE)
215 Handlers.push_back(HandlerInfo(DE, EHTimerName, DWARFGroupName));
216 return false;
209 return false;
210 }
211
212 llvm_unreachable("Unknown exception type.");
217213 }
218214
219215 void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
314310 // sections and expected to be contiguous (e.g. ObjC metadata).
315311 unsigned AlignLog = getGVAlignmentLog2(GV, *DL);
316312
317 for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
318 const HandlerInfo &OI = Handlers[I];
319 NamedRegionTimer T(OI.TimerName, OI.TimerGroupName, TimePassesIsEnabled);
320 OI.Handler->setSymbolSize(GVSym, Size);
321 }
313 if (DD)
314 DD->setSymbolSize(GVSym, Size);
322315
323316 // Handle common and BSS local symbols (.lcomm).
324317 if (GVKind.isCommon() || GVKind.isBSSLocal()) {
488481 }
489482
490483 // Emit pre-function debug and/or EH information.
491 for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
492 const HandlerInfo &OI = Handlers[I];
493 NamedRegionTimer T(OI.TimerName, OI.TimerGroupName, TimePassesIsEnabled);
494 OI.Handler->beginFunction(MF);
484 if (DE) {
485 NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
486 DE->beginFunction(MF);
487 }
488 if (DD) {
489 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
490 DD->beginFunction(MF);
495491 }
496492
497493 // Emit the prefix data.
696692 // Emit target-specific gunk before the function body.
697693 EmitFunctionBodyStart();
698694
699 bool ShouldPrintDebugScopes = MMI->hasDebugInfo();
695 bool ShouldPrintDebugScopes = DD && MMI->hasDebugInfo();
700696
701697 // Print out code for the function.
702698 bool HasAnyRealCode = false;
717713 }
718714
719715 if (ShouldPrintDebugScopes) {
720 for (unsigned III = 0, EEE = Handlers.size(); III != EEE; ++III) {
721 const HandlerInfo &OI = Handlers[III];
722 NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
723 TimePassesIsEnabled);
724 OI.Handler->beginInstruction(II);
725 }
716 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
717 DD->beginInstruction(II);
726718 }
727719
728720 if (isVerbose())
761753 }
762754
763755 if (ShouldPrintDebugScopes) {
764 for (unsigned III = 0, EEE = Handlers.size(); III != EEE; ++III) {
765 const HandlerInfo &OI = Handlers[III];
766 NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
767 TimePassesIsEnabled);
768 OI.Handler->endInstruction();
769 }
756 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
757 DD->endInstruction(II);
770758 }
771759 }
772760 }
822810 OutStreamer.EmitELFSize(CurrentFnSym, SizeExp);
823811 }
824812
825 // Emit post-function debug and/or EH information.
826 for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
827 const HandlerInfo &OI = Handlers[I];
828 NamedRegionTimer T(OI.TimerName, OI.TimerGroupName, TimePassesIsEnabled);
829 OI.Handler->endFunction();
813 // Emit post-function debug information.
814 if (DD) {
815 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
816 DD->endFunction(MF);
817 }
818 if (DE) {
819 NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
820 DE->endFunction();
830821 }
831822 MMI->EndFunction();
832823
915906 OutStreamer.Flush();
916907
917908 // Finalize debug and EH information.
918 for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
919 const HandlerInfo &OI = Handlers[I];
920 NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
921 TimePassesIsEnabled);
922 OI.Handler->endModule();
923 delete OI.Handler;
924 }
925 Handlers.clear();
926 DD = 0;
909 if (DE) {
910 {
911 NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
912 DE->endModule();
913 }
914 delete DE; DE = 0;
915 }
916 if (DD) {
917 {
918 NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
919 DD->endModule();
920 }
921 delete DD; DD = 0;
922 }
927923
928924 // If the target wants to know about weak references, print them all.
929925 if (MAI->getWeakRefDirective()) {
+0
-53
lib/CodeGen/AsmPrinter/AsmPrinterHandler.h less more
None //===-- lib/CodeGen/AsmPrinter/AsmPrinterHandler.h -------------*- C++ -*--===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains a generic interface for AsmPrinter handlers,
10 // like debug and EH info emitters.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef CODEGEN_ASMPRINTER_ASMPRINTERHANDLER_H__
15 #define CODEGEN_ASMPRINTER_ASMPRINTERHANDLER_H__
16
17 #include "llvm/Support/DataTypes.h"
18
19 namespace llvm {
20
21 class MachineFunction;
22 class MachineInstr;
23 class MCSymbol;
24
25 /// \brief Collects and handles AsmPrinter objects required to build debug
26 /// or EH information.
27 class AsmPrinterHandler {
28 public:
29 virtual ~AsmPrinterHandler() {}
30
31 /// \brief For symbols that have a size designated (e.g. common symbols),
32 /// this tracks that size.
33 virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) = 0;
34
35 /// \brief Emit all sections that should come after the content.
36 virtual void endModule() = 0;
37
38 /// \brief Gather pre-function debug information.
39 virtual void beginFunction(const MachineFunction *MF) = 0;
40
41 /// \brief Gather post-function debug information.
42 virtual void endFunction() = 0;
43
44 /// \brief Process beginning of an instruction.
45 virtual void beginInstruction(const MachineInstr *MI) = 0;
46
47 /// \brief Process end of an instruction.
48 virtual void endInstruction() = 0;
49 };
50 } // End of namespace llvm
51
52 #endif
389389 // specified to be four bytes in the DWARF 32-bit format and eight bytes
390390 // in the DWARF 64-bit format, while DWARF Version 2 specifies that such
391391 // references have the same size as an address on the target system.
392 const DwarfDebug *DD = AP->getDwarfDebug();
393 assert(DD && "Expected Dwarf Debug info to be available");
394 if (DD->getDwarfVersion() == 2)
392 if (AP->getDwarfDebug()->getDwarfVersion() == 2)
395393 return AP->getDataLayout().getPointerSize();
396394 return sizeof(int32_t);
397395 }
196196 DwarfAddrSectionSym = 0;
197197 DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = 0;
198198 FunctionBeginSym = FunctionEndSym = 0;
199 CurFn = 0; CurMI = 0;
200199
201200 // Turn on accelerator tables for Darwin by default, pubnames by
202201 // default for non-Darwin, and handle split dwarf.
11441143
11451144 // Emit all Dwarf sections that should come after the content.
11461145 void DwarfDebug::endModule() {
1147 assert(CurFn == 0);
11481146
11491147 if (!FirstCU)
11501148 return;
12261224 }
12271225
12281226 // If Var is a current function argument then add it to CurrentFnArguments list.
1229 bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
1227 bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,
1228 DbgVariable *Var, LexicalScope *Scope) {
12301229 if (!LScopes.isCurrentFunctionScope(Scope))
12311230 return false;
12321231 DIVariable DV = Var->getVariable();
12381237
12391238 size_t Size = CurrentFnArguments.size();
12401239 if (Size == 0)
1241 CurrentFnArguments.resize(CurFn->getFunction()->arg_size());
1240 CurrentFnArguments.resize(MF->getFunction()->arg_size());
12421241 // llvm::Function argument size is not good indicator of how many
12431242 // arguments does the function have at source level.
12441243 if (ArgNo > Size)
12491248
12501249 // Collect variable information from side table maintained by MMI.
12511250 void DwarfDebug::collectVariableInfoFromMMITable(
1252 SmallPtrSet &Processed) {
1251 const MachineFunction *MF, SmallPtrSet &Processed) {
12531252 MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
12541253 for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
12551254 VE = VMap.end();
12701269 DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
12711270 DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);
12721271 RegVar->setFrameIndex(VP.first);
1273 if (!addCurrentFnArgument(RegVar, Scope))
1272 if (!addCurrentFnArgument(MF, RegVar, Scope))
12741273 addScopeVariable(Scope, RegVar);
12751274 if (AbsDbgVariable)
12761275 AbsDbgVariable->setFrameIndex(VP.first);
13171316
13181317 // Find variables for each lexical scope.
13191318 void
1320 DwarfDebug::collectVariableInfo(SmallPtrSet &Processed) {
1319 DwarfDebug::collectVariableInfo(const MachineFunction *MF,
1320 SmallPtrSet &Processed) {
13211321
13221322 // Grab the variable info that was squirreled away in the MMI side-table.
1323 collectVariableInfoFromMMITable(Processed);
1323 collectVariableInfoFromMMITable(MF, Processed);
13241324
13251325 for (SmallVectorImpl::const_iterator
13261326 UVI = UserVariables.begin(),
13401340 DIVariable DV(Var);
13411341 LexicalScope *Scope = NULL;
13421342 if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
1343 DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
1343 DISubprogram(DV.getContext()).describes(MF->getFunction()))
13441344 Scope = LScopes.getCurrentFunctionScope();
13451345 else if (MDNode *IA = DV.getInlinedAt())
13461346 Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
13541354 assert(MInsn->isDebugValue() && "History must begin with debug value");
13551355 DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
13561356 DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);
1357 if (!addCurrentFnArgument(RegVar, Scope))
1357 if (!addCurrentFnArgument(MF, RegVar, Scope))
13581358 addScopeVariable(Scope, RegVar);
13591359 if (AbsVar)
13601360 AbsVar->setMInsn(MInsn);
14361436
14371437 // Process beginning of an instruction.
14381438 void DwarfDebug::beginInstruction(const MachineInstr *MI) {
1439 assert(CurMI == 0);
1440 CurMI = MI;
14411439 // Check if source location changes, but ignore DBG_VALUE locations.
14421440 if (!MI->isDebugValue()) {
14431441 DebugLoc DL = MI->getDebugLoc();
14791477 }
14801478
14811479 // Process end of an instruction.
1482 void DwarfDebug::endInstruction() {
1483 assert(CurMI != 0);
1480 void DwarfDebug::endInstruction(const MachineInstr *MI) {
14841481 // Don't create a new label after DBG_VALUE instructions.
14851482 // They don't generate code.
1486 if (!CurMI->isDebugValue())
1483 if (!MI->isDebugValue())
14871484 PrevLabel = 0;
14881485
14891486 DenseMap::iterator I =
1490 LabelsAfterInsn.find(CurMI);
1491 CurMI = 0;
1487 LabelsAfterInsn.find(MI);
14921488
14931489 // No label needed.
14941490 if (I == LabelsAfterInsn.end())
15681564 // Gather pre-function debug information. Assumes being called immediately
15691565 // after the function entry point has been emitted.
15701566 void DwarfDebug::beginFunction(const MachineFunction *MF) {
1571 CurFn = MF;
15721567
15731568 // If there's no debug info for the function we're not going to do anything.
15741569 if (!MMI->hasDebugInfo())
17951790 }
17961791
17971792 // Gather and emit post-function debug information.
1798 void DwarfDebug::endFunction() {
1799 assert(CurFn != 0);
1800
1801 if (!MMI->hasDebugInfo() || LScopes.empty()) {
1802 CurFn = 0;
1793 void DwarfDebug::endFunction(const MachineFunction *MF) {
1794 if (!MMI->hasDebugInfo() || LScopes.empty())
18031795 return;
1804 }
18051796
18061797 // Define end label for subprogram.
18071798 FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());
18111802 Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
18121803
18131804 SmallPtrSet ProcessedVars;
1814 collectVariableInfo(ProcessedVars);
1805 collectVariableInfo(MF, ProcessedVars);
18151806
18161807 LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
18171808 CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
18451836
18461837 DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
18471838
1848 if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))
1839 if (!MF->getTarget().Options.DisableFramePointerElim(*MF))
18491840 TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
18501841
18511842 // Clear debug info
18611852 LabelsBeforeInsn.clear();
18621853 LabelsAfterInsn.clear();
18631854 PrevLabel = NULL;
1864 CurFn = 0;
18651855 }
18661856
18671857 // Register a source line with debug info. Returns the unique label that was
1313 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
1414 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
1515
16 #include "AsmPrinterHandler.h"
1716 #include "DIE.h"
1817 #include "llvm/ADT/DenseMap.h"
1918 #include "llvm/ADT/FoldingSet.h"
316315 };
317316
318317 /// \brief Collects and handles dwarf debug information.
319 class DwarfDebug : public AsmPrinterHandler {
318 class DwarfDebug {
320319 // Target of Dwarf emission.
321320 AsmPrinter *Asm;
322321
417416 // This location indicates end of function prologue and beginning of function
418417 // body.
419418 DebugLoc PrologEndLoc;
420
421 // If nonnull, stores the current machine function we're processing.
422 const MachineFunction *CurFn;
423
424 // If nonnull, stores the current machine instruction we're processing.
425 const MachineInstr *CurMI;
426419
427420 // Section Symbols: these are assembler temporary labels that are emitted at
428421 // the beginning of each supported dwarf section. These are used to form
654647
655648 /// \brief If Var is an current function argument that add it in
656649 /// CurrentFnArguments list.
657 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
650 bool addCurrentFnArgument(const MachineFunction *MF,
651 DbgVariable *Var, LexicalScope *Scope);
658652
659653 /// \brief Populate LexicalScope entries with variables' info.
660 void collectVariableInfo(SmallPtrSet &ProcessedVars);
654 void collectVariableInfo(const MachineFunction *,
655 SmallPtrSet &ProcessedVars);
661656
662657 /// \brief Collect variable information from the side table maintained
663658 /// by MMI.
664 void collectVariableInfoFromMMITable(SmallPtrSet &P);
659 void collectVariableInfoFromMMITable(const MachineFunction * MF,
660 SmallPtrSet &P);
665661
666662 /// \brief Ensure that a label will be emitted before MI.
667663 void requestLabelBeforeInsn(const MachineInstr *MI) {
703699 void beginFunction(const MachineFunction *MF);
704700
705701 /// \brief Gather and emit post-function debug information.
706 void endFunction();
702 void endFunction(const MachineFunction *MF);
707703
708704 /// \brief Process beginning of an instruction.
709705 void beginInstruction(const MachineInstr *MI);
710706
711707 /// \brief Process end of an instruction.
712 void endInstruction();
708 void endInstruction(const MachineInstr *MI);
713709
714710 /// \brief Add a DIE to the set of types that we're going to pull into
715711 /// type units.
1313 #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
1414 #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
1515
16 #include "AsmPrinterHandler.h"
1716 #include "llvm/ADT/DenseMap.h"
1817 #include "llvm/CodeGen/AsmPrinter.h"
1918 #include
3534 //===----------------------------------------------------------------------===//
3635 /// DwarfException - Emits Dwarf exception handling directives.
3736 ///
38 class DwarfException : public AsmPrinterHandler {
37 class DwarfException {
3938 protected:
4039 /// Asm - Target of Dwarf emission.
4140 AsmPrinter *Asm;
140139
141140 /// endFunction - Gather and emit post-function exception information.
142141 virtual void endFunction();
143
144 // We don't need these.
145 virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
146 virtual void beginInstruction(const MachineInstr *MI) {}
147 virtual void endInstruction() {}
148142 };
149143
150144 class DwarfCFIException : public DwarfException {