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