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
This commit is contained in:
NAKAMURA Takumi 2013-12-03 13:15:54 +00:00
parent c6a2cbbacb
commit b5dd6691ca
7 changed files with 76 additions and 164 deletions

View File

@ -22,7 +22,6 @@
#include "llvm/Support/ErrorHandling.h"
namespace llvm {
class AsmPrinterHandler;
class BlockAddress;
class GCStrategy;
class Constant;
@ -111,21 +110,13 @@ 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);

View File

@ -99,14 +99,14 @@ AsmPrinter::AsmPrinter(TargetMachine &tm, MCStreamer &Streamer)
OutContext(Streamer.getContext()),
OutStreamer(Streamer),
LastMI(0), LastFn(0), Counter(~0U), SetCounter(0) {
DD = 0; MMI = 0; LI = 0; MF = 0;
DD = 0; DE = 0; MMI = 0; LI = 0; MF = 0;
CurrentFnSym = CurrentFnSymForSize = 0;
GCMetadataPrinters = 0;
VerboseAsm = Streamer.isVerboseAsm();
}
AsmPrinter::~AsmPrinter() {
assert(DD == 0 && Handlers.empty() && "Debug/EH info didn't get finalized");
assert(DD == 0 && DE == 0 && "Debug/EH info didn't get finalized");
if (GCMetadataPrinters != 0) {
gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
@ -192,29 +192,25 @@ bool AsmPrinter::doInitialization(Module &M) {
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:
break;
return false;
case ExceptionHandling::SjLj:
case ExceptionHandling::DwarfCFI:
DE = new DwarfCFIException(this);
break;
return false;
case ExceptionHandling::ARM:
DE = new ARMException(this);
break;
return false;
case ExceptionHandling::Win64:
DE = new Win64Exception(this);
break;
return false;
}
if (DE)
Handlers.push_back(HandlerInfo(DE, EHTimerName, DWARFGroupName));
return false;
llvm_unreachable("Unknown exception type.");
}
void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
@ -315,11 +311,8 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
// sections and expected to be contiguous (e.g. ObjC metadata).
unsigned AlignLog = getGVAlignmentLog2(GV, *DL);
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);
}
if (DD)
DD->setSymbolSize(GVSym, Size);
// Handle common and BSS local symbols (.lcomm).
if (GVKind.isCommon() || GVKind.isBSSLocal()) {
@ -489,10 +482,13 @@ void AsmPrinter::EmitFunctionHeader() {
}
// Emit pre-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->beginFunction(MF);
if (DE) {
NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
DE->beginFunction(MF);
}
if (DD) {
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
DD->beginFunction(MF);
}
// Emit the prefix data.
@ -697,7 +693,7 @@ void AsmPrinter::EmitFunctionBody() {
// Emit target-specific gunk before the function body.
EmitFunctionBodyStart();
bool ShouldPrintDebugScopes = MMI->hasDebugInfo();
bool ShouldPrintDebugScopes = DD && MMI->hasDebugInfo();
// Print out code for the function.
bool HasAnyRealCode = false;
@ -718,12 +714,8 @@ void AsmPrinter::EmitFunctionBody() {
}
if (ShouldPrintDebugScopes) {
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);
}
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
DD->beginInstruction(II);
}
if (isVerbose())
@ -762,12 +754,8 @@ void AsmPrinter::EmitFunctionBody() {
}
if (ShouldPrintDebugScopes) {
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();
}
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
DD->endInstruction(II);
}
}
}
@ -823,11 +811,14 @@ void AsmPrinter::EmitFunctionBody() {
OutStreamer.EmitELFSize(CurrentFnSym, SizeExp);
}
// 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();
// Emit post-function debug information.
if (DD) {
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
DD->endFunction(MF);
}
if (DE) {
NamedRegionTimer T(EHTimerName, DWARFGroupName, TimePassesIsEnabled);
DE->endFunction();
}
MMI->EndFunction();
@ -916,15 +907,20 @@ bool AsmPrinter::doFinalization(Module &M) {
OutStreamer.Flush();
// Finalize debug and 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->endModule();
delete OI.Handler;
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;
}
Handlers.clear();
DD = 0;
// If the target wants to know about weak references, print them all.
if (MAI->getWeakRefDirective()) {

View File

@ -1,53 +0,0 @@
//===-- 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.
virtual void beginFunction(const MachineFunction *MF) = 0;
/// \brief Gather post-function debug information.
virtual void endFunction() = 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

View File

@ -390,9 +390,7 @@ unsigned DIEEntry::getRefAddrSize(AsmPrinter *AP) {
// 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.
const DwarfDebug *DD = AP->getDwarfDebug();
assert(DD && "Expected Dwarf Debug info to be available");
if (DD->getDwarfVersion() == 2)
if (AP->getDwarfDebug()->getDwarfVersion() == 2)
return AP->getDataLayout().getPointerSize();
return sizeof(int32_t);
}

View File

@ -197,7 +197,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
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.
@ -1145,7 +1144,6 @@ void DwarfDebug::endSections() {
// Emit all Dwarf sections that should come after the content.
void DwarfDebug::endModule() {
assert(CurFn == 0);
if (!FirstCU)
return;
@ -1227,7 +1225,8 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV,
}
// If Var is a current function argument then add it to CurrentFnArguments list.
bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,
DbgVariable *Var, LexicalScope *Scope) {
if (!LScopes.isCurrentFunctionScope(Scope))
return false;
DIVariable DV = Var->getVariable();
@ -1239,7 +1238,7 @@ bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
size_t Size = CurrentFnArguments.size();
if (Size == 0)
CurrentFnArguments.resize(CurFn->getFunction()->arg_size());
CurrentFnArguments.resize(MF->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)
@ -1250,7 +1249,7 @@ bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
// Collect variable information from side table maintained by MMI.
void DwarfDebug::collectVariableInfoFromMMITable(
SmallPtrSet<const MDNode *, 16> &Processed) {
const MachineFunction *MF, SmallPtrSet<const MDNode *, 16> &Processed) {
MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
VE = VMap.end();
@ -1271,7 +1270,7 @@ void DwarfDebug::collectVariableInfoFromMMITable(
DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);
RegVar->setFrameIndex(VP.first);
if (!addCurrentFnArgument(RegVar, Scope))
if (!addCurrentFnArgument(MF, RegVar, Scope))
addScopeVariable(Scope, RegVar);
if (AbsDbgVariable)
AbsDbgVariable->setFrameIndex(VP.first);
@ -1318,10 +1317,11 @@ static DotDebugLocEntry getDebugLocEntry(AsmPrinter *Asm,
// Find variables for each lexical scope.
void
DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
DwarfDebug::collectVariableInfo(const MachineFunction *MF,
SmallPtrSet<const MDNode *, 16> &Processed) {
// Grab the variable info that was squirreled away in the MMI side-table.
collectVariableInfoFromMMITable(Processed);
collectVariableInfoFromMMITable(MF, Processed);
for (SmallVectorImpl<const MDNode *>::const_iterator
UVI = UserVariables.begin(),
@ -1341,7 +1341,7 @@ DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
DIVariable DV(Var);
LexicalScope *Scope = NULL;
if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
DISubprogram(DV.getContext()).describes(MF->getFunction()))
Scope = LScopes.getCurrentFunctionScope();
else if (MDNode *IA = DV.getInlinedAt())
Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
@ -1355,7 +1355,7 @@ DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
assert(MInsn->isDebugValue() && "History must begin with debug value");
DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);
if (!addCurrentFnArgument(RegVar, Scope))
if (!addCurrentFnArgument(MF, RegVar, Scope))
addScopeVariable(Scope, RegVar);
if (AbsVar)
AbsVar->setMInsn(MInsn);
@ -1437,8 +1437,6 @@ MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
// 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();
@ -1480,16 +1478,14 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
}
// Process end of an instruction.
void DwarfDebug::endInstruction() {
assert(CurMI != 0);
void DwarfDebug::endInstruction(const MachineInstr *MI) {
// Don't create a new label after DBG_VALUE instructions.
// They don't generate code.
if (!CurMI->isDebugValue())
if (!MI->isDebugValue())
PrevLabel = 0;
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
LabelsAfterInsn.find(CurMI);
CurMI = 0;
LabelsAfterInsn.find(MI);
// No label needed.
if (I == LabelsAfterInsn.end())
@ -1569,7 +1565,6 @@ static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) {
// 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())
@ -1796,13 +1791,9 @@ void DwarfDebug::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
}
// Gather and emit post-function debug information.
void DwarfDebug::endFunction() {
assert(CurFn != 0);
if (!MMI->hasDebugInfo() || LScopes.empty()) {
CurFn = 0;
void DwarfDebug::endFunction(const MachineFunction *MF) {
if (!MMI->hasDebugInfo() || LScopes.empty())
return;
}
// Define end label for subprogram.
FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());
@ -1812,7 +1803,7 @@ void DwarfDebug::endFunction() {
Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
SmallPtrSet<const MDNode *, 16> ProcessedVars;
collectVariableInfo(ProcessedVars);
collectVariableInfo(MF, ProcessedVars);
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
@ -1846,7 +1837,7 @@ void DwarfDebug::endFunction() {
DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))
if (!MF->getTarget().Options.DisableFramePointerElim(*MF))
TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
// Clear debug info
@ -1862,7 +1853,6 @@ void DwarfDebug::endFunction() {
LabelsBeforeInsn.clear();
LabelsAfterInsn.clear();
PrevLabel = NULL;
CurFn = 0;
}
// Register a source line with debug info. Returns the unique label that was

View File

@ -14,7 +14,6 @@
#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"
@ -317,7 +316,7 @@ struct SymbolCU {
};
/// \brief Collects and handles dwarf debug information.
class DwarfDebug : public AsmPrinterHandler {
class DwarfDebug {
// Target of Dwarf emission.
AsmPrinter *Asm;
@ -419,12 +418,6 @@ class DwarfDebug : public AsmPrinterHandler {
// 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.
@ -655,14 +648,17 @@ class DwarfDebug : public AsmPrinterHandler {
/// \brief If Var is an current function argument that add it in
/// CurrentFnArguments list.
bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
bool addCurrentFnArgument(const MachineFunction *MF,
DbgVariable *Var, LexicalScope *Scope);
/// \brief Populate LexicalScope entries with variables' info.
void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
void collectVariableInfo(const MachineFunction *,
SmallPtrSet<const MDNode *, 16> &ProcessedVars);
/// \brief Collect variable information from the side table maintained
/// by MMI.
void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
void collectVariableInfoFromMMITable(const MachineFunction * MF,
SmallPtrSet<const MDNode *, 16> &P);
/// \brief Ensure that a label will be emitted before MI.
void requestLabelBeforeInsn(const MachineInstr *MI) {
@ -704,13 +700,13 @@ public:
void beginFunction(const MachineFunction *MF);
/// \brief Gather and emit post-function debug information.
void endFunction();
void endFunction(const MachineFunction *MF);
/// \brief Process beginning of an instruction.
void beginInstruction(const MachineInstr *MI);
/// \brief Process end of an instruction.
void endInstruction();
void endInstruction(const MachineInstr *MI);
/// \brief Add a DIE to the set of types that we're going to pull into
/// type units.

View File

@ -14,7 +14,6 @@
#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>
@ -36,7 +35,7 @@ class AsmPrinter;
//===----------------------------------------------------------------------===//
/// DwarfException - Emits Dwarf exception handling directives.
///
class DwarfException : public AsmPrinterHandler {
class DwarfException {
protected:
/// Asm - Target of Dwarf emission.
AsmPrinter *Asm;
@ -141,11 +140,6 @@ public:
/// endFunction - Gather and emit post-function exception information.
virtual void endFunction();
// 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 {