[llvm-commits] [llvm] r169079 [1/2] - in /llvm/trunk: lib/Transforms/IPO/GlobalOpt.cpp test/Transforms/GlobalOpt/big-memory-footprint.ll

Sheng Zhou zhousheng00 at gmail.com
Sat Dec 1 02:55:58 PST 2012


Sorry, reverted.
Thanks for the kind reminding.

On Sat, Dec 1, 2012 at 5:10 PM, Chandler Carruth <chandlerc at google.com>wrote:

> Zhou, this commit was not approved in code review. Please revert and ping
> the code review thread until the review concludes with an explicit approval
> to commit. Commit after approval is really fundamental to the LLVM
> development process, don't circumvent it.
>
>
> On Fri, Nov 30, 2012 at 8:38 PM, Zhou Sheng <zhousheng00 at gmail.com> wrote:
>
>> Author: sheng
>> Date: Fri Nov 30 22:38:53 2012
>> New Revision: 169079
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=169079&view=rev
>> Log:
>> The patch is to improve the memory footprint of pass GlobalOpt.
>> Also check in a case to repeat the issue, on which 'opt -globalopt'
>> consumes 1.6GB memory.
>> The big memory footprint cause is that current GlobalOpt one by one
>> hoists and stores the leaf element constant into the global array, in each
>> iteration, it recreates the global array initializer constant and leave the
>> old initializer alone. This may result in many obsolete constants left.
>> For example:  we have global array @rom = global [16 x i32]
>> zeroinitializer
>> After the first element value is hoisted and installed:   @rom = global
>> [16 x i32] [ 1, 0, 0, ... ]
>> After the second element value is installed:  @rom = global [16 x 32] [
>> 1, 2, 0, 0, ... ]        // here the previous initializer is obsolete
>> ...
>> When the transform is done, we have 15 obsolete initializers left useless.
>>
>> Added:
>>     llvm/trunk/test/Transforms/GlobalOpt/big-memory-footprint.ll
>> Modified:
>>     llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
>>
>> Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=169079&r1=169078&r2=169079&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
>> +++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Fri Nov 30 22:38:53 2012
>> @@ -36,6 +36,7 @@
>>  #include "llvm/ADT/DenseMap.h"
>>  #include "llvm/ADT/SmallPtrSet.h"
>>  #include "llvm/ADT/SmallVector.h"
>> +#include "llvm/ADT/SetVector.h"
>>  #include "llvm/ADT/Statistic.h"
>>  #include "llvm/ADT/STLExtras.h"
>>  #include <algorithm>
>> @@ -2398,7 +2399,8 @@
>>  /// initializer.  This returns 'Init' modified to reflect 'Val' stored
>> into it.
>>  /// At this point, the GEP operands of Addr [0, OpNo) have been stepped
>> into.
>>  static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
>> -                                   ConstantExpr *Addr, unsigned OpNo) {
>> +                                   ConstantExpr *Addr, unsigned OpNo,
>> +                                   SetVector<Constant*>& Obsolete) {
>>    // Base case of the recursion.
>>    if (OpNo == Addr->getNumOperands()) {
>>      assert(Val->getType() == Init->getType() && "Type mismatch!");
>> @@ -2415,7 +2417,9 @@
>>      ConstantInt *CU = cast<ConstantInt>(Addr->getOperand(OpNo));
>>      unsigned Idx = CU->getZExtValue();
>>      assert(Idx < STy->getNumElements() && "Struct index out of range!");
>> -    Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1);
>> +    if (Elts[Idx]->getType()->isAggregateType())
>> +      Obsolete.insert(Elts[Idx]);
>> +    Elts[Idx] = EvaluateStoreInto(Elts[Idx], Val, Addr, OpNo+1,
>> Obsolete);
>>
>>      // Return the modified struct.
>>      return ConstantStruct::get(STy, Elts);
>> @@ -2435,8 +2439,11 @@
>>      Elts.push_back(Init->getAggregateElement(i));
>>
>>    assert(CI->getZExtValue() < NumElts);
>> +  Constant *OrigElem = Elts[CI->getZExtValue()];
>> +  if (OrigElem->getType()->isAggregateType())
>> +    Obsolete.insert(OrigElem);
>>    Elts[CI->getZExtValue()] =
>> -    EvaluateStoreInto(Elts[CI->getZExtValue()], Val, Addr, OpNo+1);
>> +    EvaluateStoreInto(OrigElem, Val, Addr, OpNo+1, Obsolete);
>>
>>    if (Init->getType()->isArrayTy())
>>      return ConstantArray::get(cast<ArrayType>(InitTy), Elts);
>> @@ -2452,9 +2459,20 @@
>>      return;
>>    }
>>
>> +  // Collect obsolete constants created in previous CommitValueTo()
>> invoke.
>> +  SetVector<Constant*> Obsolete;
>>    ConstantExpr *CE = cast<ConstantExpr>(Addr);
>>    GlobalVariable *GV = cast<GlobalVariable>(CE->getOperand(0));
>> -  GV->setInitializer(EvaluateStoreInto(GV->getInitializer(), Val, CE,
>> 2));
>> +  Constant *OrigInit = GV->getInitializer();
>> +  if (OrigInit->getType()->isAggregateType())
>> +    Obsolete.insert(OrigInit);
>> +  Constant *Init = EvaluateStoreInto(OrigInit, Val, CE, 2, Obsolete);
>> +  GV->setInitializer(Init);
>> +
>> +  for (unsigned i = 0; i < Obsolete.size(); ++i) {
>> +    if (Obsolete[i]->use_empty())
>> +      Obsolete[i]->destroyConstant();
>> +  }
>>  }
>>
>>  namespace {
>>
>>
>> _______________________________________________
>> 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/20121201/7f43c097/attachment.html>


More information about the llvm-commits mailing list