From: Chris Lattner Date: Tue, 9 Apr 2002 05:14:14 +0000 (+0000) Subject: * General cleanups X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fb005fe5c2b3cca4e982c8cc055964322c187ca2;p=oota-llvm.git * General cleanups * In calcLiveVarSetsForBB, do not leak a ValueSet every time the function is called! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2189 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp index a0b410ec250..e9e4245cca6 100644 --- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp @@ -94,11 +94,12 @@ void MethodLiveVarInfo::constructBBs(const Function *M) { // do one backward pass over the CFG (for iterative analysis) //----------------------------------------------------------------------------- -bool MethodLiveVarInfo::doSingleBackwardPass(const Function *M, unsigned int iter) { +bool MethodLiveVarInfo::doSingleBackwardPass(const Function *M, unsigned iter) { if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n"; bool NeedAnotherIteration = false; - for (po_iterator BBI = po_begin(M); BBI != po_end(M) ; ++BBI) { + for (po_iterator BBI = po_begin(M), BBE = po_end(M); + BBI != BBE; ++BBI) { BBLiveVar *LVBB = BBLiveVar::GetFromBB(*BBI); assert(LVBB && "BasicBlock information not set for block!"); @@ -108,9 +109,10 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Function *M, unsigned int ite if(LVBB->isOutSetChanged()) LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet - // OutSets are initialized to EMPTY. Recompute on first iter or if InSet changed. + // OutSets are initialized to EMPTY. Recompute on first iter or if InSet + // changed. if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds - NeedAnotherIteration = LVBB->applyFlowFunc() || NeedAnotherIteration; + NeedAnotherIteration |= LVBB->applyFlowFunc(); if (DEBUG_LV) LVBB->printInOutSets(); } @@ -208,17 +210,15 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { for (MachineInstr::const_val_op_iterator OpI = MInst->begin(), OpE = MInst->end(); OpI != OpE; ++OpI) { - if (isa(*OpI)) continue; // don't process labels - - if (!OpI.isDef()) // add only if this operand is a use - LVS.insert(*OpI); // An operand is a use - so add to use set + if (!isa(*OpI)) // don't process labels + if (!OpI.isDef()) // add only if this operand is a use + LVS.insert(*OpI); // An operand is a use - so add to use set } // do for implicit operands as well - for (unsigned i = 0; i < MInst->getNumImplicitRefs(); ++i) { + for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i) if (!MInst->implicitRefIsDefined(i)) LVS.insert(MInst->getImplicitRef(i)); - } } //----------------------------------------------------------------------------- @@ -230,13 +230,13 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec(); - if (DEBUG_LV >= LV_DEBUG_Instr) { - std::cerr << endl << "======For BB " << BB->getName() << ": Live var sets for instructions======" << endl; - } + if (DEBUG_LV >= LV_DEBUG_Instr) + std::cerr << "\n======For BB " << BB->getName() + << ": Live var sets for instructions======\n"; - ValueSet *CurSet = new ValueSet(); + ValueSet CurSet; const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet - set_union(*CurSet, *SetAI); // CurSet now contains OutSet + set_union(CurSet, *SetAI); // CurSet now contains OutSet // iterate over all the machine instructions in BB for (MachineCodeForBasicBlock::const_reverse_iterator MII = MIVec.rbegin(), @@ -246,16 +246,16 @@ void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { MInst2LVSetAI[MI] = SetAI; // record in After Inst map - applyTranferFuncForMInst(*CurSet, MI); // apply the transfer Func - ValueSet *NewSet = new ValueSet(); // create a new set and - set_union(*NewSet, *CurSet); // copy the set after T/F to it + applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func + ValueSet *NewSet = new ValueSet(); // create a new set and + set_union(*NewSet, CurSet); // copy the set after T/F to it MInst2LVSetBI[MI] = NewSet; // record in Before Inst map if (DEBUG_LV >= LV_DEBUG_Instr) { - std::cerr << endl << "Live var sets before/after instruction " << *MI; - cerr << " Before: "; printSet(*NewSet); cerr << endl; - cerr << " After : "; printSet(*SetAI); cerr << endl; + std::cerr << "\nLive var sets before/after instruction " << *MI; + cerr << " Before: "; printSet(*NewSet); cerr << "\n"; + cerr << " After : "; printSet(*SetAI); cerr << "\n"; } // SetAI will be used in the next iteration diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp index a0b410ec250..e9e4245cca6 100644 --- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp +++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp @@ -94,11 +94,12 @@ void MethodLiveVarInfo::constructBBs(const Function *M) { // do one backward pass over the CFG (for iterative analysis) //----------------------------------------------------------------------------- -bool MethodLiveVarInfo::doSingleBackwardPass(const Function *M, unsigned int iter) { +bool MethodLiveVarInfo::doSingleBackwardPass(const Function *M, unsigned iter) { if (DEBUG_LV) std::cerr << "\n After Backward Pass " << iter << "...\n"; bool NeedAnotherIteration = false; - for (po_iterator BBI = po_begin(M); BBI != po_end(M) ; ++BBI) { + for (po_iterator BBI = po_begin(M), BBE = po_end(M); + BBI != BBE; ++BBI) { BBLiveVar *LVBB = BBLiveVar::GetFromBB(*BBI); assert(LVBB && "BasicBlock information not set for block!"); @@ -108,9 +109,10 @@ bool MethodLiveVarInfo::doSingleBackwardPass(const Function *M, unsigned int ite if(LVBB->isOutSetChanged()) LVBB->applyTransferFunc(); // apply the Tran Func to calc InSet - // OutSets are initialized to EMPTY. Recompute on first iter or if InSet changed. + // OutSets are initialized to EMPTY. Recompute on first iter or if InSet + // changed. if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds - NeedAnotherIteration = LVBB->applyFlowFunc() || NeedAnotherIteration; + NeedAnotherIteration |= LVBB->applyFlowFunc(); if (DEBUG_LV) LVBB->printInOutSets(); } @@ -208,17 +210,15 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { for (MachineInstr::const_val_op_iterator OpI = MInst->begin(), OpE = MInst->end(); OpI != OpE; ++OpI) { - if (isa(*OpI)) continue; // don't process labels - - if (!OpI.isDef()) // add only if this operand is a use - LVS.insert(*OpI); // An operand is a use - so add to use set + if (!isa(*OpI)) // don't process labels + if (!OpI.isDef()) // add only if this operand is a use + LVS.insert(*OpI); // An operand is a use - so add to use set } // do for implicit operands as well - for (unsigned i = 0; i < MInst->getNumImplicitRefs(); ++i) { + for (unsigned i = 0, e = MInst->getNumImplicitRefs(); i != e; ++i) if (!MInst->implicitRefIsDefined(i)) LVS.insert(MInst->getImplicitRef(i)); - } } //----------------------------------------------------------------------------- @@ -230,13 +230,13 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) { void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec(); - if (DEBUG_LV >= LV_DEBUG_Instr) { - std::cerr << endl << "======For BB " << BB->getName() << ": Live var sets for instructions======" << endl; - } + if (DEBUG_LV >= LV_DEBUG_Instr) + std::cerr << "\n======For BB " << BB->getName() + << ": Live var sets for instructions======\n"; - ValueSet *CurSet = new ValueSet(); + ValueSet CurSet; const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet - set_union(*CurSet, *SetAI); // CurSet now contains OutSet + set_union(CurSet, *SetAI); // CurSet now contains OutSet // iterate over all the machine instructions in BB for (MachineCodeForBasicBlock::const_reverse_iterator MII = MIVec.rbegin(), @@ -246,16 +246,16 @@ void MethodLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) { MInst2LVSetAI[MI] = SetAI; // record in After Inst map - applyTranferFuncForMInst(*CurSet, MI); // apply the transfer Func - ValueSet *NewSet = new ValueSet(); // create a new set and - set_union(*NewSet, *CurSet); // copy the set after T/F to it + applyTranferFuncForMInst(CurSet, MI); // apply the transfer Func + ValueSet *NewSet = new ValueSet(); // create a new set and + set_union(*NewSet, CurSet); // copy the set after T/F to it MInst2LVSetBI[MI] = NewSet; // record in Before Inst map if (DEBUG_LV >= LV_DEBUG_Instr) { - std::cerr << endl << "Live var sets before/after instruction " << *MI; - cerr << " Before: "; printSet(*NewSet); cerr << endl; - cerr << " After : "; printSet(*SetAI); cerr << endl; + std::cerr << "\nLive var sets before/after instruction " << *MI; + cerr << " Before: "; printSet(*NewSet); cerr << "\n"; + cerr << " After : "; printSet(*SetAI); cerr << "\n"; } // SetAI will be used in the next iteration