llvm.org GIT mirror llvm / 6b61f58
Replace DebugLocTuple with DILocation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93630 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 10 years ago
10 changed file(s) with 57 addition(s) and 103 deletion(s). Raw diff Collapse all Expand all
1616 #define LLVM_CODEGEN_ASMPRINTER_H
1717
1818 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/Analysis/DebugInfo.h"
1920 #include "llvm/Support/DebugLoc.h"
2021 #include "llvm/Target/TargetMachine.h"
2122 #include "llvm/ADT/DenseMap.h"
150151 mutable unsigned Counter;
151152
152153 // Private state for processDebugLoc()
153 mutable DebugLocTuple PrevDLT;
154 mutable DILocation PrevDLT;
154155
155156 protected:
156157 explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM,
367367 // Debug location.
368368 //
369369
370 /// getDebugLocTuple - Get the DebugLocTuple for a given DebugLoc object.
371 DebugLocTuple getDebugLocTuple(DebugLoc DL) const;
370 /// getDILocation - Get the DILocation for a given DebugLoc object.
371 DILocation getDILocation(DebugLoc DL) const;
372372
373373 /// getDefaultDebugLoc - Get the default debug location for the machine
374374 /// function.
2020 namespace llvm {
2121 class MDNode;
2222
23 /// DebugLocTuple - Debug location tuple of filename id, line and column.
24 ///
25 struct DebugLocTuple {
26 MDNode *Scope;
27 MDNode *InlinedAtLoc;
28 unsigned Line, Col;
29
30 DebugLocTuple()
31 : Scope(0), InlinedAtLoc(0), Line(~0U), Col(~0U) {}
32
33 DebugLocTuple(MDNode *n, MDNode *i, unsigned l, unsigned c)
34 : Scope(n), InlinedAtLoc(i), Line(l), Col(c) {}
35
36 bool operator==(const DebugLocTuple &DLT) const {
37 return Scope == DLT.Scope &&
38 InlinedAtLoc == DLT.InlinedAtLoc &&
39 Line == DLT.Line && Col == DLT.Col;
40 }
41 bool operator!=(const DebugLocTuple &DLT) const {
42 return !(*this == DLT);
43 }
44 };
45
4623 /// DebugLoc - Debug location id. This is carried by SDNode and MachineInstr
4724 /// to index into a vector of unique debug location tuples.
4825 class DebugLoc {
6441 bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
6542 };
6643
67 // Specialize DenseMapInfo for DebugLocTuple.
68 template<> struct DenseMapInfo {
69 static inline DebugLocTuple getEmptyKey() {
70 return DebugLocTuple(0, 0, ~0U, ~0U);
71 }
72 static inline DebugLocTuple getTombstoneKey() {
73 return DebugLocTuple((MDNode*)~1U, (MDNode*)~1U, ~1U, ~1U);
74 }
75 static unsigned getHashValue(const DebugLocTuple &Val) {
76 return DenseMapInfo::getHashValue(Val.Scope) ^
77 DenseMapInfo::getHashValue(Val.InlinedAtLoc) ^
78 DenseMapInfo::getHashValue(Val.Line) ^
79 DenseMapInfo::getHashValue(Val.Col);
80 }
81 static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
82 return LHS.Scope == RHS.Scope &&
83 LHS.InlinedAtLoc == RHS.InlinedAtLoc &&
84 LHS.Line == RHS.Line &&
85 LHS.Col == RHS.Col;
86 }
87 };
88 template <> struct isPodLike {static const bool value = true;};
89
90
91 /// DebugLocTracker - This class tracks debug location information.
44 /// DebugLocTracker - This class tracks debug location information.
9245 ///
9346 struct DebugLocTracker {
9447 /// DebugLocations - A vector of unique DebugLocTuple's.
9548 ///
96 std::vector<DebugLocTuple> DebugLocations;
49 std::vector<MDNode *> DebugLocations;
9750
9851 /// DebugIdMap - This maps DebugLocTuple's to indices into the
9952 /// DebugLocations vector.
100 DenseMap<DebugLocTuple, unsigned> DebugIdMap;
53 DenseMap<MDNode *, unsigned> DebugIdMap;
10154
10255 DebugLocTracker() {}
10356 };
13191319 /// from DILocation.
13201320 DebugLoc llvm::ExtractDebugLocation(DILocation &Loc,
13211321 DebugLocTracker &DebugLocInfo) {
1322 DebugLoc DL;
1323 MDNode *Context = Loc.getScope().getNode();
1324 MDNode *InlinedLoc = NULL;
1325 if (!Loc.getOrigLocation().isNull())
1326 InlinedLoc = Loc.getOrigLocation().getNode();
1327 // If this location is already tracked then use it.
1328 DebugLocTuple Tuple(Context, InlinedLoc, Loc.getLineNumber(),
1329 Loc.getColumnNumber());
1330 DenseMap::iterator II
1331 = DebugLocInfo.DebugIdMap.find(Tuple);
1322 DenseMap::iterator II
1323 = DebugLocInfo.DebugIdMap.find(Loc.getNode());
13321324 if (II != DebugLocInfo.DebugIdMap.end())
13331325 return DebugLoc::get(II->second);
13341326
13351327 // Add a new location entry.
13361328 unsigned Id = DebugLocInfo.DebugLocations.size();
1337 DebugLocInfo.DebugLocations.push_back(Tuple);
1338 DebugLocInfo.DebugIdMap[Tuple] = Id;
1329 DebugLocInfo.DebugLocations.push_back(Loc.getNode());
1330 DebugLocInfo.DebugIdMap[Loc.getNode()] = Id;
13391331
13401332 return DebugLoc::get(Id);
13411333 }
6060 // FIXME: Pass instprinter to streamer.
6161 OutStreamer(*createAsmStreamer(OutContext, O, *T, 0)),
6262
63 LastMI(0), LastFn(0), Counter(~0U),
64 PrevDLT(0, 0, ~0U, ~0U) {
63 LastMI(0), LastFn(0), Counter(~0U), PrevDLT(NULL) {
6564 DW = 0; MMI = 0;
6665 switch (AsmVerbose) {
6766 case cl::BOU_UNSET: VerboseAsm = VDef; break;
14051404 DebugLoc DL = MI->getDebugLoc();
14061405 if (DL.isUnknown())
14071406 return;
1408 DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
1409 if (CurDLT.Scope == 0)
1407 DILocation CurDLT = MF->getDILocation(DL);
1408 if (CurDLT.getScope().isNull())
14101409 return;
14111410
14121411 if (BeforePrintingInsn) {
1413 if (CurDLT != PrevDLT) {
1414 unsigned L = DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
1415 CurDLT.Scope);
1412 if (CurDLT.getNode() != PrevDLT.getNode()) {
1413 unsigned L = DW->RecordSourceLine(CurDLT.getLineNumber(),
1414 CurDLT.getColumnNumber(),
1415 CurDLT.getScope().getNode());
14161416 printLabel(L);
14171417 O << '\n';
14181418 DW->BeginScope(MI, L);
19091909 bool Newline = false;
19101910
19111911 if (!MI.getDebugLoc().isUnknown()) {
1912 DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
1912 DILocation DLT = MF->getDILocation(MI.getDebugLoc());
19131913
19141914 // Print source line info.
19151915 O.PadToColumn(MAI->getCommentColumn());
19161916 O << MAI->getCommentString() << ' ';
1917 DIScope Scope(DLT.Scope);
1917 DIScope Scope = DLT.getScope();
19181918 // Omit the directory, because it's likely to be long and uninteresting.
19191919 if (!Scope.isNull())
19201920 O << Scope.getFilename();
19211921 else
19221922 O << "";
1923 O << ':' << DLT.Line;
1924 if (DLT.Col != 0)
1925 O << ':' << DLT.Col;
1923 O << ':' << DLT.getLineNumber();
1924 if (DLT.getColumnNumber() != 0)
1925 O << ':' << DLT.getColumnNumber();
19261926 Newline = true;
19271927 }
19281928
20002000 MIIndexMap[MInsn] = MIIndex++;
20012001 DebugLoc DL = MInsn->getDebugLoc();
20022002 if (DL.isUnknown()) continue;
2003 DebugLocTuple DLT = MF->getDebugLocTuple(DL);
2004 if (!DLT.Scope) continue;
2003 DILocation DLT = MF->getDILocation(DL);
2004 DIScope DLTScope = DLT.getScope();
2005 if (DLTScope.isNull()) continue;
20052006 // There is no need to create another DIE for compile unit. For all
20062007 // other scopes, create one DbgScope now. This will be translated
20072008 // into a scope DIE at the end.
2008 if (DIDescriptor(DLT.Scope).isCompileUnit()) continue;
2009 createDbgScope(DLT.Scope, DLT.InlinedAtLoc);
2009 if (DLTScope.isCompileUnit()) continue;
2010 createDbgScope(DLTScope.getNode(), DLT.getOrigLocation().getNode());
20102011 }
20112012 }
20122013
20192020 const MachineInstr *MInsn = II;
20202021 DebugLoc DL = MInsn->getDebugLoc();
20212022 if (DL.isUnknown()) continue;
2022 DebugLocTuple DLT = MF->getDebugLocTuple(DL);
2023 if (!DLT.Scope) continue;
2023 DILocation DLT = MF->getDILocation(DL);
2024 DIScope DLTScope = DLT.getScope();
2025 if (DLTScope.isNull()) continue;
20242026 // There is no need to create another DIE for compile unit. For all
20252027 // other scopes, create one DbgScope now. This will be translated
20262028 // into a scope DIE at the end.
2027 if (DIDescriptor(DLT.Scope).isCompileUnit()) continue;
2028 DbgScope *Scope = getUpdatedDbgScope(DLT.Scope, MInsn, DLT.InlinedAtLoc);
2029 if (DLTScope.isCompileUnit()) continue;
2030 DbgScope *Scope = getUpdatedDbgScope(DLTScope.getNode(), MInsn,
2031 DLT.getOrigLocation().getNode());
20292032 Scope->setLastInsn(MInsn);
20302033 }
20312034 }
20902093 // function.
20912094 DebugLoc FDL = MF->getDefaultDebugLoc();
20922095 if (!FDL.isUnknown()) {
2093 DebugLocTuple DLT = MF->getDebugLocTuple(FDL);
2096 DILocation DLT = MF->getDILocation(FDL);
20942097 unsigned LabelID = 0;
2095 DISubprogram SP = getDISubprogram(DLT.Scope);
2098 DISubprogram SP = getDISubprogram(DLT.getScope().getNode());
20962099 if (!SP.isNull())
2097 LabelID = recordSourceLine(SP.getLineNumber(), 0, DLT.Scope);
2100 LabelID = recordSourceLine(SP.getLineNumber(), 0,
2101 DLT.getScope().getNode());
20982102 else
2099 LabelID = recordSourceLine(DLT.Line, DLT.Col, DLT.Scope);
2103 LabelID = recordSourceLine(DLT.getLineNumber(),
2104 DLT.getColumnNumber(),
2105 DLT.getScope().getNode());
21002106 Asm->printLabel(LabelID);
21012107 O << '\n';
21022108 }
425425 return VReg;
426426 }
427427
428 /// getDebugLocTuple - Get the DebugLocTuple for a given DebugLoc object.
429 DebugLocTuple MachineFunction::getDebugLocTuple(DebugLoc DL) const {
428 /// getDILocation - Get the DILocation for a given DebugLoc object.
429 DILocation MachineFunction::getDILocation(DebugLoc DL) const {
430430 unsigned Idx = DL.getIndex();
431431 assert(Idx < DebugLocInfo.DebugLocations.size() &&
432432 "Invalid index into debug locations!");
433 return DebugLocInfo.DebugLocations[Idx];
433 return DILocation(DebugLocInfo.DebugLocations[Idx]);
434434 }
435435
436436 //===----------------------------------------------------------------------===//
11881188
11891189 // TODO: print InlinedAtLoc information
11901190
1191 DebugLocTuple DLT = MF->getDebugLocTuple(debugLoc);
1192 DIScope Scope(DLT.Scope);
1191 DILocation DLT = MF->getDILocation(debugLoc);
1192 DIScope Scope = DLT.getScope();
11931193 OS << " dbg:";
11941194 // Omit the directory, since it's usually long and uninteresting.
11951195 if (!Scope.isNull())
11961196 OS << Scope.getFilename();
11971197 else
11981198 OS << "";
1199 OS << ':' << DLT.Line;
1200 if (DLT.Col != 0)
1201 OS << ':' << DLT.Col;
1199 OS << ':' << DLT.getLineNumber();
1200 if (DLT.getColumnNumber() != 0)
1201 OS << ':' << DLT.getColumnNumber();
12021202 }
12031203
12041204 OS << "\n";
367367 // the stub is unused.
368368 DenseMap > StubFnRefs;
369369
370 DebugLocTuple PrevDLT;
370 DILocation PrevDLT;
371371
372372 public:
373373 JITEmitter(JIT &jit, JITMemoryManager *JMM, TargetMachine &TM)
374374 : SizeEstimate(0), Resolver(jit, *this), MMI(0), CurFn(0),
375 EmittedFunctions(this) {
375 EmittedFunctions(this), PrevDLT(NULL) {
376376 MemMgr = JMM ? JMM : JITMemoryManager::CreateDefaultMemManager();
377377 if (jit.getJITInfo().needsGOT()) {
378378 MemMgr->AllocateGOT();
805805
806806 void JITEmitter::processDebugLoc(DebugLoc DL, bool BeforePrintingInsn) {
807807 if (!DL.isUnknown()) {
808 DebugLocTuple CurDLT = EmissionDetails.MF->getDebugLocTuple(DL);
808 DILocation CurDLT = EmissionDetails.MF->getDILocation(DL);
809809
810810 if (BeforePrintingInsn) {
811 if (CurDLT.Scope != 0 && PrevDLT != CurDLT) {
811 if (CurDLT.getScope().getNode() != 0
812 && PrevDLT.getNode() != CurDLT.getNode()) {
812813 JITEvent_EmittedFunctionDetails::LineStart NextLine;
813814 NextLine.Address = getCurrentPCValue();
814815 NextLine.Loc = DL;
258258 if (! EmitDebugDirectives) return;
259259 assert (! DL.isUnknown() && "can't change to invalid debug loc");
260260
261 MDNode *CU = MF.getDebugLocTuple(DL).Scope;
262 unsigned line = MF.getDebugLocTuple(DL).Line;
261 DILocation Loc = MF.getDILocation(DL);
262 MDNode *CU = Loc.getScope().getNode();
263 unsigned line = Loc.getLineNumber();
263264
264265 SwitchToCU(CU);
265266 SwitchToLine(line, IsInBeginFunction);