From: Chris Lattner Date: Thu, 23 Oct 2003 16:29:12 +0000 (+0000) Subject: Actually share constants local to a function! X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=d97487d1e0252a7b8fc27902b70562832d287e7d;p=oota-llvm.git Actually share constants local to a function! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9417 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/MachineConstantPool.h b/include/llvm/CodeGen/MachineConstantPool.h index 74b7585a081..441a43a9b94 100644 --- a/include/llvm/CodeGen/MachineConstantPool.h +++ b/include/llvm/CodeGen/MachineConstantPool.h @@ -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; }