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 // get M-N from function attribute (CodeGenFunction subtracts N
942 // from M to yield the correct patchable-function-entry).
943 unsigned Num = F.getFnAttributeAsParsedInteger("patchable-function-entry");
944 // Emit M-N 2-byte nops. Use getNop() here instead of emitNops()
945 // to keep it aligned with the common code implementation emitting
946 // the prefix nops.
947 for (unsigned I = 0; I < Num; ++I)
948 EmitToStreamer(*OutStreamer, MF.getSubtarget().getInstrInfo()->getNop());
949 return;
950 }
951 // Otherwise, emit xray sled.
952 // .begin:
953 // j .end # -> stmg %r2, %r15, 16(%r15)
954 // nop
955 // llilf %2, FuncID
956 // brasl %r14, __xray_FunctionEntry@GOT
957 // .end:
958 //
959 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
960 // of instructions change.
961 bool HasVectorFeature =
962 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector) &&
963 !TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureSoftFloat);
964 MCSymbol *FuncEntry = OutContext.getOrCreateSymbol(
965 HasVectorFeature ? "__xray_FunctionEntryVec" : "__xray_FunctionEntry");
966 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
967 MCSymbol *EndOfSled = OutContext.createTempSymbol();
968 OutStreamer->emitLabel(BeginOfSled);
970 MCInstBuilder(SystemZ::J)
971 .addExpr(MCSymbolRefExpr::create(EndOfSled, OutContext)));
974 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
975 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
976 .addReg(SystemZ::R14D)
978 FuncEntry, SystemZ::S_PLT, OutContext)));
979 OutStreamer->emitLabel(EndOfSled);
980 recordSled(BeginOfSled, MI, SledKind::FUNCTION_ENTER, 2);
981}
982
983void SystemZAsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI,
984 SystemZMCInstLower &Lower) {
985 unsigned OpCode = MI.getOperand(0).getImm();
986 MCSymbol *FallthroughLabel = nullptr;
987 if (OpCode == SystemZ::CondReturn) {
988 FallthroughLabel = OutContext.createTempSymbol();
989 int64_t Cond0 = MI.getOperand(1).getImm();
990 int64_t Cond1 = MI.getOperand(2).getImm();
991 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRC)
992 .addImm(Cond0)
993 .addImm(Cond1 ^ Cond0)
995 FallthroughLabel, OutContext)));
996 }
997 // .begin:
998 // br %r14 # -> stmg %r2, %r15, 24(%r15)
999 // nop
1000 // nop
1001 // llilf %2,FuncID
1002 // j __xray_FunctionExit@GOT
1003 //
1004 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
1005 // of instructions change.
1006 bool HasVectorFeature =
1007 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector) &&
1008 !TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureSoftFloat);
1009 MCSymbol *FuncExit = OutContext.getOrCreateSymbol(
1010 HasVectorFeature ? "__xray_FunctionExitVec" : "__xray_FunctionExit");
1011 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
1012 OutStreamer->emitLabel(BeginOfSled);
1014 MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D));
1017 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
1018 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::J)
1019 .addExpr(MCSymbolRefExpr::create(
1020 FuncExit, SystemZ::S_PLT, OutContext)));
1021 if (FallthroughLabel)
1022 OutStreamer->emitLabel(FallthroughLabel);
1023 recordSled(BeginOfSled, MI, SledKind::FUNCTION_EXIT, 2);
1024}
1025
1026// The *alignment* of 128-bit vector types is different between the software
1027// and hardware vector ABIs. If the there is an externally visible use of a
1028// vector type in the module it should be annotated with an attribute.
1029void SystemZAsmPrinter::emitAttributes(Module &M) {
1030 if (M.getModuleFlag("s390x-visible-vector-ABI")) {
1031 bool HasVectorFeature =
1032 TM.getMCSubtargetInfo()->hasFeature(SystemZ::FeatureVector);
1033 OutStreamer->emitGNUAttribute(8, HasVectorFeature ? 2 : 1);
1034 }
1035}
1036
1037// Convert a SystemZ-specific constant pool modifier into the associated
1038// specifier.
1040 switch (Modifier) {
1041 case SystemZCP::TLSGD:
1042 return SystemZ::S_TLSGD;
1043 case SystemZCP::TLSLDM:
1044 return SystemZ::S_TLSLDM;
1045 case SystemZCP::DTPOFF:
1046 return SystemZ::S_DTPOFF;
1047 case SystemZCP::NTPOFF:
1048 return SystemZ::S_NTPOFF;
1049 }
1050 llvm_unreachable("Invalid SystemCPModifier!");
1051}
1052
1055 auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
1056
1057 const MCExpr *Expr = MCSymbolRefExpr::create(
1058 getSymbol(ZCPV->getGlobalValue()),
1059 getSpecifierFromModifier(ZCPV->getModifier()), OutContext);
1060 uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
1061
1062 OutStreamer->emitValue(Expr, Size);
1063}
1064
1065// Emit the ctor or dtor list taking into account the init priority.
1067 const Constant *List, bool IsCtor) {
1068 if (!TM.getTargetTriple().isOSBinFormatGOFF())
1069 return AsmPrinter::emitXXStructorList(DL, List, IsCtor);
1070
1071 SmallVector<Structor, 8> Structors;
1072 preprocessXXStructorList(DL, List, Structors);
1073 if (Structors.empty())
1074 return;
1075
1076 const Align Align = llvm::Align(4);
1077 const TargetLoweringObjectFileGOFF &Obj =
1078 static_cast<const TargetLoweringObjectFileGOFF &>(getObjFileLowering());
1079 for (Structor &S : Structors) {
1080 MCSectionGOFF *Section =
1081 static_cast<MCSectionGOFF *>(Obj.getStaticXtorSection(S.Priority));
1082 OutStreamer->switchSection(Section);
1083 if (OutStreamer->getCurrentSection() != OutStreamer->getPreviousSection())
1085
1086 // The priority is provided as an input to getStaticXtorSection(), and is
1087 // recalculated within that function as `Prio` going to going into the
1088 // PR section.
1089 // This priority retrieved via the `SortKey` below is the recalculated
1090 // Priority.
1091 uint32_t XtorPriority = Section->getPRAttributes().SortKey;
1092
1093 const GlobalValue *GV = dyn_cast<GlobalValue>(S.Func->stripPointerCasts());
1094 assert(GV && "C++ xxtor pointer was not a GlobalValue!");
1095 MCSymbolGOFF *Symbol = static_cast<MCSymbolGOFF *>(getSymbol(GV));
1096
1097 // @@SQINIT entry: { unsigned prio; void (*ctor)(); void (*dtor)(); }
1098
1099 unsigned PointerSizeInBytes = DL.getPointerSize();
1100
1101 auto &Ctx = OutStreamer->getContext();
1102 const MCExpr *ADAFuncRefExpr;
1103 unsigned SlotKind = SystemZII::MO_ADA_DIRECT_FUNC_DESC;
1104
1105 MCSectionGOFF *ADASection =
1106 static_cast<MCSectionGOFF *>(Obj.getADASection());
1107 assert(ADASection && "ADA section must exist for GOFF targets!");
1108 const MCSymbol *ADASym = ADASection->getBeginSymbol();
1109 assert(ADASym && "ADA symbol should already be set!");
1110
1111 ADAFuncRefExpr = MCBinaryExpr::createAdd(
1114 MCConstantExpr::create(ADATable.insert(Symbol, SlotKind), Ctx), Ctx);
1115
1116 emitInt32(XtorPriority);
1117 if (IsCtor) {
1118 OutStreamer->emitValue(ADAFuncRefExpr, PointerSizeInBytes);
1119 OutStreamer->emitIntValue(0, PointerSizeInBytes);
1120 } else {
1121 OutStreamer->emitIntValue(0, PointerSizeInBytes);
1122 OutStreamer->emitValue(ADAFuncRefExpr, PointerSizeInBytes);
1123 }
1124 }
1125}
1126
1127static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
1128 raw_ostream &OS) {
1129 const char *RegName;
1130 if (MAI->getAssemblerDialect() == AD_HLASM) {
1132 // Skip register prefix so that only register number is left
1133 assert(isalpha(RegName[0]) && isdigit(RegName[1]));
1134 OS << (RegName + 1);
1135 } else {
1137 OS << '%' << RegName;
1138 }
1139}
1140
1141static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {
1142 if (!Reg)
1143 OS << '0';
1144 else
1146}
1147
1148static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
1149 raw_ostream &OS) {
1150 if (MCOp.isReg())
1151 printReg(MCOp.getReg(), MAI, OS);
1152 else if (MCOp.isImm())
1153 OS << MCOp.getImm();
1154 else if (MCOp.isExpr())
1155 MAI->printExpr(OS, *MCOp.getExpr());
1156 else
1157 llvm_unreachable("Invalid operand");
1158}
1159
1160static void printAddress(const MCAsmInfo *MAI, unsigned Base,
1161 const MCOperand &DispMO, unsigned Index,
1162 raw_ostream &OS) {
1163 printOperand(DispMO, MAI, OS);
1164 if (Base || Index) {
1165 OS << '(';
1166 if (Index) {
1167 printFormattedRegName(MAI, Index, OS);
1168 if (Base)
1169 OS << ',';
1170 }
1171 if (Base)
1173 OS << ')';
1174 }
1175}
1176
1178 const char *ExtraCode,
1179 raw_ostream &OS) {
1180 const MCRegisterInfo &MRI = *TM.getMCRegisterInfo();
1181 const MachineOperand &MO = MI->getOperand(OpNo);
1182 MCOperand MCOp;
1183 if (ExtraCode) {
1184 if (ExtraCode[0] == 'N' && !ExtraCode[1] && MO.isReg() &&
1185 SystemZ::GR128BitRegClass.contains(MO.getReg()))
1186 MCOp =
1187 MCOperand::createReg(MRI.getSubReg(MO.getReg(), SystemZ::subreg_l64));
1188 else
1189 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
1190 } else {
1191 SystemZMCInstLower Lower(MF->getContext(), *this);
1192 MCOp = Lower.lowerOperand(MO);
1193 }
1194 printOperand(MCOp, &MAI, OS);
1195 return false;
1196}
1197
1199 unsigned OpNo,
1200 const char *ExtraCode,
1201 raw_ostream &OS) {
1202 if (ExtraCode && ExtraCode[0] && !ExtraCode[1]) {
1203 switch (ExtraCode[0]) {
1204 case 'A':
1205 // Unlike EmitMachineNode(), EmitSpecialNode(INLINEASM) does not call
1206 // setMemRefs(), so MI->memoperands() is empty and the alignment
1207 // information is not available.
1208 return false;
1209 case 'O':
1210 OS << MI->getOperand(OpNo + 1).getImm();
1211 return false;
1212 case 'R':
1213 ::printReg(MI->getOperand(OpNo).getReg(), &MAI, OS);
1214 return false;
1215 }
1216 }
1217 printAddress(&MAI, MI->getOperand(OpNo).getReg(),
1218 MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
1219 MI->getOperand(OpNo + 2).getReg(), OS);
1220 return false;
1221}
1222
1224 auto TT = OutContext.getTargetTriple();
1225 if (TT.isOSzOS()) {
1226 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1227 for (auto &Info : DeferredPPA1)
1228 emitPPA1(Info);
1229 emitADASection();
1230 emitIDRLSection(M);
1231 // On z/OS, we need to associate an external data reference with an ED
1232 // symbol, for which we use the the ED of the ADA. We also need to mark the
1233 // reference as being to data, otherwise we cannot bind with code generated
1234 // by XL.
1235 for (auto &GO : M.global_objects()) {
1236 if (auto *GV = dyn_cast<GlobalVariable>(&GO)) {
1237 if (!GV->hasInitializer()) {
1238 MCSymbol *Sym = getSymbol(GV);
1239 getTargetStreamer()->emitADA(
1240 Sym, OutContext.getObjectFileInfo()->getADASection());
1241 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
1242 }
1243 }
1244 }
1245 }
1246 emitAttributes(M);
1247}
1248
1249void SystemZAsmPrinter::emitADASection() {
1250 OutStreamer->pushSection();
1251
1252 const unsigned PointerSize = getDataLayout().getPointerSize();
1253 OutStreamer->switchSection(getObjFileLowering().getADASection());
1254
1255 unsigned EmittedBytes = 0;
1256 for (auto &Entry : ADATable.getTable()) {
1257 const MCSymbol *Sym;
1258 unsigned SlotKind;
1259 std::tie(Sym, SlotKind) = Entry.first;
1260 unsigned Offset = Entry.second;
1261 assert(Offset == EmittedBytes && "Offset not as expected");
1262 (void)EmittedBytes;
1263#define EMIT_COMMENT(Str) \
1264 OutStreamer->AddComment(Twine("Offset ") \
1265 .concat(utostr(Offset)) \
1266 .concat(" " Str " ") \
1267 .concat(Sym->getName()));
1268 switch (SlotKind) {
1270 // Language Environment DLL logic requires function descriptors, for
1271 // imported functions, that are placed in the ADA to be 8 byte aligned.
1272 EMIT_COMMENT("function descriptor of");
1273 OutStreamer->emitValue(
1276 PointerSize);
1277 OutStreamer->emitValue(
1280 PointerSize);
1281 EmittedBytes += PointerSize * 2;
1282 break;
1284 EMIT_COMMENT("pointer to data symbol");
1285 OutStreamer->emitValue(
1288 PointerSize);
1289 EmittedBytes += PointerSize;
1290 break;
1293 Twine(Sym->getName()).concat("@indirect"));
1294 OutStreamer->emitSymbolAttribute(Alias, MCSA_IndirectSymbol);
1295 OutStreamer->emitSymbolAttribute(Alias, MCSA_ELF_TypeFunction);
1296 OutStreamer->emitSymbolAttribute(Alias, MCSA_Global);
1297 OutStreamer->emitSymbolAttribute(Alias, MCSA_Extern);
1298 MCSymbolGOFF *GOFFSym =
1299 static_cast<llvm::MCSymbolGOFF *>(const_cast<llvm::MCSymbol *>(Sym));
1300 getTargetStreamer()->emitExternalName(Alias, GOFFSym->getExternalName());
1301 EMIT_COMMENT("pointer to function descriptor");
1302 OutStreamer->emitValue(
1305 PointerSize);
1306 EmittedBytes += PointerSize;
1307 break;
1308 }
1309 default:
1310 llvm_unreachable("Unexpected slot kind");
1311 }
1312#undef EMIT_COMMENT
1313 }
1314 OutStreamer->popSection();
1315}
1316
1317static std::string getProductID(Module &M) {
1318 std::string ProductID;
1319 if (auto *MD = M.getModuleFlag("zos_product_id"))
1320 ProductID = cast<MDString>(MD)->getString().str();
1321 if (ProductID.empty())
1322 ProductID = "LLVM";
1323 return ProductID;
1324}
1325
1327 if (auto *VersionVal = mdconst::extract_or_null<ConstantInt>(
1328 M.getModuleFlag("zos_product_major_version")))
1329 return VersionVal->getZExtValue();
1330 return LLVM_VERSION_MAJOR;
1331}
1332
1334 if (auto *ReleaseVal = mdconst::extract_or_null<ConstantInt>(
1335 M.getModuleFlag("zos_product_minor_version")))
1336 return ReleaseVal->getZExtValue();
1337 return LLVM_VERSION_MINOR;
1338}
1339
1341 if (auto *PatchVal = mdconst::extract_or_null<ConstantInt>(
1342 M.getModuleFlag("zos_product_patchlevel")))
1343 return PatchVal->getZExtValue();
1344 return LLVM_VERSION_PATCH;
1345}
1346
1347static time_t getTranslationTime(Module &M) {
1348 std::time_t Time = 0;
1350 M.getModuleFlag("zos_translation_time"))) {
1351 long SecondsSinceEpoch = Val->getSExtValue();
1352 Time = static_cast<time_t>(SecondsSinceEpoch);
1353 }
1354 return Time;
1355}
1356
1357void SystemZAsmPrinter::emitIDRLSection(Module &M) {
1358 OutStreamer->pushSection();
1359 OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
1360 constexpr unsigned IDRLDataLength = 30;
1361 std::time_t Time = getTranslationTime(M);
1362
1363 uint32_t ProductVersion = getProductVersion(M);
1364 uint32_t ProductRelease = getProductRelease(M);
1365
1366 std::string ProductID = getProductID(M);
1367
1368 SmallString<IDRLDataLength + 1> TempStr;
1369 raw_svector_ostream O(TempStr);
1370 O << formatv("{0,-10}{1,0-2:d}{2,0-2:d}{3:%Y%m%d%H%M%S}{4,0-2}",
1371 ProductID.substr(0, 10).c_str(), ProductVersion, ProductRelease,
1372 llvm::sys::toUtcTime(Time), "0");
1373 SmallString<IDRLDataLength> Data;
1375
1376 OutStreamer->emitInt8(0); // Reserved.
1377 OutStreamer->emitInt8(3); // Format.
1378 OutStreamer->emitInt16(IDRLDataLength); // Length.
1379 OutStreamer->emitBytes(Data.str());
1380 OutStreamer->popSection();
1381}
1382
1384 if (TM.getTargetTriple().isOSzOS()) {
1385 // Emit symbol for the end of function if the z/OS target streamer
1386 // is used. This is needed to calculate the size of the function.
1387 OutStreamer->emitLabel(DeferredPPA1.back().FnEnd);
1388 }
1389}
1390
1391static void emitPPA1Flags(std::unique_ptr<MCStreamer> &OutStreamer, bool VarArg,
1392 bool StackProtector, bool FPRMask, bool VRMask,
1393 bool EHBlock, bool HasArgAreaLength, bool HasName) {
1394 enum class PPA1Flag1 : uint8_t {
1395 DSA64Bit = (0x80 >> 0),
1396 VarArg = (0x80 >> 7),
1398 };
1399 enum class PPA1Flag2 : uint8_t {
1400 ExternalProcedure = (0x80 >> 0),
1401 STACKPROTECTOR = (0x80 >> 3),
1402 LLVM_MARK_AS_BITMASK_ENUM(ExternalProcedure)
1403 };
1404 enum class PPA1Flag3 : uint8_t {
1405 HasArgAreaLength = (0x80 >> 1),
1406 FPRMask = (0x80 >> 2),
1407 LLVM_MARK_AS_BITMASK_ENUM(HasArgAreaLength)
1408 };
1409 enum class PPA1Flag4 : uint8_t {
1410 EPMOffsetPresent = (0x80 >> 0),
1411 VRMask = (0x80 >> 2),
1412 EHBlock = (0x80 >> 3),
1413 ProcedureNamePresent = (0x80 >> 7),
1414 LLVM_MARK_AS_BITMASK_ENUM(EPMOffsetPresent)
1415 };
1416
1417 // Declare optional section flags that can be modified.
1418 auto Flags1 = PPA1Flag1(0);
1419 auto Flags2 = PPA1Flag2::ExternalProcedure;
1420 auto Flags3 = PPA1Flag3(0);
1421 auto Flags4 = PPA1Flag4::EPMOffsetPresent;
1422
1423 Flags1 |= PPA1Flag1::DSA64Bit;
1424
1425 if (VarArg)
1426 Flags1 |= PPA1Flag1::VarArg;
1427
1428 if (StackProtector)
1429 Flags2 |= PPA1Flag2::STACKPROTECTOR;
1430
1431 if (HasArgAreaLength)
1432 Flags3 |= PPA1Flag3::HasArgAreaLength; // Add emit ArgAreaLength flag.
1433
1434 // SavedGPRMask, SavedFPRMask, and SavedVRMask are precomputed in.
1435 if (FPRMask)
1436 Flags3 |= PPA1Flag3::FPRMask; // Add emit FPR mask flag.
1437
1438 if (VRMask)
1439 Flags4 |= PPA1Flag4::VRMask; // Add emit VR mask flag.
1440
1441 if (EHBlock)
1442 Flags4 |= PPA1Flag4::EHBlock; // Add optional EH block.
1443
1444 if (HasName)
1445 Flags4 |= PPA1Flag4::ProcedureNamePresent; // Add optional name block.
1446
1447 OutStreamer->AddComment("PPA1 Flags 1");
1448 if ((Flags1 & PPA1Flag1::DSA64Bit) == PPA1Flag1::DSA64Bit)
1449 OutStreamer->AddComment(" Bit 0: 1 = 64-bit DSA");
1450 else
1451 OutStreamer->AddComment(" Bit 0: 0 = 32-bit DSA");
1452 if ((Flags1 & PPA1Flag1::VarArg) == PPA1Flag1::VarArg)
1453 OutStreamer->AddComment(" Bit 7: 1 = Vararg function");
1454 OutStreamer->emitInt8(static_cast<uint8_t>(Flags1)); // Flags 1.
1455
1456 OutStreamer->AddComment("PPA1 Flags 2");
1457 if ((Flags2 & PPA1Flag2::ExternalProcedure) == PPA1Flag2::ExternalProcedure)
1458 OutStreamer->AddComment(" Bit 0: 1 = External procedure");
1459 if ((Flags2 & PPA1Flag2::STACKPROTECTOR) == PPA1Flag2::STACKPROTECTOR)
1460 OutStreamer->AddComment(" Bit 3: 1 = STACKPROTECT is enabled");
1461 else
1462 OutStreamer->AddComment(" Bit 3: 0 = STACKPROTECT is not enabled");
1463 OutStreamer->emitInt8(static_cast<uint8_t>(Flags2)); // Flags 2.
1464
1465 OutStreamer->AddComment("PPA1 Flags 3");
1466 if ((Flags3 & PPA1Flag3::HasArgAreaLength) == PPA1Flag3::HasArgAreaLength)
1467 OutStreamer->AddComment(
1468 " Bit 1: 1 = Argument Area Length is in optional area");
1469 if ((Flags3 & PPA1Flag3::FPRMask) == PPA1Flag3::FPRMask)
1470 OutStreamer->AddComment(" Bit 2: 1 = FP Reg Mask is in optional area");
1471 OutStreamer->emitInt8(
1472 static_cast<uint8_t>(Flags3)); // Flags 3 (optional sections).
1473
1474 OutStreamer->AddComment("PPA1 Flags 4");
1475 if ((Flags4 & PPA1Flag4::VRMask) == PPA1Flag4::VRMask)
1476 OutStreamer->AddComment(" Bit 2: 1 = Vector Reg Mask is in optional area");
1477 if ((Flags4 & PPA1Flag4::EHBlock) == PPA1Flag4::EHBlock)
1478 OutStreamer->AddComment(" Bit 3: 1 = C++ EH block");
1479 if ((Flags4 & PPA1Flag4::ProcedureNamePresent) ==
1480 PPA1Flag4::ProcedureNamePresent)
1481 OutStreamer->AddComment(" Bit 7: 1 = Name Length and Name");
1482 OutStreamer->emitInt8(static_cast<uint8_t>(
1483 Flags4)); // Flags 4 (optional sections, always emit these).
1484}
1485
1486static void emitPPA1Name(std::unique_ptr<MCStreamer> &OutStreamer,
1487 StringRef OutName) {
1488 size_t NameSize = OutName.size();
1489 uint16_t OutSize;
1490 if (NameSize < UINT16_MAX) {
1491 OutSize = static_cast<uint16_t>(NameSize);
1492 } else {
1493 OutName = OutName.substr(0, UINT16_MAX);
1494 OutSize = UINT16_MAX;
1495 }
1496 // Emit padding to ensure that the next optional field word-aligned.
1497 uint8_t ExtraZeros = 4 - ((2 + OutSize) % 4);
1498
1499 SmallString<512> OutnameConv;
1500 ConverterEBCDIC::convertToEBCDIC(OutName, OutnameConv);
1501 OutName = OutnameConv.str();
1502
1503 OutStreamer->AddComment("Length of Name");
1504 OutStreamer->emitInt16(OutSize);
1505 OutStreamer->AddComment("Name of Function");
1506 OutStreamer->emitBytes(OutName);
1507 OutStreamer->emitZeros(ExtraZeros);
1508}
1509
1510void SystemZAsmPrinter::emitPPA1(PPA1Info &Info) {
1511 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1512
1513 // Optional Argument Area Length.
1514 // Note: This represents the length of the argument area that we reserve
1515 // in our stack for setting up arguments for calls to other
1516 // routines. If this optional field is not set, LE will reserve
1517 // 128 bytes for the argument area. This optional field is
1518 // created if greater than 128 bytes is required - to guarantee
1519 // the required space is reserved on stack extension in the new
1520 // extension. This optional field is also created if the
1521 // routine has alloca(). This may reduce stack space
1522 // if alloca() call causes a stack extension.
1523 bool HasArgAreaLength = (Info.AllocaReg != 0) || (Info.CallFrameSize > 128);
1524
1525 // Emit PPA1 section.
1526 OutStreamer->AddComment("PPA1");
1527 OutStreamer->emitLabel(Info.PPA1);
1528 OutStreamer->AddComment("Version");
1529 OutStreamer->emitInt8(0x02); // Version.
1530 OutStreamer->AddComment("LE Signature X'CE'");
1531 OutStreamer->emitInt8(0xCE); // CEL signature.
1532 OutStreamer->AddComment("Saved GPR Mask");
1533 OutStreamer->emitInt16(Info.SavedGPRMask);
1534 OutStreamer->AddComment("Offset to PPA2");
1535 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, Info.PPA1, 4);
1536
1537 emitPPA1Flags(OutStreamer, Info.IsVarArg, Info.HasStackProtector,
1538 Info.SavedFPRMask != 0, Info.SavedVRMask != 0,
1539 Info.PersonalityRoutine != nullptr, HasArgAreaLength,
1540 Info.Name.size() > 0);
1541
1542 OutStreamer->AddComment("Length/4 of Parms");
1543 OutStreamer->emitInt16(
1544 static_cast<uint16_t>(Info.SizeOfFnParams / 4)); // Parms/4.
1545 OutStreamer->AddComment("Length of Code");
1546 OutStreamer->emitAbsoluteSymbolDiff(Info.FnEnd, Info.EPMarker, 4);
1547
1548 if (HasArgAreaLength) {
1549 OutStreamer->AddComment("Argument Area Length");
1550 OutStreamer->emitInt32(Info.CallFrameSize);
1551 }
1552
1553 // Emit saved FPR mask and offset to FPR save area (0x20 of flags 3).
1554 if (Info.SavedFPRMask) {
1555 OutStreamer->AddComment("FPR mask");
1556 OutStreamer->emitInt16(Info.SavedFPRMask);
1557 OutStreamer->AddComment("AR mask");
1558 OutStreamer->emitInt16(0); // AR Mask, unused currently.
1559 OutStreamer->AddComment("FPR Save Area Locator");
1560 uint64_t FPRSaveAreaOffset = Info.OffsetFPR;
1561 assert(FPRSaveAreaOffset < 0x10000000 && "Offset out of range");
1562 FPRSaveAreaOffset &= 0x0FFFFFFF; // Lose top 4 bits.
1563 OutStreamer->AddComment(
1564 Twine(" Bit 0-3: Register R").concat(utostr(Info.FrameReg)).str());
1565 OutStreamer->AddComment(
1566 Twine(" Bit 4-31: Offset ").concat(utostr(FPRSaveAreaOffset)).str());
1567 OutStreamer->emitInt32(FPRSaveAreaOffset |
1568 (Info.FrameReg << 28)); // Offset to FPR save area
1569 // with register to add
1570 // value to (alloca reg).
1571 }
1572
1573 // Emit saved VR mask to VR save area.
1574 if (Info.SavedVRMask) {
1575 OutStreamer->AddComment("VR mask");
1576 OutStreamer->emitInt8(Info.SavedVRMask);
1577 OutStreamer->emitInt8(0); // Reserved.
1578 OutStreamer->emitInt16(0); // Also reserved.
1579 uint64_t VRSaveAreaOffset = Info.OffsetVR;
1580 assert(VRSaveAreaOffset < 0x10000000 && "Offset out of range");
1581 VRSaveAreaOffset &= 0x0FFFFFFF; // Lose top 4 bits.
1582 OutStreamer->AddComment("VR Save Area Locator");
1583 OutStreamer->AddComment(
1584 Twine(" Bit 0-3: Register R").concat(utostr(Info.FrameReg)).str());
1585 OutStreamer->AddComment(
1586 Twine(" Bit 4-31: Offset ").concat(utostr(VRSaveAreaOffset)).str());
1587 OutStreamer->emitInt32(VRSaveAreaOffset | (Info.FrameReg << 28));
1588 }
1589
1590 // Emit C++ EH information block.
1591 if (Info.PersonalityRoutine) {
1592 OutStreamer->AddComment("Version");
1593 OutStreamer->emitInt32(1);
1594 OutStreamer->AddComment("Flags");
1595 OutStreamer->emitInt32(0); // LSDA field is a WAS offset
1596 OutStreamer->AddComment("Personality routine");
1597 OutStreamer->emitInt64(ADATable.insert(
1598 Info.PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC));
1599 OutStreamer->AddComment("LSDA location");
1600 OutStreamer->emitInt64(
1601 ADATable.insert(Info.GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR));
1602 }
1603
1604 // Emit name length and name optional section (0x01 of flags 4)
1605 if (Info.Name.size())
1607
1608 // Emit offset to entry point optional section (0x80 of flags 4).
1609 OutStreamer->emitAbsoluteSymbolDiff(Info.EPMarker, Info.PPA1, 4);
1610}
1611
1612void SystemZAsmPrinter::calculatePPA1() {
1613 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1614
1615 PPA1Info Info;
1616
1617 const TargetRegisterInfo *TRI = MF->getRegInfo().getTargetRegisterInfo();
1618 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1619
1620 const SystemZMachineFunctionInfo *ZFI =
1621 MF->getInfo<SystemZMachineFunctionInfo>();
1622 const auto *ZFL = static_cast<const SystemZXPLINKFrameLowering *>(
1623 Subtarget.getFrameLowering());
1624 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1625
1626 // Get saved GPR/FPR/VPR masks.
1627 const std::vector<CalleeSavedInfo> &CSI = MFFrame.getCalleeSavedInfo();
1628 uint16_t SavedGPRMask = 0;
1629 uint16_t SavedFPRMask = 0;
1630 uint8_t SavedVRMask = 0;
1631 int64_t OffsetFPR = 0;
1632 int64_t OffsetVR = 0;
1633 const int64_t TopOfStack =
1634 MFFrame.getOffsetAdjustment() + MFFrame.getStackSize();
1635
1636 // Loop over the spilled registers. The CalleeSavedInfo can't be used because
1637 // it does not contain all spilled registers.
1638 for (unsigned I = ZFI->getSpillGPRRegs().LowGPR,
1639 E = ZFI->getSpillGPRRegs().HighGPR;
1640 I && E && I <= E; ++I) {
1641 unsigned V = TRI->getEncodingValue((Register)I);
1642 assert(V < 16 && "GPR index out of range");
1643 SavedGPRMask |= 1 << (15 - V);
1644 }
1645
1646 for (auto &CS : CSI) {
1647 unsigned Reg = CS.getReg();
1648 unsigned I = TRI->getEncodingValue(Reg);
1649
1650 if (SystemZ::FP64BitRegClass.contains(Reg)) {
1651 assert(I < 16 && "FPR index out of range");
1652 SavedFPRMask |= 1 << (15 - I);
1653 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1654 if (Temp < OffsetFPR)
1655 OffsetFPR = Temp;
1656 } else if (SystemZ::VR128BitRegClass.contains(Reg)) {
1657 assert(I >= 16 && I <= 23 && "VPR index out of range");
1658 unsigned BitNum = I - 16;
1659 SavedVRMask |= 1 << (7 - BitNum);
1660 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1661 if (Temp < OffsetVR)
1662 OffsetVR = Temp;
1663 }
1664 }
1665
1666 // Adjust the offset.
1667 OffsetFPR += (OffsetFPR < 0) ? TopOfStack : 0;
1668 OffsetVR += (OffsetVR < 0) ? TopOfStack : 0;
1669
1670 // Get alloca register.
1671 uint8_t FrameReg = TRI->getEncodingValue(TRI->getFrameRegister(*MF));
1672 uint8_t AllocaReg = ZFL->hasFP(*MF) ? FrameReg : 0;
1673 assert(AllocaReg < 16 && "Can't have alloca register larger than 15");
1674
1675 MCSymbol *PersonalityRoutine = nullptr;
1676 MCSymbol *GCCEH = nullptr;
1677 if (!MF->getLandingPads().empty()) {
1678 const Function *Per = dyn_cast<Function>(
1679 MF->getFunction().getPersonalityFn()->stripPointerCasts());
1680 PersonalityRoutine = Per ? MF->getTarget().getSymbol(Per) : nullptr;
1681 assert(PersonalityRoutine && "Missing personality routine");
1682
1683 GCCEH = MF->getContext().getOrCreateSymbol(Twine("GCC_except_table") +
1684 Twine(MF->getFunctionNumber()));
1685 }
1686
1687 // Get the name of the function, with suffix _.
1688 std::string N(MF->getFunction().hasName()
1689 ? Twine(MF->getFunction().getName()).concat("_").str()
1690 : "");
1691
1692 // Save the calculated values.
1693 if (MF->getFunction().hasName())
1694 Info.Name = MF->getFunction().getName();
1695 Info.PPA1 = OutContext.createTempSymbol(Twine("PPA1_").concat(N).str(), true);
1696 Info.EPMarker =
1697 OutContext.createTempSymbol(Twine("EPM_").concat(N).str(), true);
1698 Info.FnEnd = OutContext.createTempSymbol(Twine(N).concat("end_").str());
1699 Info.PersonalityRoutine = PersonalityRoutine;
1700 Info.GCCEH = GCCEH;
1701 Info.OffsetFPR = OffsetFPR;
1702 Info.OffsetVR = OffsetVR;
1703 Info.CallFrameSize = MFFrame.getMaxCallFrameSize();
1704 Info.SizeOfFnParams = ZFI->getSizeOfFnParams();
1705 Info.SavedGPRMask = SavedGPRMask;
1706 Info.SavedFPRMask = SavedFPRMask;
1707 Info.SavedVRMask = SavedVRMask;
1708 Info.FrameReg = FrameReg;
1709 Info.AllocaReg = AllocaReg;
1710 Info.IsVarArg = MF->getFunction().isVarArg();
1711 Info.HasStackProtector = MFFrame.hasStackProtectorIndex();
1712
1713 DeferredPPA1.push_back(Info);
1714}
1715
1717 if (TM.getTargetTriple().isOSzOS())
1718 emitPPA2(M);
1720}
1721
1722void SystemZAsmPrinter::emitPPA2(Module &M) {
1723 OutStreamer->pushSection();
1724 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1725 MCContext &OutContext = OutStreamer->getContext();
1726 // Make CELQSTRT symbol.
1727 const char *StartSymbolName = "CELQSTRT";
1728 MCSymbol *CELQSTRT = OutContext.getOrCreateSymbol(StartSymbolName);
1729 OutStreamer->emitSymbolAttribute(CELQSTRT, MCSA_OSLinkage);
1730 OutStreamer->emitSymbolAttribute(CELQSTRT, MCSA_Global);
1731
1732 // Create symbol and assign to class field for use in PPA1.
1733 PPA2Sym = OutContext.createTempSymbol("PPA2", false);
1734 MCSymbol *DateVersionSym = OutContext.createTempSymbol("DVS", false);
1735
1736 std::time_t Time = getTranslationTime(M);
1737 SmallString<14> CompilationTimeEBCDIC, CompilationTime;
1738 CompilationTime = formatv("{0:%Y%m%d%H%M%S}", llvm::sys::toUtcTime(Time));
1739
1740 uint32_t ProductVersion = getProductVersion(M),
1741 ProductRelease = getProductRelease(M),
1742 ProductPatch = getProductPatch(M);
1743
1744 SmallString<6> VersionEBCDIC, Version;
1745 Version = formatv("{0,0-2:d}{1,0-2:d}{2,0-2:d}", ProductVersion,
1746 ProductRelease, ProductPatch);
1747
1748 ConverterEBCDIC::convertToEBCDIC(CompilationTime, CompilationTimeEBCDIC);
1750
1751 enum class PPA2MemberId : uint8_t {
1752 // See z/OS Language Environment Vendor Interfaces v2r5, p.23, for
1753 // complete list. Only the C runtime is supported by this backend.
1754 LE_C_Runtime = 3,
1755 };
1756 enum class PPA2MemberSubId : uint8_t {
1757 // List of languages using the LE C runtime implementation.
1758 C = 0x00,
1759 CXX = 0x01,
1760 Swift = 0x03,
1761 Go = 0x60,
1762 LLVMBasedLang = 0xe7,
1763 };
1764 // PPA2 Flags
1765 enum class PPA2Flags : uint8_t {
1766 CompileForBinaryFloatingPoint = 0x80,
1767 CompiledWithXPLink = 0x01,
1768 CompiledUnitASCII = 0x04,
1769 HasServiceInfo = 0x20,
1770 };
1771
1772 PPA2MemberSubId MemberSubId = PPA2MemberSubId::LLVMBasedLang;
1773 if (auto *MD = M.getModuleFlag("zos_cu_language")) {
1774 StringRef Language = cast<MDString>(MD)->getString();
1775 MemberSubId = StringSwitch<PPA2MemberSubId>(Language)
1776 .Case("C", PPA2MemberSubId::C)
1777 .Case("C++", PPA2MemberSubId::CXX)
1778 .Case("Swift", PPA2MemberSubId::Swift)
1779 .Case("Go", PPA2MemberSubId::Go)
1780 .Default(PPA2MemberSubId::LLVMBasedLang);
1781 }
1782
1783 // Emit PPA2 section.
1784 OutStreamer->emitLabel(PPA2Sym);
1785 OutStreamer->emitInt8(static_cast<uint8_t>(PPA2MemberId::LE_C_Runtime));
1786 OutStreamer->emitInt8(static_cast<uint8_t>(MemberSubId));
1787 OutStreamer->emitInt8(0x22); // Member defined, c370_plist+c370_env
1788 OutStreamer->emitInt8(0x04); // Control level 4 (XPLink)
1789 OutStreamer->emitAbsoluteSymbolDiff(CELQSTRT, PPA2Sym, 4);
1790 OutStreamer->emitInt32(0x00000000);
1791 OutStreamer->emitAbsoluteSymbolDiff(DateVersionSym, PPA2Sym, 4);
1792 OutStreamer->emitInt32(
1793 0x00000000); // Offset to main entry point, always 0 (so says TR).
1794 uint8_t Flgs = static_cast<uint8_t>(PPA2Flags::CompileForBinaryFloatingPoint);
1795 Flgs |= static_cast<uint8_t>(PPA2Flags::CompiledWithXPLink);
1796
1797 bool IsASCII = true;
1798 if (auto *MD = M.getModuleFlag("zos_le_char_mode")) {
1799 const StringRef &CharMode = cast<MDString>(MD)->getString();
1800 if (CharMode == "ebcdic")
1801 IsASCII = false;
1802 else if (CharMode != "ascii")
1803 OutContext.reportError(
1804 {}, "Only ascii or ebcdic are allowed for zos_le_char_mode");
1805 }
1806 if (IsASCII)
1807 Flgs |= static_cast<uint8_t>(
1808 PPA2Flags::CompiledUnitASCII); // Setting bit for ASCII char. mode.
1809
1810 OutStreamer->emitInt8(Flgs);
1811 OutStreamer->emitInt8(0x00); // Reserved.
1812 // No MD5 signature before timestamp.
1813 // No FLOAT(AFP(VOLATILE)).
1814 // Remaining 5 flag bits reserved.
1815 OutStreamer->emitInt16(0x0000); // 16 Reserved flag bits.
1816
1817 // Emit date and version section.
1818 OutStreamer->emitLabel(DateVersionSym);
1819 OutStreamer->emitBytes(CompilationTimeEBCDIC.str());
1820 OutStreamer->emitBytes(VersionEBCDIC.str());
1821
1822 OutStreamer->emitInt16(0x0000); // Service level string length.
1823
1824 // The binder requires that the offset to the PPA2 be emitted in a different,
1825 // specially-named section.
1826 OutStreamer->switchSection(getObjFileLowering().getPPA2ListSection());
1827 // Emit 8 byte alignment.
1828 // Emit pointer to PPA2 label.
1829 OutStreamer->AddComment("A(PPA2-CELQSTRT)");
1830 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, CELQSTRT, 8);
1831 OutStreamer->popSection();
1832}
1833
1835 const GlobalAlias &GA) {
1836 if (!TM.getTargetTriple().isOSzOS())
1837 return AsmPrinter::emitGlobalAlias(M, GA);
1838
1839 // Aliased function labels have already been emitted for z/OS
1840}
1841
1843 const Constant *BaseCV,
1844 uint64_t Offset) {
1845 const Triple &TargetTriple = TM.getTargetTriple();
1846
1847 if (TargetTriple.isOSzOS()) {
1848 const GlobalAlias *GA = dyn_cast<GlobalAlias>(CV);
1850 const Function *FV = dyn_cast<Function>(CV);
1851 bool IsFunc = !GV && (FV || (GA && isa<Function>(GA->getAliaseeObject())));
1852
1853 MCSymbol *Sym = NULL;
1854
1855 if (GA)
1856 Sym = getSymbol(GA);
1857 else if (IsFunc)
1858 Sym = getSymbol(FV);
1859 else if (GV)
1860 Sym = getSymbol(GV);
1861
1862 if (IsFunc) {
1863 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
1864 if (FV->hasExternalLinkage())
1867 // Trigger creation of function descriptor in ADA for internal
1868 // functions.
1869 unsigned Disp = ADATable.insert(Sym, SystemZII::MO_ADA_DIRECT_FUNC_DESC);
1873 getObjFileLowering().getADASection()->getBeginSymbol(),
1874 OutContext),
1877 }
1878 if (Sym) {
1879 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
1881 }
1882 }
1883 return AsmPrinter::lowerConstant(CV);
1884}
1885
1887 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1888
1889 if (Subtarget.getTargetTriple().isOSzOS()) {
1890 calculatePPA1();
1891
1892 // EntryPoint Marker
1893 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1894 bool IsUsingAlloca = MFFrame.hasVarSizedObjects();
1895 uint32_t DSASize = MFFrame.getStackSize();
1896 bool IsLeaf = DSASize == 0 && MFFrame.getCalleeSavedInfo().empty();
1897
1898 // Set Flags.
1899 uint8_t Flags = 0;
1900 if (IsLeaf)
1901 Flags |= 0x08;
1902 if (IsUsingAlloca)
1903 Flags |= 0x04;
1904
1905 // Combine into top 27 bits of DSASize and bottom 5 bits of Flags.
1906 uint32_t DSAAndFlags = DSASize & 0xFFFFFFE0; // (x/32) << 5
1907 DSAAndFlags |= Flags;
1908
1909 // Emit entry point marker section.
1910 OutStreamer->AddComment("XPLINK Routine Layout Entry");
1911 OutStreamer->emitLabel(DeferredPPA1.back().EPMarker);
1912 OutStreamer->AddComment("Eyecatcher 0x00C300C500C500");
1913 OutStreamer->emitIntValueInHex(0x00C300C500C500, 7); // Eyecatcher.
1914 OutStreamer->AddComment("Mark Type C'1'");
1915 OutStreamer->emitInt8(0xF1); // Mark Type.
1916 OutStreamer->AddComment("Offset to PPA1");
1917 OutStreamer->emitAbsoluteSymbolDiff(DeferredPPA1.back().PPA1,
1918 DeferredPPA1.back().EPMarker, 4);
1919 if (OutStreamer->isVerboseAsm()) {
1920 OutStreamer->AddComment("DSA Size 0x" + Twine::utohexstr(DSASize));
1921 OutStreamer->AddComment("Entry Flags");
1922 if (Flags & 0x08)
1923 OutStreamer->AddComment(" Bit 1: 1 = Leaf function");
1924 else
1925 OutStreamer->AddComment(" Bit 1: 0 = Non-leaf function");
1926 if (Flags & 0x04)
1927 OutStreamer->AddComment(" Bit 2: 1 = Uses alloca");
1928 else
1929 OutStreamer->AddComment(" Bit 2: 0 = Does not use alloca");
1930 }
1931 OutStreamer->emitInt32(DSAAndFlags);
1932
1933 getTargetStreamer()->emitADA(CurrentFnSym,
1934 getObjFileLowering().getADASection());
1935 }
1936
1938
1939 if (Subtarget.getTargetTriple().isOSzOS()) {
1940 const Function *F = &MF->getFunction();
1941 // Emit aliasing label for function entry point label.
1942 for (const GlobalAlias *Alias : GOAliasMap[F]) {
1943 MCSymbol *Sym = getSymbol(Alias);
1944 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
1945 emitVisibility(Sym, Alias->getVisibility());
1946 emitLinkage(Alias, Sym);
1947 OutStreamer->emitLabel(Sym);
1948 }
1949 }
1950}
1951
1952char SystemZAsmPrinter::ID = 0;
1953
1954INITIALIZE_PASS(SystemZAsmPrinter, "systemz-asm-printer",
1955 "SystemZ Assembly Printer", false, false)
1956
1957// Force static initialization.
1958extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1959LLVMInitializeSystemZAsmPrinter() {
1961}
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.
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
const MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:97
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:566
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:646
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:630
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:557
@ Length
Definition DWP.cpp:557
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:1151
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,...