Coverage Report

Created: 2019-05-19 14:56

/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
413
void markLive(ArrayRef<Chunk *> Chunks) {
24
413
  ScopedTimer T(GCTimer);
25
413
26
413
  // We build up a worklist of sections which have been marked as live. We only
27
413
  // push into the worklist when we discover an unmarked section, and we mark
28
413
  // as we push, so sections never appear twice in the list.
29
413
  SmallVector<SectionChunk *, 256> Worklist;
30
413
31
413
  // COMDAT section chunks are dead by default. Add non-COMDAT chunks.
32
413
  for (Chunk *C : Chunks)
33
1.58k
    if (auto *SC = dyn_cast<SectionChunk>(C))
34
1.57k
      if (SC->Live)
35
1.30k
        Worklist.push_back(SC);
36
413
37
1.23k
  auto Enqueue = [&](SectionChunk *C) {
38
1.23k
    if (C->Live)
39
988
      return;
40
242
    C->Live = true;
41
242
    Worklist.push_back(C);
42
242
  };
43
413
44
1.36k
  auto AddSym = [&](Symbol *B) {
45
1.36k
    if (auto *Sym = dyn_cast<DefinedRegular>(B))
46
1.14k
      Enqueue(Sym->getChunk());
47
224
    else if (auto *Sym = dyn_cast<DefinedImportData>(B))
48
16
      Sym->File->Live = true;
49
208
    else if (auto *Sym = dyn_cast<DefinedImportThunk>(B))
50
79
      Sym->WrappedSym->File->Live = Sym->WrappedSym->File->ThunkLive = true;
51
1.36k
  };
52
413
53
413
  // Add GC root chunks.
54
413
  for (Symbol *B : Config->GCRoot)
55
595
    AddSym(B);
56
413
57
1.96k
  while (!Worklist.empty()) {
58
1.55k
    SectionChunk *SC = Worklist.pop_back_val();
59
1.55k
    assert(SC->Live && "We mark as live when pushing onto the worklist!");
60
1.55k
61
1.55k
    // Mark all symbols listed in the relocation table for this section.
62
1.55k
    for (Symbol *B : SC->symbols())
63
778
      if (B)
64
773
        AddSym(B);
65
1.55k
66
1.55k
    // Mark associative sections if any.
67
1.55k
    for (SectionChunk &C : SC->children())
68
86
      Enqueue(&C);
69
1.55k
  }
70
413
}
71
72
}
73
}