Generalize debug info / EH emission in AsmPrinter

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196270 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Timur Iskhodzhanov
2013-12-03 12:05:18 +00:00
parent 616c94ba87
commit c6a2cbbacb
7 changed files with 164 additions and 76 deletions

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; 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 &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:
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(const GlobalVariable *GV) {
// 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();
}
MMI->EndFunction();
@@ -907,20 +916,15 @@ bool AsmPrinter::doFinalization(Module &M) {
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()) {