Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- SystemZInstPrinter.cpp - Convert SystemZ MCInst to assembly syntax -===//
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 "SystemZInstPrinter.h"
10
#include "llvm/MC/MCExpr.h"
11
#include "llvm/MC/MCInst.h"
12
#include "llvm/MC/MCSymbol.h"
13
#include "llvm/Support/Casting.h"
14
#include "llvm/Support/ErrorHandling.h"
15
#include "llvm/Support/MathExtras.h"
16
#include "llvm/Support/raw_ostream.h"
17
#include <cassert>
18
#include <cstdint>
19
20
using namespace llvm;
21
22
#define DEBUG_TYPE "asm-printer"
23
24
#include "SystemZGenAsmWriter.inc"
25
26
void SystemZInstPrinter::printAddress(unsigned Base, int64_t Disp,
27
37.3k
                                      unsigned Index, raw_ostream &O) {
28
37.3k
  O << Disp;
29
37.3k
  if (Base || 
Index7.79k
) {
30
29.5k
    O << '(';
31
29.5k
    if (Index) {
32
1.96k
      O << '%' << getRegisterName(Index);
33
1.96k
      if (Base)
34
1.95k
        O << ',';
35
1.96k
    }
36
29.5k
    if (Base)
37
29.5k
      O << '%' << getRegisterName(Base);
38
29.5k
    O << ')';
39
29.5k
  }
40
37.3k
}
41
42
void SystemZInstPrinter::printOperand(const MCOperand &MO, const MCAsmInfo *MAI,
43
131k
                                      raw_ostream &O) {
44
131k
  if (MO.isReg())
45
131k
    O << '%' << getRegisterName(MO.getReg());
46
11
  else if (MO.isImm())
47
11
    O << MO.getImm();
48
0
  else if (MO.isExpr())
49
0
    MO.getExpr()->print(O, MAI);
50
0
  else
51
0
    llvm_unreachable("Invalid operand");
52
131k
}
53
54
void SystemZInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
55
                                   StringRef Annot,
56
88.0k
                                   const MCSubtargetInfo &STI) {
57
88.0k
  printInstruction(MI, O);
58
88.0k
  printAnnotation(O, Annot);
59
88.0k
}
60
61
3.70k
void SystemZInstPrinter::printRegName(raw_ostream &O, unsigned RegNo) const {
62
3.70k
  O << '%' << getRegisterName(RegNo);
63
3.70k
}
64
65
template <unsigned N>
66
26.4k
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
26.4k
  int64_t Value = MI->getOperand(OpNum).getImm();
68
26.4k
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
26.4k
  O << Value;
70
26.4k
}
SystemZInstPrinter.cpp:void printUImmOperand<1u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
300
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
300
  int64_t Value = MI->getOperand(OpNum).getImm();
68
300
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
300
  O << Value;
70
300
}
SystemZInstPrinter.cpp:void printUImmOperand<2u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
252
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
252
  int64_t Value = MI->getOperand(OpNum).getImm();
68
252
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
252
  O << Value;
70
252
}
SystemZInstPrinter.cpp:void printUImmOperand<3u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
118
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
118
  int64_t Value = MI->getOperand(OpNum).getImm();
68
118
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
118
  O << Value;
70
118
}
SystemZInstPrinter.cpp:void printUImmOperand<4u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
16.2k
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
16.2k
  int64_t Value = MI->getOperand(OpNum).getImm();
68
16.2k
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
16.2k
  O << Value;
70
16.2k
}
SystemZInstPrinter.cpp:void printUImmOperand<6u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
1.64k
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
1.64k
  int64_t Value = MI->getOperand(OpNum).getImm();
68
1.64k
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
1.64k
  O << Value;
70
1.64k
}
SystemZInstPrinter.cpp:void printUImmOperand<8u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
5.20k
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
5.20k
  int64_t Value = MI->getOperand(OpNum).getImm();
68
5.20k
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
5.20k
  O << Value;
70
5.20k
}
SystemZInstPrinter.cpp:void printUImmOperand<12u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
165
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
165
  int64_t Value = MI->getOperand(OpNum).getImm();
68
165
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
165
  O << Value;
70
165
}
SystemZInstPrinter.cpp:void printUImmOperand<16u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
1.34k
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
1.34k
  int64_t Value = MI->getOperand(OpNum).getImm();
68
1.34k
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
1.34k
  O << Value;
70
1.34k
}
SystemZInstPrinter.cpp:void printUImmOperand<32u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
66
1.21k
static void printUImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
67
1.21k
  int64_t Value = MI->getOperand(OpNum).getImm();
68
1.21k
  assert(isUInt<N>(Value) && "Invalid uimm argument");
69
1.21k
  O << Value;
