[llvm] r196288 - Reland 196270 "Generalize debug info / EH emission in AsmPrinter"
Eric Christopher
echristo at gmail.com
Tue Dec 3 10:50:47 PST 2013
Wat?
-eric
On Tue, Dec 3, 2013 at 7:18 AM, Timur Iskhodzhanov <timurrrr at google.com> wrote:
> For your convenience, attached is the patch against r196270, so the "fix" is
> more obvious.
>
>
> 2013/12/3 Timur Iskhodzhanov <timurrrr at google.com>
>>
>> Author: timurrrr
>> Date: Tue Dec 3 09:10:23 2013
>> New Revision: 196288
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=196288&view=rev
>> Log:
>> Reland 196270 "Generalize debug info / EH emission in AsmPrinter"
>>
>> Addressing the existense AMDGPUAsmPrinter and other subclasses of
>> AsmPrinter
>>
>> Added:
>> llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h
>> Modified:
>> llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
>> llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
>> llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h
>> llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp
>>
>> Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
>> +++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Dec 3 09:10:23 2013
>> @@ -22,6 +22,7 @@
>> #include "llvm/Support/ErrorHandling.h"
>>
>> namespace llvm {
>> + class AsmPrinterHandler;
>> class BlockAddress;
>> class GCStrategy;
>> class Constant;
>> @@ -110,13 +111,21 @@ namespace llvm {
>> /// function.
>> MachineLoopInfo *LI;
>>
>> + struct HandlerInfo {
>> + AsmPrinterHandler *Handler;
>> + const char *TimerName, *TimerGroupName;
>> + HandlerInfo(AsmPrinterHandler *Handler, const char *TimerName,
>> + const char *TimerGroupName)
>> + : Handler(Handler), TimerName(TimerName),
>> + TimerGroupName(TimerGroupName) {}
>> + };
>> + /// Handlers - a vector of all debug/EH info emitters we should use.
>> + /// This vector maintains ownership of the emitters.
>> + SmallVector<HandlerInfo, 1> Handlers;
>> +
>> /// DD - If the target supports dwarf debug info, this pointer is
>> non-null.
>> DwarfDebug *DD;
>>
>> - /// DE - If the target supports dwarf exception info, this pointer is
>> - /// non-null.
>> - DwarfException *DE;
>> -
>> protected:
>> explicit AsmPrinter(TargetMachine &TM, MCStreamer &Streamer);
>>
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp Tue Dec 3 09:10:23
>> 2013
>> @@ -66,7 +66,7 @@ void ARMException::beginFunction(const M
>>
>> /// endFunction - Gather and emit post-function exception information.
>> ///
>> -void ARMException::endFunction() {
>> +void ARMException::endFunction(const MachineFunction *) {
>> ARMTargetStreamer &ATS = getTargetStreamer();
>> if (!Asm->MF->getFunction()->needsUnwindTableEntry())
>> ATS.emitCantUnwind();
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Dec 3 09:10:23
>> 2013
>> @@ -99,14 +99,14 @@ AsmPrinter::AsmPrinter(TargetMachine &tm
>> OutContext(Streamer.getContext()),
>> OutStreamer(Streamer),
>> LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) {
>> - DD = 0; DE = 0; MMI = 0; LI = 0; MF = 0;
>> + DD = 0; MMI = 0; LI = 0; MF = 0;
>> CurrentFnSym = CurrentFnSymForSize = 0;
>> GCMetadataPrinters = 0;
>> VerboseAsm = Streamer.isVerboseAsm();
>> }
>>
>> AsmPrinter::~AsmPrinter() {
>> - assert(DD == 0 && DE == 0 && "Debug/EH info didn't get finalized");
>> + assert(DD == 0 && Handlers.empty() && "Debug/EH info didn't get
>> finalized");
>>
>> if (GCMetadataPrinters != 0) {
>> gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
>> @@ -192,25 +192,29 @@ bool AsmPrinter::doInitialization(Module
>> OutStreamer.AddBlankLine();
>> }
>>
>> - if (MAI->doesSupportDebugInformation())
>> + if (MAI->doesSupportDebugInformation()) {
>> DD = new DwarfDebug(this, &M);
>> + Handlers.push_back(HandlerInfo(DD, DbgTimerName, DWARFGroupName));
>> + }
>>
>> + DwarfException *DE = 0;
>> switch (MAI->getExceptionHandlingType()) {
>> case ExceptionHandling::None:
>> - return false;
>> + break;
>> case ExceptionHandling::SjLj:
>> case ExceptionHandling::DwarfCFI:
>> DE = new DwarfCFIException(this);
>> - return false;
>> + break;
>> case ExceptionHandling::ARM:
>> DE = new ARMException(this);
>> - return false;
>> + break;
>> case ExceptionHandling::Win64:
>> DE = new Win64Exception(this);
>> - return false;
>> + break;
>> }
>> -
>> - llvm_unreachable("Unknown exception type.");
>> + if (DE)
>> + Handlers.push_back(HandlerInfo(DE, EHTimerName, DWARFGroupName));
>> + return false;
>> }
>>
>> void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym)
>> const {
>> @@ -311,8 +315,11 @@ void AsmPrinter::EmitGlobalVariable(cons
>> // sections and expected to be contiguous (e.g. ObjC metadata).
>> unsigned AlignLog = getGVAlignmentLog2(GV, *DL);
>>
>> - if (DD)
>> - DD->setSymbolSize(GVSym, Size);
>> + for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
>> + const HandlerInfo &OI = Handlers[I];
>> + NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
>> TimePassesIsEnabled);
>> + OI.Handler->setSymbolSize(GVSym, Size);
>> + }
>>
>> // Handle common and BSS local symbols (.lcomm).
>> if (GVKind.isCommon() || GVKind.isBSSLocal()) {
>> @@ -482,13 +489,10 @@ void AsmPrinter::EmitFunctionHeader() {
>> }
>>
>> // Emit pre-function debug and/or EH information.
>> - if (DE) {
>> - NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
>> - DE->beginFunction(MF);
>> - }
>> - if (DD) {
>> - NamedRegionTimer T(DbgTimerName, DWARFGroupName,
>> TimePassesIsEnabled);
>> - DD->beginFunction(MF);
>> + for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
>> + const HandlerInfo &OI = Handlers[I];
>> + NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
>> TimePassesIsEnabled);
>> + OI.Handler->beginFunction(MF);
>> }
>>
>> // Emit the prefix data.
>> @@ -693,7 +697,7 @@ void AsmPrinter::EmitFunctionBody() {
>> // Emit target-specific gunk before the function body.
>> EmitFunctionBodyStart();
>>
>> - bool ShouldPrintDebugScopes = DD && MMI->hasDebugInfo();
>> + bool ShouldPrintDebugScopes = MMI->hasDebugInfo();
>>
>> // Print out code for the function.
>> bool HasAnyRealCode = false;
>> @@ -714,8 +718,12 @@ void AsmPrinter::EmitFunctionBody() {
>> }
>>
>> if (ShouldPrintDebugScopes) {
>> - NamedRegionTimer T(DbgTimerName, DWARFGroupName,
>> TimePassesIsEnabled);
>> - DD->beginInstruction(II);
>> + for (unsigned III = 0, EEE = Handlers.size(); III != EEE; ++III)
>> {
>> + const HandlerInfo &OI = Handlers[III];
>> + NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
>> + TimePassesIsEnabled);
>> + OI.Handler->beginInstruction(II);
>> + }
>> }
>>
>> if (isVerbose())
>> @@ -754,8 +762,12 @@ void AsmPrinter::EmitFunctionBody() {
>> }
>>
>> if (ShouldPrintDebugScopes) {
>> - NamedRegionTimer T(DbgTimerName, DWARFGroupName,
>> TimePassesIsEnabled);
>> - DD->endInstruction(II);
>> + for (unsigned III = 0, EEE = Handlers.size(); III != EEE; ++III)
>> {
>> + const HandlerInfo &OI = Handlers[III];
>> + NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
>> + TimePassesIsEnabled);
>> + OI.Handler->endInstruction();
>> + }
>> }
>> }
>> }
>> @@ -811,14 +823,11 @@ void AsmPrinter::EmitFunctionBody() {
>> OutStreamer.EmitELFSize(CurrentFnSym, SizeExp);
>> }
>>
>> - // Emit post-function debug information.
>> - if (DD) {
>> - NamedRegionTimer T(DbgTimerName, DWARFGroupName,
>> TimePassesIsEnabled);
>> - DD->endFunction(MF);
>> - }
>> - if (DE) {
>> - NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
>> - DE->endFunction();
>> + // Emit post-function debug and/or EH information.
>> + for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
>> + const HandlerInfo &OI = Handlers[I];
>> + NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
>> TimePassesIsEnabled);
>> + OI.Handler->endFunction(MF);
>> }
>> MMI->EndFunction();
>>
>> @@ -907,20 +916,15 @@ bool AsmPrinter::doFinalization(Module &
>> OutStreamer.Flush();
>>
>> // Finalize debug and EH information.
>> - if (DE) {
>> - {
>> - NamedRegionTimer T(EHTimerName, DWARFGroupName,
>> TimePassesIsEnabled);
>> - DE->endModule();
>> - }
>> - delete DE; DE = 0;
>> - }
>> - if (DD) {
>> - {
>> - NamedRegionTimer T(DbgTimerName, DWARFGroupName,
>> TimePassesIsEnabled);
>> - DD->endModule();
>> - }
>> - delete DD; DD = 0;
>> + for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
>> + const HandlerInfo &OI = Handlers[I];
>> + NamedRegionTimer T(OI.TimerName, OI.TimerGroupName,
>> + TimePassesIsEnabled);
>> + OI.Handler->endModule();
>> + delete OI.Handler;
>> }
>> + Handlers.clear();
>> + DD = 0;
>>
>> // If the target wants to know about weak references, print them all.
>> if (MAI->getWeakRefDirective()) {
>>
>> Added: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h?rev=196288&view=auto
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h (added)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterHandler.h Tue Dec 3
>> 09:10:23 2013
>> @@ -0,0 +1,56 @@
>> +//===-- lib/CodeGen/AsmPrinter/AsmPrinterHandler.h -------------*- C++
>> -*--===//
>> +//
>> +// The LLVM Compiler Infrastructure
>> +//
>> +// This file is distributed under the University of Illinois Open Source
>> +// License. See LICENSE.TXT for details.
>> +//
>>
>> +//===----------------------------------------------------------------------===//
>> +//
>> +// This file contains a generic interface for AsmPrinter handlers,
>> +// like debug and EH info emitters.
>> +//
>>
>> +//===----------------------------------------------------------------------===//
>> +
>> +#ifndef CODEGEN_ASMPRINTER_ASMPRINTERHANDLER_H__
>> +#define CODEGEN_ASMPRINTER_ASMPRINTERHANDLER_H__
>> +
>> +#include "llvm/Support/DataTypes.h"
>> +
>> +namespace llvm {
>> +
>> +class MachineFunction;
>> +class MachineInstr;
>> +class MCSymbol;
>> +
>> +/// \brief Collects and handles AsmPrinter objects required to build
>> debug
>> +/// or EH information.
>> +class AsmPrinterHandler {
>> +public:
>> + virtual ~AsmPrinterHandler() {}
>> +
>> + /// \brief For symbols that have a size designated (e.g. common
>> symbols),
>> + /// this tracks that size.
>> + virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) = 0;
>> +
>> + /// \brief Emit all sections that should come after the content.
>> + virtual void endModule() = 0;
>> +
>> + /// \brief Gather pre-function debug information.
>> + /// Every beginFunction(MF) call should be followed by an
>> endFunction(MF) call.
>> + virtual void beginFunction(const MachineFunction *MF) = 0;
>> +
>> + /// \brief Gather post-function debug information.
>> + /// Please note that some AsmPrinter implementationss may not call
>> + /// beginFunction at all.
>> + virtual void endFunction(const MachineFunction *MF) = 0;
>> +
>> + /// \brief Process beginning of an instruction.
>> + virtual void beginInstruction(const MachineInstr *MI) = 0;
>> +
>> + /// \brief Process end of an instruction.
>> + virtual void endInstruction() = 0;
>> +};
>> +} // End of namespace llvm
>> +
>> +#endif
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Tue Dec 3 09:10:23 2013
>> @@ -390,7 +390,9 @@ unsigned DIEEntry::getRefAddrSize(AsmPri
>> // specified to be four bytes in the DWARF 32-bit format and eight
>> bytes
>> // in the DWARF 64-bit format, while DWARF Version 2 specifies that
>> such
>> // references have the same size as an address on the target system.
>> - if (AP->getDwarfDebug()->getDwarfVersion() == 2)
>> + const DwarfDebug *DD = AP->getDwarfDebug();
>> + assert(DD && "Expected Dwarf Debug info to be available");
>> + if (DD->getDwarfVersion() == 2)
>> return AP->getDataLayout().getPointerSize();
>> return sizeof(int32_t);
>> }
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp Tue Dec 3
>> 09:10:23 2013
>> @@ -137,7 +137,7 @@ void DwarfCFIException::beginFunction(co
>>
>> /// endFunction - Gather and emit post-function exception information.
>> ///
>> -void DwarfCFIException::endFunction() {
>> +void DwarfCFIException::endFunction(const MachineFunction *) {
>> if (!shouldEmitPersonality && !shouldEmitMoves)
>> return;
>>
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Tue Dec 3 09:10:23
>> 2013
>> @@ -197,6 +197,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
>> DwarfAddrSectionSym = 0;
>> DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = 0;
>> FunctionBeginSym = FunctionEndSym = 0;
>> + CurFn = 0; CurMI = 0;
>>
>> // Turn on accelerator tables for Darwin by default, pubnames by
>> // default for non-Darwin, and handle split dwarf.
>> @@ -1144,6 +1145,8 @@ void DwarfDebug::endSections() {
>>
>> // Emit all Dwarf sections that should come after the content.
>> void DwarfDebug::endModule() {
>> + assert(CurFn == 0);
>> + assert(CurMI == 0);
>>
>> if (!FirstCU)
>> return;
>> @@ -1225,8 +1228,7 @@ DbgVariable *DwarfDebug::findAbstractVar
>> }
>>
>> // If Var is a current function argument then add it to
>> CurrentFnArguments list.
>> -bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,
>> - DbgVariable *Var, LexicalScope
>> *Scope) {
>> +bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope
>> *Scope) {
>> if (!LScopes.isCurrentFunctionScope(Scope))
>> return false;
>> DIVariable DV = Var->getVariable();
>> @@ -1238,7 +1240,7 @@ bool DwarfDebug::addCurrentFnArgument(co
>>
>> size_t Size = CurrentFnArguments.size();
>> if (Size == 0)
>> - CurrentFnArguments.resize(MF->getFunction()->arg_size());
>> + CurrentFnArguments.resize(CurFn->getFunction()->arg_size());
>> // llvm::Function argument size is not good indicator of how many
>> // arguments does the function have at source level.
>> if (ArgNo > Size)
>> @@ -1249,7 +1251,7 @@ bool DwarfDebug::addCurrentFnArgument(co
>>
>> // Collect variable information from side table maintained by MMI.
>> void DwarfDebug::collectVariableInfoFromMMITable(
>> - const MachineFunction *MF, SmallPtrSet<const MDNode *, 16>
>> &Processed) {
>> + SmallPtrSet<const MDNode *, 16> &Processed) {
>> MachineModuleInfo::VariableDbgInfoMapTy &VMap =
>> MMI->getVariableDbgInfo();
>> for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI =
>> VMap.begin(),
>> VE = VMap.end();
>> @@ -1270,7 +1272,7 @@ void DwarfDebug::collectVariableInfoFrom
>> DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
>> DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);
>> RegVar->setFrameIndex(VP.first);
>> - if (!addCurrentFnArgument(MF, RegVar, Scope))
>> + if (!addCurrentFnArgument(RegVar, Scope))
>> addScopeVariable(Scope, RegVar);
>> if (AbsDbgVariable)
>> AbsDbgVariable->setFrameIndex(VP.first);
>> @@ -1317,11 +1319,10 @@ static DotDebugLocEntry getDebugLocEntry
>>
>> // Find variables for each lexical scope.
>> void
>> -DwarfDebug::collectVariableInfo(const MachineFunction *MF,
>> - SmallPtrSet<const MDNode *, 16>
>> &Processed) {
>> +DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16>
>> &Processed) {
>>
>> // Grab the variable info that was squirreled away in the MMI
>> side-table.
>> - collectVariableInfoFromMMITable(MF, Processed);
>> + collectVariableInfoFromMMITable(Processed);
>>
>> for (SmallVectorImpl<const MDNode *>::const_iterator
>> UVI = UserVariables.begin(),
>> @@ -1341,7 +1342,7 @@ DwarfDebug::collectVariableInfo(const Ma
>> DIVariable DV(Var);
>> LexicalScope *Scope = NULL;
>> if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
>> - DISubprogram(DV.getContext()).describes(MF->getFunction()))
>> + DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
>> Scope = LScopes.getCurrentFunctionScope();
>> else if (MDNode *IA = DV.getInlinedAt())
>> Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
>> @@ -1355,7 +1356,7 @@ DwarfDebug::collectVariableInfo(const Ma
>> assert(MInsn->isDebugValue() && "History must begin with debug
>> value");
>> DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
>> DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);
>> - if (!addCurrentFnArgument(MF, RegVar, Scope))
>> + if (!addCurrentFnArgument(RegVar, Scope))
>> addScopeVariable(Scope, RegVar);
>> if (AbsVar)
>> AbsVar->setMInsn(MInsn);
>> @@ -1437,6 +1438,8 @@ MCSymbol *DwarfDebug::getLabelAfterInsn(
>>
>> // Process beginning of an instruction.
>> void DwarfDebug::beginInstruction(const MachineInstr *MI) {
>> + assert(CurMI == 0);
>> + CurMI = MI;
>> // Check if source location changes, but ignore DBG_VALUE locations.
>> if (!MI->isDebugValue()) {
>> DebugLoc DL = MI->getDebugLoc();
>> @@ -1478,14 +1481,16 @@ void DwarfDebug::beginInstruction(const
>> }
>>
>> // Process end of an instruction.
>> -void DwarfDebug::endInstruction(const MachineInstr *MI) {
>> +void DwarfDebug::endInstruction() {
>> + assert(CurMI != 0);
>> // Don't create a new label after DBG_VALUE instructions.
>> // They don't generate code.
>> - if (!MI->isDebugValue())
>> + if (!CurMI->isDebugValue())
>> PrevLabel = 0;
>>
>> DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
>> - LabelsAfterInsn.find(MI);
>> + LabelsAfterInsn.find(CurMI);
>> + CurMI = 0;
>>
>> // No label needed.
>> if (I == LabelsAfterInsn.end())
>> @@ -1565,6 +1570,7 @@ static DebugLoc getFnDebugLoc(DebugLoc D
>> // Gather pre-function debug information. Assumes being called
>> immediately
>> // after the function entry point has been emitted.
>> void DwarfDebug::beginFunction(const MachineFunction *MF) {
>> + CurFn = MF;
>>
>> // If there's no debug info for the function we're not going to do
>> anything.
>> if (!MMI->hasDebugInfo())
>> @@ -1792,8 +1798,19 @@ void DwarfDebug::addScopeVariable(Lexica
>>
>> // Gather and emit post-function debug information.
>> void DwarfDebug::endFunction(const MachineFunction *MF) {
>> - if (!MMI->hasDebugInfo() || LScopes.empty())
>> + // Every beginFunction(MF) call should be followed by an
>> endFunction(MF) call,
>> + // though the beginFunction may not be called at all.
>> + // We should handle both cases.
>> + if (CurFn == 0)
>> + CurFn = MF;
>> + else
>> + assert(CurFn == MF);
>> + assert(CurFn != 0);
>> +
>> + if (!MMI->hasDebugInfo() || LScopes.empty()) {
>> + CurFn = 0;
>> return;
>> + }
>>
>> // Define end label for subprogram.
>> FunctionEndSym = Asm->GetTempSymbol("func_end",
>> Asm->getFunctionNumber());
>> @@ -1803,7 +1820,7 @@ void DwarfDebug::endFunction(const Machi
>> Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
>>
>> SmallPtrSet<const MDNode *, 16> ProcessedVars;
>> - collectVariableInfo(MF, ProcessedVars);
>> + collectVariableInfo(ProcessedVars);
>>
>> LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
>> CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
>> @@ -1837,7 +1854,7 @@ void DwarfDebug::endFunction(const Machi
>>
>> DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
>>
>> - if (!MF->getTarget().Options.DisableFramePointerElim(*MF))
>> + if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))
>> TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
>>
>> // Clear debug info
>> @@ -1853,6 +1870,7 @@ void DwarfDebug::endFunction(const Machi
>> LabelsBeforeInsn.clear();
>> LabelsAfterInsn.clear();
>> PrevLabel = NULL;
>> + CurFn = 0;
>> }
>>
>> // Register a source line with debug info. Returns the unique label that
>> was
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Tue Dec 3 09:10:23
>> 2013
>> @@ -14,6 +14,7 @@
>> #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
>> #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
>>
>> +#include "AsmPrinterHandler.h"
>> #include "DIE.h"
>> #include "llvm/ADT/DenseMap.h"
>> #include "llvm/ADT/FoldingSet.h"
>> @@ -316,7 +317,7 @@ struct SymbolCU {
>> };
>>
>> /// \brief Collects and handles dwarf debug information.
>> -class DwarfDebug {
>> +class DwarfDebug : public AsmPrinterHandler {
>> // Target of Dwarf emission.
>> AsmPrinter *Asm;
>>
>> @@ -418,6 +419,12 @@ class DwarfDebug {
>> // body.
>> DebugLoc PrologEndLoc;
>>
>> + // If nonnull, stores the current machine function we're processing.
>> + const MachineFunction *CurFn;
>> +
>> + // If nonnull, stores the current machine instruction we're processing.
>> + const MachineInstr *CurMI;
>> +
>> // Section Symbols: these are assembler temporary labels that are
>> emitted at
>> // the beginning of each supported dwarf section. These are used to
>> form
>> // section offsets and are created by EmitSectionLabels.
>> @@ -648,17 +655,14 @@ class DwarfDebug {
>>
>> /// \brief If Var is an current function argument that add it in
>> /// CurrentFnArguments list.
>> - bool addCurrentFnArgument(const MachineFunction *MF,
>> - DbgVariable *Var, LexicalScope *Scope);
>> + bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
>>
>> /// \brief Populate LexicalScope entries with variables' info.
>> - void collectVariableInfo(const MachineFunction *,
>> - SmallPtrSet<const MDNode *, 16>
>> &ProcessedVars);
>> + void collectVariableInfo(SmallPtrSet<const MDNode *, 16>
>> &ProcessedVars);
>>
>> /// \brief Collect variable information from the side table maintained
>> /// by MMI.
>> - void collectVariableInfoFromMMITable(const MachineFunction * MF,
>> - SmallPtrSet<const MDNode *, 16>
>> &P);
>> + void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16>
>> &P);
>>
>> /// \brief Ensure that a label will be emitted before MI.
>> void requestLabelBeforeInsn(const MachineInstr *MI) {
>> @@ -706,7 +710,7 @@ public:
>> void beginInstruction(const MachineInstr *MI);
>>
>> /// \brief Process end of an instruction.
>> - void endInstruction(const MachineInstr *MI);
>> + void endInstruction();
>>
>> /// \brief Add a DIE to the set of types that we're going to pull into
>> /// type units.
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.cpp Tue Dec 3
>> 09:10:23 2013
>> @@ -730,7 +730,6 @@ void DwarfException::beginFunction(const
>> }
>>
>> /// endFunction - Gather and emit post-function exception information.
>> -///
>> -void DwarfException::endFunction() {
>> +void DwarfException::endFunction(const MachineFunction *) {
>> llvm_unreachable("Should be implemented");
>> }
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfException.h Tue Dec 3 09:10:23
>> 2013
>> @@ -14,6 +14,7 @@
>> #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
>> #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
>>
>> +#include "AsmPrinterHandler.h"
>> #include "llvm/ADT/DenseMap.h"
>> #include "llvm/CodeGen/AsmPrinter.h"
>> #include <vector>
>> @@ -35,7 +36,7 @@ class AsmPrinter;
>>
>> //===----------------------------------------------------------------------===//
>> /// DwarfException - Emits Dwarf exception handling directives.
>> ///
>> -class DwarfException {
>> +class DwarfException : public AsmPrinterHandler {
>> protected:
>> /// Asm - Target of Dwarf emission.
>> AsmPrinter *Asm;
>> @@ -139,7 +140,12 @@ public:
>> virtual void beginFunction(const MachineFunction *MF);
>>
>> /// endFunction - Gather and emit post-function exception information.
>> - virtual void endFunction();
>> + virtual void endFunction(const MachineFunction *);
>> +
>> + // We don't need these.
>> + virtual void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {}
>> + virtual void beginInstruction(const MachineInstr *MI) {}
>> + virtual void endInstruction() {}
>> };
>>
>> class DwarfCFIException : public DwarfException {
>> @@ -173,7 +179,7 @@ public:
>> virtual void beginFunction(const MachineFunction *MF);
>>
>> /// endFunction - Gather and emit post-function exception information.
>> - virtual void endFunction();
>> + virtual void endFunction(const MachineFunction *);
>> };
>>
>> class ARMException : public DwarfException {
>> @@ -196,7 +202,7 @@ public:
>> virtual void beginFunction(const MachineFunction *MF);
>>
>> /// endFunction - Gather and emit post-function exception information.
>> - virtual void endFunction();
>> + virtual void endFunction(const MachineFunction *);
>> };
>>
>> class Win64Exception : public DwarfException {
>> @@ -228,7 +234,7 @@ public:
>> virtual void beginFunction(const MachineFunction *MF);
>>
>> /// endFunction - Gather and emit post-function exception information.
>> - virtual void endFunction();
>> + virtual void endFunction(const MachineFunction *);
>> };
>>
>> } // End of namespace llvm
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp?rev=196288&r1=196287&r2=196288&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp Tue Dec 3
>> 09:10:23 2013
>> @@ -88,7 +88,7 @@ void Win64Exception::beginFunction(const
>>
>> /// endFunction - Gather and emit post-function exception information.
>> ///
>> -void Win64Exception::endFunction() {
>> +void Win64Exception::endFunction(const MachineFunction *) {
>> if (!shouldEmitPersonality && !shouldEmitMoves)
>> return;
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
More information about the llvm-commits
mailing list