LLVM 22.0.0git
SystemZAsmPrinter.cpp
Go to the documentation of this file.
1//===-- SystemZAsmPrinter.cpp - SystemZ LLVM assembly printer -------------===//
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// Streams SystemZ assembly language and associated data, in the form of
10// MCInsts and MCExprs respectively.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SystemZAsmPrinter.h"
20#include "SystemZMCInstLower.h"
27#include "llvm/IR/Mangler.h"
28#include "llvm/IR/Module.h"
29#include "llvm/MC/MCExpr.h"
32#include "llvm/MC/MCStreamer.h"
34#include "llvm/Support/Chrono.h"
38
39using namespace llvm;
40
41// Return an RI instruction like MI with opcode Opcode, but with the
42// GR64 register operands turned into GR32s.
43static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode) {
44 if (MI->isCompare())
45 return MCInstBuilder(Opcode)
46 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
47 .addImm(MI->getOperand(1).getImm());
48 else
49 return MCInstBuilder(Opcode)
50 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
51 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(1).getReg()))
52 .addImm(MI->getOperand(2).getImm());
53}
54
55// Return an RI instruction like MI with opcode Opcode, but with the
56// GR64 register operands turned into GRH32s.
57static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode) {
58 if (MI->isCompare())
59 return MCInstBuilder(Opcode)
60 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
61 .addImm(MI->getOperand(1).getImm());
62 else
63 return MCInstBuilder(Opcode)
64 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
65 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(1).getReg()))
66 .addImm(MI->getOperand(2).getImm());
67}
68
69// Return an RI instruction like MI with opcode Opcode, but with the
70// R2 register turned into a GR64.
71static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode) {
72 return MCInstBuilder(Opcode)
73 .addReg(MI->getOperand(0).getReg())
74 .addReg(MI->getOperand(1).getReg())
75 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()))
76 .addImm(MI->getOperand(3).getImm())
77 .addImm(MI->getOperand(4).getImm())
78 .addImm(MI->getOperand(5).getImm());
79}
80
81static const MCSymbolRefExpr *getTLSGetOffset(MCContext &Context) {
82 StringRef Name = "__tls_get_offset";
83 return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
85}
86
88 StringRef Name = "_GLOBAL_OFFSET_TABLE_";
89 return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
90 Context);
91}
92
93// MI is an instruction that accepts an optional alignment hint,
94// and which was already lowered to LoweredMI. If the alignment
95// of the original memory operand is known, update LoweredMI to
96// an instruction with the corresponding hint set.
97static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI,
98 unsigned Opcode) {
99 if (MI->memoperands_empty())
100 return;
101
102 Align Alignment = Align(16);
103 for (MachineInstr::mmo_iterator MMOI = MI->memoperands_begin(),
104 EE = MI->memoperands_end(); MMOI != EE; ++MMOI)
105 if ((*MMOI)->getAlign() < Alignment)
106 Alignment = (*MMOI)->getAlign();
107
108 unsigned AlignmentHint = 0;
109 if (Alignment >= Align(16))
110 AlignmentHint = 4;
111 else if (Alignment >= Align(8))
112 AlignmentHint = 3;
113 if (AlignmentHint == 0)
114 return;
115
116 LoweredMI.setOpcode(Opcode);
117 LoweredMI.addOperand(MCOperand::createImm(AlignmentHint));
118}
119
120// MI loads the high part of a vector from memory. Return an instruction
121// that uses replicating vector load Opcode to do the same thing.
122static MCInst lowerSubvectorLoad(const MachineInstr *MI, unsigned Opcode) {
123 return MCInstBuilder(Opcode)
124 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
125 .addReg(MI->getOperand(1).getReg())
126 .addImm(MI->getOperand(2).getImm())
127 .addReg(MI->getOperand(3).getReg());
128}
129
130// MI stores the high part of a vector to memory. Return an instruction
131// that uses elemental vector store Opcode to do the same thing.
132static MCInst lowerSubvectorStore(const MachineInstr *MI, unsigned Opcode) {
133 return MCInstBuilder(Opcode)
134 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
135 .addReg(MI->getOperand(1).getReg())
136 .addImm(MI->getOperand(2).getImm())
137 .addReg(MI->getOperand(3).getReg())
138 .addImm(0);
139}
140
141// MI extracts the first element of the source vector.
142static MCInst lowerVecEltExtraction(const MachineInstr *MI, unsigned Opcode) {
143 return MCInstBuilder(Opcode)
144 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(0).getReg()))
145 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(1).getReg()))
146 .addReg(0)
147 .addImm(0);
148}
149
150// MI inserts value into the first element of the destination vector.
151static MCInst lowerVecEltInsertion(const MachineInstr *MI, unsigned Opcode) {
152 return MCInstBuilder(Opcode)
153 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
154 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
155 .addReg(MI->getOperand(1).getReg())
156 .addReg(0)
157 .addImm(0);
158}
159
160// The XPLINK ABI requires that a no-op encoding the call type is emitted after
161// each call to a subroutine. This information can be used by the called
162// function to determine its entry point, e.g. for generating a backtrace. The
163// call type is encoded as a register number in the bcr instruction. See
164// enumeration CallType for the possible values.
165void SystemZAsmPrinter::emitCallInformation(CallType CT) {
167 MCInstBuilder(SystemZ::BCRAsm)
168 .addImm(0)
169 .addReg(SystemZMC::GR64Regs[static_cast<unsigned>(CT)]));
170}
171
172uint32_t SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MCSymbol *Sym,
173 unsigned SlotKind) {
174 auto Key = std::make_pair(Sym, SlotKind);
175 auto It = Displacements.find(Key);
176
177 if (It != Displacements.end())
178 return (*It).second;
179
180 // Determine length of descriptor.
182 switch (SlotKind) {
184 Length = 2 * PointerSize;
185 break;
186 default:
188 break;
189 }
190
191 uint32_t Displacement = NextDisplacement;
192 Displacements[std::make_pair(Sym, SlotKind)] = NextDisplacement;
193 NextDisplacement += Length;
194
195 return Displacement;
196}
197
199SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MachineOperand MO) {
200 MCSymbol *Sym;
202 const GlobalValue *GV = MO.getGlobal();
203 Sym = MO.getParent()->getMF()->getTarget().getSymbol(GV);
204 assert(Sym && "No symbol");
205 } else if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
206 const char *SymName = MO.getSymbolName();
207 Sym = MO.getParent()->getMF()->getContext().getOrCreateSymbol(SymName);
208 assert(Sym && "No symbol");
209 } else
210 llvm_unreachable("Unexpected operand type");
211
212 unsigned ADAslotType = MO.getTargetFlags();
213 return insert(Sym, ADAslotType);
214}
215
217 SystemZ_MC::verifyInstructionPredicates(MI->getOpcode(),
218 getSubtargetInfo().getFeatureBits());
219
221 MCInst LoweredMI;
222 switch (MI->getOpcode()) {
223 case SystemZ::Return:
224 LoweredMI = MCInstBuilder(SystemZ::BR)
225 .addReg(SystemZ::R14D);
226 break;
227
228 case SystemZ::Return_XPLINK:
229 LoweredMI = MCInstBuilder(SystemZ::B)
230 .addReg(SystemZ::R7D)
231 .addImm(2)
232 .addReg(0);
233 break;
234
235 case SystemZ::CondReturn:
236 LoweredMI = MCInstBuilder(SystemZ::BCR)
237 .addImm(MI->getOperand(0).getImm())
238 .addImm(MI->getOperand(1).getImm())
239 .addReg(SystemZ::R14D);
240 break;
241
242 case SystemZ::CondReturn_XPLINK:
243 LoweredMI = MCInstBuilder(SystemZ::BC)
244 .addImm(MI->getOperand(0).getImm())
245 .addImm(MI->getOperand(1).getImm())
246 .addReg(SystemZ::R7D)
247 .addImm(2)
248 .addReg(0);
249 break;
250
251 case SystemZ::CRBReturn:
252 LoweredMI = MCInstBuilder(SystemZ::CRB)
253 .addReg(MI->getOperand(0).getReg())
254 .addReg(MI->getOperand(1).getReg())
255 .addImm(MI->getOperand(2).getImm())
256 .addReg(SystemZ::R14D)
257 .addImm(0);
258 break;
259
260 case SystemZ::CGRBReturn:
261 LoweredMI = MCInstBuilder(SystemZ::CGRB)
262 .addReg(MI->getOperand(0).getReg())
263 .addReg(MI->getOperand(1).getReg())
264 .addImm(MI->getOperand(2).getImm())
265 .addReg(SystemZ::R14D)
266 .addImm(0);
267 break;
268
269 case SystemZ::CIBReturn:
270 LoweredMI = MCInstBuilder(SystemZ::CIB)
271 .addReg(MI->getOperand(0).getReg())
272 .addImm(MI->getOperand(1).getImm())
273 .addImm(MI->getOperand(2).getImm())
274 .addReg(SystemZ::R14D)
275 .addImm(0);
276 break;
277
278 case SystemZ::CGIBReturn:
279 LoweredMI = MCInstBuilder(SystemZ::CGIB)
280 .addReg(MI->getOperand(0).getReg())
281 .addImm(MI->getOperand(1).getImm())
282 .addImm(MI->getOperand(2).getImm())
283 .addReg(SystemZ::R14D)
284 .addImm(0);
285 break;
286
287 case SystemZ::CLRBReturn:
288 LoweredMI = MCInstBuilder(SystemZ::CLRB)
289 .addReg(MI->getOperand(0).getReg())
290 .addReg(MI->getOperand(1).getReg())
291 .addImm(MI->getOperand(2).getImm())
292 .addReg(SystemZ::R14D)
293 .addImm(0);
294 break;
295
296 case SystemZ::CLGRBReturn:
297 LoweredMI = MCInstBuilder(SystemZ::CLGRB)
298 .addReg(MI->getOperand(0).getReg())
299 .addReg(MI->getOperand(1).getReg())
300 .addImm(MI->getOperand(2).getImm())
301 .addReg(SystemZ::R14D)
302 .addImm(0);
303 break;
304
305 case SystemZ::CLIBReturn:
306 LoweredMI = MCInstBuilder(SystemZ::CLIB)
307 .addReg(MI->getOperand(0).getReg())
308 .addImm(MI->getOperand(1).getImm())
309 .addImm(MI->getOperand(2).getImm())
310 .addReg(SystemZ::R14D)
311 .addImm(0);
312 break;
313
314 case SystemZ::CLGIBReturn:
315 LoweredMI = MCInstBuilder(SystemZ::CLGIB)
316 .addReg(MI->getOperand(0).getReg())
317 .addImm(MI->getOperand(1).getImm())
318 .addImm(MI->getOperand(2).getImm())
319 .addReg(SystemZ::R14D)
320 .addImm(0);
321 break;
322
323 case SystemZ::CallBRASL_XPLINK64:
325 .addReg(SystemZ::R7D)
326 .addExpr(Lower.getExpr(MI->getOperand(0),
328 emitCallInformation(CallType::BRASL7);
329 return;
330
331 case SystemZ::CallBASR_XPLINK64:
333 .addReg(SystemZ::R7D)
334 .addReg(MI->getOperand(0).getReg()));
335 emitCallInformation(CallType::BASR76);
336 return;
337
338 case SystemZ::CallBASR_STACKEXT:
340 .addReg(SystemZ::R3D)
341 .addReg(MI->getOperand(0).getReg()));
342 emitCallInformation(CallType::BASR33);
343 return;
344
345 case SystemZ::ADA_ENTRY_VALUE:
346 case SystemZ::ADA_ENTRY: {
347 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
348 const SystemZInstrInfo *TII = Subtarget.getInstrInfo();
349 uint32_t Disp = ADATable.insert(MI->getOperand(1));
350 Register TargetReg = MI->getOperand(0).getReg();
351
352 Register ADAReg = MI->getOperand(2).getReg();
353 Disp += MI->getOperand(3).getImm();
354 bool LoadAddr = MI->getOpcode() == SystemZ::ADA_ENTRY;
355
356 unsigned Op0 = LoadAddr ? SystemZ::LA : SystemZ::LG;
357 unsigned Op = TII->getOpcodeForOffset(Op0, Disp);
358
359 Register IndexReg = 0;
360 if (!Op) {
361 if (TargetReg != ADAReg) {
362 IndexReg = TargetReg;
363 // Use TargetReg to store displacement.
366 MCInstBuilder(SystemZ::LLILF).addReg(TargetReg).addImm(Disp));
367 } else
369 .addReg(TargetReg)
370 .addReg(TargetReg)
371 .addImm(Disp));
372 Disp = 0;
373 Op = Op0;
374 }
376 .addReg(TargetReg)
377 .addReg(ADAReg)
378 .addImm(Disp)
379 .addReg(IndexReg));
380
381 return;
382 }
383 case SystemZ::CallBRASL:
384 LoweredMI = MCInstBuilder(SystemZ::BRASL)
385 .addReg(SystemZ::R14D)
386 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_PLT));
387 break;
388
389 case SystemZ::CallBASR:
390 LoweredMI = MCInstBuilder(SystemZ::BASR)
391 .addReg(SystemZ::R14D)
392 .addReg(MI->getOperand(0).getReg());
393 break;
394
395 case SystemZ::CallJG:
396 LoweredMI = MCInstBuilder(SystemZ::JG)
397 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_PLT));
398 break;
399
400 case SystemZ::CallBRCL:
401 LoweredMI = MCInstBuilder(SystemZ::BRCL)
402 .addImm(MI->getOperand(0).getImm())
403 .addImm(MI->getOperand(1).getImm())
404 .addExpr(Lower.getExpr(MI->getOperand(2), SystemZ::S_PLT));
405 break;
406
407 case SystemZ::CallBR:
408 LoweredMI = MCInstBuilder(SystemZ::BR)
409 .addReg(MI->getOperand(0).getReg());
410 break;
411
412 case SystemZ::CallBCR:
413 LoweredMI = MCInstBuilder(SystemZ::BCR)
414 .addImm(MI->getOperand(0).getImm())
415 .addImm(MI->getOperand(1).getImm())
416 .addReg(MI->getOperand(2).getReg());
417 break;
418
419 case SystemZ::CRBCall:
420 LoweredMI = MCInstBuilder(SystemZ::CRB)
421 .addReg(MI->getOperand(0).getReg())
422 .addReg(MI->getOperand(1).getReg())
423 .addImm(MI->getOperand(2).getImm())
424 .addReg(MI->getOperand(3).getReg())
425 .addImm(0);
426 break;
427
428 case SystemZ::CGRBCall:
429 LoweredMI = MCInstBuilder(SystemZ::CGRB)
430 .addReg(MI->getOperand(0).getReg())
431 .addReg(MI->getOperand(1).getReg())
432 .addImm(MI->getOperand(2).getImm())
433 .addReg(MI->getOperand(3).getReg())
434 .addImm(0);
435 break;
436
437 case SystemZ::CIBCall:
438 LoweredMI = MCInstBuilder(SystemZ::CIB)
439 .addReg(MI->getOperand(0).getReg())
440 .addImm(MI->getOperand(1).getImm())
441 .addImm(MI->getOperand(2).getImm())
442 .addReg(MI->getOperand(3).getReg())
443 .addImm(0);
444 break;
445
446 case SystemZ::CGIBCall:
447 LoweredMI = MCInstBuilder(SystemZ::CGIB)
448 .addReg(MI->getOperand(0).getReg())
449 .addImm(MI->getOperand(1).getImm())
450 .addImm(MI->getOperand(2).getImm())
451 .addReg(MI->getOperand(3).getReg())
452 .addImm(0);
453 break;
454
455 case SystemZ::CLRBCall:
456 LoweredMI = MCInstBuilder(SystemZ::CLRB)
457 .addReg(MI->getOperand(0).getReg())
458 .addReg(MI->getOperand(1).getReg())
459 .addImm(MI->getOperand(2).getImm())
460 .addReg(MI->getOperand(3).getReg())
461 .addImm(0);
462 break;
463
464 case SystemZ::CLGRBCall:
465 LoweredMI = MCInstBuilder(SystemZ::CLGRB)
466 .addReg(MI->getOperand(0).getReg())
467 .addReg(MI->getOperand(1).getReg())
468 .addImm(MI->getOperand(2).getImm())
469 .addReg(MI->getOperand(3).getReg())
470 .addImm(0);
471 break;
472
473 case SystemZ::CLIBCall:
474 LoweredMI = MCInstBuilder(SystemZ::CLIB)
475 .addReg(MI->getOperand(0).getReg())
476 .addImm(MI->getOperand(1).getImm())
477 .addImm(MI->getOperand(2).getImm())
478 .addReg(MI->getOperand(3).getReg())
479 .addImm(0);
480 break;
481
482 case SystemZ::CLGIBCall:
483 LoweredMI = MCInstBuilder(SystemZ::CLGIB)
484 .addReg(MI->getOperand(0).getReg())
485 .addImm(MI->getOperand(1).getImm())
486 .addImm(MI->getOperand(2).getImm())
487 .addReg(MI->getOperand(3).getReg())
488 .addImm(0);
489 break;
490
491 case SystemZ::TLS_GDCALL:
492 LoweredMI =
493 MCInstBuilder(SystemZ::BRASL)
494 .addReg(SystemZ::R14D)
496 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_TLSGD));
497 break;
498
499 case SystemZ::TLS_LDCALL:
500 LoweredMI =
501 MCInstBuilder(SystemZ::BRASL)
502 .addReg(SystemZ::R14D)
504 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_TLSLDM));
505 break;
506
507 case SystemZ::GOT:
508 LoweredMI = MCInstBuilder(SystemZ::LARL)
509 .addReg(MI->getOperand(0).getReg())
511 break;
512
513 case SystemZ::IILF64:
514 LoweredMI = MCInstBuilder(SystemZ::IILF)
515 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
516 .addImm(MI->getOperand(2).getImm());
517 break;
518
519 case SystemZ::IIHF64:
520 LoweredMI = MCInstBuilder(SystemZ::IIHF)
521 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
522 .addImm(MI->getOperand(2).getImm());
523 break;
524
525 case SystemZ::RISBHH:
526 case SystemZ::RISBHL:
527 LoweredMI = lowerRIEfLow(MI, SystemZ::RISBHG);
528 break;
529
530 case SystemZ::RISBLH:
531 case SystemZ::RISBLL:
532 LoweredMI = lowerRIEfLow(MI, SystemZ::RISBLG);
533 break;
534
535 case SystemZ::VLVGP32:
536 LoweredMI = MCInstBuilder(SystemZ::VLVGP)
537 .addReg(MI->getOperand(0).getReg())
538 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(1).getReg()))
539 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()));
540 break;
541
542 case SystemZ::VLR32:
543 case SystemZ::VLR64:
544 LoweredMI = MCInstBuilder(SystemZ::VLR)
545 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
546 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(1).getReg()));
547 break;
548
549 case SystemZ::VL:
550 Lower.lower(MI, LoweredMI);
551 lowerAlignmentHint(MI, LoweredMI, SystemZ::VLAlign);
552 break;
553
554 case SystemZ::VST:
555 Lower.lower(MI, LoweredMI);
556 lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTAlign);
557 break;
558
559 case SystemZ::VLM:
560 Lower.lower(MI, LoweredMI);
561 lowerAlignmentHint(MI, LoweredMI, SystemZ::VLMAlign);
562 break;
563
564 case SystemZ::VSTM:
565 Lower.lower(MI, LoweredMI);
566 lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTMAlign);
567 break;
568
569 case SystemZ::VL16:
570 LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPH);
571 break;
572
573 case SystemZ::VL32:
574 LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPF);
575 break;
576
577 case SystemZ::VL64:
578 LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPG);
579 break;
580
581 case SystemZ::VST16:
582 LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEH);
583 break;
584
585 case SystemZ::VST32:
586 LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEF);
587 break;
588
589 case SystemZ::VST64:
590 LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEG);
591 break;
592
593 case SystemZ::LFER:
594 LoweredMI = lowerVecEltExtraction(MI, SystemZ::VLGVF);
595 break;
596
597 case SystemZ::LFER_16:
598 LoweredMI = lowerVecEltExtraction(MI, SystemZ::VLGVH);
599 break;
600
601 case SystemZ::LEFR:
602 LoweredMI = lowerVecEltInsertion(MI, SystemZ::VLVGF);
603 break;
604
605 case SystemZ::LEFR_16:
606 LoweredMI = lowerVecEltInsertion(MI, SystemZ::VLVGH);
607 break;
608
609#define LOWER_LOW(NAME) \
610 case SystemZ::NAME##64: LoweredMI = lowerRILow(MI, SystemZ::NAME); break
611
612 LOWER_LOW(IILL);
613 LOWER_LOW(IILH);
614 LOWER_LOW(TMLL);
615 LOWER_LOW(TMLH);
616 LOWER_LOW(NILL);
617 LOWER_LOW(NILH);
618 LOWER_LOW(NILF);
619 LOWER_LOW(OILL);
620 LOWER_LOW(OILH);
621 LOWER_LOW(OILF);
622 LOWER_LOW(XILF);
623
624#undef LOWER_LOW
625
626#define LOWER_HIGH(NAME) \
627 case SystemZ::NAME##64: LoweredMI = lowerRIHigh(MI, SystemZ::NAME); break
628
629 LOWER_HIGH(IIHL);
630 LOWER_HIGH(IIHH);
631 LOWER_HIGH(TMHL);
632 LOWER_HIGH(TMHH);
633 LOWER_HIGH(NIHL);
634 LOWER_HIGH(NIHH);
635 LOWER_HIGH(NIHF);
636 LOWER_HIGH(OIHL);
637 LOWER_HIGH(OIHH);
638 LOWER_HIGH(OIHF);
639 LOWER_HIGH(XIHF);
640
641#undef LOWER_HIGH
642
643 case SystemZ::Serialize:
644 if (MF->getSubtarget<SystemZSubtarget>().hasFastSerialization())
645 LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
646 .addImm(14).addReg(SystemZ::R0D);
647 else
648 LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
649 .addImm(15).addReg(SystemZ::R0D);
650 break;
651
652 // We want to emit "j .+2" for traps, jumping to the relative immediate field
653 // of the jump instruction, which is an illegal instruction. We cannot emit a
654 // "." symbol, so create and emit a temp label before the instruction and use
655 // that instead.
656 case SystemZ::Trap: {
658 OutStreamer->emitLabel(DotSym);
659
661 const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
662 LoweredMI = MCInstBuilder(SystemZ::J)
663 .addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
664 }
665 break;
666
667 // Conditional traps will create a branch on condition instruction that jumps
668 // to the relative immediate field of the jump instruction. (eg. "jo .+2")
669 case SystemZ::CondTrap: {
671 OutStreamer->emitLabel(DotSym);
672
674 const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
675 LoweredMI = MCInstBuilder(SystemZ::BRC)
676 .addImm(MI->getOperand(0).getImm())
677 .addImm(MI->getOperand(1).getImm())
678 .addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
679 }
680 break;
681
682 case TargetOpcode::FENTRY_CALL:
683 LowerFENTRY_CALL(*MI, Lower);
684 return;
685
686 case TargetOpcode::STACKMAP:
687 LowerSTACKMAP(*MI);
688 return;
689
690 case TargetOpcode::PATCHPOINT:
691 LowerPATCHPOINT(*MI, Lower);
692 return;
693
694 case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
695 LowerPATCHABLE_FUNCTION_ENTER(*MI, Lower);
696 return;
697
698 case TargetOpcode::PATCHABLE_RET:
699 LowerPATCHABLE_RET(*MI, Lower);
700 return;
701
702 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
703 llvm_unreachable("PATCHABLE_FUNCTION_EXIT should never be emitted");
704
705 case TargetOpcode::PATCHABLE_TAIL_CALL:
706 // TODO: Define a trampoline `__xray_FunctionTailExit` and differentiate a
707 // normal function exit from a tail exit.
708 llvm_unreachable("Tail call is handled in the normal case. See comments "
709 "around this assert.");
710
711 case SystemZ::EXRL_Pseudo: {
712 unsigned TargetInsOpc = MI->getOperand(0).getImm();
713 Register LenMinus1Reg = MI->getOperand(1).getReg();
714 Register DestReg = MI->getOperand(2).getReg();
715 int64_t DestDisp = MI->getOperand(3).getImm();
716 Register SrcReg = MI->getOperand(4).getReg();
717 int64_t SrcDisp = MI->getOperand(5).getImm();
718
719 SystemZTargetStreamer *TS = getTargetStreamer();
720 MCInst ET = MCInstBuilder(TargetInsOpc)
721 .addReg(DestReg)
722 .addImm(DestDisp)
723 .addImm(1)
724 .addReg(SrcReg)
725 .addImm(SrcDisp);
727 auto [It, Inserted] = TS->EXRLTargets2Sym.try_emplace(ET_STI);
728 if (Inserted)
729 It->second = OutContext.createTempSymbol();
730 MCSymbol *DotSym = It->second;
734 MCInstBuilder(SystemZ::EXRL).addReg(LenMinus1Reg).addExpr(Dot));
735 return;
736 }
737
738 // EH_SjLj_Setup is a dummy terminator instruction of size 0.
739 // It is used to handle the clobber register for builtin setjmp.
740 case SystemZ::EH_SjLj_Setup:
741 return;
742
743 default:
744 Lower.lower(MI, LoweredMI);
745 break;
746 }
747 EmitToStreamer(*OutStreamer, LoweredMI);
748}
749
750// Emit the largest nop instruction smaller than or equal to NumBytes
751// bytes. Return the size of nop emitted.
752static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer,
753 unsigned NumBytes, const MCSubtargetInfo &STI) {
754 if (NumBytes < 2) {
755 llvm_unreachable("Zero nops?");
756 return 0;
757 }
758 else if (NumBytes < 4) {
759 OutStreamer.emitInstruction(
760 MCInstBuilder(SystemZ::BCRAsm).addImm(0).addReg(SystemZ::R0D), STI);
761 return 2;
762 }
763 else if (NumBytes < 6) {
764 OutStreamer.emitInstruction(
765 MCInstBuilder(SystemZ::BCAsm).addImm(0).addReg(0).addImm(0).addReg(0),
766 STI);
767 return 4;
768 }
769 else {
770 MCSymbol *DotSym = OutContext.createTempSymbol();
771 const MCSymbolRefExpr *Dot = MCSymbolRefExpr::create(DotSym, OutContext);
772 OutStreamer.emitLabel(DotSym);
773 OutStreamer.emitInstruction(
774 MCInstBuilder(SystemZ::BRCLAsm).addImm(0).addExpr(Dot), STI);
775 return 6;
776 }
777}
778
779void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
781 MCContext &Ctx = MF->getContext();
782 if (MF->getFunction().hasFnAttribute("mrecord-mcount")) {
784 OutStreamer->pushSection();
785 OutStreamer->switchSection(
786 Ctx.getELFSection("__mcount_loc", ELF::SHT_PROGBITS, ELF::SHF_ALLOC));
787 OutStreamer->emitSymbolValue(DotSym, 8);
788 OutStreamer->popSection();
789 OutStreamer->emitLabel(DotSym);
790 }
791
792 if (MF->getFunction().hasFnAttribute("mnop-mcount")) {
794 return;
795 }
796
797 MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
798 const MCSymbolRefExpr *Op =
800 OutStreamer->emitInstruction(
801 MCInstBuilder(SystemZ::BRASL).addReg(SystemZ::R0D).addExpr(Op),
803}
804
805void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
806 auto *TII = MF->getSubtarget<SystemZSubtarget>().getInstrInfo();
807
808 unsigned NumNOPBytes = MI.getOperand(1).getImm();
809
810 auto &Ctx = OutStreamer->getContext();
811 MCSymbol *MILabel = Ctx.createTempSymbol();
812 OutStreamer->emitLabel(MILabel);
813
814 SM.recordStackMap(*MILabel, MI);
815 assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!");
816
817 // Scan ahead to trim the shadow.
818 unsigned ShadowBytes = 0;
819 const MachineBasicBlock &MBB = *MI.getParent();
821 ++MII;
822 while (ShadowBytes < NumNOPBytes) {
823 if (MII == MBB.end() ||
824 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
825 MII->getOpcode() == TargetOpcode::STACKMAP)
826 break;
827 ShadowBytes += TII->getInstSizeInBytes(*MII);
828 if (MII->isCall())
829 break;
830 ++MII;
831 }
832
833 // Emit nops.
834 while (ShadowBytes < NumNOPBytes)
835 ShadowBytes += EmitNop(OutContext, *OutStreamer, NumNOPBytes - ShadowBytes,
837}
838
839// Lower a patchpoint of the form:
840// [<def>], <id>, <numBytes>, <target>, <numArgs>
841void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
843 auto &Ctx = OutStreamer->getContext();
844 MCSymbol *MILabel = Ctx.createTempSymbol();
845 OutStreamer->emitLabel(MILabel);
846
847 SM.recordPatchPoint(*MILabel, MI);
848 PatchPointOpers Opers(&MI);
849
850 unsigned EncodedBytes = 0;
851 const MachineOperand &CalleeMO = Opers.getCallTarget();
852
853 if (CalleeMO.isImm()) {
854 uint64_t CallTarget = CalleeMO.getImm();
855 if (CallTarget) {
856 unsigned ScratchIdx = -1;
857 unsigned ScratchReg = 0;
858 do {
859 ScratchIdx = Opers.getNextScratchIdx(ScratchIdx + 1);
860 ScratchReg = MI.getOperand(ScratchIdx).getReg();
861 } while (ScratchReg == SystemZ::R0D);
862
863 // Materialize the call target address
865 .addReg(ScratchReg)
866 .addImm(CallTarget & 0xFFFFFFFF));
867 EncodedBytes += 6;
868 if (CallTarget >> 32) {
870 .addReg(ScratchReg)
871 .addImm(CallTarget >> 32));
872 EncodedBytes += 6;
873 }
874
876 .addReg(SystemZ::R14D)
877 .addReg(ScratchReg));
878 EncodedBytes += 2;
879 }
880 } else if (CalleeMO.isGlobal()) {
881 const MCExpr *Expr = Lower.getExpr(CalleeMO, SystemZ::S_PLT);
883 .addReg(SystemZ::R14D)
884 .addExpr(Expr));
885 EncodedBytes += 6;
886 }
887
888 // Emit padding.
889 unsigned NumBytes = Opers.getNumPatchBytes();
890 assert(NumBytes >= EncodedBytes &&
891 "Patchpoint can't request size less than the length of a call.");
892 assert((NumBytes - EncodedBytes) % 2 == 0 &&
893 "Invalid number of NOP bytes requested!");
894 while (EncodedBytes < NumBytes)
895 EncodedBytes += EmitNop(OutContext, *OutStreamer, NumBytes - EncodedBytes,
897}
898
899void SystemZAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(
901 // .begin:
902 // j .end # -> stmg %r2, %r15, 16(%r15)
903 // nop
904 // llilf %2, FuncID
905 // brasl %r14, __xray_FunctionEntry@GOT
906 // .end:
907 //
908 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
909 // of instructions change.
910 bool HasVectorFeature =
911 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector) &&
912 !TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureSoftFloat);
914 HasVectorFeature ? "__xray_FunctionEntryVec" : "__xray_FunctionEntry");
915 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
916 MCSymbol *EndOfSled = OutContext.createTempSymbol();
917 OutStreamer->emitLabel(BeginOfSled);
919 MCInstBuilder(SystemZ::J)
920 .addExpr(MCSymbolRefExpr::create(EndOfSled, OutContext)));
923 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
925 .addReg(SystemZ::R14D)
927 FuncEntry, SystemZ::S_PLT, OutContext)));
928 OutStreamer->emitLabel(EndOfSled);
929 recordSled(BeginOfSled, MI, SledKind::FUNCTION_ENTER, 2);
930}
931
932void SystemZAsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI,
934 unsigned OpCode = MI.getOperand(0).getImm();
935 MCSymbol *FallthroughLabel = nullptr;
936 if (OpCode == SystemZ::CondReturn) {
937 FallthroughLabel = OutContext.createTempSymbol();
938 int64_t Cond0 = MI.getOperand(1).getImm();
939 int64_t Cond1 = MI.getOperand(2).getImm();
941 .addImm(Cond0)
942 .addImm(Cond1 ^ Cond0)
944 FallthroughLabel, OutContext)));
945 }
946 // .begin:
947 // br %r14 # -> stmg %r2, %r15, 24(%r15)
948 // nop
949 // nop
950 // llilf %2,FuncID
951 // j __xray_FunctionExit@GOT
952 //
953 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
954 // of instructions change.
955 bool HasVectorFeature =
956 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector) &&
957 !TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureSoftFloat);
959 HasVectorFeature ? "__xray_FunctionExitVec" : "__xray_FunctionExit");
960 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
961 OutStreamer->emitLabel(BeginOfSled);
963 MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D));
966 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
969 FuncExit, SystemZ::S_PLT, OutContext)));
970 if (FallthroughLabel)
971 OutStreamer->emitLabel(FallthroughLabel);
972 recordSled(BeginOfSled, MI, SledKind::FUNCTION_EXIT, 2);
973}
974
975// The *alignment* of 128-bit vector types is different between the software
976// and hardware vector ABIs. If the there is an externally visible use of a
977// vector type in the module it should be annotated with an attribute.
978void SystemZAsmPrinter::emitAttributes(Module &M) {
979 if (M.getModuleFlag("s390x-visible-vector-ABI")) {
980 bool HasVectorFeature =
981 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector);
982 OutStreamer->emitGNUAttribute(8, HasVectorFeature ? 2 : 1);
983 }
984}
985
986// Convert a SystemZ-specific constant pool modifier into the associated
987// specifier.
989 switch (Modifier) {
990 case SystemZCP::TLSGD:
991 return SystemZ::S_TLSGD;
993 return SystemZ::S_TLSLDM;
995 return SystemZ::S_DTPOFF;
997 return SystemZ::S_NTPOFF;
998 }
999 llvm_unreachable("Invalid SystemCPModifier!");
1000}
1001
1004 auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
1005
1006 const MCExpr *Expr = MCSymbolRefExpr::create(
1007 getSymbol(ZCPV->getGlobalValue()),
1008 getSpecifierFromModifier(ZCPV->getModifier()), OutContext);
1009 uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
1010
1011 OutStreamer->emitValue(Expr, Size);
1012}
1013
1014static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
1015 raw_ostream &OS) {
1016 const char *RegName;
1017 if (MAI->getAssemblerDialect() == AD_HLASM) {
1019 // Skip register prefix so that only register number is left
1020 assert(isalpha(RegName[0]) && isdigit(RegName[1]));
1021 OS << (RegName + 1);
1022 } else {
1024 OS << '%' << RegName;
1025 }
1026}
1027
1028static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {
1029 if (!Reg)
1030 OS << '0';
1031 else
1032 printFormattedRegName(MAI, Reg, OS);
1033}
1034
1035static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
1036 raw_ostream &OS) {
1037 if (MCOp.isReg())
1038 printReg(MCOp.getReg(), MAI, OS);
1039 else if (MCOp.isImm())
1040 OS << MCOp.getImm();
1041 else if (MCOp.isExpr())
1042 MAI->printExpr(OS, *MCOp.getExpr());
1043 else
1044 llvm_unreachable("Invalid operand");
1045}
1046
1047static void printAddress(const MCAsmInfo *MAI, unsigned Base,
1048 const MCOperand &DispMO, unsigned Index,
1049 raw_ostream &OS) {
1050 printOperand(DispMO, MAI, OS);
1051 if (Base || Index) {
1052 OS << '(';
1053 if (Index) {
1054 printFormattedRegName(MAI, Index, OS);
1055 if (Base)
1056 OS << ',';
1057 }
1058 if (Base)
1060 OS << ')';
1061 }
1062}
1063
1065 const char *ExtraCode,
1066 raw_ostream &OS) {
1068 const MachineOperand &MO = MI->getOperand(OpNo);
1069 MCOperand MCOp;
1070 if (ExtraCode) {
1071 if (ExtraCode[0] == 'N' && !ExtraCode[1] && MO.isReg() &&
1072 SystemZ::GR128BitRegClass.contains(MO.getReg()))
1073 MCOp =
1074 MCOperand::createReg(MRI.getSubReg(MO.getReg(), SystemZ::subreg_l64));
1075 else
1076 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
1077 } else {
1079 MCOp = Lower.lowerOperand(MO);
1080 }
1081 printOperand(MCOp, MAI, OS);
1082 return false;
1083}
1084
1086 unsigned OpNo,
1087 const char *ExtraCode,
1088 raw_ostream &OS) {
1089 if (ExtraCode && ExtraCode[0] && !ExtraCode[1]) {
1090 switch (ExtraCode[0]) {
1091 case 'A':
1092 // Unlike EmitMachineNode(), EmitSpecialNode(INLINEASM) does not call
1093 // setMemRefs(), so MI->memoperands() is empty and the alignment
1094 // information is not available.
1095 return false;
1096 case 'O':
1097 OS << MI->getOperand(OpNo + 1).getImm();
1098 return false;
1099 case 'R':
1100 ::printReg(MI->getOperand(OpNo).getReg(), MAI, OS);
1101 return false;
1102 }
1103 }
1104 printAddress(MAI, MI->getOperand(OpNo).getReg(),
1105 MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
1106 MI->getOperand(OpNo + 2).getReg(), OS);
1107 return false;
1108}
1109
1111 auto TT = OutContext.getTargetTriple();
1112 if (TT.isOSzOS()) {
1113 emitADASection();
1114 emitIDRLSection(M);
1115 }
1116 emitAttributes(M);
1117 // Emit the END instruction in case of HLASM output. This must be the last
1118 // instruction in the source file.
1119 getTargetStreamer()->emitEnd();
1120}
1121
1122void SystemZAsmPrinter::emitADASection() {
1123 OutStreamer->pushSection();
1124
1125 const unsigned PointerSize = getDataLayout().getPointerSize();
1126 OutStreamer->switchSection(getObjFileLowering().getADASection());
1127
1128 unsigned EmittedBytes = 0;
1129 for (auto &Entry : ADATable.getTable()) {
1130 const MCSymbol *Sym;
1131 unsigned SlotKind;
1132 std::tie(Sym, SlotKind) = Entry.first;
1133 unsigned Offset = Entry.second;
1134 assert(Offset == EmittedBytes && "Offset not as expected");
1135 (void)EmittedBytes;
1136#define EMIT_COMMENT(Str) \
1137 OutStreamer->AddComment(Twine("Offset ") \
1138 .concat(utostr(Offset)) \
1139 .concat(" " Str " ") \
1140 .concat(Sym->getName()));
1141 switch (SlotKind) {
1143 // Language Environment DLL logic requires function descriptors, for
1144 // imported functions, that are placed in the ADA to be 8 byte aligned.
1145 EMIT_COMMENT("function descriptor of");
1146 OutStreamer->emitValue(
1149 PointerSize);
1150 OutStreamer->emitValue(
1153 PointerSize);
1154 EmittedBytes += PointerSize * 2;
1155 break;
1157 EMIT_COMMENT("pointer to data symbol");
1158 OutStreamer->emitValue(
1161 PointerSize);
1162 EmittedBytes += PointerSize;
1163 break;
1166 Twine(Sym->getName()).concat("@indirect"));
1167 OutStreamer->emitAssignment(Alias,
1169 OutStreamer->emitSymbolAttribute(Alias, MCSA_IndirectSymbol);
1170
1171 EMIT_COMMENT("pointer to function descriptor");
1172 OutStreamer->emitValue(
1175 PointerSize);
1176 EmittedBytes += PointerSize;
1177 break;
1178 }
1179 default:
1180 llvm_unreachable("Unexpected slot kind");
1181 }
1182#undef EMIT_COMMENT
1183 }
1184 OutStreamer->popSection();
1185}
1186
1187static std::string getProductID(Module &M) {
1188 std::string ProductID;
1189 if (auto *MD = M.getModuleFlag("zos_product_id"))
1190 ProductID = cast<MDString>(MD)->getString().str();
1191 if (ProductID.empty())
1192 ProductID = "LLVM";
1193 return ProductID;
1194}
1195
1197 if (auto *VersionVal = mdconst::extract_or_null<ConstantInt>(
1198 M.getModuleFlag("zos_product_major_version")))
1199 return VersionVal->getZExtValue();
1200 return LLVM_VERSION_MAJOR;
1201}
1202
1204 if (auto *ReleaseVal = mdconst::extract_or_null<ConstantInt>(
1205 M.getModuleFlag("zos_product_minor_version")))
1206 return ReleaseVal->getZExtValue();
1207 return LLVM_VERSION_MINOR;
1208}
1209
1211 if (auto *PatchVal = mdconst::extract_or_null<ConstantInt>(
1212 M.getModuleFlag("zos_product_patchlevel")))
1213 return PatchVal->getZExtValue();
1214 return LLVM_VERSION_PATCH;
1215}
1216
1217static time_t getTranslationTime(Module &M) {
1218 std::time_t Time = 0;
1219 if (auto *Val = mdconst::extract_or_null<ConstantInt>(
1220 M.getModuleFlag("zos_translation_time"))) {
1221 long SecondsSinceEpoch = Val->getSExtValue();
1222 Time = static_cast<time_t>(SecondsSinceEpoch);
1223 }
1224 return Time;
1225}
1226
1227void SystemZAsmPrinter::emitIDRLSection(Module &M) {
1228 OutStreamer->pushSection();
1229 OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
1230 constexpr unsigned IDRLDataLength = 30;
1231 std::time_t Time = getTranslationTime(M);
1232
1233 uint32_t ProductVersion = getProductVersion(M);
1234 uint32_t ProductRelease = getProductRelease(M);
1235
1236 std::string ProductID = getProductID(M);
1237
1239 raw_svector_ostream O(TempStr);
1240 O << formatv("{0,-10}{1,0-2:d}{2,0-2:d}{3:%Y%m%d%H%M%S}{4,0-2}",
1241 ProductID.substr(0, 10).c_str(), ProductVersion, ProductRelease,
1242 llvm::sys::toUtcTime(Time), "0");
1245
1246 OutStreamer->emitInt8(0); // Reserved.
1247 OutStreamer->emitInt8(3); // Format.
1248 OutStreamer->emitInt16(IDRLDataLength); // Length.
1249 OutStreamer->emitBytes(Data.str());
1250 OutStreamer->popSection();
1251}
1252
1254 if (TM.getTargetTriple().isOSzOS()) {
1255 // Emit symbol for the end of function if the z/OS target streamer
1256 // is used. This is needed to calculate the size of the function.
1257 MCSymbol *FnEndSym = createTempSymbol("func_end");
1258 OutStreamer->emitLabel(FnEndSym);
1259
1260 OutStreamer->pushSection();
1261 OutStreamer->switchSection(getObjFileLowering().getTextSection(),
1263 emitPPA1(FnEndSym);
1264 OutStreamer->popSection();
1265
1266 CurrentFnPPA1Sym = nullptr;
1267 CurrentFnEPMarkerSym = nullptr;
1268 }
1269}
1270
1271static void emitPPA1Flags(std::unique_ptr<MCStreamer> &OutStreamer, bool VarArg,
1272 bool StackProtector, bool FPRMask, bool VRMask,
1273 bool EHBlock, bool HasName) {
1274 enum class PPA1Flag1 : uint8_t {
1275 DSA64Bit = (0x80 >> 0),
1276 VarArg = (0x80 >> 7),
1278 };
1279 enum class PPA1Flag2 : uint8_t {
1280 ExternalProcedure = (0x80 >> 0),
1281 STACKPROTECTOR = (0x80 >> 3),
1282 LLVM_MARK_AS_BITMASK_ENUM(ExternalProcedure)
1283 };
1284 enum class PPA1Flag3 : uint8_t {
1285 FPRMask = (0x80 >> 2),
1287 };
1288 enum class PPA1Flag4 : uint8_t {
1289 EPMOffsetPresent = (0x80 >> 0),
1290 VRMask = (0x80 >> 2),
1291 EHBlock = (0x80 >> 3),
1292 ProcedureNamePresent = (0x80 >> 7),
1293 LLVM_MARK_AS_BITMASK_ENUM(EPMOffsetPresent)
1294 };
1295
1296 // Declare optional section flags that can be modified.
1297 auto Flags1 = PPA1Flag1(0);
1298 auto Flags2 = PPA1Flag2::ExternalProcedure;
1299 auto Flags3 = PPA1Flag3(0);
1300 auto Flags4 = PPA1Flag4::EPMOffsetPresent;
1301
1302 Flags1 |= PPA1Flag1::DSA64Bit;
1303
1304 if (VarArg)
1305 Flags1 |= PPA1Flag1::VarArg;
1306
1307 if (StackProtector)
1308 Flags2 |= PPA1Flag2::STACKPROTECTOR;
1309
1310 // SavedGPRMask, SavedFPRMask, and SavedVRMask are precomputed in.
1311 if (FPRMask)
1312 Flags3 |= PPA1Flag3::FPRMask; // Add emit FPR mask flag.
1313
1314 if (VRMask)
1315 Flags4 |= PPA1Flag4::VRMask; // Add emit VR mask flag.
1316
1317 if (EHBlock)
1318 Flags4 |= PPA1Flag4::EHBlock; // Add optional EH block.
1319
1320 if (HasName)
1321 Flags4 |= PPA1Flag4::ProcedureNamePresent; // Add optional name block.
1322
1323 OutStreamer->AddComment("PPA1 Flags 1");
1324 if ((Flags1 & PPA1Flag1::DSA64Bit) == PPA1Flag1::DSA64Bit)
1325 OutStreamer->AddComment(" Bit 0: 1 = 64-bit DSA");
1326 else
1327 OutStreamer->AddComment(" Bit 0: 0 = 32-bit DSA");
1328 if ((Flags1 & PPA1Flag1::VarArg) == PPA1Flag1::VarArg)
1329 OutStreamer->AddComment(" Bit 7: 1 = Vararg function");
1330 OutStreamer->emitInt8(static_cast<uint8_t>(Flags1)); // Flags 1.
1331
1332 OutStreamer->AddComment("PPA1 Flags 2");
1333 if ((Flags2 & PPA1Flag2::ExternalProcedure) == PPA1Flag2::ExternalProcedure)
1334 OutStreamer->AddComment(" Bit 0: 1 = External procedure");
1335 if ((Flags2 & PPA1Flag2::STACKPROTECTOR) == PPA1Flag2::STACKPROTECTOR)
1336 OutStreamer->AddComment(" Bit 3: 1 = STACKPROTECT is enabled");
1337 else
1338 OutStreamer->AddComment(" Bit 3: 0 = STACKPROTECT is not enabled");
1339 OutStreamer->emitInt8(static_cast<uint8_t>(Flags2)); // Flags 2.
1340
1341 OutStreamer->AddComment("PPA1 Flags 3");
1342 if ((Flags3 & PPA1Flag3::FPRMask) == PPA1Flag3::FPRMask)
1343 OutStreamer->AddComment(" Bit 2: 1 = FP Reg Mask is in optional area");
1344 OutStreamer->emitInt8(
1345 static_cast<uint8_t>(Flags3)); // Flags 3 (optional sections).
1346
1347 OutStreamer->AddComment("PPA1 Flags 4");
1348 if ((Flags4 & PPA1Flag4::VRMask) == PPA1Flag4::VRMask)
1349 OutStreamer->AddComment(" Bit 2: 1 = Vector Reg Mask is in optional area");
1350 if ((Flags4 & PPA1Flag4::EHBlock) == PPA1Flag4::EHBlock)
1351 OutStreamer->AddComment(" Bit 3: 1 = C++ EH block");
1352 if ((Flags4 & PPA1Flag4::ProcedureNamePresent) ==
1353 PPA1Flag4::ProcedureNamePresent)
1354 OutStreamer->AddComment(" Bit 7: 1 = Name Length and Name");
1355 OutStreamer->emitInt8(static_cast<uint8_t>(
1356 Flags4)); // Flags 4 (optional sections, always emit these).
1357}
1358
1359static void emitPPA1Name(std::unique_ptr<MCStreamer> &OutStreamer,
1360 StringRef OutName) {
1361 size_t NameSize = OutName.size();
1362 uint16_t OutSize;
1363 if (NameSize < UINT16_MAX) {
1364 OutSize = static_cast<uint16_t>(NameSize);
1365 } else {
1366 OutName = OutName.substr(0, UINT16_MAX);
1367 OutSize = UINT16_MAX;
1368 }
1369 // Emit padding to ensure that the next optional field word-aligned.
1370 uint8_t ExtraZeros = 4 - ((2 + OutSize) % 4);
1371
1372 SmallString<512> OutnameConv;
1373 ConverterEBCDIC::convertToEBCDIC(OutName, OutnameConv);
1374 OutName = OutnameConv.str();
1375
1376 OutStreamer->AddComment("Length of Name");
1377 OutStreamer->emitInt16(OutSize);
1378 OutStreamer->AddComment("Name of Function");
1379 OutStreamer->emitBytes(OutName);
1380 OutStreamer->emitZeros(ExtraZeros);
1381}
1382
1383void SystemZAsmPrinter::emitPPA1(MCSymbol *FnEndSym) {
1384 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1385
1387 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1388 const auto TargetHasVector = Subtarget.hasVector();
1389
1390 const SystemZMachineFunctionInfo *ZFI =
1392 const auto *ZFL = static_cast<const SystemZXPLINKFrameLowering *>(
1393 Subtarget.getFrameLowering());
1394 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1395
1396 // Get saved GPR/FPR/VPR masks.
1397 const std::vector<CalleeSavedInfo> &CSI = MFFrame.getCalleeSavedInfo();
1398 uint16_t SavedGPRMask = 0;
1399 uint16_t SavedFPRMask = 0;
1400 uint8_t SavedVRMask = 0;
1401 int64_t OffsetFPR = 0;
1402 int64_t OffsetVR = 0;
1403 const int64_t TopOfStack =
1404 MFFrame.getOffsetAdjustment() + MFFrame.getStackSize();
1405
1406 // Loop over the spilled registers. The CalleeSavedInfo can't be used because
1407 // it does not contain all spilled registers.
1408 for (unsigned I = ZFI->getSpillGPRRegs().LowGPR,
1409 E = ZFI->getSpillGPRRegs().HighGPR;
1410 I && E && I <= E; ++I) {
1411 unsigned V = TRI->getEncodingValue((Register)I);
1412 assert(V < 16 && "GPR index out of range");
1413 SavedGPRMask |= 1 << (15 - V);
1414 }
1415
1416 for (auto &CS : CSI) {
1417 unsigned Reg = CS.getReg();
1418 unsigned I = TRI->getEncodingValue(Reg);
1419
1420 if (SystemZ::FP64BitRegClass.contains(Reg)) {
1421 assert(I < 16 && "FPR index out of range");
1422 SavedFPRMask |= 1 << (15 - I);
1423 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1424 if (Temp < OffsetFPR)
1425 OffsetFPR = Temp;
1426 } else if (SystemZ::VR128BitRegClass.contains(Reg)) {
1427 assert(I >= 16 && I <= 23 && "VPR index out of range");
1428 unsigned BitNum = I - 16;
1429 SavedVRMask |= 1 << (7 - BitNum);
1430 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1431 if (Temp < OffsetVR)
1432 OffsetVR = Temp;
1433 }
1434 }
1435
1436 // Adjust the offset.
1437 OffsetFPR += (OffsetFPR < 0) ? TopOfStack : 0;
1438 OffsetVR += (OffsetVR < 0) ? TopOfStack : 0;
1439
1440 // Get alloca register.
1441 uint8_t FrameReg = TRI->getEncodingValue(TRI->getFrameRegister(*MF));
1442 uint8_t AllocaReg = ZFL->hasFP(*MF) ? FrameReg : 0;
1443 assert(AllocaReg < 16 && "Can't have alloca register larger than 15");
1444 (void)AllocaReg;
1445
1446 // Build FPR save area offset.
1447 uint32_t FrameAndFPROffset = 0;
1448 if (SavedFPRMask) {
1449 uint64_t FPRSaveAreaOffset = OffsetFPR;
1450 assert(FPRSaveAreaOffset < 0x10000000 && "Offset out of range");
1451
1452 FrameAndFPROffset = FPRSaveAreaOffset & 0x0FFFFFFF; // Lose top 4 bits.
1453 FrameAndFPROffset |= FrameReg << 28; // Put into top 4 bits.
1454 }
1455
1456 // Build VR save area offset.
1457 uint32_t FrameAndVROffset = 0;
1458 if (TargetHasVector && SavedVRMask) {
1459 uint64_t VRSaveAreaOffset = OffsetVR;
1460 assert(VRSaveAreaOffset < 0x10000000 && "Offset out of range");
1461
1462 FrameAndVROffset = VRSaveAreaOffset & 0x0FFFFFFF; // Lose top 4 bits.
1463 FrameAndVROffset |= FrameReg << 28; // Put into top 4 bits.
1464 }
1465
1466 // Emit PPA1 section.
1467 OutStreamer->AddComment("PPA1");
1468 OutStreamer->emitLabel(CurrentFnPPA1Sym);
1469 OutStreamer->AddComment("Version");
1470 OutStreamer->emitInt8(0x02); // Version.
1471 OutStreamer->AddComment("LE Signature X'CE'");
1472 OutStreamer->emitInt8(0xCE); // CEL signature.
1473 OutStreamer->AddComment("Saved GPR Mask");
1474 OutStreamer->emitInt16(SavedGPRMask);
1475 OutStreamer->AddComment("Offset to PPA2");
1476 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, CurrentFnPPA1Sym, 4);
1477
1478 bool NeedEmitEHBlock = !MF->getLandingPads().empty();
1479
1480 bool HasName =
1481 MF->getFunction().hasName() && MF->getFunction().getName().size() > 0;
1482
1484 MFFrame.hasStackProtectorIndex(), SavedFPRMask != 0,
1485 TargetHasVector && SavedVRMask != 0, NeedEmitEHBlock, HasName);
1486
1487 OutStreamer->AddComment("Length/4 of Parms");
1488 OutStreamer->emitInt16(
1489 static_cast<uint16_t>(ZFI->getSizeOfFnParams() / 4)); // Parms/4.
1490 OutStreamer->AddComment("Length of Code");
1491 OutStreamer->emitAbsoluteSymbolDiff(FnEndSym, CurrentFnEPMarkerSym, 4);
1492
1493 // Emit saved FPR mask and offset to FPR save area (0x20 of flags 3).
1494 if (SavedFPRMask) {
1495 OutStreamer->AddComment("FPR mask");
1496 OutStreamer->emitInt16(SavedFPRMask);
1497 OutStreamer->AddComment("AR mask");
1498 OutStreamer->emitInt16(0); // AR Mask, unused currently.
1499 OutStreamer->AddComment("FPR Save Area Locator");
1500 OutStreamer->AddComment(Twine(" Bit 0-3: Register R")
1501 .concat(utostr(FrameAndFPROffset >> 28))
1502 .str());
1503 OutStreamer->AddComment(Twine(" Bit 4-31: Offset ")
1504 .concat(utostr(FrameAndFPROffset & 0x0FFFFFFF))
1505 .str());
1506 OutStreamer->emitInt32(FrameAndFPROffset); // Offset to FPR save area with
1507 // register to add value to
1508 // (alloca reg).
1509 }
1510
1511 // Emit saved VR mask to VR save area.
1512 if (TargetHasVector && SavedVRMask) {
1513 OutStreamer->AddComment("VR mask");
1514 OutStreamer->emitInt8(SavedVRMask);
1515 OutStreamer->emitInt8(0); // Reserved.
1516 OutStreamer->emitInt16(0); // Also reserved.
1517 OutStreamer->AddComment("VR Save Area Locator");
1518 OutStreamer->AddComment(Twine(" Bit 0-3: Register R")
1519 .concat(utostr(FrameAndVROffset >> 28))
1520 .str());
1521 OutStreamer->AddComment(Twine(" Bit 4-31: Offset ")
1522 .concat(utostr(FrameAndVROffset & 0x0FFFFFFF))
1523 .str());
1524 OutStreamer->emitInt32(FrameAndVROffset);
1525 }
1526
1527 // Emit C++ EH information block
1528 const Function *Per = nullptr;
1529 if (NeedEmitEHBlock) {
1530 Per = dyn_cast<Function>(
1532 MCSymbol *PersonalityRoutine =
1533 Per ? MF->getTarget().getSymbol(Per) : nullptr;
1534 assert(PersonalityRoutine && "Missing personality routine");
1535
1536 OutStreamer->AddComment("Version");
1537 OutStreamer->emitInt32(1);
1538 OutStreamer->AddComment("Flags");
1539 OutStreamer->emitInt32(0); // LSDA field is a WAS offset
1540 OutStreamer->AddComment("Personality routine");
1541 OutStreamer->emitInt64(ADATable.insert(
1542 PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC));
1543 OutStreamer->AddComment("LSDA location");
1545 Twine("GCC_except_table") + Twine(MF->getFunctionNumber()));
1546 OutStreamer->emitInt64(
1547 ADATable.insert(GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR));
1548 }
1549
1550 // Emit name length and name optional section (0x01 of flags 4)
1551 if (HasName)
1553
1554 // Emit offset to entry point optional section (0x80 of flags 4).
1555 OutStreamer->emitAbsoluteSymbolDiff(CurrentFnEPMarkerSym, CurrentFnPPA1Sym,
1556 4);
1557}
1558
1560 if (TM.getTargetTriple().isOSzOS())
1561 emitPPA2(M);
1563}
1564
1565void SystemZAsmPrinter::emitPPA2(Module &M) {
1566 OutStreamer->pushSection();
1567 OutStreamer->switchSection(getObjFileLowering().getTextSection(),
1569 MCContext &OutContext = OutStreamer->getContext();
1570 // Make CELQSTRT symbol.
1571 const char *StartSymbolName = "CELQSTRT";
1572 MCSymbol *CELQSTRT = OutContext.getOrCreateSymbol(StartSymbolName);
1573
1574 // Create symbol and assign to class field for use in PPA1.
1575 PPA2Sym = OutContext.createTempSymbol("PPA2", false);
1576 MCSymbol *DateVersionSym = OutContext.createTempSymbol("DVS", false);
1577
1578 std::time_t Time = getTranslationTime(M);
1579 SmallString<15> CompilationTime; // 14 + null
1580 raw_svector_ostream O(CompilationTime);
1581 O << formatv("{0:%Y%m%d%H%M%S}", llvm::sys::toUtcTime(Time));
1582
1583 uint32_t ProductVersion = getProductVersion(M),
1584 ProductRelease = getProductRelease(M),
1585 ProductPatch = getProductPatch(M);
1586
1587 SmallString<7> Version; // 6 + null
1589 ostr << formatv("{0,0-2:d}{1,0-2:d}{2,0-2:d}", ProductVersion, ProductRelease,
1590 ProductPatch);
1591
1592 // Drop 0 during conversion.
1593 SmallString<sizeof(CompilationTime) - 1> CompilationTimeStr;
1594 SmallString<sizeof(Version) - 1> VersionStr;
1595
1596 ConverterEBCDIC::convertToEBCDIC(CompilationTime, CompilationTimeStr);
1598
1599 enum class PPA2MemberId : uint8_t {
1600 // See z/OS Language Environment Vendor Interfaces v2r5, p.23, for
1601 // complete list. Only the C runtime is supported by this backend.
1602 LE_C_Runtime = 3,
1603 };
1604 enum class PPA2MemberSubId : uint8_t {
1605 // List of languages using the LE C runtime implementation.
1606 C = 0x00,
1607 CXX = 0x01,
1608 Swift = 0x03,
1609 Go = 0x60,
1610 LLVMBasedLang = 0xe7,
1611 };
1612 // PPA2 Flags
1613 enum class PPA2Flags : uint8_t {
1614 CompileForBinaryFloatingPoint = 0x80,
1615 CompiledWithXPLink = 0x01,
1616 CompiledUnitASCII = 0x04,
1617 HasServiceInfo = 0x20,
1618 };
1619
1620 PPA2MemberSubId MemberSubId = PPA2MemberSubId::LLVMBasedLang;
1621 if (auto *MD = M.getModuleFlag("zos_cu_language")) {
1622 StringRef Language = cast<MDString>(MD)->getString();
1623 MemberSubId = StringSwitch<PPA2MemberSubId>(Language)
1624 .Case("C", PPA2MemberSubId::C)
1625 .Case("C++", PPA2MemberSubId::CXX)
1626 .Case("Swift", PPA2MemberSubId::Swift)
1627 .Case("Go", PPA2MemberSubId::Go)
1628 .Default(PPA2MemberSubId::LLVMBasedLang);
1629 }
1630
1631 // Emit PPA2 section.
1632 OutStreamer->emitLabel(PPA2Sym);
1633 OutStreamer->emitInt8(static_cast<uint8_t>(PPA2MemberId::LE_C_Runtime));
1634 OutStreamer->emitInt8(static_cast<uint8_t>(MemberSubId));
1635 OutStreamer->emitInt8(0x22); // Member defined, c370_plist+c370_env
1636 OutStreamer->emitInt8(0x04); // Control level 4 (XPLink)
1637 OutStreamer->emitAbsoluteSymbolDiff(CELQSTRT, PPA2Sym, 4);
1638 OutStreamer->emitInt32(0x00000000);
1639 OutStreamer->emitAbsoluteSymbolDiff(DateVersionSym, PPA2Sym, 4);
1640 OutStreamer->emitInt32(
1641 0x00000000); // Offset to main entry point, always 0 (so says TR).
1642 uint8_t Flgs = static_cast<uint8_t>(PPA2Flags::CompileForBinaryFloatingPoint);
1643 Flgs |= static_cast<uint8_t>(PPA2Flags::CompiledWithXPLink);
1644
1645 if (auto *MD = M.getModuleFlag("zos_le_char_mode")) {
1646 const StringRef &CharMode = cast<MDString>(MD)->getString();
1647 if (CharMode == "ascii") {
1648 Flgs |= static_cast<uint8_t>(
1649 PPA2Flags::CompiledUnitASCII); // Setting bit for ASCII char. mode.
1650 } else if (CharMode != "ebcdic") {
1652 "Only ascii or ebcdic are valid values for zos_le_char_mode "
1653 "metadata");
1654 }
1655 }
1656
1657 OutStreamer->emitInt8(Flgs);
1658 OutStreamer->emitInt8(0x00); // Reserved.
1659 // No MD5 signature before timestamp.
1660 // No FLOAT(AFP(VOLATILE)).
1661 // Remaining 5 flag bits reserved.
1662 OutStreamer->emitInt16(0x0000); // 16 Reserved flag bits.
1663
1664 // Emit date and version section.
1665 OutStreamer->emitLabel(DateVersionSym);
1666 OutStreamer->emitBytes(CompilationTimeStr.str());
1667 OutStreamer->emitBytes(VersionStr.str());
1668
1669 OutStreamer->emitInt16(0x0000); // Service level string length.
1670
1671 // The binder requires that the offset to the PPA2 be emitted in a different,
1672 // specially-named section.
1673 OutStreamer->switchSection(getObjFileLowering().getPPA2ListSection());
1674 // Emit 8 byte alignment.
1675 // Emit pointer to PPA2 label.
1676 OutStreamer->AddComment("A(PPA2-CELQSTRT)");
1677 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, CELQSTRT, 8);
1678 OutStreamer->popSection();
1679}
1680
1682 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1683
1684 if (Subtarget.getTargetTriple().isOSzOS()) {
1685 MCContext &OutContext = OutStreamer->getContext();
1686
1687 // Save information for later use.
1688 std::string N(MF->getFunction().hasName()
1689 ? Twine(MF->getFunction().getName()).concat("_").str()
1690 : "");
1691
1692 CurrentFnEPMarkerSym =
1693 OutContext.createTempSymbol(Twine("EPM_").concat(N).str(), true);
1694 CurrentFnPPA1Sym =
1695 OutContext.createTempSymbol(Twine("PPA1_").concat(N).str(), true);
1696
1697 // EntryPoint Marker
1698 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1699 bool IsUsingAlloca = MFFrame.hasVarSizedObjects();
1700 uint32_t DSASize = MFFrame.getStackSize();
1701 bool IsLeaf = DSASize == 0 && MFFrame.getCalleeSavedInfo().empty();
1702
1703 // Set Flags.
1704 uint8_t Flags = 0;
1705 if (IsLeaf)
1706 Flags |= 0x08;
1707 if (IsUsingAlloca)
1708 Flags |= 0x04;
1709
1710 // Combine into top 27 bits of DSASize and bottom 5 bits of Flags.
1711 uint32_t DSAAndFlags = DSASize & 0xFFFFFFE0; // (x/32) << 5
1712 DSAAndFlags |= Flags;
1713
1714 // Emit entry point marker section.
1715 OutStreamer->AddComment("XPLINK Routine Layout Entry");
1716 OutStreamer->emitLabel(CurrentFnEPMarkerSym);
1717 OutStreamer->AddComment("Eyecatcher 0x00C300C500C500");
1718 OutStreamer->emitIntValueInHex(0x00C300C500C500, 7); // Eyecatcher.
1719 OutStreamer->AddComment("Mark Type C'1'");
1720 OutStreamer->emitInt8(0xF1); // Mark Type.
1721 OutStreamer->AddComment("Offset to PPA1");
1722 OutStreamer->emitAbsoluteSymbolDiff(CurrentFnPPA1Sym, CurrentFnEPMarkerSym,
1723 4);
1724 if (OutStreamer->isVerboseAsm()) {
1725 OutStreamer->AddComment("DSA Size 0x" + Twine::utohexstr(DSASize));
1726 OutStreamer->AddComment("Entry Flags");
1727 if (Flags & 0x08)
1728 OutStreamer->AddComment(" Bit 1: 1 = Leaf function");
1729 else
1730 OutStreamer->AddComment(" Bit 1: 0 = Non-leaf function");
1731 if (Flags & 0x04)
1732 OutStreamer->AddComment(" Bit 2: 1 = Uses alloca");
1733 else
1734 OutStreamer->AddComment(" Bit 2: 0 = Does not use alloca");
1735 }
1736 OutStreamer->emitInt32(DSAAndFlags);
1737 }
1738
1740}
1741
1742char SystemZAsmPrinter::ID = 0;
1743
1744INITIALIZE_PASS(SystemZAsmPrinter, "systemz-asm-printer",
1745 "SystemZ Assembly Printer", false, false)
1746
1747// Force static initialization.
1749LLVMInitializeSystemZAsmPrinter() {
1751}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
This file provides utility functions for converting between EBCDIC-1047 and UTF-8.
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define RegName(no)
#define I(x, y, z)
Definition: MD5.cpp:58
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:56
raw_pwrite_stream & OS
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:480
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
This file contains some functions that are useful when dealing with strings.
static MCInst lowerVecEltExtraction(const MachineInstr *MI, unsigned Opcode)
static uint8_t getSpecifierFromModifier(SystemZCP::SystemZCPModifier Modifier)
static void emitPPA1Name(std::unique_ptr< MCStreamer > &OutStreamer, StringRef OutName)
#define LOWER_LOW(NAME)
static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI, unsigned Opcode)
#define EMIT_COMMENT(Str)
static const MCSymbolRefExpr * getGlobalOffsetTable(MCContext &Context)
#define LOWER_HIGH(NAME)
static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo, raw_ostream &OS)
static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode)
static uint32_t getProductVersion(Module &M)
static std::string getProductID(Module &M)
static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode)
static void emitPPA1Flags(std::unique_ptr< MCStreamer > &OutStreamer, bool VarArg, bool StackProtector, bool FPRMask, bool VRMask, bool EHBlock, bool HasName)
static void printAddress(const MCAsmInfo *MAI, unsigned Base, const MCOperand &DispMO, unsigned Index, raw_ostream &OS)
static time_t getTranslationTime(Module &M)
static const MCSymbolRefExpr * getTLSGetOffset(MCContext &Context)
static MCInst lowerSubvectorStore(const MachineInstr *MI, unsigned Opcode)
static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer, unsigned NumBytes, const MCSubtargetInfo &STI)
static MCInst lowerVecEltInsertion(const MachineInstr *MI, unsigned Opcode)
static uint32_t getProductRelease(Module &M)
static MCInst lowerSubvectorLoad(const MachineInstr *MI, unsigned Opcode)
static uint32_t getProductPatch(Module &M)
static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode)
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:413
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:706
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:433
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:93
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:96
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:108
virtual void emitStartOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the start of their fi...
Definition: AsmPrinter.h:605
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:100
MCSymbol * createTempSymbol(const Twine &Name) const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:105
StackMaps SM
Definition: AsmPrinter.h:248
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:417
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:428
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
const Constant * stripPointerCasts() const
Definition: Constant.h:219
This class represents an Operation in the Expression.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:504
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
Definition: DataLayout.cpp:738
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1036
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.h:227
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:727
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
unsigned getAssemblerDialect() const
Definition: MCAsmInfo.h:560
void printExpr(raw_ostream &, const MCExpr &) const
Definition: MCAsmInfo.cpp:153
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.h:343
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:212
Context object for machine code objects.
Definition: MCContext.h:83
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:386
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:549
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:203
const Triple & getTargetTriple() const
Definition: MCContext.h:400
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
MCInstBuilder & addReg(MCRegister Reg)
Add a new register operand.
Definition: MCInstBuilder.h:37
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Definition: MCInstBuilder.h:43
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
Definition: MCInstBuilder.h:61
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
void addOperand(const MCOperand Op)
Definition: MCInst.h:215
void setOpcode(unsigned Op)
Definition: MCInst.h:201
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:40
int64_t getImm() const
Definition: MCInst.h:84
static MCOperand createReg(MCRegister Reg)
Definition: MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:145
bool isImm() const
Definition: MCInst.h:66
bool isReg() const
Definition: MCInst.h:65
MCRegister getReg() const
Returns the register number.
Definition: MCInst.h:73
const MCExpr * getExpr() const
Definition: MCInst.h:118
bool isExpr() const
Definition: MCInst.h:69
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:743
Streaming machine code generation interface.
Definition: MCStreamer.h:220
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:395
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:190
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Abstract base class for all machine specific constantpool value subclasses.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
bool hasStackProtectorIndex() const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
Definition: MachineInstr.h:72
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
@ MO_GlobalAddress
Address of a global value.
@ MO_ExternalSymbol
Name of external global symbol.
const TargetRegisterInfo * getTargetRegisterInfo() const
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
MI-level patchpoint operands.
Definition: StackMaps.h:77
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:254
LLVM_ABI void recordPatchPoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a patchpoint instruction.
Definition: StackMaps.cpp:539
LLVM_ABI void recordStackMap(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a stackmap instruction.
Definition: StackMaps.cpp:529
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:581
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:154
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:68
R Default(T Value)
Definition: StringSwitch.h:177
void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
A SystemZ-specific constant pool value.
static const char * getRegisterName(MCRegister Reg)
static const char * getRegisterName(MCRegister Reg)
const SystemZInstrInfo * getInstrInfo() const override
const TargetFrameLowering * getFrameLowering() const override
std::pair< MCInst, const MCSubtargetInfo * > MCInstSTIPair
const Triple & getTargetTriple() const
const MCSubtargetInfo * getMCSubtargetInfo() const
MCSymbol * getSymbol(const GlobalValue *GV) const
const MCRegisterInfo * getMCRegisterInfo() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isOSzOS() const
Definition: Triple.h:599
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
Twine concat(const Twine &Suffix) const
Definition: Twine.h:530
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:418
bool hasName() const
Definition: Value.h:262
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:322
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:692
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
Key
PAL metadata keys.
@ Swift
Calling convention for Swift.
Definition: CallingConv.h:69
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
LLVM_ABI std::error_code convertToEBCDIC(StringRef Source, SmallVectorImpl< char > &Result)
@ SHT_PROGBITS
Definition: ELF.h:1140
@ SHF_ALLOC
Definition: ELF.h:1240
@ SK_PPA1
Definition: GOFF.h:169
@ SK_PPA2
Definition: GOFF.h:170
unsigned getRegAsGR32(unsigned Reg)
const unsigned GR64Regs[16]
unsigned getRegAsGRH32(unsigned Reg)
unsigned getRegAsVR128(unsigned Reg)
unsigned getRegAsGR64(unsigned Reg)
Reg
All possible values of the reg field in the ModR/M byte.
constexpr size_t NameSize
Definition: XCOFF.h:30
UtcTime< std::chrono::seconds > toUtcTime(std::time_t T)
Convert a std::time_t to a UtcTime.
Definition: Chrono.h:44
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Target & getTheSystemZTarget()
@ Offset
Definition: DWP.cpp:477
@ Length
Definition: DWP.cpp:477
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition: STLExtras.h:1197
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
Definition: MCDirectives.h:35
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...