Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/MarkLive.cpp
Line
Count
Source
1
//===- MarkLive.cpp -------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "Chunks.h"
10
#include "Symbols.h"
11
#include "lld/Common/Timer.h"
12
#include "llvm/ADT/STLExtras.h"
13
#include <vector>
14
15
namespace lld {
16
namespace coff {
17
18
static Timer gctimer("GC", Timer::root());
19
20
// Set live bit on for each reachable chunk. Unmarked (unreachable)
21
// COMDAT chunks will be ignored by Writer, so they will be excluded
22
// from the final output.
23
437
void markLive(ArrayRef<Chunk *> chunks) {
24
437
  ScopedTimer t(gctimer);
25
437
26
437
  // We build up a worklist of sections which have been marked as live. We only
27
437
  // push into the worklist when we discover an unmarked section, and we mark
28
437
  // as we push, so sections never appear twice in the list.
29
437
  SmallVector<SectionChunk *, 256> worklist;
30
437
31
437
  // COMDAT section chunks are dead by default. Add non-COMDAT chunks.
32
437
  for (Chunk *c : chunks)
33
1.69k
    if (auto *sc = dyn_cast<SectionChunk>(c))
34
1.67k
      if (sc->live)
35
1.40k
        worklist.push_back(sc);
36
437
37
1.27k
  auto enqueue = [&](SectionChunk *c) {
38
1.27k
    if (c->live)
39
1.02k
      return;
40
254
    c->live = true;
41
254
    worklist.push_back(c);
42
254
  };
43
437
44
1.42k
  auto addSym = [&](Symbol *b) {
45
1.42k
    if (auto *sym = dyn_cast<DefinedRegular>(b))
46
1.19k
      enqueue(sym->getChunk());
47
234
    else if (auto *sym = dyn_cast<DefinedImportData>(b))
48
16
      sym->file->live = true;
49
218
    else if (auto *sym = dyn_cast<DefinedImportThunk>(b))
50
79
      sym->wrappedSym->file->live = sym->wrappedSym->file->thunkLive = true;
51
1.42k
  };
52
437
53
437
  // Add GC root chunks.
54
437
  for (Symbol *b : config->gcroot)
55
623
    addSym(b);
56
437
57
2.09k
  while (!worklist.empty()) {
58
1.65k
    SectionChunk *sc = worklist.pop_back_val();
59
1.65k
    assert(sc->live && "We mark as live when pushing onto the worklist!");
60
1.65k
61
1.65k
    // Mark all symbols listed in the relocation table for this section.
62
1.65k
    for (Symbol *b : sc->symbols())
63
806
      if (b)
64
801
        addSym(b);
65
1.65k
66
1.65k
    // Mark associative sections if any.
67
1.65k
    for (SectionChunk &c : sc->children())
68
89
      enqueue(&c);
69
1.65k
  }
70
437
}
71
72
}
73
}