70
1.21k
}
Unexecuted instantiation: SystemZInstPrinter.cpp:void printUImmOperand<48u>(llvm::MCInst const*, int, llvm::raw_ostream&)
71
72
template <unsigned N>
73
6.70k
static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
74
6.70k
  int64_t Value = MI->getOperand(OpNum).getImm();
75
6.70k
  assert(isInt<N>(Value) && "Invalid simm argument");
76
6.70k
  O << Value;
77
6.70k
}
SystemZInstPrinter.cpp:void printSImmOperand<8u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
73
765
static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
74
765
  int64_t Value = MI->getOperand(OpNum).getImm();
75
765
  assert(isInt<N>(Value) && "Invalid simm argument");
76
765
  O << Value;
77
765
}
SystemZInstPrinter.cpp:void printSImmOperand<16u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
73
4.39k
static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
74
4.39k
  int64_t Value = MI->getOperand(OpNum).getImm();
75
4.39k
  assert(isInt<N>(Value) && "Invalid simm argument");
76
4.39k
  O << Value;
77
4.39k
}
SystemZInstPrinter.cpp:void printSImmOperand<32u>(llvm::MCInst const*, int, llvm::raw_ostream&)
Line
Count
Source
73
1.54k
static void printSImmOperand(const MCInst *MI, int OpNum, raw_ostream &O) {
74
1.54k
  int64_t Value = MI->getOperand(OpNum).getImm();
75
1.54k
  assert(isInt<N>(Value) && "Invalid simm argument");
76
1.54k
  O << Value;
77
1.54k
}
78
79
void SystemZInstPrinter::printU1ImmOperand(const MCInst *MI, int OpNum,
80
300
                                           raw_ostream &O) {
81
300
  printUImmOperand<1>(MI, OpNum, O);
82
300
}
83
84
void SystemZInstPrinter::printU2ImmOperand(const MCInst *MI, int OpNum,
85
252
                                           raw_ostream &O) {
86
252
  printUImmOperand<2>(MI, OpNum, O);
87
252
}
88
89
void SystemZInstPrinter::printU3ImmOperand(const MCInst *MI, int OpNum,
90
118
                                           raw_ostream &O) {
91
118
  printUImmOperand<3>(MI, OpNum, O);
92
118
}
93
94
void SystemZInstPrinter::printU4ImmOperand(const MCInst *MI, int OpNum,
95
16.2k
                                           raw_ostream &O) {
96
16.2k
  printUImmOperand<4>(MI, OpNum, O);
97
16.2k
}
98
99
void SystemZInstPrinter::printU6ImmOperand(const MCInst *MI, int OpNum,
100
1.64k
                                           raw_ostream &O) {
101
1.64k
  printUImmOperand<6>(MI, OpNum, O);
102
1.64k
}
103
104
void SystemZInstPrinter::printS8ImmOperand(const MCInst *MI, int OpNum,
105
765
                                           raw_ostream &O) {
106
765
  printSImmOperand<8>(MI, OpNum, O);
107
765
}
108
109
void SystemZInstPrinter::printU8ImmOperand(const MCInst *MI, int OpNum,
110
5.20k
                                           raw_ostream &O) {
111
5.20k
  printUImmOperand<8>(MI, OpNum, O);
112
5.20k
}
113
114
void SystemZInstPrinter::printU12ImmOperand(const MCInst *MI, int OpNum,
115
165
                                            raw_ostream &O) {
116
165
  printUImmOperand<12>(MI, OpNum, O);
117
165
}
118
119
void SystemZInstPrinter::printS16ImmOperand(const MCInst *MI, int OpNum,
120
4.39k
                                            raw_ostream &O) {
121
4.39k
  printSImmOperand<16>(MI, OpNum, O);
122
4.39k
}
123
124
void SystemZInstPrinter::printU16ImmOperand(const MCInst *MI, int OpNum,
125
1.34k
                                            raw_ostream &O) {
126
1.34k
  printUImmOperand<16>(MI, OpNum, O);
127
1.34k
}
128
129
void SystemZInstPrinter::printS32ImmOperand(const MCInst *MI, int OpNum,
130
1.54k
                                            raw_ostream &O) {
131
1.54k
  printSImmOperand<32>(MI, OpNum, O);
132
1.54k
}
133
134
void SystemZInstPrinter::printU32ImmOperand(const MCInst *MI, int OpNum,
135
1.21k
                                            raw_ostream &O) {
136
1.21k
  printUImmOperand<32>(MI, OpNum, O);
137
1.21k
}
138
139
void SystemZInstPrinter::printU48ImmOperand(const MCInst *MI, int OpNum,
140
0
                                            raw_ostream &O) {
141
0
  printUImmOperand<48>(MI, OpNum, O);
142
0
}
143
144
void SystemZInstPrinter::printPCRelOperand(const MCInst *MI, int OpNum,
145
5.46k
                                           raw_ostream &O) {
146
5.46k
  const MCOperand &MO = MI->getOperand(OpNum);
147
5.46k
  if (MO.isImm()) {
148
502
    O << "0x";
149
502
    O.write_hex(MO.getImm());
150
502
  } else
151
4.96k
    MO.getExpr()->print(O, &MAI);
152
5.46k
}
153
154
void SystemZInstPrinter::printPCRelTLSOperand(const MCInst *MI, int OpNum,
155
894
                                              raw_ostream &O) {
156
894
  // Output the PC-relative operand.
157
894
  printPCRelOperand(MI, OpNum, O);
158
894
159
894
  // Output the TLS marker if present.
160
894
  if ((unsigned)OpNum + 1 < MI->getNumOperands()) {
161
14
    const MCOperand &MO = MI->getOperand(OpNum + 1);
162
14
    const MCSymbolRefExpr &refExp = cast<MCSymbolRefExpr>(*MO.getExpr());
163
14
    switch (refExp.getKind()) {
164
14
      case MCSymbolRefExpr::VK_TLSGD:
165
9
        O << ":tls_gdcall:";
166
9
        break;
167
14
      case MCSymbolRefExpr::VK_TLSLDM:
168
5
        O << ":tls_ldcall:";
169
5
        break;
170
14
      default:
171
0
        llvm_unreachable("Unexpected symbol kind");
172
14
    }
173
14
    O << refExp.getSymbol().getName();
174
14
  }
175
894
}
176
177
void SystemZInstPrinter::printOperand(const MCInst *MI, int OpNum,
178
131k
                                      raw_ostream &O) {
179
131k
  printOperand(MI->getOperand(OpNum), &MAI, O);
180
131k
}
181
182
void SystemZInstPrinter::printBDAddrOperand(const MCInst *MI, int OpNum,
183
12.1k
                                            raw_ostream &O) {
184
12.1k
  printAddress(MI->getOperand(OpNum).getReg(),
185
12.1k
               MI->getOperand(OpNum + 1).getImm(), 0, O);
186
12.1k
}
187
188
void SystemZInstPrinter::printBDXAddrOperand(const MCInst *MI, int OpNum,
189
24.9k
                                             raw_ostream &O) {
190
24.9k
  printAddress(MI->getOperand(OpNum).getReg(),
191
24.9k
               MI->getOperand(OpNum + 1).getImm(),
192
24.9k
               MI->getOperand(OpNum + 2).getReg(), O);
193
24.9k
}
194
195
void SystemZInstPrinter::printBDLAddrOperand(const MCInst *MI, int OpNum,
196
1.52k
                                             raw_ostream &O) {
197
1.52k
  unsigned Base = MI->getOperand(OpNum).getReg();
198
1.52k
  uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
199
1.52k
  uint64_t Length = MI->getOperand(OpNum + 2).getImm();
200
1.52k
  O << Disp << '(' << Length;
201
1.52k
  if (Base)
202
941
    O << ",%" << getRegisterName(Base);
203
1.52k
  O << ')';
204
1.52k
}
205
206
void SystemZInstPrinter::printBDRAddrOperand(const MCInst *MI, int OpNum,
207
73
                                             raw_ostream &O) {
208
73
  unsigned Base = MI->getOperand(OpNum).getReg();
209
73
  uint64_t Disp = MI->getOperand(OpNum + 1).getImm();
210
73
  unsigned Length = MI->getOperand(OpNum + 2).getReg();
211
73
  O << Disp << "(%" << getRegisterName(Length);
212
73
  if (Base)
213
34
    O << ",%" << getRegisterName(Base);
214
73
  O << ')';
215
73
}
216
217
void SystemZInstPrinter::printBDVAddrOperand(const MCInst *MI, int OpNum,
218
164
                                             raw_ostream &O) {
219
164
  printAddress(MI->getOperand(OpNum).getReg(),
220
164
               MI->getOperand(OpNum + 1).getImm(),
221
164
               MI->getOperand(OpNum + 2).getReg(), O);
222
164
}
223
224
void SystemZInstPrinter::printCond4Operand(const MCInst *MI, int OpNum,
225
2.60k
                                           raw_ostream &O) {
226
2.60k
  static const char *const CondNames[] = {
227
2.60k
    "o", "h", "nle", "l", "nhe", "lh", "ne",
228
2.60k
    "e", "nlh", "he", "nl", "le", "nh", "no"
229
2.60k
  };
230
2.60k
  uint64_t Imm = MI->getOperand(OpNum).getImm();
231
2.60k
  assert(Imm > 0 && Imm < 15 && "Invalid condition");
232
2.60k
  O << CondNames[Imm - 1];
233
2.60k
}