Convert typerec to be a structure instead of a pair
authorChris Lattner <sabre@nondot.org>
Fri, 18 Oct 2002 18:22:46 +0000 (18:22 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 18 Oct 2002 18:22:46 +0000 (18:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4226 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/DSGraph.h
include/llvm/Analysis/DataStructure/DSGraph.h
lib/Analysis/DataStructure/DataStructure.cpp
lib/Analysis/DataStructure/Local.cpp
lib/Analysis/DataStructure/Printer.cpp

index fb2f28bc1a0b69186173ffa584ef81124e16eb8f..efb82bc10f5223847a6bf15701937eaa4f9bffee 100644 (file)
@@ -120,7 +120,23 @@ class DSNode {
   /// different types can be represented by this single DSNode.  This vector is
   /// kept sorted.
   ///
-  typedef std::pair<const Type *, unsigned> TypeRec;
+  struct TypeRec {
+    const Type *Ty;
+    unsigned Offset;
+
+    TypeRec() : Ty(0), Offset(0) {}
+    TypeRec(const Type *T, unsigned O) : Ty(T), Offset(O) {}
+
+    bool operator<(const TypeRec &TR) const {
+      // Sort first by offset!
+      return Offset < TR.Offset || (Offset == TR.Offset && Ty < TR.Ty);
+    }
+    bool operator==(const TypeRec &TR) const {
+      return Ty == TR.Ty && Offset == TR.Offset;
+    }
+    bool operator!=(const TypeRec &TR) const { return !operator==(TR); }
+  };
+
   std::vector<TypeRec> TypeEntries;
 
   /// Globals - The list of global values that are merged into this node.
index fb2f28bc1a0b69186173ffa584ef81124e16eb8f..efb82bc10f5223847a6bf15701937eaa4f9bffee 100644 (file)
@@ -120,7 +120,23 @@ class DSNode {
   /// different types can be represented by this single DSNode.  This vector is
   /// kept sorted.
   ///
-  typedef std::pair<const Type *, unsigned> TypeRec;
+  struct TypeRec {
+    const Type *Ty;
+    unsigned Offset;
+
+    TypeRec() : Ty(0), Offset(0) {}
+    TypeRec(const Type *T, unsigned O) : Ty(T), Offset(O) {}
+
+    bool operator<(const TypeRec &TR) const {
+      // Sort first by offset!
+      return Offset < TR.Offset || (Offset == TR.Offset && Ty < TR.Ty);
+    }
+    bool operator==(const TypeRec &TR) const {
+      return Ty == TR.Ty && Offset == TR.Offset;
+    }
+    bool operator!=(const TypeRec &TR) const { return !operator==(TR); }
+  };
+
   std::vector<TypeRec> TypeEntries;
 
   /// Globals - The list of global values that are merged into this node.
index 2313cd09e8724bc6b657e35fce0e9ee98e2993e0..e7e40108c60e9f4d55acc1645cd99ed350dc7cd0 100644 (file)
@@ -61,7 +61,7 @@ DSNode::DSNode(enum NodeTy NT, const Type *T) : NodeType(NT) {
     }
   }
 
-  TypeEntries.push_back(std::make_pair(T, 0));
+  TypeEntries.push_back(TypeRec(T, 0));
 }
 
 // DSNode copy constructor... do not copy over the referrers list!
@@ -323,9 +323,9 @@ void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) {
 
   // If this merging into node has more than just void nodes in it, merge!
   assert(!N->TypeEntries.empty() && "TypeEntries is empty for a node?");
-  if (N->TypeEntries.size() != 1 || N->TypeEntries[0].first != Type::VoidTy) {
+  if (N->TypeEntries.size() != 1 || N->TypeEntries[0].Ty != Type::VoidTy) {
     // If the current node just has a Void entry in it, remove it.
-    if (TypeEntries.size() == 1 && TypeEntries[0].first == Type::VoidTy)
+    if (TypeEntries.size() == 1 && TypeEntries[0].Ty == Type::VoidTy)
       TypeEntries.clear();
 
     // Adjust all of the type entries we are merging in by the offset... and add
@@ -334,7 +334,7 @@ void DSNode::mergeWith(const DSNodeHandle &NH, unsigned Offset) {
     if (NOffset != 0) {  // This case is common enough to optimize for
       // Offset all of the TypeEntries in N with their new offset
       for (unsigned i = 0, e = N->TypeEntries.size(); i != e; ++i)
-        N->TypeEntries[i].second += NOffset;
+        N->TypeEntries[i].Offset += NOffset;
     }
 
     MergeSortedVectors(TypeEntries, N->TypeEntries);
index 43fd5a4a5449d78667950c8256783a16da08cab7..b27652379ef525ad76b98aaad182d99107122e6e 100644 (file)
@@ -413,4 +413,3 @@ bool LocalDataStructures::run(Module &M) {
       DSInfo.insert(std::make_pair(I, new DSGraph(*I)));
   return false;
 }
-
index 8b29c1c6c0ba02e6a4c1b04dae76724844423c1e..7539aac102529cd3e36fe3cba772243ed801ddd2 100644 (file)
@@ -28,9 +28,9 @@ static string getCaption(const DSNode *N, const DSGraph *G) {
   Module *M = G && &G->getFunction() ? G->getFunction().getParent() : 0;
 
   for (unsigned i = 0, e = N->getTypeEntries().size(); i != e; ++i) {
-    WriteTypeSymbolic(OS, N->getTypeEntries()[i].first, M);
-    if (N->getTypeEntries()[i].second)
-      OS << "@" << N->getTypeEntries()[i].second;
+    WriteTypeSymbolic(OS, N->getTypeEntries()[i].Ty, M);
+    if (N->getTypeEntries()[i].Offset)
+      OS << "@" << N->getTypeEntries()[i].Offset;
     OS << "\n";
   }