Actually share constants local to a function!
authorChris Lattner <sabre@nondot.org>
Thu, 23 Oct 2003 16:29:12 +0000 (16:29 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 23 Oct 2003 16:29:12 +0000 (16:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9417 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineConstantPool.h

index 74b7585a081698d08f717bc305dd985f38d393a5..441a43a9b9400b331d0cabc6254846f730d2c7ff 100644 (file)
@@ -30,10 +30,15 @@ class MachineConstantPool {
 public:
 
   /// getConstantPoolIndex - Create a new entry in the constant pool or return
-  /// an existing one.  This should eventually allow sharing of duplicate
-  /// objects in the constant pool, but this is adequate for now.
+  /// an existing one.
   ///
   unsigned getConstantPoolIndex(Constant *C) {
+    // Check to see if we already have this constant.
+    //
+    // FIXME, this could be made much more efficient for large constant pools.
+    for (unsigned i = 0, e = Constants.size(); i != e; ++i)
+      if (Constants[i] == C)
+        return i;
     Constants.push_back(C);
     return Constants.size()-1;
   }