LLVM 23.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"
28#include "llvm/IR/Mangler.h"
29#include "llvm/IR/Module.h"
31#include "llvm/MC/MCExpr.h"
34#include "llvm/MC/MCStreamer.h"
37#include "llvm/Support/Chrono.h"
41
42using namespace llvm;
43
44// Return an RI instruction like MI with opcode Opcode, but with the
45// GR64 register operands turned into GR32s.
46static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode) {
47 if (MI->isCompare())
48 return MCInstBuilder(Opcode)
49 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
50 .addImm(MI->getOperand(1).getImm());
51 else
52 return MCInstBuilder(Opcode)
53 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
54 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(1).getReg()))
55 .addImm(MI->getOperand(2).getImm());
56}
57
58// Return an RI instruction like MI with opcode Opcode, but with the
59// GR64 register operands turned into GRH32s.
60static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode) {
61 if (MI->isCompare())
62 return MCInstBuilder(Opcode)
63 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
64 .addImm(MI->getOperand(1).getImm());
65 else
66 return MCInstBuilder(Opcode)
67 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
68 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(1).getReg()))
69 .addImm(MI->getOperand(2).getImm());
70}
71
72// Return an RI instruction like MI with opcode Opcode, but with the
73// R2 register turned into a GR64.
74static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode) {
75 return MCInstBuilder(Opcode)
76 .addReg(MI->getOperand(0).getReg())
77 .addReg(MI->getOperand(1).getReg())
78 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()))
79 .addImm(MI->getOperand(3).getImm())
80 .addImm(MI->getOperand(4).getImm())
81 .addImm(MI->getOperand(5).getImm());
82}
83
84static const MCSymbolRefExpr *getTLSGetOffset(MCContext &Context) {
85 StringRef Name = "__tls_get_offset";
86 return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
87 SystemZ::S_PLT, Context);
88}
89
91 StringRef Name = "_GLOBAL_OFFSET_TABLE_";
92 return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
93 Context);
94}
95
96// MI is an instruction that accepts an optional alignment hint,
97// and which was already lowered to LoweredMI. If the alignment
98// of the original memory operand is known, update LoweredMI to
99// an instruction with the corresponding hint set.
100static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI,
101 unsigned Opcode) {
102 if (MI->memoperands_empty())
103 return;
104
105 Align Alignment = Align(16);
106 for (MachineInstr::mmo_iterator MMOI = MI->memoperands_begin(),
107 EE = MI->memoperands_end(); MMOI != EE; ++MMOI)
108 if ((*MMOI)->getAlign() < Alignment)
109 Alignment = (*MMOI)->getAlign();
110
111 unsigned AlignmentHint = 0;
112 if (Alignment >= Align(16))
113 AlignmentHint = 4;
114 else if (Alignment >= Align(8))
115 AlignmentHint = 3;
116 if (AlignmentHint == 0)
117 return;
118
119 LoweredMI.setOpcode(Opcode);
120 LoweredMI.addOperand(MCOperand::createImm(AlignmentHint));
121}
122
123// MI loads the high part of a vector from memory. Return an instruction
124// that uses replicating vector load Opcode to do the same thing.
125static MCInst lowerSubvectorLoad(const MachineInstr *MI, unsigned Opcode) {
126 return MCInstBuilder(Opcode)
127 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
128 .addReg(MI->getOperand(1).getReg())
129 .addImm(MI->getOperand(2).getImm())
130 .addReg(MI->getOperand(3).getReg());
131}
132
133// MI stores the high part of a vector to memory. Return an instruction
134// that uses elemental vector store Opcode to do the same thing.
135static MCInst lowerSubvectorStore(const MachineInstr *MI, unsigned Opcode) {
136 return MCInstBuilder(Opcode)
137 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
138 .addReg(MI->getOperand(1).getReg())
139 .addImm(MI->getOperand(2).getImm())
140 .addReg(MI->getOperand(3).getReg())
141 .addImm(0);
142}
143
144// MI extracts the first element of the source vector.
145static MCInst lowerVecEltExtraction(const MachineInstr *MI, unsigned Opcode) {
146 return MCInstBuilder(Opcode)
147 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(0).getReg()))
148 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(1).getReg()))
149 .addReg(0)
150 .addImm(0);
151}
152
153// MI inserts value into the first element of the destination vector.
154static MCInst lowerVecEltInsertion(const MachineInstr *MI, unsigned Opcode) {
155 return MCInstBuilder(Opcode)
156 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
157 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
158 .addReg(MI->getOperand(1).getReg())
159 .addReg(0)
160 .addImm(0);
161}
162
164 SM.reset();
165
166 // In HLASM, the only way to represent aliases is to use the
167 // extra-label-at-definition strategy. This is similar to the AIX
168 // implementation with the additional caveat that all symbol attributes must
169 // be emitted before the label is emitted.
170 if (TM.getTargetTriple().isOSzOS()) {
171 // Construct an aliasing list for each GlobalObject.
172 for (const auto &Alias : M.aliases()) {
173 const GlobalObject *Aliasee = Alias.getAliaseeObject();
174 if (!Aliasee)
175 OutContext.reportError(
176 {}, "Alias without a base object is not yet supported on z/OS.");
177
178 bool IsFunc = isa<Function>(Aliasee->stripPointerCasts());
179 if (IsFunc) {
180 if (Alias.hasWeakLinkage() || Alias.hasLinkOnceLinkage())
181 OutContext.reportError({},
182 "Weak alias/reference not supported on z/OS");
183
184 GOAliasMap[Aliasee].push_back(&Alias);
185 } else
186 OutContext.reportError(
187 {}, "Only aliases to functions is supported in GOFF.");
188 }
189 }
191}
192
193// The XPLINK ABI requires that a no-op encoding the call type is emitted after
194// each call to a subroutine. This information can be used by the called
195// function to determine its entry point, e.g. for generating a backtrace. The
196// call type is encoded as a register number in the bcr instruction. See
197// enumeration CallType for the possible values.
198void SystemZAsmPrinter::emitCallInformation(CallType CT) {
200 MCInstBuilder(SystemZ::BCRAsm)
201 .addImm(0)
202 .addReg(SystemZMC::GR64Regs[static_cast<unsigned>(CT)]));
203}
204
205uint32_t SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MCSymbol *Sym,
206 unsigned SlotKind) {
207 auto Key = std::make_pair(Sym, SlotKind);
208 auto It = Displacements.find(Key);
209
210 if (It != Displacements.end())
211 return (*It).second;
212
213 // Determine length of descriptor.
215 switch (SlotKind) {
217 Length = 2 * PointerSize;
218 break;
219 default:
220 Length = PointerSize;
221 break;
222 }
223
224 uint32_t Displacement = NextDisplacement;
225 Displacements[std::make_pair(Sym, SlotKind)] = NextDisplacement;
226 NextDisplacement += Length;
227
228 return Displacement;
229}
230
231uint32_t
232SystemZAsmPrinter::AssociatedDataAreaTable::insert(const MachineOperand MO) {
233 MCSymbol *Sym;
235 const GlobalValue *GV = MO.getGlobal();
236 Sym = MO.getParent()->getMF()->getTarget().getSymbol(GV);
237 assert(Sym && "No symbol");
238 } else if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
239 const char *SymName = MO.getSymbolName();
240 Sym = MO.getParent()->getMF()->getContext().getOrCreateSymbol(SymName);
241 assert(Sym && "No symbol");
242 } else
243 llvm_unreachable("Unexpected operand type");
244
245 unsigned ADAslotType = MO.getTargetFlags();
246 return insert(Sym, ADAslotType);
247}
248
250 SystemZ_MC::verifyInstructionPredicates(MI->getOpcode(),
251 getSubtargetInfo().getFeatureBits());
252
253 SystemZMCInstLower Lower(MF->getContext(), *this);
254 MCInst LoweredMI;
255 switch (MI->getOpcode()) {
256 case SystemZ::Return:
257 LoweredMI = MCInstBuilder(SystemZ::BR)
258 .addReg(SystemZ::R14D);
259 break;
260
261 case SystemZ::Return_XPLINK:
262 LoweredMI = MCInstBuilder(SystemZ::B)
263 .addReg(SystemZ::R7D)
264 .addImm(2)
265 .addReg(0);
266 break;
267
268 case SystemZ::CondReturn:
269 LoweredMI = MCInstBuilder(SystemZ::BCR)
270 .addImm(MI->getOperand(0).getImm())
271 .addImm(MI->getOperand(1).getImm())
272 .addReg(SystemZ::R14D);
273 break;
274
275 case SystemZ::CondReturn_XPLINK:
276 LoweredMI = MCInstBuilder(SystemZ::BC)
277 .addImm(MI->getOperand(0).getImm())
278 .addImm(MI->getOperand(1).getImm())
279 .addReg(SystemZ::R7D)
280 .addImm(2)
281 .addReg(0);
282 break;
283
284 case SystemZ::CRBReturn:
285 LoweredMI = MCInstBuilder(SystemZ::CRB)
286 .addReg(MI->getOperand(0).getReg())
287 .addReg(MI->getOperand(1).getReg())
288 .addImm(MI->getOperand(2).getImm())
289 .addReg(SystemZ::R14D)
290 .addImm(0);
291 break;
292
293 case SystemZ::CGRBReturn:
294 LoweredMI = MCInstBuilder(SystemZ::CGRB)
295 .addReg(MI->getOperand(0).getReg())
296 .addReg(MI->getOperand(1).getReg())
297 .addImm(MI->getOperand(2).getImm())
298 .addReg(SystemZ::R14D)
299 .addImm(0);
300 break;
301
302 case SystemZ::CIBReturn:
303 LoweredMI = MCInstBuilder(SystemZ::CIB)
304 .addReg(MI->getOperand(0).getReg())
305 .addImm(MI->getOperand(1).getImm())
306 .addImm(MI->getOperand(2).getImm())
307 .addReg(SystemZ::R14D)
308 .addImm(0);
309 break;
310
311 case SystemZ::CGIBReturn:
312 LoweredMI = MCInstBuilder(SystemZ::CGIB)
313 .addReg(MI->getOperand(0).getReg())
314 .addImm(MI->getOperand(1).getImm())
315 .addImm(MI->getOperand(2).getImm())
316 .addReg(SystemZ::R14D)
317 .addImm(0);
318 break;
319
320 case SystemZ::CLRBReturn:
321 LoweredMI = MCInstBuilder(SystemZ::CLRB)
322 .addReg(MI->getOperand(0).getReg())
323 .addReg(MI->getOperand(1).getReg())
324 .addImm(MI->getOperand(2).getImm())
325 .addReg(SystemZ::R14D)
326 .addImm(0);
327 break;
328
329 case SystemZ::CLGRBReturn:
330 LoweredMI = MCInstBuilder(SystemZ::CLGRB)
331 .addReg(MI->getOperand(0).getReg())
332 .addReg(MI->getOperand(1).getReg())
333 .addImm(MI->getOperand(2).getImm())
334 .addReg(SystemZ::R14D)
335 .addImm(0);
336 break;
337
338 case SystemZ::CLIBReturn:
339 LoweredMI = MCInstBuilder(SystemZ::CLIB)
340 .addReg(MI->getOperand(0).getReg())
341 .addImm(MI->getOperand(1).getImm())
342 .addImm(MI->getOperand(2).getImm())
343 .addReg(SystemZ::R14D)
344 .addImm(0);
345 break;
346
347 case SystemZ::CLGIBReturn:
348 LoweredMI = MCInstBuilder(SystemZ::CLGIB)
349 .addReg(MI->getOperand(0).getReg())
350 .addImm(MI->getOperand(1).getImm())
351 .addImm(MI->getOperand(2).getImm())
352 .addReg(SystemZ::R14D)
353 .addImm(0);
354 break;
355
356 case SystemZ::CallBRASL_XPLINK64:
358 .addReg(SystemZ::R7D)
359 .addExpr(Lower.getExpr(MI->getOperand(0),
361 emitCallInformation(CallType::BRASL7);
362 return;
363
364 case SystemZ::CallBASR_XPLINK64:
366 .addReg(SystemZ::R7D)
367 .addReg(MI->getOperand(0).getReg()));
368 emitCallInformation(CallType::BASR76);
369 return;
370
371 case SystemZ::CallBASR_STACKEXT:
373 .addReg(SystemZ::R3D)
374 .addReg(MI->getOperand(0).getReg()));
375 emitCallInformation(CallType::BASR33);
376 return;
377
378 case SystemZ::ADA_ENTRY_VALUE:
379 case SystemZ::ADA_ENTRY: {
380 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
381 const SystemZInstrInfo *TII = Subtarget.getInstrInfo();
382 uint32_t Disp = ADATable.insert(MI->getOperand(1));
383 Register TargetReg = MI->getOperand(0).getReg();
384
385 Register ADAReg = MI->getOperand(2).getReg();
386 Disp += MI->getOperand(3).getImm();
387 bool LoadAddr = MI->getOpcode() == SystemZ::ADA_ENTRY;
388
389 unsigned Op0 = LoadAddr ? SystemZ::LA : SystemZ::LG;
390 unsigned Op = TII->getOpcodeForOffset(Op0, Disp);
391
392 Register IndexReg = 0;
393 if (!Op) {
394 if (TargetReg != ADAReg) {
395 IndexReg = TargetReg;
396 // Use TargetReg to store displacement.
399 MCInstBuilder(SystemZ::LLILF).addReg(TargetReg).addImm(Disp));
400 } else
402 .addReg(TargetReg)
403 .addReg(TargetReg)
404 .addImm(Disp));
405 Disp = 0;
406 Op = Op0;
407 }
409 .addReg(TargetReg)
410 .addReg(ADAReg)
411 .addImm(Disp)
412 .addReg(IndexReg));
413
414 return;
415 }
416 case SystemZ::CallBRASL:
417 LoweredMI = MCInstBuilder(SystemZ::BRASL)
418 .addReg(SystemZ::R14D)
419 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_PLT));
420 break;
421
422 case SystemZ::CallBASR:
423 LoweredMI = MCInstBuilder(SystemZ::BASR)
424 .addReg(SystemZ::R14D)
425 .addReg(MI->getOperand(0).getReg());
426 break;
427
428 case SystemZ::CallJG:
429 LoweredMI = MCInstBuilder(SystemZ::JG)
430 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_PLT));
431 break;
432
433 case SystemZ::CallBRCL:
434 LoweredMI = MCInstBuilder(SystemZ::BRCL)
435 .addImm(MI->getOperand(0).getImm())
436 .addImm(MI->getOperand(1).getImm())
437 .addExpr(Lower.getExpr(MI->getOperand(2), SystemZ::S_PLT));
438 break;
439
440 case SystemZ::CallBR:
441 LoweredMI = MCInstBuilder(SystemZ::BR)
442 .addReg(MI->getOperand(0).getReg());
443 break;
444
445 case SystemZ::CallBCR:
446 LoweredMI = MCInstBuilder(SystemZ::BCR)
447 .addImm(MI->getOperand(0).getImm())
448 .addImm(MI->getOperand(1).getImm())
449 .addReg(MI->getOperand(2).getReg());
450 break;
451
452 case SystemZ::CRBCall:
453 LoweredMI = MCInstBuilder(SystemZ::CRB)
454 .addReg(MI->getOperand(0).getReg())
455 .addReg(MI->getOperand(1).getReg())
456 .addImm(MI->getOperand(2).getImm())
457 .addReg(MI->getOperand(3).getReg())
458 .addImm(0);
459 break;
460
461 case SystemZ::CGRBCall:
462 LoweredMI = MCInstBuilder(SystemZ::CGRB)
463 .addReg(MI->getOperand(0).getReg())
464 .addReg(MI->getOperand(1).getReg())
465 .addImm(MI->getOperand(2).getImm())
466 .addReg(MI->getOperand(3).getReg())
467 .addImm(0);
468 break;
469
470 case SystemZ::CIBCall:
471 LoweredMI = MCInstBuilder(SystemZ::CIB)
472 .addReg(MI->getOperand(0).getReg())
473 .addImm(MI->getOperand(1).getImm())
474 .addImm(MI->getOperand(2).getImm())
475 .addReg(MI->getOperand(3).getReg())
476 .addImm(0);
477 break;
478
479 case SystemZ::CGIBCall:
480 LoweredMI = MCInstBuilder(SystemZ::CGIB)
481 .addReg(MI->getOperand(0).getReg())
482 .addImm(MI->getOperand(1).getImm())
483 .addImm(MI->getOperand(2).getImm())
484 .addReg(MI->getOperand(3).getReg())
485 .addImm(0);
486 break;
487
488 case SystemZ::CLRBCall:
489 LoweredMI = MCInstBuilder(SystemZ::CLRB)
490 .addReg(MI->getOperand(0).getReg())
491 .addReg(MI->getOperand(1).getReg())
492 .addImm(MI->getOperand(2).getImm())
493 .addReg(MI->getOperand(3).getReg())
494 .addImm(0);
495 break;
496
497 case SystemZ::CLGRBCall:
498 LoweredMI = MCInstBuilder(SystemZ::CLGRB)
499 .addReg(MI->getOperand(0).getReg())
500 .addReg(MI->getOperand(1).getReg())
501 .addImm(MI->getOperand(2).getImm())
502 .addReg(MI->getOperand(3).getReg())
503 .addImm(0);
504 break;
505
506 case SystemZ::CLIBCall:
507 LoweredMI = MCInstBuilder(SystemZ::CLIB)
508 .addReg(MI->getOperand(0).getReg())
509 .addImm(MI->getOperand(1).getImm())
510 .addImm(MI->getOperand(2).getImm())
511 .addReg(MI->getOperand(3).getReg())
512 .addImm(0);
513 break;
514
515 case SystemZ::CLGIBCall:
516 LoweredMI = MCInstBuilder(SystemZ::CLGIB)
517 .addReg(MI->getOperand(0).getReg())
518 .addImm(MI->getOperand(1).getImm())
519 .addImm(MI->getOperand(2).getImm())
520 .addReg(MI->getOperand(3).getReg())
521 .addImm(0);
522 break;
523
524 case SystemZ::TLS_GDCALL:
525 LoweredMI =
526 MCInstBuilder(SystemZ::BRASL)
527 .addReg(SystemZ::R14D)
528 .addExpr(getTLSGetOffset(MF->getContext()))
529 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_TLSGD));
530 break;
531
532 case SystemZ::TLS_LDCALL:
533 LoweredMI =
534 MCInstBuilder(SystemZ::BRASL)
535 .addReg(SystemZ::R14D)
536 .addExpr(getTLSGetOffset(MF->getContext()))
537 .addExpr(Lower.getExpr(MI->getOperand(0), SystemZ::S_TLSLDM));
538 break;
539
540 case SystemZ::GOT:
541 LoweredMI = MCInstBuilder(SystemZ::LARL)
542 .addReg(MI->getOperand(0).getReg())
543 .addExpr(getGlobalOffsetTable(MF->getContext()));
544 break;
545
546 case SystemZ::IILF64:
547 LoweredMI = MCInstBuilder(SystemZ::IILF)
548 .addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
549 .addImm(MI->getOperand(2).getImm());
550 break;
551
552 case SystemZ::IIHF64:
553 LoweredMI = MCInstBuilder(SystemZ::IIHF)
554 .addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
555 .addImm(MI->getOperand(2).getImm());
556 break;
557
558 case SystemZ::RISBHH:
559 case SystemZ::RISBHL:
560 LoweredMI = lowerRIEfLow(MI, SystemZ::RISBHG);
561 break;
562
563 case SystemZ::RISBLH:
564 case SystemZ::RISBLL:
565 LoweredMI = lowerRIEfLow(MI, SystemZ::RISBLG);
566 break;
567
568 case SystemZ::VLVGP32:
569 LoweredMI = MCInstBuilder(SystemZ::VLVGP)
570 .addReg(MI->getOperand(0).getReg())
571 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(1).getReg()))
572 .addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()));
573 break;
574
575 case SystemZ::VLR16:
576 case SystemZ::VLR32:
577 case SystemZ::VLR64:
578 LoweredMI = MCInstBuilder(SystemZ::VLR)
579 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
580 .addReg(SystemZMC::getRegAsVR128(MI->getOperand(1).getReg()));
581 break;
582
583 case SystemZ::VL:
584 Lower.lower(MI, LoweredMI);
585 lowerAlignmentHint(MI, LoweredMI, SystemZ::VLAlign);
586 break;
587
588 case SystemZ::VST:
589 Lower.lower(MI, LoweredMI);
590 lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTAlign);
591 break;
592
593 case SystemZ::VLM:
594 Lower.lower(MI, LoweredMI);
595 lowerAlignmentHint(MI, LoweredMI, SystemZ::VLMAlign);
596 break;
597
598 case SystemZ::VSTM:
599 Lower.lower(MI, LoweredMI);
600 lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTMAlign);
601 break;
602
603 case SystemZ::VL16:
604 LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPH);
605 break;
606
607 case SystemZ::VL32:
608 LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPF);
609 break;
610
611 case SystemZ::VL64:
612 LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPG);
613 break;
614
615 case SystemZ::VST16:
616 LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEH);
617 break;
618
619 case SystemZ::VST32:
620 LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEF);
621 break;
622
623 case SystemZ::VST64:
624 LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEG);
625 break;
626
627 case SystemZ::LFER:
628 LoweredMI = lowerVecEltExtraction(MI, SystemZ::VLGVF);
629 break;
630
631 case SystemZ::LFER_16:
632 LoweredMI = lowerVecEltExtraction(MI, SystemZ::VLGVH);
633 break;
634
635 case SystemZ::LEFR:
636 LoweredMI = lowerVecEltInsertion(MI, SystemZ::VLVGF);
637 break;
638
639 case SystemZ::LEFR_16:
640 LoweredMI = lowerVecEltInsertion(MI, SystemZ::VLVGH);
641 break;
642
643#define LOWER_LOW(NAME) \
644 case SystemZ::NAME##64: LoweredMI = lowerRILow(MI, SystemZ::NAME); break
645
646 LOWER_LOW(IILL);
647 LOWER_LOW(IILH);
648 LOWER_LOW(TMLL);
649 LOWER_LOW(TMLH);
650 LOWER_LOW(NILL);
651 LOWER_LOW(NILH);
652 LOWER_LOW(NILF);
653 LOWER_LOW(OILL);
654 LOWER_LOW(OILH);
655 LOWER_LOW(OILF);
656 LOWER_LOW(XILF);
657
658#undef LOWER_LOW
659
660#define LOWER_HIGH(NAME) \
661 case SystemZ::NAME##64: LoweredMI = lowerRIHigh(MI, SystemZ::NAME); break
662
663 LOWER_HIGH(IIHL);
664 LOWER_HIGH(IIHH);
665 LOWER_HIGH(TMHL);
666 LOWER_HIGH(TMHH);
667 LOWER_HIGH(NIHL);
668 LOWER_HIGH(NIHH);
669 LOWER_HIGH(NIHF);
670 LOWER_HIGH(OIHL);
671 LOWER_HIGH(OIHH);
672 LOWER_HIGH(OIHF);
673 LOWER_HIGH(XIHF);
674
675#undef LOWER_HIGH
676
677 case SystemZ::Serialize:
678 if (MF->getSubtarget<SystemZSubtarget>().hasFastSerialization())
679 LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
680 .addImm(14).addReg(SystemZ::R0D);
681 else
682 LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
683 .addImm(15).addReg(SystemZ::R0D);
684 break;
685
686 // We want to emit "j .+2" for traps, jumping to the relative immediate field
687 // of the jump instruction, which is an illegal instruction. We cannot emit a
688 // "." symbol, so create and emit a temp label before the instruction and use
689 // that instead.
690 case SystemZ::Trap: {
691 MCSymbol *DotSym = OutContext.createTempSymbol();
692 OutStreamer->emitLabel(DotSym);
693
695 const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
696 LoweredMI = MCInstBuilder(SystemZ::J)
697 .addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
698 }
699 break;
700
701 // Conditional traps will create a branch on condition instruction that jumps
702 // to the relative immediate field of the jump instruction. (eg. "jo .+2")
703 case SystemZ::CondTrap: {
704 MCSymbol *DotSym = OutContext.createTempSymbol();
705 OutStreamer->emitLabel(DotSym);
706
708 const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
709 LoweredMI = MCInstBuilder(SystemZ::BRC)
710 .addImm(MI->getOperand(0).getImm())
711 .addImm(MI->getOperand(1).getImm())
712 .addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
713 }
714 break;
715
716 case TargetOpcode::FENTRY_CALL:
717 LowerFENTRY_CALL(*MI, Lower);
718 return;
719
720 case TargetOpcode::STACKMAP:
721 LowerSTACKMAP(*MI);
722 return;
723
724 case TargetOpcode::PATCHPOINT:
725 LowerPATCHPOINT(*MI, Lower);
726 return;
727
728 case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
729 LowerPATCHABLE_FUNCTION_ENTER(*MI, Lower);
730 return;
731
732 case TargetOpcode::PATCHABLE_RET:
733 LowerPATCHABLE_RET(*MI, Lower);
734 return;
735
736 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
737 llvm_unreachable("PATCHABLE_FUNCTION_EXIT should never be emitted");
738
739 case TargetOpcode::PATCHABLE_TAIL_CALL:
740 // TODO: Define a trampoline `__xray_FunctionTailExit` and differentiate a
741 // normal function exit from a tail exit.
742 llvm_unreachable("Tail call is handled in the normal case. See comments "
743 "around this assert.");
744
745 case SystemZ::EXRL_Pseudo: {
746 unsigned TargetInsOpc = MI->getOperand(0).getImm();
747 Register LenMinus1Reg = MI->getOperand(1).getReg();
748 Register DestReg = MI->getOperand(2).getReg();
749 int64_t DestDisp = MI->getOperand(3).getImm();
750 Register SrcReg = MI->getOperand(4).getReg();
751 int64_t SrcDisp = MI->getOperand(5).getImm();
752
753 SystemZTargetStreamer *TS = getTargetStreamer();
754 MCInst ET = MCInstBuilder(TargetInsOpc)
755 .addReg(DestReg)
756 .addImm(DestDisp)
757 .addImm(1)
758 .addReg(SrcReg)
759 .addImm(SrcDisp);
760 SystemZTargetStreamer::MCInstSTIPair ET_STI(ET, &MF->getSubtarget());
761 auto [It, Inserted] = TS->EXRLTargets2Sym.try_emplace(ET_STI);
762 if (Inserted)
763 It->second = OutContext.createTempSymbol();
764 MCSymbol *DotSym = It->second;
768 MCInstBuilder(SystemZ::EXRL).addReg(LenMinus1Reg).addExpr(Dot));
769 return;
770 }
771
772 // EH_SjLj_Setup is a dummy terminator instruction of size 0.
773 // It is used to handle the clobber register for builtin setjmp.
774 case SystemZ::EH_SjLj_Setup:
775 return;
776
777 default:
778 Lower.lower(MI, LoweredMI);
779 break;
780 }
781 EmitToStreamer(*OutStreamer, LoweredMI);
782}
783
784// Emit the largest nop instruction smaller than or equal to NumBytes
785// bytes. Return the size of nop emitted.
787 unsigned NumBytes, const MCSubtargetInfo &STI) {
788 if (NumBytes < 2) {
789 llvm_unreachable("Zero nops?");
790 return 0;
791 }
792 else if (NumBytes < 4) {
793 OutStreamer.emitInstruction(
794 MCInstBuilder(SystemZ::BCRAsm).addImm(0).addReg(SystemZ::R0D), STI);
795 return 2;
796 }
797 else if (NumBytes < 6) {
798 OutStreamer.emitInstruction(
799 MCInstBuilder(SystemZ::BCAsm).addImm(0).addReg(0).addImm(0).addReg(0),
800 STI);
801 return 4;
802 }
803 else {
806 OutStreamer.emitLabel(DotSym);
807 OutStreamer.emitInstruction(
808 MCInstBuilder(SystemZ::BRCLAsm).addImm(0).addExpr(Dot), STI);
809 return 6;
810 }
811}
812
813void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
814 SystemZMCInstLower &Lower) {
815 MCContext &Ctx = MF->getContext();
816 if (MF->getFunction().hasFnAttribute("mrecord-mcount")) {
817 MCSymbol *DotSym = OutContext.createTempSymbol();
818 OutStreamer->pushSection();
819 OutStreamer->switchSection(
820 Ctx.getELFSection("__mcount_loc", ELF::SHT_PROGBITS, ELF::SHF_ALLOC));
821 OutStreamer->emitSymbolValue(DotSym, 8);
822 OutStreamer->popSection();
823 OutStreamer->emitLabel(DotSym);
824 }
825
826 if (MF->getFunction().hasFnAttribute("mnop-mcount")) {
828 return;
829 }
830
831 MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
832 const MCSymbolRefExpr *Op =
834 OutStreamer->emitInstruction(
835 MCInstBuilder(SystemZ::BRASL).addReg(SystemZ::R0D).addExpr(Op),
837}
838
839void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
840 auto *TII = MF->getSubtarget<SystemZSubtarget>().getInstrInfo();
841
842 unsigned NumNOPBytes = MI.getOperand(1).getImm();
843
844 auto &Ctx = OutStreamer->getContext();
845 MCSymbol *MILabel = Ctx.createTempSymbol();
846 OutStreamer->emitLabel(MILabel);
847
848 SM.recordStackMap(*MILabel, MI);
849 assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!");
850
851 // Scan ahead to trim the shadow.
852 unsigned ShadowBytes = 0;
853 const MachineBasicBlock &MBB = *MI.getParent();
855 ++MII;
856 while (ShadowBytes < NumNOPBytes) {
857 if (MII == MBB.end() ||
858 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
859 MII->getOpcode() == TargetOpcode::STACKMAP)
860 break;
861 ShadowBytes += TII->getInstSizeInBytes(*MII);
862 if (MII->isCall())
863 break;
864 ++MII;
865 }
866
867 // Emit nops.
868 while (ShadowBytes < NumNOPBytes)
869 ShadowBytes += EmitNop(OutContext, *OutStreamer, NumNOPBytes - ShadowBytes,
871}
872
873// Lower a patchpoint of the form:
874// [<def>], <id>, <numBytes>, <target>, <numArgs>
875void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
876 SystemZMCInstLower &Lower) {
877 auto &Ctx = OutStreamer->getContext();
878 MCSymbol *MILabel = Ctx.createTempSymbol();
879 OutStreamer->emitLabel(MILabel);
880
881 SM.recordPatchPoint(*MILabel, MI);
882 PatchPointOpers Opers(&MI);
883
884 unsigned EncodedBytes = 0;
885 const MachineOperand &CalleeMO = Opers.getCallTarget();
886
887 if (CalleeMO.isImm()) {
888 uint64_t CallTarget = CalleeMO.getImm();
889 if (CallTarget) {
890 unsigned ScratchIdx = -1;
891 unsigned ScratchReg = 0;
892 do {
893 ScratchIdx = Opers.getNextScratchIdx(ScratchIdx + 1);
894 ScratchReg = MI.getOperand(ScratchIdx).getReg();
895 } while (ScratchReg == SystemZ::R0D);
896
897 // Materialize the call target address
898 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::LLILF)
899 .addReg(ScratchReg)
900 .addImm(CallTarget & 0xFFFFFFFF));
901 EncodedBytes += 6;
902 if (CallTarget >> 32) {
903 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::IIHF)
904 .addReg(ScratchReg)
905 .addImm(CallTarget >> 32));
906 EncodedBytes += 6;
907 }
908
909 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BASR)
910 .addReg(SystemZ::R14D)
911 .addReg(ScratchReg));
912 EncodedBytes += 2;
913 }
914 } else if (CalleeMO.isGlobal()) {
915 const MCExpr *Expr = Lower.getExpr(CalleeMO, SystemZ::S_PLT);
916 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
917 .addReg(SystemZ::R14D)
918 .addExpr(Expr));
919 EncodedBytes += 6;
920 }
921
922 // Emit padding.
923 unsigned NumBytes = Opers.getNumPatchBytes();
924 assert(NumBytes >= EncodedBytes &&
925 "Patchpoint can't request size less than the length of a call.");
926 assert((NumBytes - EncodedBytes) % 2 == 0 &&
927 "Invalid number of NOP bytes requested!");
928 while (EncodedBytes < NumBytes)
929 EncodedBytes += EmitNop(OutContext, *OutStreamer, NumBytes - EncodedBytes,
931}
932
933void SystemZAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(
934 const MachineInstr &MI, SystemZMCInstLower &Lower) {
935
936 const MachineFunction &MF = *(MI.getParent()->getParent());
937 const Function &F = MF.getFunction();
938
939 // If patchable-function-entry is set, emit in-function nops here.
940 if (F.hasFnAttribute("patchable-function-entry")) {
941 unsigned Num;
942 // get M-N from function attribute (CodeGenFunction subtracts N
943 // from M to yield the correct patchable-function-entry).
944 if (F.getFnAttribute("patchable-function-entry")
945 .getValueAsString()
946 .getAsInteger(10, Num))
947 return;
948 // Emit M-N 2-byte nops. Use getNop() here instead of emitNops()
949 // to keep it aligned with the common code implementation emitting
950 // the prefix nops.
951 for (unsigned I = 0; I < Num; ++I)
952 EmitToStreamer(*OutStreamer, MF.getSubtarget().getInstrInfo()->getNop());
953 return;
954 }
955 // Otherwise, emit xray sled.
956 // .begin:
957 // j .end # -> stmg %r2, %r15, 16(%r15)
958 // nop
959 // llilf %2, FuncID
960 // brasl %r14, __xray_FunctionEntry@GOT
961 // .end:
962 //
963 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
964 // of instructions change.
965 bool HasVectorFeature =
966 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector) &&
967 !TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureSoftFloat);
968 MCSymbol *FuncEntry = OutContext.getOrCreateSymbol(
969 HasVectorFeature ? "__xray_FunctionEntryVec" : "__xray_FunctionEntry");
970 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
971 MCSymbol *EndOfSled = OutContext.createTempSymbol();
972 OutStreamer->emitLabel(BeginOfSled);
974 MCInstBuilder(SystemZ::J)
975 .addExpr(MCSymbolRefExpr::create(EndOfSled, OutContext)));
978 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
979 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
980 .addReg(SystemZ::R14D)
982 FuncEntry, SystemZ::S_PLT, OutContext)));
983 OutStreamer->emitLabel(EndOfSled);
984 recordSled(BeginOfSled, MI, SledKind::FUNCTION_ENTER, 2);
985}
986
987void SystemZAsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI,
988 SystemZMCInstLower &Lower) {
989 unsigned OpCode = MI.getOperand(0).getImm();
990 MCSymbol *FallthroughLabel = nullptr;
991 if (OpCode == SystemZ::CondReturn) {
992 FallthroughLabel = OutContext.createTempSymbol();
993 int64_t Cond0 = MI.getOperand(1).getImm();
994 int64_t Cond1 = MI.getOperand(2).getImm();
995 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRC)
996 .addImm(Cond0)
997 .addImm(Cond1 ^ Cond0)
999 FallthroughLabel, OutContext)));
1000 }
1001 // .begin:
1002 // br %r14 # -> stmg %r2, %r15, 24(%r15)
1003 // nop
1004 // nop
1005 // llilf %2,FuncID
1006 // j __xray_FunctionExit@GOT
1007 //
1008 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
1009 // of instructions change.
1010 bool HasVectorFeature =
1011 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector) &&
1012 !TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureSoftFloat);
1013 MCSymbol *FuncExit = OutContext.getOrCreateSymbol(
1014 HasVectorFeature ? "__xray_FunctionExitVec" : "__xray_FunctionExit");
1015 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
1016 OutStreamer->emitLabel(BeginOfSled);
1018 MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D));
1021 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
1022 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::J)
1023 .addExpr(MCSymbolRefExpr::create(
1024 FuncExit, SystemZ::S_PLT, OutContext)));
1025 if (FallthroughLabel)
1026 OutStreamer->emitLabel(FallthroughLabel);
1027 recordSled(BeginOfSled, MI, SledKind::FUNCTION_EXIT, 2);
1028}
1029
1030// The *alignment* of 128-bit vector types is different between the software
1031// and hardware vector ABIs. If the there is an externally visible use of a
1032// vector type in the module it should be annotated with an attribute.
1033void SystemZAsmPrinter::emitAttributes(Module &M) {
1034 if (M.getModuleFlag("s390x-visible-vector-ABI")) {
1035 bool HasVectorFeature =
1036 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector);
1037 OutStreamer->emitGNUAttribute(8, HasVectorFeature ? 2 : 1);
1038 }
1039}
1040
1041// Convert a SystemZ-specific constant pool modifier into the associated
1042// specifier.
1044 switch (Modifier) {
1045 case SystemZCP::TLSGD:
1046 return SystemZ::S_TLSGD;
1047 case SystemZCP::TLSLDM:
1048 return SystemZ::S_TLSLDM;
1049 case SystemZCP::DTPOFF:
1050 return SystemZ::S_DTPOFF;
1051 case SystemZCP::NTPOFF:
1052 return SystemZ::S_NTPOFF;
1053 }
1054 llvm_unreachable("Invalid SystemCPModifier!");
1055}
1056
1059 auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
1060
1061 const MCExpr *Expr = MCSymbolRefExpr::create(
1062 getSymbol(ZCPV->getGlobalValue()),
1063 getSpecifierFromModifier(ZCPV->getModifier()), OutContext);
1064 uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
1065
1066 OutStreamer->emitValue(Expr, Size);
1067}
1068
1069// Emit the ctor or dtor list taking into account the init priority.
1071 const Constant *List, bool IsCtor) {
1072 if (!TM.getTargetTriple().isOSBinFormatGOFF())
1073 return AsmPrinter::emitXXStructorList(DL, List, IsCtor);
1074
1075 SmallVector<Structor, 8> Structors;
1076 preprocessXXStructorList(DL, List, Structors);
1077 if (Structors.empty())
1078 return;
1079
1080 const Align Align = llvm::Align(4);
1081 const TargetLoweringObjectFileGOFF &Obj =
1082 static_cast<const TargetLoweringObjectFileGOFF &>(getObjFileLowering());
1083 for (Structor &S : Structors) {
1084 MCSectionGOFF *Section =
1085 static_cast<MCSectionGOFF *>(Obj.getStaticXtorSection(S.Priority));
1086 OutStreamer->switchSection(Section);
1087 if (OutStreamer->getCurrentSection() != OutStreamer->getPreviousSection())
1089
1090 // The priority is provided as an input to getStaticXtorSection(), and is
1091 // recalculated within that function as `Prio` going to going into the
1092 // PR section.
1093 // This priority retrieved via the `SortKey` below is the recalculated
1094 // Priority.
1095 uint32_t XtorPriority = Section->getPRAttributes().SortKey;
1096
1097 const GlobalValue *GV = dyn_cast<GlobalValue>(S.Func->stripPointerCasts());
1098 assert(GV && "C++ xxtor pointer was not a GlobalValue!");
1099 MCSymbolGOFF *Symbol = static_cast<MCSymbolGOFF *>(getSymbol(GV));
1100
1101 // @@SQINIT entry: { unsigned prio; void (*ctor)(); void (*dtor)(); }
1102
1103 unsigned PointerSizeInBytes = DL.getPointerSize();
1104
1105 auto &Ctx = OutStreamer->getContext();
1106 const MCExpr *ADAFuncRefExpr;
1107 unsigned SlotKind = SystemZII::MO_ADA_DIRECT_FUNC_DESC;
1108
1109 MCSectionGOFF *ADASection =
1110 static_cast<MCSectionGOFF *>(Obj.getADASection());
1111 assert(ADASection && "ADA section must exist for GOFF targets!");
1112 const MCSymbol *ADASym = ADASection->getBeginSymbol();
1113 assert(ADASym && "ADA symbol should already be set!");
1114
1115 ADAFuncRefExpr = MCBinaryExpr::createAdd(
1118 MCConstantExpr::create(ADATable.insert(Symbol, SlotKind), Ctx), Ctx);
1119
1120 emitInt32(XtorPriority);
1121 if (IsCtor) {
1122 OutStreamer->emitValue(ADAFuncRefExpr, PointerSizeInBytes);
1123 OutStreamer->emitIntValue(0, PointerSizeInBytes);
1124 } else {
1125 OutStreamer->emitIntValue(0, PointerSizeInBytes);
1126 OutStreamer->emitValue(ADAFuncRefExpr, PointerSizeInBytes);
1127 }
1128 }
1129}
1130
1131static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
1132 raw_ostream &OS) {
1133 const char *RegName;
1134 if (MAI->getAssemblerDialect() == AD_HLASM) {
1136 // Skip register prefix so that only register number is left
1137 assert(isalpha(RegName[0]) && isdigit(RegName[1]));
1138 OS << (RegName + 1);
1139 } else {
1141 OS << '%' << RegName;
1142 }
1143}
1144
1145static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {
1146 if (!Reg)
1147 OS << '0';
1148 else
1150}
1151
1152static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
1153 raw_ostream &OS) {
1154 if (MCOp.isReg())
1155 printReg(MCOp.getReg(), MAI, OS);
1156 else if (MCOp.isImm())
1157 OS << MCOp.getImm();
1158 else if (MCOp.isExpr())
1159 MAI->printExpr(OS, *MCOp.getExpr());
1160 else
1161 llvm_unreachable("Invalid operand");
1162}
1163
1164static void printAddress(const MCAsmInfo *MAI, unsigned Base,
1165 const MCOperand &DispMO, unsigned Index,
1166 raw_ostream &OS) {
1167 printOperand(DispMO, MAI, OS);
1168 if (Base || Index) {
1169 OS << '(';
1170 if (Index) {
1171 printFormattedRegName(MAI, Index, OS);
1172 if (Base)
1173 OS << ',';
1174 }
1175 if (Base)
1177 OS << ')';
1178 }
1179}
1180
1182 const char *ExtraCode,
1183 raw_ostream &OS) {
1184 const MCRegisterInfo &MRI = *TM.getMCRegisterInfo();
1185 const MachineOperand &MO = MI->getOperand(OpNo);
1186 MCOperand MCOp;
1187 if (ExtraCode) {
1188 if (ExtraCode[0] == 'N' && !ExtraCode[1] && MO.isReg() &&
1189 SystemZ::GR128BitRegClass.contains(MO.getReg()))
1190 MCOp =
1191 MCOperand::createReg(MRI.getSubReg(MO.getReg(), SystemZ::subreg_l64));
1192 else
1193 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
1194 } else {
1195 SystemZMCInstLower Lower(MF->getContext(), *this);
1196 MCOp = Lower.lowerOperand(MO);
1197 }
1198 printOperand(MCOp, MAI, OS);
1199 return false;
1200}
1201
1203 unsigned OpNo,
1204 const char *ExtraCode,
1205 raw_ostream &OS) {
1206 if (ExtraCode && ExtraCode[0] && !ExtraCode[1]) {
1207 switch (ExtraCode[0]) {
1208 case 'A':
1209 // Unlike EmitMachineNode(), EmitSpecialNode(INLINEASM) does not call
1210 // setMemRefs(), so MI->memoperands() is empty and the alignment
1211 // information is not available.
1212 return false;
1213 case 'O':
1214 OS << MI->getOperand(OpNo + 1).getImm();
1215 return false;
1216 case 'R':
1217 ::printReg(MI->getOperand(OpNo).getReg(), MAI, OS);
1218 return false;
1219 }
1220 }
1221 printAddress(MAI, MI->getOperand(OpNo).getReg(),
1222 MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
1223 MI->getOperand(OpNo + 2).getReg(), OS);
1224 return false;
1225}
1226
1228 auto TT = OutContext.getTargetTriple();
1229 if (TT.isOSzOS()) {
1230 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1231 for (auto &Info : DeferredPPA1)
1232 emitPPA1(Info);
1233 emitADASection();
1234 emitIDRLSection(M);
1235 // On z/OS, we need to associate an external data reference with an ED
1236 // symbol, for which we use the the ED of the ADA. We also need to mark the
1237 // reference as being to data, otherwise we cannot bind with code generated
1238 // by XL.
1239 for (auto &GO : M.global_objects()) {
1240 if (auto *GV = dyn_cast<GlobalVariable>(&GO)) {
1241 if (!GV->hasInitializer()) {
1242 MCSymbol *Sym = getSymbol(GV);
1243 getTargetStreamer()->emitADA(
1244 Sym, OutContext.getObjectFileInfo()->getADASection());
1245 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
1246 }
1247 }
1248 }
1249 }
1250 emitAttributes(M);
1251}
1252
1253void SystemZAsmPrinter::emitADASection() {
1254 OutStreamer->pushSection();
1255
1256 const unsigned PointerSize = getDataLayout().getPointerSize();
1257 OutStreamer->switchSection(getObjFileLowering().getADASection());
1258
1259 unsigned EmittedBytes = 0;
1260 for (auto &Entry : ADATable.getTable()) {
1261 const MCSymbol *Sym;
1262 unsigned SlotKind;
1263 std::tie(Sym, SlotKind) = Entry.first;
1264 unsigned Offset = Entry.second;
1265 assert(Offset == EmittedBytes && "Offset not as expected");
1266 (void)EmittedBytes;
1267#define EMIT_COMMENT(Str) \
1268 OutStreamer->AddComment(Twine("Offset ") \
1269 .concat(utostr(Offset)) \
1270 .concat(" " Str " ") \
1271 .concat(Sym->getName()));
1272 switch (SlotKind) {
1274 // Language Environment DLL logic requires function descriptors, for
1275 // imported functions, that are placed in the ADA to be 8 byte aligned.
1276 EMIT_COMMENT("function descriptor of");
1277 OutStreamer->emitValue(
1280 PointerSize);
1281 OutStreamer->emitValue(
1284 PointerSize);
1285 EmittedBytes += PointerSize * 2;
1286 break;
1288 EMIT_COMMENT("pointer to data symbol");
1289 OutStreamer->emitValue(
1292 PointerSize);
1293 EmittedBytes += PointerSize;
1294 break;
1297 Twine(Sym->getName()).concat("@indirect"));
1298 OutStreamer->emitSymbolAttribute(Alias, MCSA_IndirectSymbol);
1299 OutStreamer->emitSymbolAttribute(Alias, MCSA_ELF_TypeFunction);
1300 OutStreamer->emitSymbolAttribute(Alias, MCSA_Global);
1301 OutStreamer->emitSymbolAttribute(Alias, MCSA_Extern);
1302 MCSymbolGOFF *GOFFSym =
1303 static_cast<llvm::MCSymbolGOFF *>(const_cast<llvm::MCSymbol *>(Sym));
1304 getTargetStreamer()->emitExternalName(Alias, GOFFSym->getExternalName());
1305 EMIT_COMMENT("pointer to function descriptor");
1306 OutStreamer->emitValue(
1309 PointerSize);
1310 EmittedBytes += PointerSize;
1311 break;
1312 }
1313 default:
1314 llvm_unreachable("Unexpected slot kind");
1315 }
1316#undef EMIT_COMMENT
1317 }
1318 OutStreamer->popSection();
1319}
1320
1321static std::string getProductID(Module &M) {
1322 std::string ProductID;
1323 if (auto *MD = M.getModuleFlag("zos_product_id"))
1324 ProductID = cast<MDString>(MD)->getString().str();
1325 if (ProductID.empty())
1326 ProductID = "LLVM";
1327 return ProductID;
1328}
1329
1331 if (auto *VersionVal = mdconst::extract_or_null<ConstantInt>(
1332 M.getModuleFlag("zos_product_major_version")))
1333 return VersionVal->getZExtValue();
1334 return LLVM_VERSION_MAJOR;
1335}
1336
1338 if (auto *ReleaseVal = mdconst::extract_or_null<ConstantInt>(
1339 M.getModuleFlag("zos_product_minor_version")))
1340 return ReleaseVal->getZExtValue();
1341 return LLVM_VERSION_MINOR;
1342}
1343
1345 if (auto *PatchVal = mdconst::extract_or_null<ConstantInt>(
1346 M.getModuleFlag("zos_product_patchlevel")))
1347 return PatchVal->getZExtValue();
1348 return LLVM_VERSION_PATCH;
1349}
1350
1351static time_t getTranslationTime(Module &M) {
1352 std::time_t Time = 0;
1354 M.getModuleFlag("zos_translation_time"))) {
1355 long SecondsSinceEpoch = Val->getSExtValue();
1356 Time = static_cast<time_t>(SecondsSinceEpoch);
1357 }
1358 return Time;
1359}
1360
1361void SystemZAsmPrinter::emitIDRLSection(Module &M) {
1362 OutStreamer->pushSection();
1363 OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
1364 constexpr unsigned IDRLDataLength = 30;
1365 std::time_t Time = getTranslationTime(M);
1366
1367 uint32_t ProductVersion = getProductVersion(M);
1368 uint32_t ProductRelease = getProductRelease(M);
1369
1370 std::string ProductID = getProductID(M);
1371
1372 SmallString<IDRLDataLength + 1> TempStr;
1373 raw_svector_ostream O(TempStr);
1374 O << formatv("{0,-10}{1,0-2:d}{2,0-2:d}{3:%Y%m%d%H%M%S}{4,0-2}",
1375 ProductID.substr(0, 10).c_str(), ProductVersion, ProductRelease,
1376 llvm::sys::toUtcTime(Time), "0");
1377 SmallString<IDRLDataLength> Data;
1379
1380 OutStreamer->emitInt8(0); // Reserved.
1381 OutStreamer->emitInt8(3); // Format.
1382 OutStreamer->emitInt16(IDRLDataLength); // Length.
1383 OutStreamer->emitBytes(Data.str());
1384 OutStreamer->popSection();
1385}
1386
1388 if (TM.getTargetTriple().isOSzOS()) {
1389 // Emit symbol for the end of function if the z/OS target streamer
1390 // is used. This is needed to calculate the size of the function.
1391 OutStreamer->emitLabel(DeferredPPA1.back().FnEnd);
1392 }
1393}
1394
1395static void emitPPA1Flags(std::unique_ptr<MCStreamer> &OutStreamer, bool VarArg,
1396 bool StackProtector, bool FPRMask, bool VRMask,
1397 bool EHBlock, bool HasArgAreaLength, bool HasName) {
1398 enum class PPA1Flag1 : uint8_t {
1399 DSA64Bit = (0x80 >> 0),
1400 VarArg = (0x80 >> 7),
1402 };
1403 enum class PPA1Flag2 : uint8_t {
1404 ExternalProcedure = (0x80 >> 0),
1405 STACKPROTECTOR = (0x80 >> 3),
1406 LLVM_MARK_AS_BITMASK_ENUM(ExternalProcedure)
1407 };
1408 enum class PPA1Flag3 : uint8_t {
1409 HasArgAreaLength = (0x80 >> 1),
1410 FPRMask = (0x80 >> 2),
1411 LLVM_MARK_AS_BITMASK_ENUM(HasArgAreaLength)
1412 };
1413 enum class PPA1Flag4 : uint8_t {
1414 EPMOffsetPresent = (0x80 >> 0),
1415 VRMask = (0x80 >> 2),
1416 EHBlock = (0x80 >> 3),
1417 ProcedureNamePresent = (0x80 >> 7),
1418 LLVM_MARK_AS_BITMASK_ENUM(EPMOffsetPresent)
1419 };
1420
1421 // Declare optional section flags that can be modified.
1422 auto Flags1 = PPA1Flag1(0);
1423 auto Flags2 = PPA1Flag2::ExternalProcedure;
1424 auto Flags3 = PPA1Flag3(0);
1425 auto Flags4 = PPA1Flag4::EPMOffsetPresent;
1426
1427 Flags1 |= PPA1Flag1::DSA64Bit;
1428
1429 if (VarArg)
1430 Flags1 |= PPA1Flag1::VarArg;
1431
1432 if (StackProtector)
1433 Flags2 |= PPA1Flag2::STACKPROTECTOR;
1434
1435 if (HasArgAreaLength)
1436 Flags3 |= PPA1Flag3::HasArgAreaLength; // Add emit ArgAreaLength flag.
1437
1438 // SavedGPRMask, SavedFPRMask, and SavedVRMask are precomputed in.
1439 if (FPRMask)
1440 Flags3 |= PPA1Flag3::FPRMask; // Add emit FPR mask flag.
1441
1442 if (VRMask)
1443 Flags4 |= PPA1Flag4::VRMask; // Add emit VR mask flag.
1444
1445 if (EHBlock)
1446 Flags4 |= PPA1Flag4::EHBlock; // Add optional EH block.
1447
1448 if (HasName)
1449 Flags4 |= PPA1Flag4::ProcedureNamePresent; // Add optional name block.
1450
1451 OutStreamer->AddComment("PPA1 Flags 1");
1452 if ((Flags1 & PPA1Flag1::DSA64Bit) == PPA1Flag1::DSA64Bit)
1453 OutStreamer->AddComment(" Bit 0: 1 = 64-bit DSA");
1454 else
1455 OutStreamer->AddComment(" Bit 0: 0 = 32-bit DSA");
1456 if ((Flags1 & PPA1Flag1::VarArg) == PPA1Flag1::VarArg)
1457 OutStreamer->AddComment(" Bit 7: 1 = Vararg function");
1458 OutStreamer->emitInt8(static_cast<uint8_t>(Flags1)); // Flags 1.
1459
1460 OutStreamer->AddComment("PPA1 Flags 2");
1461 if ((Flags2 & PPA1Flag2::ExternalProcedure) == PPA1Flag2::ExternalProcedure)
1462 OutStreamer->AddComment(" Bit 0: 1 = External procedure");
1463 if ((Flags2 & PPA1Flag2::STACKPROTECTOR) == PPA1Flag2::STACKPROTECTOR)
1464 OutStreamer->AddComment(" Bit 3: 1 = STACKPROTECT is enabled");
1465 else
1466 OutStreamer->AddComment(" Bit 3: 0 = STACKPROTECT is not enabled");
1467 OutStreamer->emitInt8(static_cast<uint8_t>(Flags2)); // Flags 2.
1468
1469 OutStreamer->AddComment("PPA1 Flags 3");
1470 if ((Flags3 & PPA1Flag3::HasArgAreaLength) == PPA1Flag3::HasArgAreaLength)
1471 OutStreamer->AddComment(
1472 " Bit 1: 1 = Argument Area Length is in optional area");
1473 if ((Flags3 & PPA1Flag3::FPRMask) == PPA1Flag3::FPRMask)
1474 OutStreamer->AddComment(" Bit 2: 1 = FP Reg Mask is in optional area");
1475 OutStreamer->emitInt8(
1476 static_cast<uint8_t>(Flags3)); // Flags 3 (optional sections).
1477
1478 OutStreamer->AddComment("PPA1 Flags 4");
1479 if ((Flags4 & PPA1Flag4::VRMask) == PPA1Flag4::VRMask)
1480 OutStreamer->AddComment(" Bit 2: 1 = Vector Reg Mask is in optional area");
1481 if ((Flags4 & PPA1Flag4::EHBlock) == PPA1Flag4::EHBlock)
1482 OutStreamer->AddComment(" Bit 3: 1 = C++ EH block");
1483 if ((Flags4 & PPA1Flag4::ProcedureNamePresent) ==
1484 PPA1Flag4::ProcedureNamePresent)
1485 OutStreamer->AddComment(" Bit 7: 1 = Name Length and Name");
1486 OutStreamer->emitInt8(static_cast<uint8_t>(
1487 Flags4)); // Flags 4 (optional sections, always emit these).
1488}
1489
1490static void emitPPA1Name(std::unique_ptr<MCStreamer> &OutStreamer,
1491 StringRef OutName) {
1492 size_t NameSize = OutName.size();
1493 uint16_t OutSize;
1494 if (NameSize < UINT16_MAX) {
1495 OutSize = static_cast<uint16_t>(NameSize);
1496 } else {
1497 OutName = OutName.substr(0, UINT16_MAX);
1498 OutSize = UINT16_MAX;
1499 }
1500 // Emit padding to ensure that the next optional field word-aligned.
1501 uint8_t ExtraZeros = 4 - ((2 + OutSize) % 4);
1502
1503 SmallString<512> OutnameConv;
1504 ConverterEBCDIC::convertToEBCDIC(OutName, OutnameConv);
1505 OutName = OutnameConv.str();
1506
1507 OutStreamer->AddComment("Length of Name");
1508 OutStreamer->emitInt16(OutSize);
1509 OutStreamer->AddComment("Name of Function");
1510 OutStreamer->emitBytes(OutName);
1511 OutStreamer->emitZeros(ExtraZeros);
1512}
1513
1514void SystemZAsmPrinter::emitPPA1(PPA1Info &Info) {
1515 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1516
1517 // Optional Argument Area Length.
1518 // Note: This represents the length of the argument area that we reserve
1519 // in our stack for setting up arguments for calls to other
1520 // routines. If this optional field is not set, LE will reserve
1521 // 128 bytes for the argument area. This optional field is
1522 // created if greater than 128 bytes is required - to guarantee
1523 // the required space is reserved on stack extension in the new
1524 // extension. This optional field is also created if the
1525 // routine has alloca(). This may reduce stack space
1526 // if alloca() call causes a stack extension.
1527 bool HasArgAreaLength = (Info.AllocaReg != 0) || (Info.CallFrameSize > 128);
1528
1529 // Emit PPA1 section.
1530 OutStreamer->AddComment("PPA1");
1531 OutStreamer->emitLabel(Info.PPA1);
1532 OutStreamer->AddComment("Version");
1533 OutStreamer->emitInt8(0x02); // Version.
1534 OutStreamer->AddComment("LE Signature X'CE'");
1535 OutStreamer->emitInt8(0xCE); // CEL signature.
1536 OutStreamer->AddComment("Saved GPR Mask");
1537 OutStreamer->emitInt16(Info.SavedGPRMask);
1538 OutStreamer->AddComment("Offset to PPA2");
1539 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, Info.PPA1, 4);
1540
1541 emitPPA1Flags(OutStreamer, Info.IsVarArg, Info.HasStackProtector,
1542 Info.SavedFPRMask != 0, Info.SavedVRMask != 0,
1543 Info.PersonalityRoutine != nullptr, HasArgAreaLength,
1544 Info.Name.size() > 0);
1545
1546 OutStreamer->AddComment("Length/4 of Parms");
1547 OutStreamer->emitInt16(
1548 static_cast<uint16_t>(Info.SizeOfFnParams / 4)); // Parms/4.
1549 OutStreamer->AddComment("Length of Code");
1550 OutStreamer->emitAbsoluteSymbolDiff(Info.FnEnd, Info.EPMarker, 4);
1551
1552 if (HasArgAreaLength) {
1553 OutStreamer->AddComment("Argument Area Length");
1554 OutStreamer->emitInt32(Info.CallFrameSize);
1555 }
1556
1557 // Emit saved FPR mask and offset to FPR save area (0x20 of flags 3).
1558 if (Info.SavedFPRMask) {
1559 OutStreamer->AddComment("FPR mask");
1560 OutStreamer->emitInt16(Info.SavedFPRMask);
1561 OutStreamer->AddComment("AR mask");
1562 OutStreamer->emitInt16(0); // AR Mask, unused currently.
1563 OutStreamer->AddComment("FPR Save Area Locator");
1564 uint64_t FPRSaveAreaOffset = Info.OffsetFPR;
1565 assert(FPRSaveAreaOffset < 0x10000000 && "Offset out of range");
1566 FPRSaveAreaOffset &= 0x0FFFFFFF; // Lose top 4 bits.
1567 OutStreamer->AddComment(
1568 Twine(" Bit 0-3: Register R").concat(utostr(Info.FrameReg)).str());
1569 OutStreamer->AddComment(
1570 Twine(" Bit 4-31: Offset ").concat(utostr(FPRSaveAreaOffset)).str());
1571 OutStreamer->emitInt32(FPRSaveAreaOffset |
1572 (Info.FrameReg << 28)); // Offset to FPR save area
1573 // with register to add
1574 // value to (alloca reg).
1575 }
1576
1577 // Emit saved VR mask to VR save area.
1578 if (Info.SavedVRMask) {
1579 OutStreamer->AddComment("VR mask");
1580 OutStreamer->emitInt8(Info.SavedVRMask);
1581 OutStreamer->emitInt8(0); // Reserved.
1582 OutStreamer->emitInt16(0); // Also reserved.
1583 uint64_t VRSaveAreaOffset = Info.OffsetVR;
1584 assert(VRSaveAreaOffset < 0x10000000 && "Offset out of range");
1585 VRSaveAreaOffset &= 0x0FFFFFFF; // Lose top 4 bits.
1586 OutStreamer->AddComment("VR Save Area Locator");
1587 OutStreamer->AddComment(
1588 Twine(" Bit 0-3: Register R").concat(utostr(Info.FrameReg)).str());
1589 OutStreamer->AddComment(
1590 Twine(" Bit 4-31: Offset ").concat(utostr(VRSaveAreaOffset)).str());
1591 OutStreamer->emitInt32(VRSaveAreaOffset | (Info.FrameReg << 28));
1592 }
1593
1594 // Emit C++ EH information block.
1595 if (Info.PersonalityRoutine) {
1596 OutStreamer->AddComment("Version");
1597 OutStreamer->emitInt32(1);
1598 OutStreamer->AddComment("Flags");
1599 OutStreamer->emitInt32(0); // LSDA field is a WAS offset
1600 OutStreamer->AddComment("Personality routine");
1601 OutStreamer->emitInt64(ADATable.insert(
1602 Info.PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC));
1603 OutStreamer->AddComment("LSDA location");
1604 OutStreamer->emitInt64(
1605 ADATable.insert(Info.GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR));
1606 }
1607
1608 // Emit name length and name optional section (0x01 of flags 4)
1609 if (Info.Name.size())
1611
1612 // Emit offset to entry point optional section (0x80 of flags 4).
1613 OutStreamer->emitAbsoluteSymbolDiff(Info.EPMarker, Info.PPA1, 4);
1614}
1615
1616void SystemZAsmPrinter::calculatePPA1() {
1617 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1618
1619 PPA1Info Info;
1620
1621 const TargetRegisterInfo *TRI = MF->getRegInfo().getTargetRegisterInfo();
1622 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1623
1624 const SystemZMachineFunctionInfo *ZFI =
1625 MF->getInfo<SystemZMachineFunctionInfo>();
1626 const auto *ZFL = static_cast<const SystemZXPLINKFrameLowering *>(
1627 Subtarget.getFrameLowering());
1628 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1629
1630 // Get saved GPR/FPR/VPR masks.
1631 const std::vector<CalleeSavedInfo> &CSI = MFFrame.getCalleeSavedInfo();
1632 uint16_t SavedGPRMask = 0;
1633 uint16_t SavedFPRMask = 0;
1634 uint8_t SavedVRMask = 0;
1635 int64_t OffsetFPR = 0;
1636 int64_t OffsetVR = 0;
1637 const int64_t TopOfStack =
1638 MFFrame.getOffsetAdjustment() + MFFrame.getStackSize();
1639
1640 // Loop over the spilled registers. The CalleeSavedInfo can't be used because
1641 // it does not contain all spilled registers.
1642 for (unsigned I = ZFI->getSpillGPRRegs().LowGPR,
1643 E = ZFI->getSpillGPRRegs().HighGPR;
1644 I && E && I <= E; ++I) {
1645 unsigned V = TRI->getEncodingValue((Register)I);
1646 assert(V < 16 && "GPR index out of range");
1647 SavedGPRMask |= 1 << (15 - V);
1648 }
1649
1650 for (auto &CS : CSI) {
1651 unsigned Reg = CS.getReg();
1652 unsigned I = TRI->getEncodingValue(Reg);
1653
1654 if (SystemZ::FP64BitRegClass.contains(Reg)) {
1655 assert(I < 16 && "FPR index out of range");
1656 SavedFPRMask |= 1 << (15 - I);
1657 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1658 if (Temp < OffsetFPR)
1659 OffsetFPR = Temp;
1660 } else if (SystemZ::VR128BitRegClass.contains(Reg)) {
1661 assert(I >= 16 && I <= 23 && "VPR index out of range");
1662 unsigned BitNum = I - 16;
1663 SavedVRMask |= 1 << (7 - BitNum);
1664 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1665 if (Temp < OffsetVR)
1666 OffsetVR = Temp;
1667 }
1668 }
1669
1670 // Adjust the offset.
1671 OffsetFPR += (OffsetFPR < 0) ? TopOfStack : 0;
1672 OffsetVR += (OffsetVR < 0) ? TopOfStack : 0;
1673
1674 // Get alloca register.
1675 uint8_t FrameReg = TRI->getEncodingValue(TRI->getFrameRegister(*MF));
1676 uint8_t AllocaReg = ZFL->hasFP(*MF) ? FrameReg : 0;
1677 assert(AllocaReg < 16 && "Can't have alloca register larger than 15");
1678
1679 MCSymbol *PersonalityRoutine = nullptr;
1680 MCSymbol *GCCEH = nullptr;
1681 if (!MF->getLandingPads().empty()) {
1682 const Function *Per = dyn_cast<Function>(
1683 MF->getFunction().getPersonalityFn()->stripPointerCasts());
1684 PersonalityRoutine = Per ? MF->getTarget().getSymbol(Per) : nullptr;
1685 assert(PersonalityRoutine && "Missing personality routine");
1686
1687 GCCEH = MF->getContext().getOrCreateSymbol(Twine("GCC_except_table") +
1688 Twine(MF->getFunctionNumber()));
1689 }
1690
1691 // Get the name of the function, with suffix _.
1692 std::string N(MF->getFunction().hasName()
1693 ? Twine(MF->getFunction().getName()).concat("_").str()
1694 : "");
1695
1696 // Save the calculated values.
1697 if (MF->getFunction().hasName())
1698 Info.Name = MF->getFunction().getName();
1699 Info.PPA1 = OutContext.createTempSymbol(Twine("PPA1_").concat(N).str(), true);
1700 Info.EPMarker =
1701 OutContext.createTempSymbol(Twine("EPM_").concat(N).str(), true);
1702 Info.FnEnd = OutContext.createTempSymbol(Twine(N).concat("end_").str());
1703 Info.PersonalityRoutine = PersonalityRoutine;
1704 Info.GCCEH = GCCEH;
1705 Info.OffsetFPR = OffsetFPR;
1706 Info.OffsetVR = OffsetVR;
1707 Info.CallFrameSize = MFFrame.getMaxCallFrameSize();
1708 Info.SizeOfFnParams = ZFI->getSizeOfFnParams();
1709 Info.SavedGPRMask = SavedGPRMask;
1710 Info.SavedFPRMask = SavedFPRMask;
1711 Info.SavedVRMask = SavedVRMask;
1712 Info.FrameReg = FrameReg;
1713 Info.AllocaReg = AllocaReg;
1714 Info.IsVarArg = MF->getFunction().isVarArg();
1715 Info.HasStackProtector = MFFrame.hasStackProtectorIndex();
1716
1717 DeferredPPA1.push_back(Info);
1718}
1719
1721 if (TM.getTargetTriple().isOSzOS())
1722 emitPPA2(M);
1724}
1725
1726void SystemZAsmPrinter::emitPPA2(Module &M) {
1727 OutStreamer->pushSection();
1728 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1729 MCContext &OutContext = OutStreamer->getContext();
1730 // Make CELQSTRT symbol.
1731 const char *StartSymbolName = "CELQSTRT";
1732 MCSymbol *CELQSTRT = OutContext.getOrCreateSymbol(StartSymbolName);
1733 OutStreamer->emitSymbolAttribute(CELQSTRT, MCSA_OSLinkage);
1734 OutStreamer->emitSymbolAttribute(CELQSTRT, MCSA_Global);
1735
1736 // Create symbol and assign to class field for use in PPA1.
1737 PPA2Sym = OutContext.createTempSymbol("PPA2", false);
1738 MCSymbol *DateVersionSym = OutContext.createTempSymbol("DVS", false);
1739
1740 std::time_t Time = getTranslationTime(M);
1741 SmallString<14> CompilationTimeEBCDIC, CompilationTime;
1742 CompilationTime = formatv("{0:%Y%m%d%H%M%S}", llvm::sys::toUtcTime(Time));
1743
1744 uint32_t ProductVersion = getProductVersion(M),
1745 ProductRelease = getProductRelease(M),
1746 ProductPatch = getProductPatch(M);
1747
1748 SmallString<6> VersionEBCDIC, Version;
1749 Version = formatv("{0,0-2:d}{1,0-2:d}{2,0-2:d}", ProductVersion,
1750 ProductRelease, ProductPatch);
1751
1752 ConverterEBCDIC::convertToEBCDIC(CompilationTime, CompilationTimeEBCDIC);
1754
1755 enum class PPA2MemberId : uint8_t {
1756 // See z/OS Language Environment Vendor Interfaces v2r5, p.23, for
1757 // complete list. Only the C runtime is supported by this backend.
1758 LE_C_Runtime = 3,
1759 };
1760 enum class PPA2MemberSubId : uint8_t {
1761 // List of languages using the LE C runtime implementation.
1762 C = 0x00,
1763 CXX = 0x01,
1764 Swift = 0x03,
1765 Go = 0x60,
1766 LLVMBasedLang = 0xe7,
1767 };
1768 // PPA2 Flags
1769 enum class PPA2Flags : uint8_t {
1770 CompileForBinaryFloatingPoint = 0x80,
1771 CompiledWithXPLink = 0x01,
1772 CompiledUnitASCII = 0x04,
1773 HasServiceInfo = 0x20,
1774 };
1775
1776 PPA2MemberSubId MemberSubId = PPA2MemberSubId::LLVMBasedLang;
1777 if (auto *MD = M.getModuleFlag("zos_cu_language")) {
1778 StringRef Language = cast<MDString>(MD)->getString();
1779 MemberSubId = StringSwitch<PPA2MemberSubId>(Language)
1780 .Case("C", PPA2MemberSubId::C)
1781 .Case("C++", PPA2MemberSubId::CXX)
1782 .Case("Swift", PPA2MemberSubId::Swift)
1783 .Case("Go", PPA2MemberSubId::Go)
1784 .Default(PPA2MemberSubId::LLVMBasedLang);
1785 }
1786
1787 // Emit PPA2 section.
1788 OutStreamer->emitLabel(PPA2Sym);
1789 OutStreamer->emitInt8(static_cast<uint8_t>(PPA2MemberId::LE_C_Runtime));
1790 OutStreamer->emitInt8(static_cast<uint8_t>(MemberSubId));
1791 OutStreamer->emitInt8(0x22); // Member defined, c370_plist+c370_env
1792 OutStreamer->emitInt8(0x04); // Control level 4 (XPLink)
1793 OutStreamer->emitAbsoluteSymbolDiff(CELQSTRT, PPA2Sym, 4);
1794 OutStreamer->emitInt32(0x00000000);
1795 OutStreamer->emitAbsoluteSymbolDiff(DateVersionSym, PPA2Sym, 4);
1796 OutStreamer->emitInt32(
1797 0x00000000); // Offset to main entry point, always 0 (so says TR).
1798 uint8_t Flgs = static_cast<uint8_t>(PPA2Flags::CompileForBinaryFloatingPoint);
1799 Flgs |= static_cast<uint8_t>(PPA2Flags::CompiledWithXPLink);
1800
1801 bool IsASCII = true;
1802 if (auto *MD = M.getModuleFlag("zos_le_char_mode")) {
1803 const StringRef &CharMode = cast<MDString>(MD)->getString();
1804 if (CharMode == "ebcdic")
1805 IsASCII = false;
1806 else if (CharMode != "ascii")
1807 OutContext.reportError(
1808 {}, "Only ascii or ebcdic are allowed for zos_le_char_mode");
1809 }
1810 if (IsASCII)
1811 Flgs |= static_cast<uint8_t>(
1812 PPA2Flags::CompiledUnitASCII); // Setting bit for ASCII char. mode.
1813
1814 OutStreamer->emitInt8(Flgs);
1815 OutStreamer->emitInt8(0x00); // Reserved.
1816 // No MD5 signature before timestamp.
1817 // No FLOAT(AFP(VOLATILE)).
1818 // Remaining 5 flag bits reserved.
1819 OutStreamer->emitInt16(0x0000); // 16 Reserved flag bits.
1820
1821 // Emit date and version section.
1822 OutStreamer->emitLabel(DateVersionSym);
1823 OutStreamer->emitBytes(CompilationTimeEBCDIC.str());
1824 OutStreamer->emitBytes(VersionEBCDIC.str());
1825
1826 OutStreamer->emitInt16(0x0000); // Service level string length.
1827
1828 // The binder requires that the offset to the PPA2 be emitted in a different,
1829 // specially-named section.
1830 OutStreamer->switchSection(getObjFileLowering().getPPA2ListSection());
1831 // Emit 8 byte alignment.
1832 // Emit pointer to PPA2 label.
1833 OutStreamer->AddComment("A(PPA2-CELQSTRT)");
1834 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, CELQSTRT, 8);
1835 OutStreamer->popSection();
1836}
1837
1839 const GlobalAlias &GA) {
1840 if (!TM.getTargetTriple().isOSzOS())
1841 return AsmPrinter::emitGlobalAlias(M, GA);
1842
1843 // Aliased function labels have already been emitted for z/OS
1844}
1845
1847 const Constant *BaseCV,
1848 uint64_t Offset) {
1849 const Triple &TargetTriple = TM.getTargetTriple();
1850
1851 if (TargetTriple.isOSzOS()) {
1852 const GlobalAlias *GA = dyn_cast<GlobalAlias>(CV);
1854 const Function *FV = dyn_cast<Function>(CV);
1855 bool IsFunc = !GV && (FV || (GA && isa<Function>(GA->getAliaseeObject())));
1856
1857 MCSymbol *Sym = NULL;
1858
1859 if (GA)
1860 Sym = getSymbol(GA);
1861 else if (IsFunc)
1862 Sym = getSymbol(FV);
1863 else if (GV)
1864 Sym = getSymbol(GV);
1865
1866 if (IsFunc) {
1867 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
1868 if (FV->hasExternalLinkage())
1871 // Trigger creation of function descriptor in ADA for internal
1872 // functions.
1873 unsigned Disp = ADATable.insert(Sym, SystemZII::MO_ADA_DIRECT_FUNC_DESC);
1877 getObjFileLowering().getADASection()->getBeginSymbol(),
1878 OutContext),
1881 }
1882 if (Sym) {
1883 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
1885 }
1886 }
1887 return AsmPrinter::lowerConstant(CV);
1888}
1889
1891 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1892
1893 if (Subtarget.getTargetTriple().isOSzOS()) {
1894 calculatePPA1();
1895
1896 // EntryPoint Marker
1897 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1898 bool IsUsingAlloca = MFFrame.hasVarSizedObjects();
1899 uint32_t DSASize = MFFrame.getStackSize();
1900 bool IsLeaf = DSASize == 0 && MFFrame.getCalleeSavedInfo().empty();
1901
1902 // Set Flags.
1903 uint8_t Flags = 0;
1904 if (IsLeaf)
1905 Flags |= 0x08;
1906 if (IsUsingAlloca)
1907 Flags |= 0x04;
1908
1909 // Combine into top 27 bits of DSASize and bottom 5 bits of Flags.
1910 uint32_t DSAAndFlags = DSASize & 0xFFFFFFE0; // (x/32) << 5
1911 DSAAndFlags |= Flags;
1912
1913 // Emit entry point marker section.
1914 OutStreamer->AddComment("XPLINK Routine Layout Entry");
1915 OutStreamer->emitLabel(DeferredPPA1.back().EPMarker);
1916 OutStreamer->AddComment("Eyecatcher 0x00C300C500C500");
1917 OutStreamer->emitIntValueInHex(0x00C300C500C500, 7); // Eyecatcher.
1918 OutStreamer->AddComment("Mark Type C'1'");
1919 OutStreamer->emitInt8(0xF1); // Mark Type.
1920 OutStreamer->AddComment("Offset to PPA1");
1921 OutStreamer->emitAbsoluteSymbolDiff(DeferredPPA1.back().PPA1,
1922 DeferredPPA1.back().EPMarker, 4);
1923 if (OutStreamer->isVerboseAsm()) {
1924 OutStreamer->AddComment("DSA Size 0x" + Twine::utohexstr(DSASize));
1925 OutStreamer->AddComment("Entry Flags");
1926 if (Flags & 0x08)
1927 OutStreamer->AddComment(" Bit 1: 1 = Leaf function");
1928 else
1929 OutStreamer->AddComment(" Bit 1: 0 = Non-leaf function");
1930 if (Flags & 0x04)
1931 OutStreamer->AddComment(" Bit 2: 1 = Uses alloca");
1932 else
1933 OutStreamer->AddComment(" Bit 2: 0 = Does not use alloca");
1934 }
1935 OutStreamer->emitInt32(DSAAndFlags);
1936
1937 getTargetStreamer()->emitADA(CurrentFnSym,
1938 getObjFileLowering().getADASection());
1939 }
1940
1942
1943 if (Subtarget.getTargetTriple().isOSzOS()) {
1944 const Function *F = &MF->getFunction();
1945 // Emit aliasing label for function entry point label.
1946 for (const GlobalAlias *Alias : GOAliasMap[F]) {
1947 MCSymbol *Sym = getSymbol(Alias);
1948 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
1949 emitVisibility(Sym, Alias->getVisibility());
1950 emitLinkage(Alias, Sym);
1951 OutStreamer->emitLabel(Sym);
1952 }
1953 }
1954}
1955
1956char SystemZAsmPrinter::ID = 0;
1957
1958INITIALIZE_PASS(SystemZAsmPrinter, "systemz-asm-printer",
1959 "SystemZ Assembly Printer", false, false)
1960
1961// Force static initialization.
1962extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1963LLVMInitializeSystemZAsmPrinter() {
1965}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
#define X(NUM, ENUM, NAME)
Definition ELF.h:851
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#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.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define RegName(no)
This file contains the MCSymbolGOFF class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:483
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 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 void emitPPA1Flags(std::unique_ptr< MCStreamer > &OutStreamer, bool VarArg, bool StackProtector, bool FPRMask, bool VRMask, bool EHBlock, bool HasArgAreaLength, bool HasName)
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.
MCSymbol * getSymbol(const GlobalValue *GV) const
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:94
virtual void emitGlobalAlias(const Module &M, const GlobalAlias &GA)
Align emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const
Emit an alignment directive to the specified power of two boundary.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition AsmPrinter.h:97
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:109
virtual const MCExpr * lowerConstant(const Constant *CV, const Constant *BaseCV=nullptr, uint64_t Offset=0)
Lower the specified LLVM Constant to an MCExpr.
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:617
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target.
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition AsmPrinter.h:128
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:101
virtual void emitXXStructorList(const DataLayout &DL, const Constant *List, bool IsCtor)
This method emits llvm.global_ctors or llvm.global_dtors list.
void emitVisibility(MCSymbol *Sym, unsigned Visibility, bool IsDefinition=true) const
This emits visibility information about symbol, if this is supported by the target.
void emitInt32(int Value) const
Emit a long directive and value.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:106
void preprocessXXStructorList(const DataLayout &DL, const Constant *List, SmallVector< Structor, 8 > &Structors)
This method gathers an array of Structors and then sorts them out by Priority.
const DataLayout & getDataLayout() const
Return information about data layout.
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
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.
This is an important base class in LLVM.
Definition Constant.h:43
const Constant * stripPointerCasts() const
Definition Constant.h:219
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:659
bool hasExternalLinkage() const
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:450
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:567
void printExpr(raw_ostream &, const MCExpr &) const
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.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition MCContext.h:550
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
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.
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
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...
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
MCSymbol * getBeginSymbol()
Definition MCSection.h:642
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:222
Generic base class for all target subtargets.
StringRef getExternalName() 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
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
MachineInstrBundleIterator< const MachineInstr > const_iterator
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.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
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.
MCContext & getContext() const
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
ArrayRef< MachineMemOperand * >::iterator mmo_iterator
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.
iterator end()
Definition MapVector.h:67
iterator find(const KeyT &Key)
Definition MapVector.h:154
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Wrapper class representing virtual and physical registers.
Definition Register.h:20
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.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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:591
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:143
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.
void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override
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.
const MCExpr * lowerConstant(const Constant *CV, const Constant *BaseCV=nullptr, uint64_t Offset=0) override
Lower the specified LLVM Constant to an MCExpr.
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 emitXXStructorList(const DataLayout &DL, const Constant *List, bool IsCtor) override
This method emits llvm.global_ctors or llvm.global_dtors list.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
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
virtual void emitExternalName(MCSymbol *Sym, StringRef Name)
MCSymbol * getSymbol(const GlobalValue *GV) const
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
bool isOSzOS() const
Definition Triple.h:632
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
Twine concat(const Twine &Suffix) const
Definition Twine.h:497
static Twine utohexstr(uint64_t Val)
Definition Twine.h:385
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
@ 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)
@ SHF_ALLOC
Definition ELF.h:1249
@ SHT_PROGBITS
Definition ELF.h:1148
unsigned getRegAsGR32(unsigned Reg)
const unsigned GR64Regs[16]
unsigned getRegAsGRH32(unsigned Reg)
unsigned getRegAsVR128(unsigned Reg)
unsigned getRegAsGR64(unsigned Reg)
constexpr size_t NameSize
Definition XCOFF.h:30
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
Definition Metadata.h:683
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.
Target & getTheSystemZTarget()
@ Offset
Definition DWP.cpp:532
@ Length
Definition DWP.cpp:532
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
std::string utostr(uint64_t X, bool isNeg=false)
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition STLExtras.h:1152
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:334
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
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_OSLinkage
symbol uses OS linkage (GOFF)
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
llvm.global_ctors and llvm.global_dtors are arrays of Structor structs.
Definition AsmPrinter.h:550
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...