From 50be6edfa60bdc6cdf1fcb8009600e2cc11785c0 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sun, 28 Jun 2015 01:35:59 +0000 Subject: COFF: Make doICF non-recursive. NFC. llvm-svn: 240898 --- lld/COFF/ICF.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'lld/COFF') diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp index 0545d4c929ac..67ce67a4bcbe 100644 --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -37,24 +37,26 @@ struct Equals { // contents and relocations are all the same. void doICF(const std::vector &Chunks) { std::unordered_set Set; - bool removed = false; - for (Chunk *C : Chunks) { - auto *SC = dyn_cast(C); - if (!SC || !SC->isCOMDAT() || !SC->isLive()) - continue; - auto P = Set.insert(SC); - bool Inserted = P.second; - if (Inserted) - continue; - SectionChunk *Existing = *P.first; - SC->replaceWith(Existing); - removed = true; - } - // By merging sections, two relocations that originally pointed to - // different locations can now point to the same location. - // So, repeat the process until a convegence is obtained. - if (removed) - doICF(Chunks); + bool Redo; + do { + Set.clear(); + Redo = false; + for (Chunk *C : Chunks) { + auto *SC = dyn_cast(C); + if (!SC || !SC->isCOMDAT() || !SC->isLive()) + continue; + auto P = Set.insert(SC); + bool Inserted = P.second; + if (Inserted) + continue; + SectionChunk *Existing = *P.first; + SC->replaceWith(Existing); + // By merging sections, two relocations that originally pointed to + // different locations can now point to the same location. + // So, repeat the process until a convegence is obtained. + Redo = true; + } + } while (Redo); } } // namespace coff -- cgit v1.2.3