Comment some and reformat for clarity beginFunction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193894 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher
2013-11-01 23:14:17 +00:00
parent 96bf70c13b
commit 31ed50c225

View File

@@ -1595,13 +1595,25 @@ static DebugLoc getFnDebugLoc(DebugLoc DL, const LLVMContext &Ctx) {
// Gather pre-function debug information. Assumes being called immediately // Gather pre-function debug information. Assumes being called immediately
// after the function entry point has been emitted. // after the function entry point has been emitted.
void DwarfDebug::beginFunction(const MachineFunction *MF) { void DwarfDebug::beginFunction(const MachineFunction *MF) {
if (!MMI->hasDebugInfo()) return;
// If there's no debug info for the function we're not going to do anything.
if (!MMI->hasDebugInfo())
return;
// Grab the lexical scopes for the function, if we don't have any of those
// then we're not going to be able to do anything.
LScopes.initialize(*MF); LScopes.initialize(*MF);
if (LScopes.empty()) return; if (LScopes.empty())
return;
assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned");
// Make sure that each lexical scope will have a begin/end label.
identifyScopeMarkers(); identifyScopeMarkers();
// Set DwarfCompileUnitID in MCContext to the Compile Unit this function // Set DwarfCompileUnitID in MCContext to the Compile Unit this function
// belongs to. // belongs to so that we add to the correct per-cu line table in the
// non-asm case.
LexicalScope *FnScope = LScopes.getCurrentFunctionScope(); LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode()); CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
assert(TheCU && "Unable to find compile unit!"); assert(TheCU && "Unable to find compile unit!");
@@ -1611,19 +1623,17 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
else else
Asm->OutStreamer.getContext().setDwarfCompileUnitID(TheCU->getUniqueID()); Asm->OutStreamer.getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
FunctionBeginSym = Asm->GetTempSymbol("func_begin", // Emit a label for the function so that we have a beginning address.
Asm->getFunctionNumber()); FunctionBeginSym = Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber());
// Assumes in correct section after the entry point. // Assumes in correct section after the entry point.
Asm->OutStreamer.EmitLabel(FunctionBeginSym); Asm->OutStreamer.EmitLabel(FunctionBeginSym);
assert(UserVariables.empty() && DbgValues.empty() && "Maps weren't cleaned");
const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo(); const TargetRegisterInfo *TRI = Asm->TM.getRegisterInfo();
// LiveUserVar - Map physreg numbers to the MDNode they contain. // LiveUserVar - Map physreg numbers to the MDNode they contain.
std::vector<const MDNode*> LiveUserVar(TRI->getNumRegs()); std::vector<const MDNode *> LiveUserVar(TRI->getNumRegs());
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
I != E; ++I) { ++I) {
bool AtBlockEntry = true; bool AtBlockEntry = true;
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
II != IE; ++II) { II != IE; ++II) {
@@ -1641,7 +1651,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
LiveUserVar[MI->getOperand(0).getReg()] = Var; LiveUserVar[MI->getOperand(0).getReg()] = Var;
// Check the history of this variable. // Check the history of this variable.
SmallVectorImpl<const MachineInstr*> &History = DbgValues[Var]; SmallVectorImpl<const MachineInstr *> &History = DbgValues[Var];
if (History.empty()) { if (History.empty()) {
UserVariables.push_back(Var); UserVariables.push_back(Var);
// The first mention of a function argument gets the FunctionBeginSym // The first mention of a function argument gets the FunctionBeginSym
@@ -1659,8 +1669,8 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
if (History.size() >= 2 && if (History.size() >= 2 &&
Prev->isIdenticalTo(History[History.size() - 2])) { Prev->isIdenticalTo(History[History.size() - 2])) {
DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n" DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
<< "\t" << *Prev << "\t" << *Prev << "\t"
<< "\t" << *History[History.size() - 2] << "\n"); << *History[History.size() - 2] << "\n");
History.pop_back(); History.pop_back();
} }
@@ -1697,11 +1707,12 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
// Check if the instruction clobbers any registers with debug vars. // Check if the instruction clobbers any registers with debug vars.
for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(), for (MachineInstr::const_mop_iterator MOI = MI->operands_begin(),
MOE = MI->operands_end(); MOI != MOE; ++MOI) { MOE = MI->operands_end();
MOI != MOE; ++MOI) {
if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg()) if (!MOI->isReg() || !MOI->isDef() || !MOI->getReg())
continue; continue;
for (MCRegAliasIterator AI(MOI->getReg(), TRI, true); for (MCRegAliasIterator AI(MOI->getReg(), TRI, true); AI.isValid();
AI.isValid(); ++AI) { ++AI) {
unsigned Reg = *AI; unsigned Reg = *AI;
const MDNode *Var = LiveUserVar[Reg]; const MDNode *Var = LiveUserVar[Reg];
if (!Var) if (!Var)
@@ -1713,7 +1724,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
DbgValueHistoryMap::iterator HistI = DbgValues.find(Var); DbgValueHistoryMap::iterator HistI = DbgValues.find(Var);
if (HistI == DbgValues.end()) if (HistI == DbgValues.end())
continue; continue;
SmallVectorImpl<const MachineInstr*> &History = HistI->second; SmallVectorImpl<const MachineInstr *> &History = HistI->second;
if (History.empty()) if (History.empty())
continue; continue;
const MachineInstr *Prev = History.back(); const MachineInstr *Prev = History.back();
@@ -1735,7 +1746,7 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end(); for (DbgValueHistoryMap::iterator I = DbgValues.begin(), E = DbgValues.end();
I != E; ++I) { I != E; ++I) {
SmallVectorImpl<const MachineInstr*> &History = I->second; SmallVectorImpl<const MachineInstr *> &History = I->second;
if (History.empty()) if (History.empty())
continue; continue;
@@ -1768,9 +1779,10 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
// Record beginning of function. // Record beginning of function.
if (!PrologEndLoc.isUnknown()) { if (!PrologEndLoc.isUnknown()) {
DebugLoc FnStartDL = getFnDebugLoc(PrologEndLoc, DebugLoc FnStartDL =
MF->getFunction()->getContext()); getFnDebugLoc(PrologEndLoc, MF->getFunction()->getContext());
recordSourceLine(FnStartDL.getLine(), FnStartDL.getCol(), recordSourceLine(
FnStartDL.getLine(), FnStartDL.getCol(),
FnStartDL.getScope(MF->getFunction()->getContext()), FnStartDL.getScope(MF->getFunction()->getContext()),
// We'd like to list the prologue as "not statements" but GDB behaves // We'd like to list the prologue as "not statements" but GDB behaves
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing. // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.