Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp
Line
Count
Source
1
//=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
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
// This file implements the NVPTXTargetStreamer class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "NVPTXTargetStreamer.h"
14
#include "llvm/MC/MCAsmInfo.h"
15
#include "llvm/MC/MCContext.h"
16
#include "llvm/MC/MCObjectFileInfo.h"
17
18
using namespace llvm;
19
20
//
21
// NVPTXTargetStreamer Implemenation
22
//
23
258
NVPTXTargetStreamer::NVPTXTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
24
25
250
NVPTXTargetStreamer::~NVPTXTargetStreamer() = default;
26
27
273
void NVPTXTargetStreamer::outputDwarfFileDirectives() {
28
273
  for (const std::string &S : DwarfFiles)
29
24
    getStreamer().EmitRawText(S.data());
30
273
  DwarfFiles.clear();
31
273
}
32
33
9
void NVPTXTargetStreamer::closeLastSection() {
34
9
  if (HasSections)
35
7
    getStreamer().EmitRawText("\t}");
36
9
}
37
38
24
void NVPTXTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
39
24
  DwarfFiles.emplace_back(Directive);
40
24
}
41
42
static bool isDwarfSection(const MCObjectFileInfo *FI,
43
974
                           const MCSection *Section) {
44
974
  // FIXME: the checks for the DWARF sections are very fragile and should be
45
974
  // fixed up in a followup patch.
46
974
  if (!Section || 
Section->getKind().isText()719
||
47
974
      
Section->getKind().isWriteable()255
)
48
719
    return false;
49
255
  return Section == FI->getDwarfAbbrevSection() ||
50
255
         
Section == FI->getDwarfInfoSection()241
||
51
255
         
Section == FI->getDwarfMacinfoSection()227
||
52
255
         
Section == FI->getDwarfFrameSection()219
||
53
255
         
Section == FI->getDwarfAddrSection()219
||
54
255
         
Section == FI->getDwarfRangesSection()219
||
55
255
         
Section == FI->getDwarfARangesSection()219
||
56
255
         
Section == FI->getDwarfLocSection()219
||
57
255
         
Section == FI->getDwarfStrSection()219
||
58
255
         
Section == FI->getDwarfLineSection()219
||
59
255
         
Section == FI->getDwarfStrOffSection()219
||
60
255
         
Section == FI->getDwarfLineStrSection()219
||
61
255
         
Section == FI->getDwarfPubNamesSection()219
||
62
255
         
Section == FI->getDwarfPubTypesSection()217
||
63
255
         
Section == FI->getDwarfSwiftASTSection()216
||
64
255
         
Section == FI->getDwarfTypesDWOSection()216
||
65
255
         
Section == FI->getDwarfAbbrevDWOSection()216
||
66
255
         
Section == FI->getDwarfAccelObjCSection()216
||
67
255
         
Section == FI->getDwarfAccelNamesSection()216
||
68
255
         
Section == FI->getDwarfAccelTypesSection()216
||
69
255
         
Section == FI->getDwarfAccelNamespaceSection()216
||
70
255
         
Section == FI->getDwarfLocDWOSection()216
||
71
255
         
Section == FI->getDwarfStrDWOSection()216
||
72
255
         
Section == FI->getDwarfCUIndexSection()216
||
73
255
         
Section == FI->getDwarfInfoDWOSection()216
||
74
255
         
Section == FI->getDwarfLineDWOSection()216
||
75
255
         
Section == FI->getDwarfTUIndexSection()216
||
76
255
         
Section == FI->getDwarfStrOffDWOSection()216
||
77
255
         
Section == FI->getDwarfDebugNamesSection()216
||
78
255
         
Section == FI->getDwarfDebugInlineSection()216
||
79
255
         
Section == FI->getDwarfGnuPubNamesSection()216
||
80
255
         
Section == FI->getDwarfGnuPubTypesSection()216
;
81
255
}
82
83
void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
84
                                        MCSection *Section,
85
                                        const MCExpr *SubSection,
86
487
                                        raw_ostream &OS) {
87
487
  assert(!SubSection && "SubSection is not null!");
88
487
  const MCObjectFileInfo *FI = getStreamer().getContext().getObjectFileInfo();
89
487
  // Emit closing brace for DWARF sections only.
90
487
  if (isDwarfSection(FI, CurSection))
91
16
    OS << "\t}\n";
92
487
  if (isDwarfSection(FI, Section)) {
93
23
    // Emit DWARF .file directives in the outermost scope.
94
23
    outputDwarfFileDirectives();
95
23
    OS << "\t.section";
96
23
    Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
97
23
                                  FI->getTargetTriple(), OS, SubSection);
98
23
    // DWARF sections are enclosed into braces - emit the open one.
99
23
    OS << "\t{\n";
100
23
    HasSections = true;
101
23
  }
102
487
}
103
104
2.32k
void NVPTXTargetStreamer::emitRawBytes(StringRef Data) {
105
2.32k
  MCTargetStreamer::emitRawBytes(Data);
106
2.32k
  // TODO: enable this once the bug in the ptxas with the packed bytes is
107
2.32k
  // resolved. Currently, (it is confirmed by NVidia) it causes a crash in
108
2.32k
  // ptxas.
109
#if 0
110
  const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
111
  const char *Directive = MAI->getData8bitsDirective();
112
  unsigned NumElements = Data.size();
113
  const unsigned MaxLen = 40;
114
  unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
115
  // Split the very long directives into several parts if the limit is
116
  // specified.
117
  for (unsigned I = 0; I < NumChunks; ++I) {
118
    SmallString<128> Str;
119
    raw_svector_ostream OS(Str);
120
121
    const char *Label = Directive;
122
    for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
123
              End = (I == NumChunks - 1)
124
                        ? Data.bytes_end()
125
                        : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
126
         It != End; ++It) {
127
      OS << Label << (unsigned)*It;
128
      if (Label == Directive)
129
        Label = ",";
130
    }
131
    Streamer.EmitRawText(OS.str());
132
  }
133
#endif
134
}
135