1 //===- GVN.cpp - Eliminate redundant values and loads ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the Owen Anderson and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass performs global value numbering to eliminate fully redundant
11 // instructions. It also performs simple dead load elimination.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "gvn"
16 #include "llvm/Value.h"
17 #include "llvm/Transforms/Scalar.h"
18 #include "llvm/Instructions.h"
19 #include "llvm/Function.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Analysis/Dominators.h"
22 #include "llvm/ADT/BitVector.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/DepthFirstIterator.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/Statistic.h"
28 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
29 #include "llvm/Support/CFG.h"
30 #include "llvm/Support/Compiler.h"
33 //===----------------------------------------------------------------------===//
35 //===----------------------------------------------------------------------===//
37 /// This class holds the mapping between values and value numbers. It is used
38 /// as an efficient mechanism to determine the expression-wise equivalence of
41 struct VISIBILITY_HIDDEN Expression {
42 enum ExpressionOpcode { ADD, SUB, MUL, UDIV, SDIV, FDIV, UREM, SREM,
43 FREM, SHL, LSHR, ASHR, AND, OR, XOR, ICMPEQ,
44 ICMPNE, ICMPUGT, ICMPUGE, ICMPULT, ICMPULE,
45 ICMPSGT, ICMPSGE, ICMPSLT, ICMPSLE, FCMPOEQ,
46 FCMPOGT, FCMPOGE, FCMPOLT, FCMPOLE, FCMPONE,
47 FCMPORD, FCMPUNO, FCMPUEQ, FCMPUGT, FCMPUGE,
48 FCMPULT, FCMPULE, FCMPUNE, EXTRACT, INSERT,
49 SHUFFLE, SELECT, TRUNC, ZEXT, SEXT, FPTOUI,
50 FPTOSI, UITOFP, SITOFP, FPTRUNC, FPEXT,
51 PTRTOINT, INTTOPTR, BITCAST, GEP, EMPTY,
54 ExpressionOpcode opcode;
59 SmallVector<uint32_t, 4> varargs;
62 Expression(ExpressionOpcode o) : opcode(o) { }
64 bool operator==(const Expression &other) const {
65 if (opcode != other.opcode)
67 else if (opcode == EMPTY || opcode == TOMBSTONE)
69 else if (type != other.type)
71 else if (firstVN != other.firstVN)
73 else if (secondVN != other.secondVN)
75 else if (thirdVN != other.thirdVN)
78 if (varargs.size() != other.varargs.size())
81 for (size_t i = 0; i < varargs.size(); ++i)
82 if (varargs[i] != other.varargs[i])
89 bool operator!=(const Expression &other) const {
90 if (opcode != other.opcode)
92 else if (opcode == EMPTY || opcode == TOMBSTONE)
94 else if (type != other.type)
96 else if (firstVN != other.firstVN)
98 else if (secondVN != other.secondVN)
100 else if (thirdVN != other.thirdVN)
103 if (varargs.size() != other.varargs.size())
106 for (size_t i = 0; i < varargs.size(); ++i)
107 if (varargs[i] != other.varargs[i])
115 class VISIBILITY_HIDDEN ValueTable {
117 DenseMap<Value*, uint32_t> valueNumbering;
118 DenseMap<Expression, uint32_t> expressionNumbering;
120 uint32_t nextValueNumber;
122 Expression::ExpressionOpcode getOpcode(BinaryOperator* BO);
123 Expression::ExpressionOpcode getOpcode(CmpInst* C);
124 Expression::ExpressionOpcode getOpcode(CastInst* C);
125 Expression create_expression(BinaryOperator* BO);
126 Expression create_expression(CmpInst* C);
127 Expression create_expression(ShuffleVectorInst* V);
128 Expression create_expression(ExtractElementInst* C);
129 Expression create_expression(InsertElementInst* V);
130 Expression create_expression(SelectInst* V);
131 Expression create_expression(CastInst* C);
132 Expression create_expression(GetElementPtrInst* G);
134 ValueTable() { nextValueNumber = 1; }
135 uint32_t lookup_or_add(Value* V);
136 uint32_t lookup(Value* V) const;
137 void add(Value* V, uint32_t num);
139 void erase(Value* v);
145 template <> struct DenseMapKeyInfo<Expression> {
146 static inline Expression getEmptyKey() { return Expression(Expression::EMPTY); }
147 static inline Expression getTombstoneKey() { return Expression(Expression::TOMBSTONE); }
149 static unsigned getHashValue(const Expression e) {
150 unsigned hash = e.opcode;
152 hash = e.firstVN + hash * 37;
153 hash = e.secondVN + hash * 37;
154 hash = e.thirdVN + hash * 37;
156 hash = (unsigned)((uintptr_t)e.type >> 4) ^
157 (unsigned)((uintptr_t)e.type >> 9) +
160 for (SmallVector<uint32_t, 4>::const_iterator I = e.varargs.begin(), E = e.varargs.end();
162 hash = *I + hash * 37;
166 static bool isPod() { return true; }
170 //===----------------------------------------------------------------------===//
171 // ValueTable Internal Functions
172 //===----------------------------------------------------------------------===//
173 Expression::ExpressionOpcode
174 ValueTable::getOpcode(BinaryOperator* BO) {
175 switch(BO->getOpcode()) {
176 case Instruction::Add:
177 return Expression::ADD;
178 case Instruction::Sub:
179 return Expression::SUB;
180 case Instruction::Mul:
181 return Expression::MUL;
182 case Instruction::UDiv:
183 return Expression::UDIV;
184 case Instruction::SDiv:
185 return Expression::SDIV;
186 case Instruction::FDiv:
187 return Expression::FDIV;
188 case Instruction::URem:
189 return Expression::UREM;
190 case Instruction::SRem:
191 return Expression::SREM;
192 case Instruction::FRem:
193 return Expression::FREM;
194 case Instruction::Shl:
195 return Expression::SHL;
196 case Instruction::LShr:
197 return Expression::LSHR;
198 case Instruction::AShr:
199 return Expression::ASHR;
200 case Instruction::And:
201 return Expression::AND;
202 case Instruction::Or:
203 return Expression::OR;
204 case Instruction::Xor:
205 return Expression::XOR;
207 // THIS SHOULD NEVER HAPPEN
209 assert(0 && "Binary operator with unknown opcode?");
210 return Expression::ADD;
214 Expression::ExpressionOpcode ValueTable::getOpcode(CmpInst* C) {
215 if (C->getOpcode() == Instruction::ICmp) {
216 switch (C->getPredicate()) {
217 case ICmpInst::ICMP_EQ:
218 return Expression::ICMPEQ;
219 case ICmpInst::ICMP_NE:
220 return Expression::ICMPNE;
221 case ICmpInst::ICMP_UGT:
222 return Expression::ICMPUGT;
223 case ICmpInst::ICMP_UGE:
224 return Expression::ICMPUGE;
225 case ICmpInst::ICMP_ULT:
226 return Expression::ICMPULT;
227 case ICmpInst::ICMP_ULE:
228 return Expression::ICMPULE;
229 case ICmpInst::ICMP_SGT:
230 return Expression::ICMPSGT;
231 case ICmpInst::ICMP_SGE:
232 return Expression::ICMPSGE;
233 case ICmpInst::ICMP_SLT:
234 return Expression::ICMPSLT;
235 case ICmpInst::ICMP_SLE:
236 return Expression::ICMPSLE;
238 // THIS SHOULD NEVER HAPPEN
240 assert(0 && "Comparison with unknown predicate?");
241 return Expression::ICMPEQ;
244 switch (C->getPredicate()) {
245 case FCmpInst::FCMP_OEQ:
246 return Expression::FCMPOEQ;
247 case FCmpInst::FCMP_OGT:
248 return Expression::FCMPOGT;
249 case FCmpInst::FCMP_OGE:
250 return Expression::FCMPOGE;
251 case FCmpInst::FCMP_OLT:
252 return Expression::FCMPOLT;
253 case FCmpInst::FCMP_OLE:
254 return Expression::FCMPOLE;
255 case FCmpInst::FCMP_ONE:
256 return Expression::FCMPONE;
257 case FCmpInst::FCMP_ORD:
258 return Expression::FCMPORD;
259 case FCmpInst::FCMP_UNO:
260 return Expression::FCMPUNO;
261 case FCmpInst::FCMP_UEQ:
262 return Expression::FCMPUEQ;
263 case FCmpInst::FCMP_UGT:
264 return Expression::FCMPUGT;
265 case FCmpInst::FCMP_UGE:
266 return Expression::FCMPUGE;
267 case FCmpInst::FCMP_ULT:
268 return Expression::FCMPULT;
269 case FCmpInst::FCMP_ULE:
270 return Expression::FCMPULE;
271 case FCmpInst::FCMP_UNE:
272 return Expression::FCMPUNE;
274 // THIS SHOULD NEVER HAPPEN
276 assert(0 && "Comparison with unknown predicate?");
277 return Expression::FCMPOEQ;
282 Expression::ExpressionOpcode
283 ValueTable::getOpcode(CastInst* C) {
284 switch(C->getOpcode()) {
285 case Instruction::Trunc:
286 return Expression::TRUNC;
287 case Instruction::ZExt:
288 return Expression::ZEXT;
289 case Instruction::SExt:
290 return Expression::SEXT;
291 case Instruction::FPToUI:
292 return Expression::FPTOUI;
293 case Instruction::FPToSI:
294 return Expression::FPTOSI;
295 case Instruction::UIToFP:
296 return Expression::UITOFP;
297 case Instruction::SIToFP:
298 return Expression::SITOFP;
299 case Instruction::FPTrunc:
300 return Expression::FPTRUNC;
301 case Instruction::FPExt:
302 return Expression::FPEXT;
303 case Instruction::PtrToInt:
304 return Expression::PTRTOINT;
305 case Instruction::IntToPtr:
306 return Expression::INTTOPTR;
307 case Instruction::BitCast:
308 return Expression::BITCAST;
310 // THIS SHOULD NEVER HAPPEN
312 assert(0 && "Cast operator with unknown opcode?");
313 return Expression::BITCAST;
317 Expression ValueTable::create_expression(BinaryOperator* BO) {
320 e.firstVN = lookup_or_add(BO->getOperand(0));
321 e.secondVN = lookup_or_add(BO->getOperand(1));
323 e.type = BO->getType();
324 e.opcode = getOpcode(BO);
329 Expression ValueTable::create_expression(CmpInst* C) {
332 e.firstVN = lookup_or_add(C->getOperand(0));
333 e.secondVN = lookup_or_add(C->getOperand(1));
335 e.type = C->getType();
336 e.opcode = getOpcode(C);
341 Expression ValueTable::create_expression(CastInst* C) {
344 e.firstVN = lookup_or_add(C->getOperand(0));
347 e.type = C->getType();
348 e.opcode = getOpcode(C);
353 Expression ValueTable::create_expression(ShuffleVectorInst* S) {
356 e.firstVN = lookup_or_add(S->getOperand(0));
357 e.secondVN = lookup_or_add(S->getOperand(1));
358 e.thirdVN = lookup_or_add(S->getOperand(2));
359 e.type = S->getType();
360 e.opcode = Expression::SHUFFLE;
365 Expression ValueTable::create_expression(ExtractElementInst* E) {
368 e.firstVN = lookup_or_add(E->getOperand(0));
369 e.secondVN = lookup_or_add(E->getOperand(1));
371 e.type = E->getType();
372 e.opcode = Expression::EXTRACT;
377 Expression ValueTable::create_expression(InsertElementInst* I) {
380 e.firstVN = lookup_or_add(I->getOperand(0));
381 e.secondVN = lookup_or_add(I->getOperand(1));
382 e.thirdVN = lookup_or_add(I->getOperand(2));
383 e.type = I->getType();
384 e.opcode = Expression::INSERT;
389 Expression ValueTable::create_expression(SelectInst* I) {
392 e.firstVN = lookup_or_add(I->getCondition());
393 e.secondVN = lookup_or_add(I->getTrueValue());
394 e.thirdVN = lookup_or_add(I->getFalseValue());
395 e.type = I->getType();
396 e.opcode = Expression::SELECT;
401 Expression ValueTable::create_expression(GetElementPtrInst* G) {
404 e.firstVN = lookup_or_add(G->getPointerOperand());
407 e.type = G->getType();
408 e.opcode = Expression::GEP;
410 for (GetElementPtrInst::op_iterator I = G->idx_begin(), E = G->idx_end();
412 e.varargs.push_back(lookup_or_add(*I));
417 //===----------------------------------------------------------------------===//
418 // ValueTable External Functions
419 //===----------------------------------------------------------------------===//
421 /// lookup_or_add - Returns the value number for the specified value, assigning
422 /// it a new number if it did not have one before.
423 uint32_t ValueTable::lookup_or_add(Value* V) {
424 DenseMap<Value*, uint32_t>::iterator VI = valueNumbering.find(V);
425 if (VI != valueNumbering.end())
429 if (BinaryOperator* BO = dyn_cast<BinaryOperator>(V)) {
430 Expression e = create_expression(BO);
432 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
433 if (EI != expressionNumbering.end()) {
434 valueNumbering.insert(std::make_pair(V, EI->second));
437 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
438 valueNumbering.insert(std::make_pair(V, nextValueNumber));
440 return nextValueNumber++;
442 } else if (CmpInst* C = dyn_cast<CmpInst>(V)) {
443 Expression e = create_expression(C);
445 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
446 if (EI != expressionNumbering.end()) {
447 valueNumbering.insert(std::make_pair(V, EI->second));
450 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
451 valueNumbering.insert(std::make_pair(V, nextValueNumber));
453 return nextValueNumber++;
455 } else if (ShuffleVectorInst* U = dyn_cast<ShuffleVectorInst>(V)) {
456 Expression e = create_expression(U);
458 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
459 if (EI != expressionNumbering.end()) {
460 valueNumbering.insert(std::make_pair(V, EI->second));
463 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
464 valueNumbering.insert(std::make_pair(V, nextValueNumber));
466 return nextValueNumber++;
468 } else if (ExtractElementInst* U = dyn_cast<ExtractElementInst>(V)) {
469 Expression e = create_expression(U);
471 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
472 if (EI != expressionNumbering.end()) {
473 valueNumbering.insert(std::make_pair(V, EI->second));
476 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
477 valueNumbering.insert(std::make_pair(V, nextValueNumber));
479 return nextValueNumber++;
481 } else if (InsertElementInst* U = dyn_cast<InsertElementInst>(V)) {
482 Expression e = create_expression(U);
484 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
485 if (EI != expressionNumbering.end()) {
486 valueNumbering.insert(std::make_pair(V, EI->second));
489 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
490 valueNumbering.insert(std::make_pair(V, nextValueNumber));
492 return nextValueNumber++;
494 } else if (SelectInst* U = dyn_cast<SelectInst>(V)) {
495 Expression e = create_expression(U);
497 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
498 if (EI != expressionNumbering.end()) {
499 valueNumbering.insert(std::make_pair(V, EI->second));
502 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
503 valueNumbering.insert(std::make_pair(V, nextValueNumber));
505 return nextValueNumber++;
507 } else if (CastInst* U = dyn_cast<CastInst>(V)) {
508 Expression e = create_expression(U);
510 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
511 if (EI != expressionNumbering.end()) {
512 valueNumbering.insert(std::make_pair(V, EI->second));
515 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
516 valueNumbering.insert(std::make_pair(V, nextValueNumber));
518 return nextValueNumber++;
520 } else if (GetElementPtrInst* U = dyn_cast<GetElementPtrInst>(V)) {
521 Expression e = create_expression(U);
523 DenseMap<Expression, uint32_t>::iterator EI = expressionNumbering.find(e);
524 if (EI != expressionNumbering.end()) {
525 valueNumbering.insert(std::make_pair(V, EI->second));
528 expressionNumbering.insert(std::make_pair(e, nextValueNumber));
529 valueNumbering.insert(std::make_pair(V, nextValueNumber));
531 return nextValueNumber++;
534 valueNumbering.insert(std::make_pair(V, nextValueNumber));
535 return nextValueNumber++;
539 /// lookup - Returns the value number of the specified value. Fails if
540 /// the value has not yet been numbered.
541 uint32_t ValueTable::lookup(Value* V) const {
542 DenseMap<Value*, uint32_t>::iterator VI = valueNumbering.find(V);
543 if (VI != valueNumbering.end())
546 assert(0 && "Value not numbered?");
551 /// clear - Remove all entries from the ValueTable
552 void ValueTable::clear() {
553 valueNumbering.clear();
554 expressionNumbering.clear();
558 //===----------------------------------------------------------------------===//
559 // ValueNumberedSet Class
560 //===----------------------------------------------------------------------===//
562 class ValueNumberedSet {
564 SmallPtrSet<Value*, 8> contents;
567 ValueNumberedSet() { numbers.resize(1); }
568 ValueNumberedSet(const ValueNumberedSet& other) {
569 numbers = other.numbers;
570 contents = other.contents;
573 typedef SmallPtrSet<Value*, 8>::iterator iterator;
575 iterator begin() { return contents.begin(); }
576 iterator end() { return contents.end(); }
578 bool insert(Value* v) { return contents.insert(v); }
579 void insert(iterator I, iterator E) { contents.insert(I, E); }
580 void erase(Value* v) { contents.erase(v); }
581 unsigned count(Value* v) { return contents.count(v); }
582 size_t size() { return contents.size(); }
584 void set(unsigned i) {
585 if (i >= numbers.size())
591 void operator=(const ValueNumberedSet& other) {
592 contents = other.contents;
593 numbers = other.numbers;
596 void reset(unsigned i) {
597 if (i < numbers.size())
601 bool test(unsigned i) {
602 if (i >= numbers.size())
605 return numbers.test(i);
615 //===----------------------------------------------------------------------===//
617 //===----------------------------------------------------------------------===//
621 class VISIBILITY_HIDDEN GVN : public FunctionPass {
622 bool runOnFunction(Function &F);
624 static char ID; // Pass identification, replacement for typeid
625 GVN() : FunctionPass((intptr_t)&ID) { }
630 DenseMap<BasicBlock*, ValueNumberedSet> availableOut;
632 // This transformation requires dominator postdominator info
633 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
634 AU.setPreservesCFG();
635 AU.addRequired<DominatorTree>();
636 AU.addRequired<MemoryDependenceAnalysis>();
637 AU.addPreserved<MemoryDependenceAnalysis>();
641 // FIXME: eliminate or document these better
642 Value* find_leader(ValueNumberedSet& vals, uint32_t v) ;
643 void val_insert(ValueNumberedSet& s, Value* v);
644 bool processLoad(LoadInst* L,
645 DenseMap<Value*, LoadInst*>& lastLoad,
646 SmallVector<Instruction*, 4>& toErase);
647 bool processInstruction(Instruction* I,
648 ValueNumberedSet& currAvail,
649 DenseMap<Value*, LoadInst*>& lastSeenLoad,
650 SmallVector<Instruction*, 4>& toErase);
657 // createGVNPass - The public interface to this file...
658 FunctionPass *llvm::createGVNPass() { return new GVN(); }
660 static RegisterPass<GVN> X("gvn",
661 "Global Value Numbering");
663 STATISTIC(NumGVNInstr, "Number of instructions deleted");
664 STATISTIC(NumGVNLoad, "Number of loads deleted");
666 /// find_leader - Given a set and a value number, return the first
667 /// element of the set with that value number, or 0 if no such element
669 Value* GVN::find_leader(ValueNumberedSet& vals, uint32_t v) {
673 for (ValueNumberedSet::iterator I = vals.begin(), E = vals.end();
675 if (v == VN.lookup(*I))
678 assert(0 && "No leader found, but present bit is set?");
682 /// val_insert - Insert a value into a set only if there is not a value
683 /// with the same value number already in the set
684 void GVN::val_insert(ValueNumberedSet& s, Value* v) {
685 uint32_t num = VN.lookup(v);
690 bool GVN::processLoad(LoadInst* L,
691 DenseMap<Value*, LoadInst*>& lastLoad,
692 SmallVector<Instruction*, 4>& toErase) {
693 if (L->isVolatile()) {
694 lastLoad[L->getPointerOperand()] = L;
698 Value* pointer = L->getPointerOperand();
699 LoadInst*& last = lastLoad[pointer];
701 // ... to a pointer that has been loaded from before...
702 MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
703 Instruction* dep = MD.getDependency(L);
704 bool deletedLoad = false;
706 while (dep != MemoryDependenceAnalysis::None &&
707 dep != MemoryDependenceAnalysis::NonLocal &&
708 (isa<LoadInst>(dep) || isa<StoreInst>(dep))) {
709 // ... that depends on a store ...
710 if (StoreInst* S = dyn_cast<StoreInst>(dep)) {
711 if (S->getPointerOperand() == pointer) {
713 MD.removeInstruction(L);
715 L->replaceAllUsesWith(S->getOperand(0));
716 toErase.push_back(L);
721 // Whether we removed it or not, we can't
725 // If we don't depend on a store, and we haven't
726 // been loaded before, bail.
728 } else if (dep == last) {
730 MD.removeInstruction(L);
732 L->replaceAllUsesWith(last);
733 toErase.push_back(L);
739 dep = MD.getDependency(L, dep);
749 /// buildsets_availout - When calculating availability, handle an instruction
750 /// by inserting it into the appropriate sets
751 bool GVN::processInstruction(Instruction* I,
752 ValueNumberedSet& currAvail,
753 DenseMap<Value*, LoadInst*>& lastSeenLoad,
754 SmallVector<Instruction*, 4>& toErase) {
755 if (LoadInst* L = dyn_cast<LoadInst>(I)) {
756 return processLoad(L, lastSeenLoad, toErase);
759 unsigned num = VN.lookup_or_add(I);
761 if (currAvail.test(num)) {
762 Value* repl = find_leader(currAvail, num);
764 I->replaceAllUsesWith(repl);
765 toErase.push_back(I);
767 } else if (!I->isTerminator()) {
775 // GVN::runOnFunction - This is the main transformation entry point for a
778 bool GVN::runOnFunction(Function &F) {
779 // Clean out global sets from any previous functions
781 availableOut.clear();
783 bool changed_function = false;
785 DominatorTree &DT = getAnalysis<DominatorTree>();
787 SmallVector<Instruction*, 4> toErase;
789 // Top-down walk of the dominator tree
790 for (df_iterator<DomTreeNode*> DI = df_begin(DT.getRootNode()),
791 E = df_end(DT.getRootNode()); DI != E; ++DI) {
793 // Get the set to update for this block
794 ValueNumberedSet& currAvail = availableOut[DI->getBlock()];
795 DenseMap<Value*, LoadInst*> lastSeenLoad;
797 BasicBlock* BB = DI->getBlock();
799 // A block inherits AVAIL_OUT from its dominator
800 if (DI->getIDom() != 0)
801 currAvail = availableOut[DI->getIDom()->getBlock()];
803 for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
805 processInstruction(BI, currAvail, lastSeenLoad, toErase);
809 NumGVNInstr = toErase.size();
811 for (SmallVector<Instruction*, 4>::iterator I = toErase.begin(),
812 E = toErase.end(); I != E; ++I)
813 (*I)->eraseFromParent();
815 return changed_function;