Skip to content

Commit

Permalink
Record variable debug info at ISel time directly.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79742 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Devang Patel committed Aug 22, 2009
1 parent 310ed13 commit 24f20e0
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 256 deletions.
7 changes: 1 addition & 6 deletions include/llvm/CodeGen/DwarfWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class DwarfWriter : public ImmutablePass {

/// RecordVariable - Indicate the declaration of a local variable.
///
void RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
const MachineInstr *MI);
void RecordVariable(GlobalVariable *GV, unsigned FrameIndex);

/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
/// be emitted.
Expand All @@ -111,10 +110,6 @@ class DwarfWriter : public ImmutablePass {

/// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
unsigned RecordInlinedFnEnd(DISubprogram SP);

/// RecordVariableScope - Record scope for the variable declared by
/// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
void RecordVariableScope(DIVariable &DV, const MachineInstr *DeclareMI);
};


Expand Down
6 changes: 0 additions & 6 deletions include/llvm/CodeGen/SelectionDAGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,6 @@ namespace ISD {
DBG_LABEL,
EH_LABEL,

// DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
// local variable declarations for debugging information. First operand is
// a chain, while the next two operands are first two arguments (address
// and variable) of a llvm.dbg.declare instruction.
DECLARE,

// STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
// value, the same type as the pointer type for the system, and an output
// chain.
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/Target/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TargetInstrInfo {
DBG_LABEL = 2,
EH_LABEL = 3,
GC_LABEL = 4,
DECLARE = 5,
// FIXME: DECLARE is removed. Readjust enum values ?

/// EXTRACT_SUBREG - This instruction takes two operands: a register
/// that has subregisters, and a subregister index. It returns the
Expand Down
10 changes: 0 additions & 10 deletions lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1567,16 +1567,6 @@ void AsmPrinter::printLabel(unsigned Id) const {
O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
}

/// printDeclare - This method prints a local variable declaration used by
/// debug tables.
/// FIXME: It doesn't really print anything rather it inserts a DebugVariable
/// entry into dwarf table.
void AsmPrinter::printDeclare(const MachineInstr *MI) const {
unsigned FI = MI->getOperand(0).getIndex();
GlobalValue *GV = MI->getOperand(1).getGlobal();
DW->RecordVariable(cast<GlobalVariable>(GV), FI, MI);
}

/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
/// instruction, using the specified assembler variant. Targets should
/// overried this to format as appropriate.
Expand Down
59 changes: 17 additions & 42 deletions lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,6 @@ void DwarfDebug::EndFunction(MachineFunction *MF) {
DbgScopeMap.clear();
DbgAbstractScopeMap.clear();
DbgConcreteScopeMap.clear();
InlinedVariableScopes.clear();
FunctionDbgScope = NULL;
LexicalScopeStack.clear();
AbstractInstanceRootList.clear();
Expand Down Expand Up @@ -1609,8 +1608,7 @@ unsigned DwarfDebug::RecordRegionEnd(GlobalVariable *V) {
}

/// RecordVariable - Indicate the declaration of a local variable.
void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
const MachineInstr *MI) {
void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
if (TimePassesIsEnabled)
DebugTimer->startTimer();

Expand All @@ -1623,18 +1621,22 @@ void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
DIGlobalVariable DG(GV);
Scope = getOrCreateScope(DG.getContext().getGV());
} else {
DenseMap<const MachineInstr *, DbgScope *>::iterator
SI = InlinedVariableScopes.find(MI);

if (SI != InlinedVariableScopes.end()) {
// or GV is an inlined local variable.
Scope = SI->second;
InlinedFnVar = true;
} else {
DIVariable DV(GV);
GlobalVariable *V = DV.getContext().getGV();

// or GV is a local variable.
bool InlinedVar = false;
DIVariable DV(GV);
GlobalVariable *V = DV.getContext().getGV();
DISubprogram SP(V);
if (!SP.isNull()) {
// SP is inserted into DbgAbstractScopeMap when inlined function
// start was recorded by RecordInlineFnStart.
DenseMap<GlobalVariable *, DbgScope *>::iterator
I = DbgAbstractScopeMap.find(SP.getGV());
if (I != DbgAbstractScopeMap.end()) {
InlinedVar = true;
Scope = I->second;
}
}
if (!InlinedVar) {
// GV is a local variable.
Scope = getOrCreateScope(V);
}
}
Expand Down Expand Up @@ -1768,33 +1770,6 @@ unsigned DwarfDebug::RecordInlinedFnEnd(DISubprogram &SP) {
return ID;
}

/// RecordVariableScope - Record scope for the variable declared by
/// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE. Record scopes
/// for only inlined subroutine variables. Other variables's scopes are
/// determined during RecordVariable().
void DwarfDebug::RecordVariableScope(DIVariable &DV,
const MachineInstr *DeclareMI) {
if (TimePassesIsEnabled)
DebugTimer->startTimer();

DISubprogram SP(DV.getContext().getGV());

if (SP.isNull()) {
if (TimePassesIsEnabled)
DebugTimer->stopTimer();

return;
}

DenseMap<GlobalVariable *, DbgScope *>::iterator
I = DbgAbstractScopeMap.find(SP.getGV());
if (I != DbgAbstractScopeMap.end())
InlinedVariableScopes[DeclareMI] = I->second;

if (TimePassesIsEnabled)
DebugTimer->stopTimer();
}

//===----------------------------------------------------------------------===//
// Emit Methods
//===----------------------------------------------------------------------===//
Expand Down
12 changes: 1 addition & 11 deletions lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ class VISIBILITY_HIDDEN DwarfDebug : public Dwarf {
/// information is used to populate debug_inlined section.
DenseMap<GlobalVariable *, SmallVector<unsigned, 4> > InlineInfo;

/// InlinedVariableScopes - Scopes information for the inlined subroutine
/// variables.
DenseMap<const MachineInstr *, DbgScope *> InlinedVariableScopes;

/// AbstractInstanceRootMap - Map of abstract instance roots of inlined
/// functions. These are subroutine entries that contain a DW_AT_inline
/// attribute.
Expand Down Expand Up @@ -516,8 +512,7 @@ class VISIBILITY_HIDDEN DwarfDebug : public Dwarf {
unsigned RecordRegionEnd(GlobalVariable *V);

/// RecordVariable - Indicate the declaration of a local variable.
void RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
const MachineInstr *MI);
void RecordVariable(GlobalVariable *GV, unsigned FrameIndex);

//// RecordInlinedFnStart - Indicate the start of inlined subroutine.
unsigned RecordInlinedFnStart(DISubprogram &SP, DICompileUnit CU,
Expand All @@ -526,11 +521,6 @@ class VISIBILITY_HIDDEN DwarfDebug : public Dwarf {
/// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
unsigned RecordInlinedFnEnd(DISubprogram &SP);

/// RecordVariableScope - Record scope for the variable declared by
/// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE. Record scopes
/// for only inlined subroutine variables. Other variables's scopes are
/// determined during RecordVariable().
void RecordVariableScope(DIVariable &DV, const MachineInstr *DeclareMI);
};

} // End of namespace llvm
Expand Down
11 changes: 2 additions & 9 deletions lib/CodeGen/AsmPrinter/DwarfWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ unsigned DwarfWriter::getRecordSourceLineCount() {

/// RecordVariable - Indicate the declaration of a local variable.
///
void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
const MachineInstr *MI) {
DD->RecordVariable(GV, FrameIndex, MI);
void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
DD->RecordVariable(GV, FrameIndex);
}

/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
Expand All @@ -119,9 +118,3 @@ unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) {
return DD->RecordInlinedFnEnd(SP);
}

/// RecordVariableScope - Record scope for the variable declared by
/// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
void DwarfWriter::RecordVariableScope(DIVariable &DV,
const MachineInstr *DeclareMI) {
DD->RecordVariableScope(DV, DeclareMI);
}
5 changes: 0 additions & 5 deletions lib/CodeGen/PrologEpilogInserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,6 @@ void PEI::replaceFrameIndices(MachineFunction &Fn) {
if (RS) RS->enterBasicBlock(BB);

for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
if (I->getOpcode() == TargetInstrInfo::DECLARE) {
// Ignore it.
++I;
continue;
}

if (I->getOpcode() == FrameSetupOpcode ||
I->getOpcode() == FrameDestroyOpcode) {
Expand Down
7 changes: 1 addition & 6 deletions lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,7 @@ bool FastISel::SelectCall(User *I) {
// Determine the debug globalvariable.
GlobalValue *GV = cast<GlobalVariable>(Variable);

// Build the DECLARE instruction.
const TargetInstrDesc &II = TII.get(TargetInstrInfo::DECLARE);
MachineInstr *DeclareMI
= BuildMI(MBB, DL, II).addFrameIndex(FI).addGlobalAddress(GV);
DIVariable DV(cast<GlobalVariable>(GV));
DW->RecordVariableScope(DV, DeclareMI);
DW->RecordVariable(cast<GlobalVariable>(GV), FI);
return true;
}
case Intrinsic::eh_exception: {
Expand Down
1 change: 0 additions & 1 deletion lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,6 @@ void SelectionDAGLegalize::ExpandNode(SDNode *Node,
Results.push_back(DAG.getConstant(1, Node->getValueType(0)));
break;
case ISD::EH_RETURN:
case ISD::DECLARE:
case ISD::DBG_LABEL:
case ISD::EH_LABEL:
case ISD::PREFETCH:
Expand Down
2 changes: 0 additions & 2 deletions lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ static bool doNotCSE(SDNode *N) {
case ISD::DBG_LABEL:
case ISD::DBG_STOPPOINT:
case ISD::EH_LABEL:
case ISD::DECLARE:
return true; // Never CSE these nodes.
}

Expand Down Expand Up @@ -5255,7 +5254,6 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
case ISD::INLINEASM: return "inlineasm";
case ISD::DBG_LABEL: return "dbg_label";
case ISD::EH_LABEL: return "eh_label";
case ISD::DECLARE: return "declare";
case ISD::HANDLENODE: return "handlenode";

// Unary operators
Expand Down
15 changes: 12 additions & 3 deletions lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3965,14 +3965,23 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
if (OptLevel != CodeGenOpt::None)
// FIXME: Variable debug info is not supported here.
return 0;

DwarfWriter *DW = DAG.getDwarfWriter();
if (!DW)
return 0;
DbgDeclareInst &DI = cast<DbgDeclareInst>(I);
if (!isValidDebugInfoIntrinsic(DI, CodeGenOpt::None))
return 0;

Value *Variable = DI.getVariable();
DAG.setRoot(DAG.getNode(ISD::DECLARE, dl, MVT::Other, getRoot(),
getValue(DI.getAddress()), getValue(Variable)));
Value *Address = DI.getAddress();
if (BitCastInst *BCI = dyn_cast<BitCastInst>(Address))
Address = BCI->getOperand(0);
AllocaInst *AI = dyn_cast<AllocaInst>(Address);
// Don't handle byval struct arguments or VLAs, for example.
if (!AI)
return 0;
int FI = FuncInfo.StaticAllocaMap[AI];
DW->RecordVariable(cast<GlobalVariable>(Variable), FI);
return 0;
}
case Intrinsic::eh_exception: {
Expand Down
1 change: 0 additions & 1 deletion lib/Target/ARM/ARMBaseInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ unsigned ARMBaseInstrInfo::GetInstSizeInBytes(const MachineInstr *MI) const {
default:
llvm_unreachable("Unknown or unset size field for instr!");
case TargetInstrInfo::IMPLICIT_DEF:
case TargetInstrInfo::DECLARE:
case TargetInstrInfo::DBG_LABEL:
case TargetInstrInfo::EH_LABEL:
return 0;
Expand Down
1 change: 0 additions & 1 deletion lib/Target/ARM/ARMCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ void Emitter<CodeEmitter>::emitPseudoInstruction(const MachineInstr &MI) {
MCE.emitLabel(MI.getOperand(0).getImm());
break;
case TargetInstrInfo::IMPLICIT_DEF:
case TargetInstrInfo::DECLARE:
case ARM::DWARF_LOC:
// Do nothing.
break;
Expand Down
41 changes: 0 additions & 41 deletions lib/Target/ARM/ARMISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,47 +1263,6 @@ SDNode *ARMDAGToDAGISel::Select(SDValue Op) {
return CurDAG->SelectNodeTo(Op.getNode(), Opc, VT, Ops, 5);
}

case ISD::DECLARE: {
SDValue Chain = Op.getOperand(0);
SDValue N1 = Op.getOperand(1);
SDValue N2 = Op.getOperand(2);
FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(N1);
// FIXME: handle VLAs.
if (!FINode) {
ReplaceUses(Op.getValue(0), Chain);
return NULL;
}
if (N2.getOpcode() == ARMISD::PIC_ADD && isa<LoadSDNode>(N2.getOperand(0)))
N2 = N2.getOperand(0);
LoadSDNode *Ld = dyn_cast<LoadSDNode>(N2);
if (!Ld) {
ReplaceUses(Op.getValue(0), Chain);
return NULL;
}
SDValue BasePtr = Ld->getBasePtr();
assert(BasePtr.getOpcode() == ARMISD::Wrapper &&
isa<ConstantPoolSDNode>(BasePtr.getOperand(0)) &&
"llvm.dbg.variable should be a constantpool node");
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(BasePtr.getOperand(0));
GlobalValue *GV = 0;
if (CP->isMachineConstantPoolEntry()) {
ARMConstantPoolValue *ACPV = (ARMConstantPoolValue*)CP->getMachineCPVal();
GV = ACPV->getGV();
} else
GV = dyn_cast<GlobalValue>(CP->getConstVal());
if (!GV) {
ReplaceUses(Op.getValue(0), Chain);
return NULL;
}

SDValue Tmp1 = CurDAG->getTargetFrameIndex(FINode->getIndex(),
TLI.getPointerTy());
SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GV, TLI.getPointerTy());
SDValue Ops[] = { Tmp1, Tmp2, Chain };
return CurDAG->getTargetNode(TargetInstrInfo::DECLARE, dl,
MVT::Other, Ops, 3);
}

case ARMISD::VLD2D: {
SDValue MemAddr, MemUpdate, MemOpc;
if (!SelectAddrMode6(Op, N->getOperand(1), MemAddr, MemUpdate, MemOpc))
Expand Down
1 change: 0 additions & 1 deletion lib/Target/Blackfin/BlackfinISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ BlackfinTargetLowering::BlackfinTargetLowering(TargetMachine &TM)
setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
setOperationAction(ISD::DBG_LABEL, MVT::Other, Expand);
setOperationAction(ISD::EH_LABEL, MVT::Other, Expand);
setOperationAction(ISD::DECLARE, MVT::Other, Expand);

// Use the default implementation.
setOperationAction(ISD::VACOPY, MVT::Other, Expand);
Expand Down
41 changes: 0 additions & 41 deletions lib/Target/PowerPC/PPCISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,47 +1094,6 @@ SDNode *PPCDAGToDAGISel::Select(SDValue Op) {
Chain), 0);
return CurDAG->SelectNodeTo(N, PPC::BCTR, MVT::Other, Chain);
}
case ISD::DECLARE: {
SDValue Chain = N->getOperand(0);
SDValue N1 = N->getOperand(1);
SDValue N2 = N->getOperand(2);
FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(N1);

// FIXME: We need to handle this for VLAs.
if (!FINode) {
ReplaceUses(Op.getValue(0), Chain);
return NULL;
}

if (N2.getOpcode() == ISD::ADD) {
if (N2.getOperand(0).getOpcode() == ISD::ADD &&
N2.getOperand(0).getOperand(0).getOpcode() == PPCISD::GlobalBaseReg &&
N2.getOperand(0).getOperand(1).getOpcode() == PPCISD::Hi &&
N2.getOperand(1).getOpcode() == PPCISD::Lo)
N2 = N2.getOperand(0).getOperand(1).getOperand(0);
else if (N2.getOperand(0).getOpcode() == ISD::ADD &&
N2.getOperand(0).getOperand(0).getOpcode() == PPCISD::GlobalBaseReg &&
N2.getOperand(0).getOperand(1).getOpcode() == PPCISD::Lo &&
N2.getOperand(1).getOpcode() == PPCISD::Hi)
N2 = N2.getOperand(0).getOperand(1).getOperand(0);
else if (N2.getOperand(0).getOpcode() == PPCISD::Hi &&
N2.getOperand(1).getOpcode() == PPCISD::Lo)
N2 = N2.getOperand(0).getOperand(0);
}

// If we don't have a global address here, the debug info is mangled, just
// drop it.
if (!isa<GlobalAddressSDNode>(N2)) {
ReplaceUses(Op.getValue(0), Chain);
return NULL;
}
int FI = cast<FrameIndexSDNode>(N1)->getIndex();
GlobalValue *GV = cast<GlobalAddressSDNode>(N2)->getGlobal();
SDValue Tmp1 = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GV, TLI.getPointerTy());
return CurDAG->SelectNodeTo(N, TargetInstrInfo::DECLARE,
MVT::Other, Tmp1, Tmp2, Chain);
}
}

return SelectCode(Op);
Expand Down
Loading

0 comments on commit 24f20e0

Please sign in to comment.