[llvm-commits] [llvm] r63008 - in /llvm/trunk: include/llvm/CodeGen/DebugLoc.h include/llvm/CodeGen/MachineFunction.h lib/CodeGen/MachineFunction.cpp
Evan Cheng
evan.cheng at apple.com
Mon Jan 26 15:34:08 PST 2009
On Jan 26, 2009, at 1:57 PM, Devang Patel wrote:
>
>
> Why not use SourceLineInfo directly instead of introducing
> DebugLocTuple ?
>
> //
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
> /// SourceLineInfo - This class is used to record source line
> correspondence.
> ///
> class SourceLineInfo {
> unsigned Line; // Source line number.
> unsigned Column; // Source column.
> unsigned SourceID; // Source ID number.
> unsigned LabelID; // Label in code ID number.
> public
> ...
>
> SourceLineInfo is managed using UniqueVector in DwarfWriter. Is
> there a known reason to use DenseMap ? I'm just curious.
Is there a way to look up the id given line, column, sourceid? It
looks like DwarfWrite is just keeping a list of source lines so it can
be dumped out at the end. There are obvious duplicates we need to get
rid. I don't particularly care the way we use DwarfWriter to track
debug info. It should be used to print dwarf, not managing debug info
like it's doing right now.
Evan
>
> -
> Devan
>
>>
>> + /// DebugLoc - Debug location id. This is carried by SDNode and
>> + /// MachineInstr to index into a vector of unique debug location
>> tuples.
>> + class DebugLoc {
>> + unsigned Idx;
>> +
>> + public:
>> + DebugLoc() : Idx(~0U) {}
>> +
>> + static DebugLoc getNoDebugLoc() { DebugLoc L; L.Idx = 0;
>> return L; }
>> + static DebugLoc get(unsigned idx) { DebugLoc L; L.Idx = idx;
>> return L; }
>> +
>> + bool isInvalid() { return Idx == ~0U; }
>> + bool isUnknown() { return Idx == 0; }
>> + };
>> +
>> + struct DebugLocTupleDenseMapInfo {
>> + static inline DebugLocTuple getEmptyKey() {
>> + return DebugLocTuple(~0U, ~0U, ~0U);
>> + }
>> + static inline DebugLocTuple getTombstoneKey() {
>> + return DebugLocTuple(~1U, ~1U, ~1U);
>> + }
>> + static unsigned getHashValue(const DebugLocTuple &Val) {
>> + return DenseMapInfo<unsigned>::getHashValue(Val.FileId) ^
>> + DenseMapInfo<unsigned>::getHashValue(Val.Line) ^
>> + DenseMapInfo<unsigned>::getHashValue(Val.Col);
>> + }
>> + static bool isEqual(const DebugLocTuple &LHS, const
>> DebugLocTuple &RHS) {
>> + return LHS.FileId == RHS.FileId &&
>> + LHS.Line == RHS.Line &&
>> + LHS.Col == RHS.Col;
>> + }
>> +
>> + static bool isPod() { return true; }
>> + };
>> +
>> + typedef DenseMap<DebugLocTuple, unsigned,
>> DebugLocTupleDenseMapInfo>
>> + DebugIdMapType;
>> +
>> + /// DebugLocTracker - This class tracks debug location
>> information.
>> + ///
>> + struct DebugLocTracker {
>> + // NumFilenames - Size of the DebugFilenames vector.
>> + //
>> + unsigned NumFilenames;
>> +
>> + // DebugFilenames - A vector of unique file names.
>> + //
>> + std::vector<std::string> DebugFilenames;
>> +
>> + // DebugFilenamesMap - File name to DebugFilenames index map.
>> + //
>> + StringMap<unsigned> DebugFilenamesMap;
>> +
>> + // NumDebugLocations - Size of the DebugLocations vector.
>> + unsigned NumDebugLocations;
>> +
>> + // DebugLocations - A vector of unique DebugLocTuple's.
>> + //
>> + std::vector<DebugLocTuple> DebugLocations;
>> +
>> + // DebugIdsMap - This maps DebugLocTuple's to indices into
>> + // DebugLocations vector.
>> + DebugIdMapType DebugIdMap;
>> +
>> + DebugLocTracker() : NumFilenames(0), NumDebugLocations(0) {}
>> +
>> + ~DebugLocTracker() {
>> + NumFilenames = 0;
>> + DebugFilenames.clear();
>> + DebugFilenamesMap.clear();
>> + DebugLocations.clear();
>> + DebugIdMap.clear();
>> + }
>> + };
>> +
>> +} // end namespace llvm
>> +
>> +#endif /* LLVM_CODEGEN_DEBUGLOC_H */
>>
>> Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=63008&r1=63007&r2=63008&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
>> +++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Mon Jan 26
>> 01:41:49 2009
>> @@ -19,6 +19,7 @@
>> #define LLVM_CODEGEN_MACHINEFUNCTION_H
>>
>> #include "llvm/ADT/ilist.h"
>> +#include "llvm/CodeGen/DebugLoc.h"
>> #include "llvm/CodeGen/MachineBasicBlock.h"
>> #include "llvm/Support/Annotation.h"
>> #include "llvm/Support/Allocator.h"
>> @@ -27,11 +28,11 @@
>> namespace llvm {
>>
>> class Function;
>> -class TargetMachine;
>> class MachineRegisterInfo;
>> class MachineFrameInfo;
>> class MachineConstantPool;
>> class MachineJumpTableInfo;
>> +class TargetMachine;
>>
>> template <>
>> struct ilist_traits<MachineBasicBlock>
>> @@ -94,6 +95,9 @@
>> typedef ilist<MachineBasicBlock> BasicBlockListType;
>> BasicBlockListType BasicBlocks;
>>
>> + // Tracks debug locations.
>> + DebugLocTracker DebugLocInfo;
>> +
>> public:
>> MachineFunction(const Function *Fn, const TargetMachine &TM);
>> ~MachineFunction();
>> @@ -302,6 +306,15 @@
>> /// DeleteMachineBasicBlock - Delete the given MachineBasicBlock.
>> ///
>> void DeleteMachineBasicBlock(MachineBasicBlock *MBB);
>> +
>> + //
>> =
>> =
>> =
>> --------------------------------------------------------------------
>> ===//
>> + // Debug location.
>> + //
>> +
>> + /// lookUpDebugLocId - Look up the DebugLocTuple index with the
>> given
>> + /// filename, line, and column. It may add a new filename and / or
>> + /// a new DebugLocTuple.
>> + unsigned lookUpDebugLocId(const char *Filename, unsigned Line,
>> unsigned Col);
>> };
>>
>> //
>> =
>> =
>> =
>> --------------------------------------------------------------------
>> ===//
>>
>> Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=63008&r1=63007&r2=63008&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Mon Jan 26 01:41:49
>> 2009
>> @@ -378,6 +378,33 @@
>> return *mc;
>> }
>>
>> +/// lookUpDebugLocId - Look up the DebugLocTuple index with the
>> given
>> +/// filename, line, and column. It may add a new filename and / or
>> +/// a new DebugLocTuple.
>> +unsigned MachineFunction::lookUpDebugLocId(const char *Filename,
>> unsigned Line,
>> + unsigned Col) {
>> + unsigned FileId;
>> + StringMap<unsigned>::iterator I =
>> + DebugLocInfo.DebugFilenamesMap.find(Filename);
>> + if (I != DebugLocInfo.DebugFilenamesMap.end())
>> + FileId = I->second;
>> + else {
>> + // Add a new filename.
>> + FileId = DebugLocInfo.NumFilenames++;
>> + DebugLocInfo.DebugFilenames.push_back(Filename);
>> + DebugLocInfo.DebugFilenamesMap[Filename] = FileId;
>> + }
>> +
>> + struct DebugLocTuple Tuple(FileId, Line, Col);
>> + DebugIdMapType::iterator II = DebugLocInfo.DebugIdMap.find(Tuple);
>> + if (II != DebugLocInfo.DebugIdMap.end())
>> + return II->second;
>> + // Add a new tuple.
>> + DebugLocInfo.DebugLocations.push_back(Tuple);
>> + DebugLocInfo.DebugIdMap[Tuple] = DebugLocInfo.NumDebugLocations;
>> + return DebugLocInfo.NumDebugLocations++;
>> +}
>> +
>> //
>> =
>> =
>> =
>> ----------------------------------------------------------------------=
>> ==//
>> // MachineFrameInfo implementation
>> //
>> =
>> =
>> =
>> ----------------------------------------------------------------------=
>> ==//
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090126/5cd12987/attachment.html>
More information about the llvm-commits
mailing list