llvm.org GIT mirror llvm / 9d4209f
1. Add a pass to fold debug label instructions so a debug info client can detect empty ranges. 2. Reorg how MachineDebugInfo maintains changes to debug labels. 3. Have dwarf writer use debug label info to simplify scopes and source line coorespondence. 4. Revert the merging of compile units until I can get the bugs ironed out. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31507 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 13 years ago
5 changed file(s) with 127 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
968968 // Lines - List of of source line correspondence.
969969 std::vector Lines;
970970
971 // LabelID - Current number assigned to unique label numbers.
972 unsigned LabelID;
971 // LabelIDList - One entry per assigned label. Normally the entry is equal to
972 // the list index(+1). If the entry is zero then the label has been deleted.
973 // Any other value indicates the label has been deleted by is mapped to
974 // another label.
975 std::vector LabelIDList;
973976
974977 // ScopeMap - Tracks the scopes in the current function.
975978 std::map ScopeMap;
978981 //
979982 DebugScope *RootScope;
980983
981 // DeletedLabelIDs - Sorted list of label IDs that have been removed from the
982 // module.
983 std::vector DeletedLabelIDs;
984
985984 // FrameMoves - List of moves done by a function's prolog. Used to construct
986985 // frame maps by debug consumers.
987986 std::vector FrameMoves;
10251024
10261025 /// NextLabelID - Return the next unique label id.
10271026 ///
1028 unsigned NextLabelID() { return ++LabelID; }
1027 unsigned NextLabelID() {
1028 unsigned ID = LabelIDList.size() + 1;
1029 LabelIDList.push_back(ID);
1030 return ID;
1031 }
10291032
10301033 /// RecordLabel - Records location information and associates it with a
10311034 /// debug label. Returns a unique label ID used to generate a label and
10341037
10351038 /// InvalidateLabel - Inhibit use of the specified label # from
10361039 /// MachineDebugInfo, for example because the code was deleted.
1037 void InvalidateLabel(unsigned LabelID);
1038
1039 /// isLabelValid - Check to make sure the label is still valid before
1040 /// attempting to use.
1041 bool isLabelValid(unsigned LabelID);
1040 void InvalidateLabel(unsigned LabelID) {
1041 // Remap to zero to indicate deletion.
1042 RemapLabel(LabelID, 0);
1043 }
1044
1045 /// RemapLabel - Indicate that a label has been merged into another.
1046 ///
1047 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1048 LabelIDList[OldLabelID - 1] = NewLabelID;
1049 }
1050
1051 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1052 /// ID != Mapped ID indicates that the label was folded into another label.
1053 unsigned MappedLabel(unsigned LabelID) const {
1054 return LabelIDList[LabelID - 1];
1055 }
10421056
10431057 /// RecordSource - Register a source file with debug info. Returns an source
10441058 /// ID.
8080 /// branches.
8181 FunctionPass *createBranchFoldingPass();
8282
83 /// DebugLabelFoldingPass - This pass prunes out redundant debug labels. This
84 /// allows a debug emitter to determine if the range of two labels is empty,
85 /// by seeing if the labels map to the same reduced label.
86 FunctionPass *createDebugLabelFoldingPass();
87
8388 /// MachineCodeDeletion Pass - This pass deletes all of the machine code for
8489 /// the current function, which should happen after the function has been
8590 /// emitted to a .s file or to memory.
16941694 return Unit;
16951695 }
16961696
1697 /// GetBaseCompileUnit - Get the main compile unit.
1698 ///
1699 CompileUnit *GetBaseCompileUnit() const {
1700 CompileUnit *Unit = CompileUnits[0];
1701 assert(Unit && "Missing compile unit.");
1702 return Unit;
1703 }
1704
16971705 /// FindCompileUnit - Get the compile unit for the given descriptor.
16981706 ///
16991707 CompileUnit *FindCompileUnit(CompileUnitDesc *UnitDesc) {
1700 #if 1
1701 // FIXME - Using only one compile unit. Needs to me fixed at the FE.
1702 CompileUnit *Unit = CompileUnits[0];
1703 #else
17041708 CompileUnit *Unit = DescToUnitMap[UnitDesc];
1705 #endif
17061709 assert(Unit && "Missing compile unit.");
17071710 return Unit;
17081711 }
18581861 // FIXME - Ignore inlined functions for the time being.
18591862 if (!Scope->getParent()) continue;
18601863
1861 unsigned StartID = Scope->getStartLabelID();
1862 unsigned EndID = Scope->getEndLabelID();
1863
1864 // Widen scope if label is discarded.
1865 // FIXME - really need to find a GOOD label if a block is dead.
1866 if (StartID && !DebugInfo->isLabelValid(StartID)) StartID = 0;
1867 if (EndID && !DebugInfo->isLabelValid(EndID)) EndID = 0;
1864 unsigned StartID = DebugInfo->MappedLabel(Scope->getStartLabelID());
1865 unsigned EndID = DebugInfo->MappedLabel(Scope->getEndLabelID());
1866
1867 // Ignore empty scopes.
1868 if (StartID == EndID && StartID != 0) continue;
1869 if (Scope->getScopes().empty() && Scope->getVariables().empty()) continue;
18681870
18691871 DIE *ScopeDie = new DIE(DW_TAG_lexical_block);
18701872
20832085 std::vector &Moves) {
20842086 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
20852087 MachineMove *Move = Moves[i];
2086 unsigned LabelID = Move->getLabelID();
2088 unsigned LabelID = DebugInfo->MappedLabel(Move->getLabelID());
20872089
20882090 // Throw out move if the label is invalid.
2089 if (LabelID && !DebugInfo->isLabelValid(LabelID)) continue;
2091 if (!LabelID) continue;
20902092
20912093 const MachineLocation &Dst = Move->getDestination();
20922094 const MachineLocation &Src = Move->getSource();
23062308 // Construct rows of the address, source, line, column matrix.
23072309 for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
23082310 const SourceLineInfo &LineInfo = LineInfos[i];
2309 unsigned LabelID = LineInfo.getLabelID();
2310
2311 // Source line labels are validated at the MachineDebugInfo level.
2311 unsigned LabelID = DebugInfo->MappedLabel(LineInfo.getLabelID());
2312 if (!LabelID) continue;
23122313
23132314 if (DwarfVerbose) {
23142315 unsigned SourceID = LineInfo.getSourceID();
24192420 void EmitFunctionDebugFrame() {
24202421 if (!TAI->getDwarfRequiresFrameSection())
24212422 return;
2423
24222424 // Start the dwarf frame section.
24232425 Asm->SwitchToDataSection(TAI->getDwarfFrameSection());
24242426
25872589 const UniqueVector CUW = DebugInfo->getCompileUnits();
25882590
25892591 for (unsigned i = 1, N = CUW.size(); i <= N; ++i) {
2590 CompileUnit *Unit = NewCompileUnit(CUW[i], i);
2592 unsigned ID = DebugInfo->RecordSource(CUW[i]);
2593 CompileUnit *Unit = NewCompileUnit(CUW[i], ID);
25912594 CompileUnits.push_back(Unit);
25922595 }
25932596 }
6565 // Branch folding must be run after regalloc and prolog/epilog insertion.
6666 if (!Fast)
6767 PM.add(createBranchFoldingPass());
68
69 // Fold redundant debug labels.
70 PM.add(createDebugLabelFoldingPass());
6871
6972 if (PrintMachineCode) // Print the register-allocated code
7073 PM.add(createMachineFunctionPrinterPass(&std::cerr));
99 #include "llvm/CodeGen/MachineDebugInfo.h"
1010
1111 #include "llvm/Constants.h"
12 #include "llvm/CodeGen/MachineFunctionPass.h"
13 #include "llvm/CodeGen/MachineFunction.h"
1214 #include "llvm/CodeGen/MachineLocation.h"
15 #include "llvm/Target/TargetInstrInfo.h"
16 #include "llvm/Target/TargetMachine.h"
1317 #include "llvm/DerivedTypes.h"
1418 #include "llvm/GlobalVariable.h"
1519 #include "llvm/Intrinsics.h"
14471451 , Directories()
14481452 , SourceFiles()
14491453 , Lines()
1450 , LabelID(0)
1454 , LabelIDList()
14511455 , ScopeMap()
14521456 , RootScope(NULL)
1453 , DeletedLabelIDs()
14541457 , FrameMoves()
14551458 {}
14561459 MachineDebugInfo::~MachineDebugInfo() {
15411544 unsigned ID = NextLabelID();
15421545 Lines.push_back(SourceLineInfo(Line, Column, Source, ID));
15431546 return ID;
1544 }
1545
1546 static bool LabelUIDComparison(const SourceLineInfo &LI, unsigned UID) {
1547 return LI.getLabelID() < UID;
1548 }
1549
1550 /// InvalidateLabel - Inhibit use of the specified label # from
1551 /// MachineDebugInfo, for example because the code was deleted.
1552 void MachineDebugInfo::InvalidateLabel(unsigned LabelID) {
1553 // Check source line list first. SourceLineInfo is sorted by LabelID.
1554 std::vector::iterator I =
1555 std::lower_bound(Lines.begin(), Lines.end(), LabelID, LabelUIDComparison);
1556 if (I != Lines.end() && I->getLabelID() == LabelID) {
1557 Lines.erase(I);
1558 return;
1559 }
1560
1561 // Otherwise add for use by isLabelValid.
1562 std::vector::iterator J =
1563 std::lower_bound(DeletedLabelIDs.begin(), DeletedLabelIDs.end(), LabelID);
1564 DeletedLabelIDs.insert(J, LabelID);
1565 }
1566
1567 /// isLabelValid - Check to make sure the label is still valid before
1568 /// attempting to use.
1569 bool MachineDebugInfo::isLabelValid(unsigned LabelID) {
1570 std::vector::iterator I =
1571 std::lower_bound(DeletedLabelIDs.begin(), DeletedLabelIDs.end(), LabelID);
1572 return I == DeletedLabelIDs.end() || *I != LabelID;
15731547 }
15741548
15751549 /// RecordSource - Register a source file with debug info. Returns an source
16411615 return Slot;
16421616 }
16431617
1644
1618 //===----------------------------------------------------------------------===//
1619 /// DebugLabelFolding pass - This pass prunes out redundant debug labels. This
1620 /// allows a debug emitter to determine if the range of two labels is empty,
1621 /// by seeing if the labels map to the same reduced label.
1622
1623 namespace llvm {
1624
1625 struct DebugLabelFolder : public MachineFunctionPass {
1626 virtual bool runOnMachineFunction(MachineFunction &MF);
1627 virtual const char *getPassName() const { return "Debug Label Folder"; }
1628 };
1629
1630 bool DebugLabelFolder::runOnMachineFunction(MachineFunction &MF) {
1631 // Get machine debug info.
1632 MachineDebugInfo *MDI = getAnalysisToUpdate();
1633 if (!MDI) return false;
1634 // Get target instruction info.
1635 const TargetInstrInfo *TII = MF.getTarget().getInstrInfo();
1636 if (!TII) return false;
1637 // Get target version of the debug label opcode.
1638 unsigned DWARF_LABELOpc = TII->getDWARF_LABELOpcode();
1639 if (!DWARF_LABELOpc) return false;
1640
1641 // Track if change is made.
1642 bool MadeChange = false;
1643 // No prior label to begin.
1644 unsigned PriorLabel = 0;
1645
1646 // Iterate through basic blocks.
1647 for (MachineFunction::iterator BB = MF.begin(), E = MF.end();
1648 BB != E; ++BB) {
1649 // Iterate through instructions.
1650 for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ) {
1651 // Is it a debug label.
1652 if ((unsigned)I->getOpcode() == DWARF_LABELOpc) {
1653 // The label ID # is always operand #0, an immediate.
1654 unsigned NextLabel = I->getOperand(0).getImm();
1655
1656 // If there was an immediate prior label.
1657 if (PriorLabel) {
1658 // Remap the current label to prior label.
1659 MDI->RemapLabel(NextLabel, PriorLabel);
1660 // Delete the current label.
1661 I = BB->erase(I);
1662 // Indicate a change has been made.
1663 MadeChange = true;
1664 continue;
1665 } else {
1666 // Start a new round.
1667 PriorLabel = NextLabel;
1668 }
1669 } else {
1670 // No consecutive labels.
1671 PriorLabel = 0;
1672 }
1673
1674 ++I;
1675 }
1676 }
1677
1678 return MadeChange;
1679 }
1680
1681 FunctionPass *createDebugLabelFoldingPass() { return new DebugLabelFolder(); }
1682
1683 }
1684