Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCAsmBackend.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MCAsmBackend.cpp - Target MC Assembly Backend ----------------------===//
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 "llvm/MC/MCAsmBackend.h"
10
#include "llvm/ADT/None.h"
11
#include "llvm/ADT/STLExtras.h"
12
#include "llvm/MC/MCCodePadder.h"
13
#include "llvm/MC/MCELFObjectWriter.h"
14
#include "llvm/MC/MCFixupKindInfo.h"
15
#include "llvm/MC/MCMachObjectWriter.h"
16
#include "llvm/MC/MCObjectWriter.h"
17
#include "llvm/MC/MCWasmObjectWriter.h"
18
#include "llvm/MC/MCWinCOFFObjectWriter.h"
19
#include "llvm/MC/MCXCOFFObjectWriter.h"
20
#include <cassert>
21
#include <cstddef>
22
#include <cstdint>
23
24
using namespace llvm;
25
26
MCAsmBackend::MCAsmBackend(support::endianness Endian)
27
47.0k
    : CodePadder(new MCCodePadder()), Endian(Endian) {}
28
29
46.8k
MCAsmBackend::~MCAsmBackend() = default;
30
31
std::unique_ptr<MCObjectWriter>
32
47.0k
MCAsmBackend::createObjectWriter(raw_pwrite_stream &OS) const {
33
47.0k
  auto TW = createObjectTargetWriter();
34
47.0k
  switch (TW->getFormat()) {
35
47.0k
  case Triple::ELF:
36
28.6k
    return createELFObjectWriter(cast<MCELFObjectTargetWriter>(std::move(TW)), OS,
37
28.6k
                                 Endian == support::little);
38
47.0k
  case Triple::MachO:
39
16.6k
    return createMachObjectWriter(cast<MCMachObjectTargetWriter>(std::move(TW)),
40
16.6k
                                  OS, Endian == support::little);
41
47.0k
  case Triple::COFF:
42
1.27k
    return createWinCOFFObjectWriter(
43
1.27k
        cast<MCWinCOFFObjectTargetWriter>(std::move(TW)), OS);
44
47.0k
  case Triple::Wasm:
45
443
    return createWasmObjectWriter(cast<MCWasmObjectTargetWriter>(std::move(TW)),
46
443
                                  OS);
47
47.0k
  case Triple::XCOFF:
48
5
    return createXCOFFObjectWriter(
49
5
        cast<MCXCOFFObjectTargetWriter>(std::move(TW)), OS);
50
47.0k
  default:
51
0
    llvm_unreachable("unexpected object format");
52
47.0k
  }
53
47.0k
}
54
55
std::unique_ptr<MCObjectWriter>
56
MCAsmBackend::createDwoObjectWriter(raw_pwrite_stream &OS,
57
15
                                    raw_pwrite_stream &DwoOS) const {
58
15
  auto TW = createObjectTargetWriter();
59
15
  if (TW->getFormat() != Triple::ELF)
60
0
    report_fatal_error("dwo only supported with ELF");
61
15
  return createELFDwoObjectWriter(cast<MCELFObjectTargetWriter>(std::move(TW)),
62
15
                                  OS, DwoOS, Endian == support::little);
63
15
}
64
65
174
Optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
66
174
  return None;
67
174
}
68
69
5.28M
const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
70
5.28M
  static const MCFixupKindInfo Builtins[] = {
71
5.28M
      {"FK_NONE", 0, 0, 0},
72
5.28M
      {"FK_Data_1", 0, 8, 0},
73
5.28M
      {"FK_Data_2", 0, 16, 0},
74
5.28M
      {"FK_Data_4", 0, 32, 0},
75
5.28M
      {"FK_Data_8", 0, 64, 0},
76
5.28M
      {"FK_Data_6b", 0, 6, 0},
77
5.28M
      {"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
78
5.28M
      {"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
79
5.28M
      {"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
80
5.28M
      {"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
81
5.28M
      {"FK_GPRel_1", 0, 8, 0},
82
5.28M
      {"FK_GPRel_2", 0, 16, 0},
83
5.28M
      {"FK_GPRel_4", 0, 32, 0},
84
5.28M
      {"FK_GPRel_8", 0, 64, 0},
85
5.28M
      {"FK_DTPRel_4", 0, 32, 0},
86
5.28M
      {"FK_DTPRel_8", 0, 64, 0},
87
5.28M
      {"FK_TPRel_4", 0, 32, 0},
88
5.28M
      {"FK_TPRel_8", 0, 64, 0},
89
5.28M
      {"FK_SecRel_1", 0, 8, 0},
90
5.28M
      {"FK_SecRel_2", 0, 16, 0},
91
5.28M
      {"FK_SecRel_4", 0, 32, 0},
92
5.28M
      {"FK_SecRel_8", 0, 64, 0},
93
5.28M
      {"FK_Data_Add_1", 0, 8, 0},
94
5.28M
      {"FK_Data_Add_2", 0, 16, 0},
95
5.28M
      {"FK_Data_Add_4", 0, 32, 0},
96
5.28M
      {"FK_Data_Add_8", 0, 64, 0},
97
5.28M
      {"FK_Data_Add_6b", 0, 6, 0},
98
5.28M
      {"FK_Data_Sub_1", 0, 8, 0},
99
5.28M
      {"FK_Data_Sub_2", 0, 16, 0},
100
5.28M
      {"FK_Data_Sub_4", 0, 32, 0},
101
5.28M
      {"FK_Data_Sub_8", 0, 64, 0},
102
5.28M
      {"FK_Data_Sub_6b", 0, 6, 0}};
103
5.28M
104
5.28M
  assert((size_t)Kind <= array_lengthof(Builtins) && "Unknown fixup kind");
105
5.28M
  return Builtins[Kind];
106
5.28M
}
107
108
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(
109
    const MCFixup &Fixup, bool Resolved, uint64_t Value,
110
    const MCRelaxableFragment *DF, const MCAsmLayout &Layout,
111
618k
    const bool WasForced) const {
112
618k
  if (!Resolved)
113
6.34k
    return true;
114
612k
  return fixupNeedsRelaxation(Fixup, Value, DF, Layout);
115
612k
}
116
117
void MCAsmBackend::handleCodePaddingBasicBlockStart(
118
2.37M
    MCObjectStreamer *OS, const MCCodePaddingContext &Context) {
119
2.37M
  CodePadder->handleBasicBlockStart(OS, Context);
120
2.37M
}
121
122
void MCAsmBackend::handleCodePaddingBasicBlockEnd(
123
2.37M
    const MCCodePaddingContext &Context) {
124
2.37M
  CodePadder->handleBasicBlockEnd(Context);
125
2.37M
}
126
127
16.7M
void MCAsmBackend::handleCodePaddingInstructionBegin(const MCInst &Inst) {
128
16.7M
  CodePadder->handleInstructionBegin(Inst);
129
16.7M
}
130
131
16.7M
void MCAsmBackend::handleCodePaddingInstructionEnd(const MCInst &Inst) {
132
16.7M
  CodePadder->handleInstructionEnd(Inst);
133
16.7M
}
134
135
0
bool MCAsmBackend::relaxFragment(MCPaddingFragment *PF, MCAsmLayout &Layout) {
136
0
  return CodePadder->relaxFragment(PF, Layout);
137
0
}