[llvm-commits] [llvm] r128988 - in /llvm/trunk: include/llvm/Support/DebugLoc.h lib/VMCore/DebugLoc.cpp

Nick Lewycky nicholas at mxc.ca
Tue Apr 5 23:54:25 PDT 2011


Chris Lattner wrote:
>
> On Apr 5, 2011, at 10:36 PM, Nick Lewycky wrote:
>
>> Author: nicholas
>> Date: Wed Apr  6 00:36:52 2011
>> New Revision: 128988
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=128988&view=rev
>> Log:
>> Support using DebugLoc's in a DenseMap.
>
> One other issue: DebugLoc() is a valid DebugLoc, but given your formulation, you can't store one in the densemap.  It might be best to change the representation of the empty key to -2.

Oh right. Thanks!

> -Chris
>
>>
>> Modified:
>>     llvm/trunk/include/llvm/Support/DebugLoc.h
>>     llvm/trunk/lib/VMCore/DebugLoc.cpp
>>
>> Modified: llvm/trunk/include/llvm/Support/DebugLoc.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DebugLoc.h?rev=128988&r1=128987&r2=128988&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Support/DebugLoc.h (original)
>> +++ llvm/trunk/include/llvm/Support/DebugLoc.h Wed Apr  6 00:36:52 2011
>> @@ -15,6 +15,8 @@
>> #ifndef LLVM_SUPPORT_DEBUGLOC_H
>> #define LLVM_SUPPORT_DEBUGLOC_H
>>
>> +#include "llvm/ADT/DenseMapInfo.h"
>> +
>> namespace llvm {
>>    class MDNode;
>>    class LLVMContext;
>> @@ -23,6 +25,16 @@
>>    /// and MachineInstr to compactly encode file/line/scope information for an
>>    /// operation.
>>    class DebugLoc {
>> +    friend struct DenseMapInfo<DebugLoc>;
>> +
>> +    /// getTombstoneKey() - A private constructor that returns an unknown that
>> +    /// is distinguishable from the usual one.
>> +    static DebugLoc getTombstoneKey() {
>> +      DebugLoc DL;
>> +      DL.LineCol = -1;
>> +      return DL;
>> +    }
>> +
>>      /// LineCol - This 32-bit value encodes the line and column number for the
>>      /// location, encoded as 24-bits for line and 8 bits for col.  A value of 0
>>      /// for either means unknown.
>> @@ -75,6 +87,14 @@
>>      }
>>      bool operator!=(const DebugLoc&DL) const { return !(*this == DL); }
>>    };
>> +
>> +  template<>
>> +  struct DenseMapInfo<DebugLoc>  {
>> +    static DebugLoc getEmptyKey();
>> +    static DebugLoc getTombstoneKey();
>> +    static unsigned getHashValue(const DebugLoc&Key);
>> +    static bool isEqual(const DebugLoc&LHS, const DebugLoc&RHS);
>> +  };
>> } // end namespace llvm
>>
>> #endif /* LLVM_DEBUGLOC_H */
>>
>> Modified: llvm/trunk/lib/VMCore/DebugLoc.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/DebugLoc.cpp?rev=128988&r1=128987&r2=128988&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/VMCore/DebugLoc.cpp (original)
>> +++ llvm/trunk/lib/VMCore/DebugLoc.cpp Wed Apr  6 00:36:52 2011
>> @@ -8,6 +8,7 @@
>> //===----------------------------------------------------------------------===//
>>
>> #include "llvm/Support/DebugLoc.h"
>> +#include "llvm/ADT/DenseMapInfo.h"
>> #include "LLVMContextImpl.h"
>> using namespace llvm;
>>
>> @@ -128,6 +129,29 @@
>> }
>>
>> //===----------------------------------------------------------------------===//
>> +// DenseMap specialization
>> +//===----------------------------------------------------------------------===//
>> +
>> +DebugLoc DenseMapInfo<DebugLoc>::getEmptyKey() {
>> +  return DebugLoc();
>> +}
>> +
>> +DebugLoc DenseMapInfo<DebugLoc>::getTombstoneKey() {
>> +  return DebugLoc::getTombstoneKey();
>> +}
>> +
>> +unsigned DenseMapInfo<DebugLoc>::getHashValue(const DebugLoc&Key) {
>> +  FoldingSetNodeID ID;
>> +  ID.AddInteger(Key.LineCol);
>> +  ID.AddInteger(Key.ScopeIdx);
>> +  return ID.ComputeHash();
>> +}
>> +
>> +bool DenseMapInfo<DebugLoc>::isEqual(const DebugLoc&LHS, const DebugLoc&RHS) {
>> +  return LHS == RHS;
>> +}
>> +
>> +//===----------------------------------------------------------------------===//
>> // LLVMContextImpl Implementation
>> //===----------------------------------------------------------------------===//
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>




More information about the llvm-commits mailing list