llvm.org GIT mirror llvm / d0adbb5
Add data structure to define and track debug location during codegen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63008 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 11 years ago
3 changed file(s) with 150 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 //===---- llvm/CodeGen/DebugLoc.h - Debug Location Information --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a number of light weight data structures used by the code
10 // generator to describe and track debug location information.
11
12 #ifndef LLVM_CODEGEN_DEBUGLOC_H
13 #define LLVM_CODEGEN_DEBUGLOC_H
14
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/StringMap.h"
17 #include
18
19 namespace llvm {
20
21 /// DebugLocTuple - Debug location tuple of filename id, line and column.
22 ///
23 struct DebugLocTuple {
24 unsigned FileId, Line, Col;
25
26 DebugLocTuple(unsigned fi, unsigned l, unsigned c)
27 : FileId(fi), Line(l), Col(c) {};
28 };
29
30 /// DebugLoc - Debug location id. This is carried by SDNode and
31 /// MachineInstr to index into a vector of unique debug location tuples.
32 class DebugLoc {
33 unsigned Idx;
34
35 public:
36 DebugLoc() : Idx(~0U) {}
37
38 static DebugLoc getNoDebugLoc() { DebugLoc L; L.Idx = 0; return L; }
39 static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx; return L; }
40
41 bool isInvalid() { return Idx == ~0U; }
42 bool isUnknown() { return Idx == 0; }
43 };
44
45 struct DebugLocTupleDenseMapInfo {
46 static inline DebugLocTuple getEmptyKey() {
47 return DebugLocTuple(~0U, ~0U, ~0U);
48 }
49 static inline DebugLocTuple getTombstoneKey() {
50 return DebugLocTuple(~1U, ~1U, ~1U);
51 }
52 static unsigned getHashValue(const DebugLocTuple &Val) {
53 return DenseMapInfo::getHashValue(Val.FileId) ^
54 DenseMapInfo::getHashValue(Val.Line) ^
55 DenseMapInfo::getHashValue(Val.Col);
56 }
57 static bool isEqual(const DebugLocTuple &LHS, const DebugLocTuple &RHS) {
58 return LHS.FileId == RHS.FileId &&
59 LHS.Line == RHS.Line &&
60 LHS.Col == RHS.Col;
61 }
62
63 static bool isPod() { return true; }
64 };
65
66 typedef DenseMap
67 DebugIdMapType;
68
69 /// DebugLocTracker - This class tracks debug location information.
70 ///
71 struct DebugLocTracker {
72 // NumFilenames - Size of the DebugFilenames vector.
73 //
74 unsigned NumFilenames;
75
76 // DebugFilenames - A vector of unique file names.
77 //
78 std::vector DebugFilenames;
79
80 // DebugFilenamesMap - File name to DebugFilenames index map.
81 //
82 StringMap DebugFilenamesMap;
83
84 // NumDebugLocations - Size of the DebugLocations vector.
85 unsigned NumDebugLocations;
86
87 // DebugLocations - A vector of unique DebugLocTuple's.
88 //
89 std::vector DebugLocations;
90
91 // DebugIdsMap - This maps DebugLocTuple's to indices into
92 // DebugLocations vector.
93 DebugIdMapType DebugIdMap;
94
95 DebugLocTracker() : NumFilenames(0), NumDebugLocations(0) {}
96
97 ~DebugLocTracker() {
98 NumFilenames = 0;
99 DebugFilenames.clear();
100 DebugFilenamesMap.clear();
101 DebugLocations.clear();
102 DebugIdMap.clear();
103 }
104 };
105
106 } // end namespace llvm
107
108 #endif /* LLVM_CODEGEN_DEBUGLOC_H */
1818 #define LLVM_CODEGEN_MACHINEFUNCTION_H
1919
2020 #include "llvm/ADT/ilist.h"
21 #include "llvm/CodeGen/DebugLoc.h"
2122 #include "llvm/CodeGen/MachineBasicBlock.h"
2223 #include "llvm/Support/Annotation.h"
2324 #include "llvm/Support/Allocator.h"
2627 namespace llvm {
2728
2829 class Function;
29 class TargetMachine;
3030 class MachineRegisterInfo;
3131 class MachineFrameInfo;
3232 class MachineConstantPool;
3333 class MachineJumpTableInfo;
34 class TargetMachine;
3435
3536 template <>
3637 struct ilist_traits
9293 // List of machine basic blocks in function
9394 typedef ilist BasicBlockListType;
9495 BasicBlockListType BasicBlocks;
96
97 // Tracks debug locations.
98 DebugLocTracker DebugLocInfo;
9599
96100 public:
97101 MachineFunction(const Function *Fn, const TargetMachine &TM);
301305 /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
302306 ///
303307 void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
308
309 //===--------------------------------------------------------------------===//
310 // Debug location.
311 //
312
313 /// lookUpDebugLocId - Look up the DebugLocTuple index with the given
314 /// filename, line, and column. It may add a new filename and / or
315 /// a new DebugLocTuple.
316 unsigned lookUpDebugLocId(const char *Filename, unsigned Line, unsigned Col);
304317 };
305318
306319 //===--------------------------------------------------------------------===//
377377 return *mc;
378378 }
379379
380 /// lookUpDebugLocId - Look up the DebugLocTuple index with the given
381 /// filename, line, and column. It may add a new filename and / or
382 /// a new DebugLocTuple.
383 unsigned MachineFunction::lookUpDebugLocId(const char *Filename, unsigned Line,
384 unsigned Col) {
385 unsigned FileId;
386 StringMap::iterator I =
387 DebugLocInfo.DebugFilenamesMap.find(Filename);
388 if (I != DebugLocInfo.DebugFilenamesMap.end())
389 FileId = I->second;
390 else {
391 // Add a new filename.
392 FileId = DebugLocInfo.NumFilenames++;
393 DebugLocInfo.DebugFilenames.push_back(Filename);
394 DebugLocInfo.DebugFilenamesMap[Filename] = FileId;
395 }
396
397 struct DebugLocTuple Tuple(FileId, Line, Col);
398 DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple);
399 if (II != DebugLocInfo.DebugIdMap.end())
400 return II->second;
401 // Add a new tuple.
402 DebugLocInfo.DebugLocations.push_back(Tuple);
403 DebugLocInfo.DebugIdMap[Tuple] = DebugLocInfo.NumDebugLocations;
404 return DebugLocInfo.NumDebugLocations++;
405 }
406
380407 //===----------------------------------------------------------------------===//
381408 // MachineFrameInfo implementation
382409 //===----------------------------------------------------------------------===//