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 case SystemZ::LOAD_TLS_BLOCK_ADDR:
778 lowerLOAD_TLS_BLOCK_ADDR(*MI, Lower);
779 return;
780 case SystemZ::LOAD_GLOBAL_STACKGUARD_ADDR:
781 lowerLOAD_GLOBAL_STACKGUARD_ADDR(*MI, Lower);
782 return;
783
784 default:
785 Lower.lower(MI, LoweredMI);
786 break;
787 }
788 EmitToStreamer(*OutStreamer, LoweredMI);
789}
790
791// Emit the largest nop instruction smaller than or equal to NumBytes
792// bytes. Return the size of nop emitted.
794 unsigned NumBytes, const MCSubtargetInfo &STI) {
795 if (NumBytes < 2) {
796 llvm_unreachable("Zero nops?");
797 return 0;
798 }
799 else if (NumBytes < 4) {
800 OutStreamer.emitInstruction(
801 MCInstBuilder(SystemZ::BCRAsm).addImm(0).addReg(SystemZ::R0D), STI);
802 return 2;
803 }
804 else if (NumBytes < 6) {
805 OutStreamer.emitInstruction(
806 MCInstBuilder(SystemZ::BCAsm).addImm(0).addReg(0).addImm(0).addReg(0),
807 STI);
808 return 4;
809 }
810 else {
813 OutStreamer.emitLabel(DotSym);
814 OutStreamer.emitInstruction(
815 MCInstBuilder(SystemZ::BRCLAsm).addImm(0).addExpr(Dot), STI);
816 return 6;
817 }
818}
819
820void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
821 SystemZMCInstLower &Lower) {
822 MCContext &Ctx = MF->getContext();
823 if (MF->getFunction().hasFnAttribute("mrecord-mcount")) {
824 MCSymbol *DotSym = OutContext.createTempSymbol();
825 OutStreamer->pushSection();
826 OutStreamer->switchSection(
827 Ctx.getELFSection("__mcount_loc", ELF::SHT_PROGBITS, ELF::SHF_ALLOC));
828 OutStreamer->emitSymbolValue(DotSym, 8);
829 OutStreamer->popSection();
830 OutStreamer->emitLabel(DotSym);
831 }
832
833 if (MF->getFunction().hasFnAttribute("mnop-mcount")) {
835 return;
836 }
837
838 MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
839 const MCSymbolRefExpr *Op =
841 OutStreamer->emitInstruction(
842 MCInstBuilder(SystemZ::BRASL).addReg(SystemZ::R0D).addExpr(Op),
844}
845
846void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
847 auto *TII = MF->getSubtarget<SystemZSubtarget>().getInstrInfo();
848
849 unsigned NumNOPBytes = MI.getOperand(1).getImm();
850
851 auto &Ctx = OutStreamer->getContext();
852 MCSymbol *MILabel = Ctx.createTempSymbol();
853 OutStreamer->emitLabel(MILabel);
854
855 SM.recordStackMap(*MILabel, MI);
856 assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!");
857
858 // Scan ahead to trim the shadow.
859 unsigned ShadowBytes = 0;
860 const MachineBasicBlock &MBB = *MI.getParent();
862 ++MII;
863 while (ShadowBytes < NumNOPBytes) {
864 if (MII == MBB.end() ||
865 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
866 MII->getOpcode() == TargetOpcode::STACKMAP)
867 break;
868 ShadowBytes += TII->getInstSizeInBytes(*MII);
869 if (MII->isCall())
870 break;
871 ++MII;
872 }
873
874 // Emit nops.
875 while (ShadowBytes < NumNOPBytes)
876 ShadowBytes += EmitNop(OutContext, *OutStreamer, NumNOPBytes - ShadowBytes,
878}
879
880// Lower a patchpoint of the form:
881// [<def>], <id>, <numBytes>, <target>, <numArgs>
882void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
883 SystemZMCInstLower &Lower) {
884 auto &Ctx = OutStreamer->getContext();
885 MCSymbol *MILabel = Ctx.createTempSymbol();
886 OutStreamer->emitLabel(MILabel);
887
888 SM.recordPatchPoint(*MILabel, MI);
889 PatchPointOpers Opers(&MI);
890
891 unsigned EncodedBytes = 0;
892 const MachineOperand &CalleeMO = Opers.getCallTarget();
893
894 if (CalleeMO.isImm()) {
895 uint64_t CallTarget = CalleeMO.getImm();
896 if (CallTarget) {
897 unsigned ScratchIdx = -1;
898 unsigned ScratchReg = 0;
899 do {
900 ScratchIdx = Opers.getNextScratchIdx(ScratchIdx + 1);
901 ScratchReg = MI.getOperand(ScratchIdx).getReg();
902 } while (ScratchReg == SystemZ::R0D);
903
904 // Materialize the call target address
905 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::LLILF)
906 .addReg(ScratchReg)
907 .addImm(CallTarget & 0xFFFFFFFF));
908 EncodedBytes += 6;
909 if (CallTarget >> 32) {
910 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::IIHF)
911 .addReg(ScratchReg)
912 .addImm(CallTarget >> 32));
913 EncodedBytes += 6;
914 }
915
916 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BASR)
917 .addReg(SystemZ::R14D)
918 .addReg(ScratchReg));
919 EncodedBytes += 2;
920 }
921 } else if (CalleeMO.isGlobal()) {
922 const MCExpr *Expr = Lower.getExpr(CalleeMO, SystemZ::S_PLT);
923 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
924 .addReg(SystemZ::R14D)
925 .addExpr(Expr));
926 EncodedBytes += 6;
927 }
928
929 // Emit padding.
930 unsigned NumBytes = Opers.getNumPatchBytes();
931 assert(NumBytes >= EncodedBytes &&
932 "Patchpoint can't request size less than the length of a call.");
933 assert((NumBytes - EncodedBytes) % 2 == 0 &&
934 "Invalid number of NOP bytes requested!");
935 while (EncodedBytes < NumBytes)
936 EncodedBytes += EmitNop(OutContext, *OutStreamer, NumBytes - EncodedBytes,
938}
939
940void SystemZAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(
941 const MachineInstr &MI, SystemZMCInstLower &Lower) {
942
943 const MachineFunction &MF = *(MI.getParent()->getParent());
944 const Function &F = MF.getFunction();
945
946 // If patchable-function-entry is set, emit in-function nops here.
947 if (F.hasFnAttribute("patchable-function-entry")) {
948 // get M-N from function attribute (CodeGenFunction subtracts N
949 // from M to yield the correct patchable-function-entry).
950 unsigned Num = F.getFnAttributeAsParsedInteger("patchable-function-entry");
951 // Emit M-N 2-byte nops. Use getNop() here instead of emitNops()
952 // to keep it aligned with the common code implementation emitting
953 // the prefix nops.
954 for (unsigned I = 0; I < Num; ++I)
955 EmitToStreamer(*OutStreamer, MF.getSubtarget().getInstrInfo()->getNop());
956 return;
957 }
958 // Otherwise, emit xray sled.
959 // .begin:
960 // j .end # -> stmg %r2, %r15, 16(%r15)
961 // nop
962 // llilf %2, FuncID
963 // brasl %r14, __xray_FunctionEntry@GOT
964 // .end:
965 //
966 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
967 // of instructions change.
968 bool HasVectorFeature =
969 TM.getMCSubtargetInfo().hasFeature(SystemZ::FeatureVector) &&
970 !TM.getMCSubtargetInfo().hasFeature(SystemZ::FeatureSoftFloat);
971 MCSymbol *FuncEntry = OutContext.getOrCreateSymbol(
972 HasVectorFeature ? "__xray_FunctionEntryVec" : "__xray_FunctionEntry");
973 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
974 MCSymbol *EndOfSled = OutContext.createTempSymbol();
975 OutStreamer->emitLabel(BeginOfSled);
977 MCInstBuilder(SystemZ::J)
978 .addExpr(MCSymbolRefExpr::create(EndOfSled, OutContext)));
981 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
982 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
983 .addReg(SystemZ::R14D)
985 FuncEntry, SystemZ::S_PLT, OutContext)));
986 OutStreamer->emitLabel(EndOfSled);
987 recordSled(BeginOfSled, MI, SledKind::FUNCTION_ENTER, 2);
988}
989
990void SystemZAsmPrinter::LowerPATCHABLE_RET(const MachineInstr &MI,
991 SystemZMCInstLower &Lower) {
992 unsigned OpCode = MI.getOperand(0).getImm();
993 MCSymbol *FallthroughLabel = nullptr;
994 if (OpCode == SystemZ::CondReturn) {
995 FallthroughLabel = OutContext.createTempSymbol();
996 int64_t Cond0 = MI.getOperand(1).getImm();
997 int64_t Cond1 = MI.getOperand(2).getImm();
998 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRC)
999 .addImm(Cond0)
1000 .addImm(Cond1 ^ Cond0)
1001 .addExpr(MCSymbolRefExpr::create(
1002 FallthroughLabel, OutContext)));
1003 }
1004 // .begin:
1005 // br %r14 # -> stmg %r2, %r15, 24(%r15)
1006 // nop
1007 // nop
1008 // llilf %2,FuncID
1009 // j __xray_FunctionExit@GOT
1010 //
1011 // Update compiler-rt/lib/xray/xray_s390x.cpp accordingly when number
1012 // of instructions change.
1013 bool HasVectorFeature =
1014 TM.getMCSubtargetInfo().hasFeature(SystemZ::FeatureVector) &&
1015 !TM.getMCSubtargetInfo().hasFeature(SystemZ::FeatureSoftFloat);
1016 MCSymbol *FuncExit = OutContext.getOrCreateSymbol(
1017 HasVectorFeature ? "__xray_FunctionExitVec" : "__xray_FunctionExit");
1018 MCSymbol *BeginOfSled = OutContext.createTempSymbol("xray_sled_", true);
1019 OutStreamer->emitLabel(BeginOfSled);
1021 MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D));
1024 MCInstBuilder(SystemZ::LLILF).addReg(SystemZ::R2D).addImm(0));
1025 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::J)
1026 .addExpr(MCSymbolRefExpr::create(
1027 FuncExit, SystemZ::S_PLT, OutContext)));
1028 if (FallthroughLabel)
1029 OutStreamer->emitLabel(FallthroughLabel);
1030 recordSled(BeginOfSled, MI, SledKind::FUNCTION_EXIT, 2);
1031}
1032
1033void SystemZAsmPrinter::lowerLOAD_TLS_BLOCK_ADDR(const MachineInstr &MI,
1034 SystemZMCInstLower &Lower) {
1035 Register AddrReg = MI.getOperand(0).getReg();
1036 const MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();
1037
1038 // EAR can only load the low subregister so use a shift for %a0 to produce
1039 // the GR containing %a0 and %a1.
1040 const Register Reg32 =
1041 MRI.getTargetRegisterInfo()->getSubReg(AddrReg, SystemZ::subreg_l32);
1042
1043 // ear <reg>, %a0
1045 MCInstBuilder(SystemZ::EAR).addReg(Reg32).addReg(SystemZ::A0));
1046
1047 // sllg <reg>, <reg>, 32
1048 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::SLLG)
1049 .addReg(AddrReg)
1050 .addReg(AddrReg)
1051 .addReg(0)
1052 .addImm(32));
1053
1054 // ear <reg>, %a1
1056 MCInstBuilder(SystemZ::EAR).addReg(Reg32).addReg(SystemZ::A1));
1057}
1058
1059void SystemZAsmPrinter::lowerLOAD_GLOBAL_STACKGUARD_ADDR(
1060 const MachineInstr &MI, SystemZMCInstLower &Lower) {
1061 Register AddrReg = MI.getOperand(0).getReg();
1062 const MachineFunction &MF = *(MI.getParent()->getParent());
1063 const Module *M = MF.getFunction().getParent();
1064 const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
1065
1066 // Obtain the global value (assert if stack guard variable can't be found).
1067 const GlobalVariable *GV = cast<GlobalVariable>(
1068 TLI->getSDagStackGuard(*M, TLI->getLibcallLoweringInfo()));
1069
1070 // If configured, emit the `__stack_protector_loc` entry
1071 if (M->hasStackProtectorGuardRecord()) {
1072 MCSymbol *Sym = OutContext.createTempSymbol();
1073 OutStreamer->pushSection();
1074 OutStreamer->switchSection(OutContext.getELFSection(
1075 "__stack_protector_loc", ELF::SHT_PROGBITS, ELF::SHF_ALLOC));
1076 OutStreamer->emitSymbolValue(Sym, getDataLayout().getPointerSize());
1077 OutStreamer->popSection();
1078 OutStreamer->emitLabel(Sym);
1079 }
1080 // Emit the address load.
1081 if (M->getPICLevel() == PICLevel::NotPIC) {
1082 EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::LARL)
1083 .addReg(AddrReg)
1084 .addExpr(MCSymbolRefExpr::create(
1085 getSymbol(GV), OutContext)));
1086 } else {
1088 MCInstBuilder(SystemZ::LGRL)
1089 .addReg(AddrReg)
1090 .addExpr(MCSymbolRefExpr::create(
1092 }
1093}
1094
1095// The *alignment* of 128-bit vector types is different between the software
1096// and hardware vector ABIs. If the there is an externally visible use of a
1097// vector type in the module it should be annotated with an attribute.
1098void SystemZAsmPrinter::emitAttributes(Module &M) {
1099 if (M.getModuleFlag("s390x-visible-vector-ABI")) {
1100 bool HasVectorFeature =
1101 TM.getMCSubtargetInfo().hasFeature(SystemZ::FeatureVector);
1102 OutStreamer->emitGNUAttribute(8, HasVectorFeature ? 2 : 1);
1103 }
1104}
1105
1106// Convert a SystemZ-specific constant pool modifier into the associated
1107// specifier.
1109 switch (Modifier) {
1110 case SystemZCP::TLSGD:
1111 return SystemZ::S_TLSGD;
1112 case SystemZCP::TLSLDM:
1113 return SystemZ::S_TLSLDM;
1114 case SystemZCP::DTPOFF:
1115 return SystemZ::S_DTPOFF;
1116 case SystemZCP::NTPOFF:
1117 return SystemZ::S_NTPOFF;
1118 }
1119 llvm_unreachable("Invalid SystemCPModifier!");
1120}
1121
1124 auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
1125
1126 const MCExpr *Expr = MCSymbolRefExpr::create(
1127 getSymbol(ZCPV->getGlobalValue()),
1128 getSpecifierFromModifier(ZCPV->getModifier()), OutContext);
1129 uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
1130
1131 OutStreamer->emitValue(Expr, Size);
1132}
1133
1134// Emit the ctor or dtor list taking into account the init priority.
1136 const Constant *List, bool IsCtor) {
1137 if (!TM.getTargetTriple().isOSBinFormatGOFF())
1138 return AsmPrinter::emitXXStructorList(DL, List, IsCtor);
1139
1140 SmallVector<Structor, 8> Structors;
1141 preprocessXXStructorList(DL, List, Structors);
1142 if (Structors.empty())
1143 return;
1144
1145 const Align Align = llvm::Align(4);
1146 const TargetLoweringObjectFileGOFF &Obj =
1147 static_cast<const TargetLoweringObjectFileGOFF &>(getObjFileLowering());
1148 for (Structor &S : Structors) {
1149 MCSectionGOFF *Section =
1150 static_cast<MCSectionGOFF *>(Obj.getStaticXtorSection(S.Priority));
1151 OutStreamer->switchSection(Section);
1152 if (OutStreamer->getCurrentSection() != OutStreamer->getPreviousSection())
1154
1155 // The priority is provided as an input to getStaticXtorSection(), and is
1156 // recalculated within that function as `Prio` going to going into the
1157 // PR section.
1158 // This priority retrieved via the `SortKey` below is the recalculated
1159 // Priority.
1160 uint32_t XtorPriority = Section->getPRAttributes().SortKey;
1161
1162 const GlobalValue *GV = dyn_cast<GlobalValue>(S.Func->stripPointerCasts());
1163 assert(GV && "C++ xxtor pointer was not a GlobalValue!");
1164 MCSymbolGOFF *Symbol = static_cast<MCSymbolGOFF *>(getSymbol(GV));
1165
1166 // @@SQINIT entry: { unsigned prio; void (*ctor)(); void (*dtor)(); }
1167
1168 unsigned PointerSizeInBytes = DL.getPointerSize();
1169
1170 auto &Ctx = OutStreamer->getContext();
1171 const MCExpr *ADAFuncRefExpr;
1172 unsigned SlotKind = SystemZII::MO_ADA_DIRECT_FUNC_DESC;
1173
1174 MCSectionGOFF *ADASection =
1175 static_cast<MCSectionGOFF *>(Obj.getADASection());
1176 assert(ADASection && "ADA section must exist for GOFF targets!");
1177 const MCSymbol *ADASym = ADASection->getBeginSymbol();
1178 assert(ADASym && "ADA symbol should already be set!");
1179
1180 ADAFuncRefExpr = MCBinaryExpr::createAdd(
1183 MCConstantExpr::create(ADATable.insert(Symbol, SlotKind), Ctx), Ctx);
1184
1185 emitInt32(XtorPriority);
1186 if (IsCtor) {
1187 OutStreamer->emitValue(ADAFuncRefExpr, PointerSizeInBytes);
1188 OutStreamer->emitIntValue(0, PointerSizeInBytes);
1189 } else {
1190 OutStreamer->emitIntValue(0, PointerSizeInBytes);
1191 OutStreamer->emitValue(ADAFuncRefExpr, PointerSizeInBytes);
1192 }
1193 }
1194}
1195
1196static void printFormattedRegName(const MCAsmInfo *MAI, unsigned RegNo,
1197 raw_ostream &OS) {
1198 const char *RegName;
1199 if (MAI->getAssemblerDialect() == AD_HLASM) {
1201 // Skip register prefix so that only register number is left
1202 assert(isalpha(RegName[0]) && isdigit(RegName[1]));
1203 OS << (RegName + 1);
1204 } else {
1206 OS << '%' << RegName;
1207 }
1208}
1209
1210static void printReg(unsigned Reg, const MCAsmInfo *MAI, raw_ostream &OS) {
1211 if (!Reg)
1212 OS << '0';
1213 else
1215}
1216
1217static void printOperand(const MCOperand &MCOp, const MCAsmInfo *MAI,
1218 raw_ostream &OS) {
1219 if (MCOp.isReg())
1220 printReg(MCOp.getReg(), MAI, OS);
1221 else if (MCOp.isImm())
1222 OS << MCOp.getImm();
1223 else if (MCOp.isExpr())
1224 MAI->printExpr(OS, *MCOp.getExpr());
1225 else
1226 llvm_unreachable("Invalid operand");
1227}
1228
1229static void printAddress(const MCAsmInfo *MAI, unsigned Base,
1230 const MCOperand &DispMO, unsigned Index,
1231 raw_ostream &OS) {
1232 printOperand(DispMO, MAI, OS);
1233 if (Base || Index) {
1234 OS << '(';
1235 if (Index) {
1236 printFormattedRegName(MAI, Index, OS);
1237 if (Base)
1238 OS << ',';
1239 }
1240 if (Base)
1242 OS << ')';
1243 }
1244}
1245
1247 const char *ExtraCode,
1248 raw_ostream &OS) {
1249 const MCRegisterInfo &MRI = TM.getMCRegisterInfo();
1250 const MachineOperand &MO = MI->getOperand(OpNo);
1251 MCOperand MCOp;
1252 if (ExtraCode) {
1253 if (ExtraCode[0] == 'N' && !ExtraCode[1] && MO.isReg() &&
1254 SystemZ::GR128BitRegClass.contains(MO.getReg()))
1255 MCOp =
1256 MCOperand::createReg(MRI.getSubReg(MO.getReg(), SystemZ::subreg_l64));
1257 else
1258 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
1259 } else {
1260 SystemZMCInstLower Lower(MF->getContext(), *this);
1261 MCOp = Lower.lowerOperand(MO);
1262 }
1263 printOperand(MCOp, &MAI, OS);
1264 return false;
1265}
1266
1268 unsigned OpNo,
1269 const char *ExtraCode,
1270 raw_ostream &OS) {
1271 if (ExtraCode && ExtraCode[0] && !ExtraCode[1]) {
1272 switch (ExtraCode[0]) {
1273 case 'A':
1274 // Unlike EmitMachineNode(), EmitSpecialNode(INLINEASM) does not call
1275 // setMemRefs(), so MI->memoperands() is empty and the alignment
1276 // information is not available.
1277 return false;
1278 case 'O':
1279 OS << MI->getOperand(OpNo + 1).getImm();
1280 return false;
1281 case 'R':
1282 ::printReg(MI->getOperand(OpNo).getReg(), &MAI, OS);
1283 return false;
1284 }
1285 }
1286 printAddress(&MAI, MI->getOperand(OpNo).getReg(),
1287 MCOperand::createImm(MI->getOperand(OpNo + 1).getImm()),
1288 MI->getOperand(OpNo + 2).getReg(), OS);
1289 return false;
1290}
1291
1293 auto TT = OutContext.getTargetTriple();
1294 if (TT.isOSzOS()) {
1295 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1296 for (auto &Info : DeferredPPA1)
1297 emitPPA1(Info);
1298 emitADASection();
1299 emitIDRLSection(M);
1300 // On z/OS, we need to associate an external data reference with an ED
1301 // symbol, for which we use the the ED of the ADA. We also need to mark the
1302 // reference as being to data, otherwise we cannot bind with code generated
1303 // by XL.
1304 for (auto &GO : M.global_objects()) {
1305 if (auto *GV = dyn_cast<GlobalVariable>(&GO)) {
1306 if (!GV->hasInitializer()) {
1307 MCSymbol *Sym = getSymbol(GV);
1308 getTargetStreamer()->emitADA(
1309 Sym, OutContext.getObjectFileInfo()->getADASection());
1310 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
1311 }
1312 }
1313 }
1314 }
1315 emitAttributes(M);
1316}
1317
1318void SystemZAsmPrinter::emitADASection() {
1319 OutStreamer->pushSection();
1320
1321 const unsigned PointerSize = getDataLayout().getPointerSize();
1322 OutStreamer->switchSection(getObjFileLowering().getADASection());
1323
1324 unsigned EmittedBytes = 0;
1325 for (auto &Entry : ADATable.getTable()) {
1326 const MCSymbol *Sym;
1327 unsigned SlotKind;
1328 std::tie(Sym, SlotKind) = Entry.first;
1329 unsigned Offset = Entry.second;
1330 assert(Offset == EmittedBytes && "Offset not as expected");
1331 (void)EmittedBytes;
1332#define EMIT_COMMENT(Str) \
1333 OutStreamer->AddComment(Twine("Offset ") \
1334 .concat(utostr(Offset)) \
1335 .concat(" " Str " ") \
1336 .concat(Sym->getName()));
1337 switch (SlotKind) {
1339 // Language Environment DLL logic requires function descriptors, for
1340 // imported functions, that are placed in the ADA to be 8 byte aligned.
1341 EMIT_COMMENT("function descriptor of");
1342 OutStreamer->emitValue(
1345 PointerSize);
1346 OutStreamer->emitValue(
1349 PointerSize);
1350 EmittedBytes += PointerSize * 2;
1351 break;
1353 EMIT_COMMENT("pointer to data symbol");
1354 OutStreamer->emitValue(
1357 PointerSize);
1358 EmittedBytes += PointerSize;
1359 break;
1362 Twine(Sym->getName()).concat("@indirect"));
1363 OutStreamer->emitSymbolAttribute(Alias, MCSA_IndirectSymbol);
1364 OutStreamer->emitSymbolAttribute(Alias, MCSA_ELF_TypeFunction);
1365 OutStreamer->emitSymbolAttribute(Alias, MCSA_Global);
1366 OutStreamer->emitSymbolAttribute(Alias, MCSA_Extern);
1367 MCSymbolGOFF *GOFFSym =
1368 static_cast<llvm::MCSymbolGOFF *>(const_cast<llvm::MCSymbol *>(Sym));
1369 getTargetStreamer()->emitExternalName(Alias, GOFFSym->getExternalName());
1370 EMIT_COMMENT("pointer to function descriptor");
1371 OutStreamer->emitValue(
1374 PointerSize);
1375 EmittedBytes += PointerSize;
1376 break;
1377 }
1378 default:
1379 llvm_unreachable("Unexpected slot kind");
1380 }
1381#undef EMIT_COMMENT
1382 }
1383 OutStreamer->popSection();
1384}
1385
1386static std::string getProductID(Module &M) {
1387 std::string ProductID;
1388 if (auto *MD = M.getModuleFlag("zos_product_id"))
1389 ProductID = cast<MDString>(MD)->getString().str();
1390 if (ProductID.empty())
1391 ProductID = "LLVM";
1392 return ProductID;
1393}
1394
1396 if (auto *VersionVal = mdconst::extract_or_null<ConstantInt>(
1397 M.getModuleFlag("zos_product_major_version")))
1398 return VersionVal->getZExtValue();
1399 return LLVM_VERSION_MAJOR;
1400}
1401
1403 if (auto *ReleaseVal = mdconst::extract_or_null<ConstantInt>(
1404 M.getModuleFlag("zos_product_minor_version")))
1405 return ReleaseVal->getZExtValue();
1406 return LLVM_VERSION_MINOR;
1407}
1408
1410 if (auto *PatchVal = mdconst::extract_or_null<ConstantInt>(
1411 M.getModuleFlag("zos_product_patchlevel")))
1412 return PatchVal->getZExtValue();
1413 return LLVM_VERSION_PATCH;
1414}
1415
1416static time_t getTranslationTime(Module &M) {
1417 std::time_t Time = 0;
1419 M.getModuleFlag("zos_translation_time"))) {
1420 long SecondsSinceEpoch = Val->getSExtValue();
1421 Time = static_cast<time_t>(SecondsSinceEpoch);
1422 }
1423 return Time;
1424}
1425
1426void SystemZAsmPrinter::emitIDRLSection(Module &M) {
1427 OutStreamer->pushSection();
1428 OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
1429 constexpr unsigned IDRLDataLength = 30;
1430 std::time_t Time = getTranslationTime(M);
1431
1432 uint32_t ProductVersion = getProductVersion(M);
1433 uint32_t ProductRelease = getProductRelease(M);
1434
1435 std::string ProductID = getProductID(M);
1436
1437 SmallString<IDRLDataLength + 1> TempStr;
1438 raw_svector_ostream O(TempStr);
1439 O << formatv("{0,-10}{1,0-2:d}{2,0-2:d}{3:%Y%m%d%H%M%S}{4,0-2}",
1440 ProductID.substr(0, 10).c_str(), ProductVersion, ProductRelease,
1441 llvm::sys::toUtcTime(Time), "0");
1442 SmallString<IDRLDataLength> Data;
1444
1445 OutStreamer->emitInt8(0); // Reserved.
1446 OutStreamer->emitInt8(3); // Format.
1447 OutStreamer->emitInt16(IDRLDataLength); // Length.
1448 OutStreamer->emitBytes(Data.str());
1449 OutStreamer->popSection();
1450}
1451
1453 if (TM.getTargetTriple().isOSzOS()) {
1454 // Emit symbol for the end of function if the z/OS target streamer
1455 // is used. This is needed to calculate the size of the function.
1456 OutStreamer->emitLabel(DeferredPPA1.back().FnEnd);
1457 }
1458}
1459
1460static void emitPPA1Flags(std::unique_ptr<MCStreamer> &OutStreamer, bool VarArg,
1461 bool StackProtector, bool FPRMask, bool VRMask,
1462 bool EHBlock, bool HasArgAreaLength, bool HasName) {
1463 enum class PPA1Flag1 : uint8_t {
1464 DSA64Bit = (0x80 >> 0),
1465 VarArg = (0x80 >> 7),
1467 };
1468 enum class PPA1Flag2 : uint8_t {
1469 ExternalProcedure = (0x80 >> 0),
1470 STACKPROTECTOR = (0x80 >> 3),
1471 LLVM_MARK_AS_BITMASK_ENUM(ExternalProcedure)
1472 };
1473 enum class PPA1Flag3 : uint8_t {
1474 HasArgAreaLength = (0x80 >> 1),
1475 FPRMask = (0x80 >> 2),
1476 LLVM_MARK_AS_BITMASK_ENUM(HasArgAreaLength)
1477 };
1478 enum class PPA1Flag4 : uint8_t {
1479 EPMOffsetPresent = (0x80 >> 0),
1480 VRMask = (0x80 >> 2),
1481 EHBlock = (0x80 >> 3),
1482 ProcedureNamePresent = (0x80 >> 7),
1483 LLVM_MARK_AS_BITMASK_ENUM(EPMOffsetPresent)
1484 };
1485
1486 // Declare optional section flags that can be modified.
1487 auto Flags1 = PPA1Flag1(0);
1488 auto Flags2 = PPA1Flag2::ExternalProcedure;
1489 auto Flags3 = PPA1Flag3(0);
1490 auto Flags4 = PPA1Flag4::EPMOffsetPresent;
1491
1492 Flags1 |= PPA1Flag1::DSA64Bit;
1493
1494 if (VarArg)
1495 Flags1 |= PPA1Flag1::VarArg;
1496
1497 if (StackProtector)
1498 Flags2 |= PPA1Flag2::STACKPROTECTOR;
1499
1500 if (HasArgAreaLength)
1501 Flags3 |= PPA1Flag3::HasArgAreaLength; // Add emit ArgAreaLength flag.
1502
1503 // SavedGPRMask, SavedFPRMask, and SavedVRMask are precomputed in.
1504 if (FPRMask)
1505 Flags3 |= PPA1Flag3::FPRMask; // Add emit FPR mask flag.
1506
1507 if (VRMask)
1508 Flags4 |= PPA1Flag4::VRMask; // Add emit VR mask flag.
1509
1510 if (EHBlock)
1511 Flags4 |= PPA1Flag4::EHBlock; // Add optional EH block.
1512
1513 if (HasName)
1514 Flags4 |= PPA1Flag4::ProcedureNamePresent; // Add optional name block.
1515
1516 OutStreamer->AddComment("PPA1 Flags 1");
1517 OutStreamer->AddComment(" Bit 0: 1 = 64-bit DSA");
1518 if ((Flags1 & PPA1Flag1::VarArg) == PPA1Flag1::VarArg)
1519 OutStreamer->AddComment(" Bit 7: 1 = Vararg function");
1520 OutStreamer->emitInt8(static_cast<uint8_t>(Flags1)); // Flags 1.
1521
1522 OutStreamer->AddComment("PPA1 Flags 2");
1523 if ((Flags2 & PPA1Flag2::ExternalProcedure) == PPA1Flag2::ExternalProcedure)
1524 OutStreamer->AddComment(" Bit 0: 1 = External procedure");
1525 if ((Flags2 & PPA1Flag2::STACKPROTECTOR) == PPA1Flag2::STACKPROTECTOR)
1526 OutStreamer->AddComment(" Bit 3: 1 = STACKPROTECT is enabled");
1527 else
1528 OutStreamer->AddComment(" Bit 3: 0 = STACKPROTECT is not enabled");
1529 OutStreamer->emitInt8(static_cast<uint8_t>(Flags2)); // Flags 2.
1530
1531 OutStreamer->AddComment("PPA1 Flags 3");
1532 if ((Flags3 & PPA1Flag3::HasArgAreaLength) == PPA1Flag3::HasArgAreaLength)
1533 OutStreamer->AddComment(
1534 " Bit 1: 1 = Argument Area Length is in optional area");
1535 if ((Flags3 & PPA1Flag3::FPRMask) == PPA1Flag3::FPRMask)
1536 OutStreamer->AddComment(" Bit 2: 1 = FP Reg Mask is in optional area");
1537 OutStreamer->emitInt8(
1538 static_cast<uint8_t>(Flags3)); // Flags 3 (optional sections).
1539
1540 OutStreamer->AddComment("PPA1 Flags 4");
1541 if ((Flags4 & PPA1Flag4::VRMask) == PPA1Flag4::VRMask)
1542 OutStreamer->AddComment(" Bit 2: 1 = Vector Reg Mask is in optional area");
1543 if ((Flags4 & PPA1Flag4::EHBlock) == PPA1Flag4::EHBlock)
1544 OutStreamer->AddComment(" Bit 3: 1 = C++ EH block");
1545 if ((Flags4 & PPA1Flag4::ProcedureNamePresent) ==
1546 PPA1Flag4::ProcedureNamePresent)
1547 OutStreamer->AddComment(" Bit 7: 1 = Name Length and Name");
1548 OutStreamer->emitInt8(static_cast<uint8_t>(
1549 Flags4)); // Flags 4 (optional sections, always emit these).
1550}
1551
1552static void emitPPA1Name(std::unique_ptr<MCStreamer> &OutStreamer,
1553 StringRef OutName) {
1554 size_t NameSize = OutName.size();
1555 uint16_t OutSize;
1556 if (NameSize < UINT16_MAX) {
1557 OutSize = static_cast<uint16_t>(NameSize);
1558 } else {
1559 OutName = OutName.substr(0, UINT16_MAX);
1560 OutSize = UINT16_MAX;
1561 }
1562 // Emit padding to ensure that the next optional field word-aligned.
1563 uint8_t ExtraZeros = 4 - ((2 + OutSize) % 4);
1564
1565 SmallString<512> OutnameConv;
1566 ConverterEBCDIC::convertToEBCDIC(OutName, OutnameConv);
1567 OutName = OutnameConv.str();
1568
1569 OutStreamer->AddComment("Length of Name");
1570 OutStreamer->emitInt16(OutSize);
1571 OutStreamer->AddComment("Name of Function");
1572 OutStreamer->emitBytes(OutName);
1573 OutStreamer->emitZeros(ExtraZeros);
1574}
1575
1576void SystemZAsmPrinter::emitPPA1(PPA1Info &Info) {
1577 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1578
1579 // Optional Argument Area Length.
1580 // Note: This represents the length of the argument area that we reserve
1581 // in our stack for setting up arguments for calls to other
1582 // routines. If this optional field is not set, LE will reserve
1583 // 128 bytes for the argument area. This optional field is
1584 // created if greater than 128 bytes is required - to guarantee
1585 // the required space is reserved on stack extension in the new
1586 // extension. This optional field is also created if the
1587 // routine has alloca(). This may reduce stack space
1588 // if alloca() call causes a stack extension.
1589 bool HasArgAreaLength = (Info.AllocaReg != 0) || (Info.CallFrameSize > 128);
1590
1591 // Emit PPA1 section.
1592 OutStreamer->AddComment("PPA1");
1593 OutStreamer->emitLabel(Info.PPA1);
1594 OutStreamer->AddComment("Version");
1595 OutStreamer->emitInt8(0x02); // Version.
1596 OutStreamer->AddComment("LE Signature X'CE'");
1597 OutStreamer->emitInt8(0xCE); // CEL signature.
1598 OutStreamer->AddComment("Saved GPR Mask");
1599 OutStreamer->emitInt16(Info.SavedGPRMask);
1600 OutStreamer->AddComment("Offset to PPA2");
1601 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, Info.PPA1, 4);
1602
1603 emitPPA1Flags(OutStreamer, Info.IsVarArg, Info.HasStackProtector,
1604 Info.SavedFPRMask != 0, Info.SavedVRMask != 0,
1605 Info.PersonalityRoutine != nullptr, HasArgAreaLength,
1606 Info.Name.size() > 0);
1607
1608 OutStreamer->AddComment("Length/4 of Parms");
1609 OutStreamer->emitInt16(
1610 static_cast<uint16_t>(Info.SizeOfFnParams / 4)); // Parms/4.
1611 OutStreamer->AddComment("Length of Code");
1612 OutStreamer->emitAbsoluteSymbolDiff(Info.FnEnd, Info.EPMarker, 4);
1613
1614 if (HasArgAreaLength) {
1615 OutStreamer->AddComment("Argument Area Length");
1616 OutStreamer->emitInt32(Info.CallFrameSize);
1617 }
1618
1619 // Emit saved FPR mask and offset to FPR save area (0x20 of flags 3).
1620 if (Info.SavedFPRMask) {
1621 OutStreamer->AddComment("FPR mask");
1622 OutStreamer->emitInt16(Info.SavedFPRMask);
1623 OutStreamer->AddComment("AR mask");
1624 OutStreamer->emitInt16(0); // AR Mask, unused currently.
1625 OutStreamer->AddComment("FPR Save Area Locator");
1626 uint64_t FPRSaveAreaOffset = Info.OffsetFPR;
1627 assert(FPRSaveAreaOffset < 0x10000000 && "Offset out of range");
1628 FPRSaveAreaOffset &= 0x0FFFFFFF; // Lose top 4 bits.
1629 OutStreamer->AddComment(
1630 Twine(" Bit 0-3: Register R").concat(utostr(Info.FrameReg)).str());
1631 OutStreamer->AddComment(
1632 Twine(" Bit 4-31: Offset ").concat(utostr(FPRSaveAreaOffset)).str());
1633 OutStreamer->emitInt32(FPRSaveAreaOffset |
1634 (Info.FrameReg << 28)); // Offset to FPR save area
1635 // with register to add
1636 // value to (alloca reg).
1637 }
1638
1639 // Emit saved VR mask to VR save area.
1640 if (Info.SavedVRMask) {
1641 OutStreamer->AddComment("VR mask");
1642 OutStreamer->emitInt8(Info.SavedVRMask);
1643 OutStreamer->emitInt8(0); // Reserved.
1644 OutStreamer->emitInt16(0); // Also reserved.
1645 uint64_t VRSaveAreaOffset = Info.OffsetVR;
1646 assert(VRSaveAreaOffset < 0x10000000 && "Offset out of range");
1647 VRSaveAreaOffset &= 0x0FFFFFFF; // Lose top 4 bits.
1648 OutStreamer->AddComment("VR Save Area Locator");
1649 OutStreamer->AddComment(
1650 Twine(" Bit 0-3: Register R").concat(utostr(Info.FrameReg)).str());
1651 OutStreamer->AddComment(
1652 Twine(" Bit 4-31: Offset ").concat(utostr(VRSaveAreaOffset)).str());
1653 OutStreamer->emitInt32(VRSaveAreaOffset | (Info.FrameReg << 28));
1654 }
1655
1656 // Emit C++ EH information block.
1657 if (Info.PersonalityRoutine) {
1658 OutStreamer->AddComment("Version");
1659 OutStreamer->emitInt32(1);
1660 OutStreamer->AddComment("Flags");
1661 OutStreamer->emitInt32(0); // LSDA field is a WAS offset
1662 OutStreamer->AddComment("Personality routine");
1663 OutStreamer->emitInt64(ADATable.insert(
1664 Info.PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC));
1665 OutStreamer->AddComment("LSDA location");
1666 OutStreamer->emitInt64(
1667 ADATable.insert(Info.GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR));
1668 }
1669
1670 // Emit name length and name optional section (0x01 of flags 4)
1671 if (Info.Name.size())
1673
1674 // Emit offset to entry point optional section (0x80 of flags 4).
1675 OutStreamer->emitAbsoluteSymbolDiff(Info.EPMarker, Info.PPA1, 4);
1676}
1677
1678void SystemZAsmPrinter::calculatePPA1() {
1679 assert(PPA2Sym != nullptr && "PPA2 Symbol not defined");
1680
1681 PPA1Info Info;
1682
1683 const TargetRegisterInfo *TRI = MF->getRegInfo().getTargetRegisterInfo();
1684 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1685
1686 const SystemZMachineFunctionInfo *ZFI =
1687 MF->getInfo<SystemZMachineFunctionInfo>();
1688 const auto *ZFL = static_cast<const SystemZXPLINKFrameLowering *>(
1689 Subtarget.getFrameLowering());
1690 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1691
1692 // Get saved GPR/FPR/VPR masks.
1693 const std::vector<CalleeSavedInfo> &CSI = MFFrame.getCalleeSavedInfo();
1694 uint16_t SavedGPRMask = 0;
1695 uint16_t SavedFPRMask = 0;
1696 uint8_t SavedVRMask = 0;
1697 int64_t OffsetFPR = 0;
1698 int64_t OffsetVR = 0;
1699 const int64_t TopOfStack =
1700 MFFrame.getOffsetAdjustment() + MFFrame.getStackSize();
1701
1702 // Loop over the spilled registers. The CalleeSavedInfo can't be used because
1703 // it does not contain all spilled registers.
1704 for (unsigned I = ZFI->getSpillGPRRegs().LowGPR,
1705 E = ZFI->getSpillGPRRegs().HighGPR;
1706 I && E && I <= E; ++I) {
1707 unsigned V = TRI->getEncodingValue((Register)I);
1708 assert(V < 16 && "GPR index out of range");
1709 SavedGPRMask |= 1 << (15 - V);
1710 }
1711
1712 for (auto &CS : CSI) {
1713 unsigned Reg = CS.getReg();
1714 unsigned I = TRI->getEncodingValue(Reg);
1715
1716 if (SystemZ::FP64BitRegClass.contains(Reg)) {
1717 assert(I < 16 && "FPR index out of range");
1718 SavedFPRMask |= 1 << (15 - I);
1719 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1720 if (Temp < OffsetFPR)
1721 OffsetFPR = Temp;
1722 } else if (SystemZ::VR128BitRegClass.contains(Reg)) {
1723 assert(I >= 16 && I <= 23 && "VPR index out of range");
1724 unsigned BitNum = I - 16;
1725 SavedVRMask |= 1 << (7 - BitNum);
1726 int64_t Temp = MFFrame.getObjectOffset(CS.getFrameIdx());
1727 if (Temp < OffsetVR)
1728 OffsetVR = Temp;
1729 }
1730 }
1731
1732 // Adjust the offset.
1733 OffsetFPR += (OffsetFPR < 0) ? TopOfStack : 0;
1734 OffsetVR += (OffsetVR < 0) ? TopOfStack : 0;
1735
1736 // Get alloca register.
1737 uint8_t FrameReg = TRI->getEncodingValue(TRI->getFrameRegister(*MF));
1738 uint8_t AllocaReg = ZFL->hasFP(*MF) ? FrameReg : 0;
1739 assert(AllocaReg < 16 && "Can't have alloca register larger than 15");
1740
1741 MCSymbol *PersonalityRoutine = nullptr;
1742 MCSymbol *GCCEH = nullptr;
1743 if (!MF->getLandingPads().empty()) {
1744 const Function *Per = dyn_cast<Function>(
1745 MF->getFunction().getPersonalityFn()->stripPointerCasts());
1746 PersonalityRoutine = Per ? MF->getTarget().getSymbol(Per) : nullptr;
1747 assert(PersonalityRoutine && "Missing personality routine");
1748
1749 GCCEH = MF->getContext().getOrCreateSymbol(Twine("GCC_except_table") +
1750 Twine(MF->getFunctionNumber()));
1751 }
1752
1753 // Get the name of the function, with suffix _.
1754 std::string N(MF->getFunction().hasName()
1755 ? Twine(MF->getFunction().getName()).concat("_").str()
1756 : "");
1757
1758 // Save the calculated values.
1759 if (MF->getFunction().hasName())
1760 Info.Name = MF->getFunction().getName();
1761 Info.PPA1 = OutContext.createTempSymbol(Twine("PPA1_").concat(N).str(), true);
1762 Info.EPMarker =
1763 OutContext.createTempSymbol(Twine("EPM_").concat(N).str(), true);
1764 Info.FnEnd = OutContext.createTempSymbol(Twine(N).concat("end_").str());
1765 Info.PersonalityRoutine = PersonalityRoutine;
1766 Info.GCCEH = GCCEH;
1767 Info.OffsetFPR = OffsetFPR;
1768 Info.OffsetVR = OffsetVR;
1769 Info.CallFrameSize = MFFrame.getMaxCallFrameSize();
1770 Info.SizeOfFnParams = ZFI->getSizeOfFnParams();
1771 Info.SavedGPRMask = SavedGPRMask;
1772 Info.SavedFPRMask = SavedFPRMask;
1773 Info.SavedVRMask = SavedVRMask;
1774 Info.FrameReg = FrameReg;
1775 Info.AllocaReg = AllocaReg;
1776 Info.IsVarArg = MF->getFunction().isVarArg();
1777 Info.HasStackProtector = MFFrame.hasStackProtectorIndex();
1778
1779 DeferredPPA1.push_back(Info);
1780}
1781
1783 if (TM.getTargetTriple().isOSzOS())
1784 emitPPA2(M);
1786}
1787
1788void SystemZAsmPrinter::emitPPA2(Module &M) {
1789 OutStreamer->pushSection();
1790 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1791 MCContext &OutContext = OutStreamer->getContext();
1792 // Make CELQSTRT symbol.
1793 const char *StartSymbolName = "CELQSTRT";
1794 MCSymbol *CELQSTRT = OutContext.getOrCreateSymbol(StartSymbolName);
1795 OutStreamer->emitSymbolAttribute(CELQSTRT, MCSA_OSLinkage);
1796 OutStreamer->emitSymbolAttribute(CELQSTRT, MCSA_Global);
1797
1798 // Create symbol and assign to class field for use in PPA1.
1799 PPA2Sym = OutContext.createTempSymbol("PPA2", false);
1800 MCSymbol *DateVersionSym = OutContext.createTempSymbol("DVS", false);
1801
1802 std::time_t Time = getTranslationTime(M);
1803 SmallString<14> CompilationTimeEBCDIC, CompilationTime;
1804 CompilationTime = formatv("{0:%Y%m%d%H%M%S}", llvm::sys::toUtcTime(Time));
1805
1806 uint32_t ProductVersion = getProductVersion(M),
1807 ProductRelease = getProductRelease(M),
1808 ProductPatch = getProductPatch(M);
1809
1810 SmallString<6> VersionEBCDIC, Version;
1811 Version = formatv("{0,0-2:d}{1,0-2:d}{2,0-2:d}", ProductVersion,
1812 ProductRelease, ProductPatch);
1813
1814 ConverterEBCDIC::convertToEBCDIC(CompilationTime, CompilationTimeEBCDIC);
1816
1817 enum class PPA2MemberId : uint8_t {
1818 // See z/OS Language Environment Vendor Interfaces v2r5, p.23, for
1819 // complete list. Only the C runtime is supported by this backend.
1820 LE_C_Runtime = 3,
1821 };
1822 enum class PPA2MemberSubId : uint8_t {
1823 // List of languages using the LE C runtime implementation.
1824 C = 0x00,
1825 CXX = 0x01,
1826 Swift = 0x03,
1827 Go = 0x60,
1828 LLVMBasedLang = 0xe7,
1829 };
1830 // PPA2 Flags
1831 enum class PPA2Flags : uint8_t {
1832 CompileForBinaryFloatingPoint = 0x80,
1833 CompiledWithXPLink = 0x01,
1834 CompiledUnitASCII = 0x04,
1835 HasServiceInfo = 0x20,
1836 };
1837
1838 PPA2MemberSubId MemberSubId = PPA2MemberSubId::LLVMBasedLang;
1839 if (auto *MD = M.getModuleFlag("zos_cu_language")) {
1840 StringRef Language = cast<MDString>(MD)->getString();
1841 MemberSubId = StringSwitch<PPA2MemberSubId>(Language)
1842 .Case("C", PPA2MemberSubId::C)
1843 .Case("C++", PPA2MemberSubId::CXX)
1844 .Case("Swift", PPA2MemberSubId::Swift)
1845 .Case("Go", PPA2MemberSubId::Go)
1846 .Default(PPA2MemberSubId::LLVMBasedLang);
1847 }
1848
1849 // Emit PPA2 section.
1850 OutStreamer->emitLabel(PPA2Sym);
1851 OutStreamer->emitInt8(static_cast<uint8_t>(PPA2MemberId::LE_C_Runtime));
1852 OutStreamer->emitInt8(static_cast<uint8_t>(MemberSubId));
1853 OutStreamer->emitInt8(0x22); // Member defined, c370_plist+c370_env
1854 OutStreamer->emitInt8(0x04); // Control level 4 (XPLink)
1855 OutStreamer->emitAbsoluteSymbolDiff(CELQSTRT, PPA2Sym, 4);
1856 OutStreamer->emitInt32(0x00000000);
1857 OutStreamer->emitAbsoluteSymbolDiff(DateVersionSym, PPA2Sym, 4);
1858 OutStreamer->emitInt32(
1859 0x00000000); // Offset to main entry point, always 0 (so says TR).
1860 uint8_t Flgs = static_cast<uint8_t>(PPA2Flags::CompileForBinaryFloatingPoint);
1861 Flgs |= static_cast<uint8_t>(PPA2Flags::CompiledWithXPLink);
1862
1863 bool IsASCII = true;
1864 if (auto *MD = M.getModuleFlag("zos_le_char_mode")) {
1865 const StringRef &CharMode = cast<MDString>(MD)->getString();
1866 if (CharMode == "ebcdic")
1867 IsASCII = false;
1868 else if (CharMode != "ascii")
1869 OutContext.reportError(
1870 {}, "Only ascii or ebcdic are allowed for zos_le_char_mode");
1871 }
1872 if (IsASCII)
1873 Flgs |= static_cast<uint8_t>(
1874 PPA2Flags::CompiledUnitASCII); // Setting bit for ASCII char. mode.
1875
1876 OutStreamer->emitInt8(Flgs);
1877 OutStreamer->emitInt8(0x00); // Reserved.
1878 // No MD5 signature before timestamp.
1879 // No FLOAT(AFP(VOLATILE)).
1880 // Remaining 5 flag bits reserved.
1881 OutStreamer->emitInt16(0x0000); // 16 Reserved flag bits.
1882
1883 // Emit date and version section.
1884 OutStreamer->emitLabel(DateVersionSym);
1885 OutStreamer->emitBytes(CompilationTimeEBCDIC.str());
1886 OutStreamer->emitBytes(VersionEBCDIC.str());
1887
1888 OutStreamer->emitInt16(0x0000); // Service level string length.
1889
1890 // The binder requires that the offset to the PPA2 be emitted in a different,
1891 // specially-named section.
1892 OutStreamer->switchSection(getObjFileLowering().getPPA2ListSection());
1893 // Emit 8 byte alignment.
1894 // Emit pointer to PPA2 label.
1895 OutStreamer->AddComment("A(PPA2-CELQSTRT)");
1896 OutStreamer->emitAbsoluteSymbolDiff(PPA2Sym, CELQSTRT, 8);
1897 OutStreamer->popSection();
1898}
1899
1901 const GlobalAlias &GA) {
1902 if (!TM.getTargetTriple().isOSzOS())
1903 return AsmPrinter::emitGlobalAlias(M, GA);
1904
1905 // Aliased function labels have already been emitted for z/OS
1906}
1907
1909 const Constant *BaseCV,
1910 uint64_t Offset) {
1911 const Triple &TargetTriple = TM.getTargetTriple();
1912
1913 if (TargetTriple.isOSzOS()) {
1914 const GlobalAlias *GA = dyn_cast<GlobalAlias>(CV);
1916 const Function *FV = dyn_cast<Function>(CV);
1917 bool IsFunc = !GV && (FV || (GA && isa<Function>(GA->getAliaseeObject())));
1918
1919 MCSymbol *Sym = NULL;
1920
1921 if (GA)
1922 Sym = getSymbol(GA);
1923 else if (IsFunc)
1924 Sym = getSymbol(FV);
1925 else if (GV)
1926 Sym = getSymbol(GV);
1927
1928 if (IsFunc) {
1929 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
1930 if (FV->hasExternalLinkage())
1933 // Trigger creation of function descriptor in ADA for internal
1934 // functions.
1935 unsigned Disp = ADATable.insert(Sym, SystemZII::MO_ADA_DIRECT_FUNC_DESC);
1939 getObjFileLowering().getADASection()->getBeginSymbol(),
1940 OutContext),
1943 }
1944 if (Sym) {
1945 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
1947 }
1948 }
1949 return AsmPrinter::lowerConstant(CV);
1950}
1951
1953 const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
1954
1955 if (Subtarget.getTargetTriple().isOSzOS()) {
1956 calculatePPA1();
1957
1958 // EntryPoint Marker
1959 const MachineFrameInfo &MFFrame = MF->getFrameInfo();
1960 bool IsUsingAlloca = MFFrame.hasVarSizedObjects();
1961 uint32_t DSASize = MFFrame.getStackSize();
1962 bool IsLeaf = DSASize == 0 && MFFrame.getCalleeSavedInfo().empty();
1963
1964 // Set Flags.
1965 uint8_t Flags = 0;
1966 if (IsLeaf)
1967 Flags |= 0x08;
1968 if (IsUsingAlloca)
1969 Flags |= 0x04;
1970
1971 // Combine into top 27 bits of DSASize and bottom 5 bits of Flags.
1972 uint32_t DSAAndFlags = DSASize & 0xFFFFFFE0; // (x/32) << 5
1973 DSAAndFlags |= Flags;
1974
1975 // Emit entry point marker section.
1976 OutStreamer->AddComment("XPLINK Routine Layout Entry");
1977 OutStreamer->emitLabel(DeferredPPA1.back().EPMarker);
1978 OutStreamer->AddComment("Eyecatcher 0x00C300C500C500");
1979 OutStreamer->emitIntValueInHex(0x00C300C500C500, 7); // Eyecatcher.
1980 OutStreamer->AddComment("Mark Type C'1'");
1981 OutStreamer->emitInt8(0xF1); // Mark Type.
1982 OutStreamer->AddComment("Offset to PPA1");
1983 OutStreamer->emitAbsoluteSymbolDiff(DeferredPPA1.back().PPA1,
1984 DeferredPPA1.back().EPMarker, 4);
1985 if (OutStreamer->isVerboseAsm()) {
1986 OutStreamer->AddComment("DSA Size 0x" + Twine::utohexstr(DSASize));
1987 OutStreamer->AddComment("Entry Flags");
1988 if (Flags & 0x08)
1989 OutStreamer->AddComment(" Bit 1: 1 = Leaf function");
1990 else
1991 OutStreamer->AddComment(" Bit 1: 0 = Non-leaf function");
1992 if (Flags & 0x04)
1993 OutStreamer->AddComment(" Bit 2: 1 = Uses alloca");
1994 else
1995 OutStreamer->AddComment(" Bit 2: 0 = Does not use alloca");
1996 }
1997 OutStreamer->emitInt32(DSAAndFlags);
1998
1999 getTargetStreamer()->emitADA(CurrentFnSym,
2000 getObjFileLowering().getADASection());
2001 }
2002
2004
2005 if (Subtarget.getTargetTriple().isOSzOS()) {
2006 const Function *F = &MF->getFunction();
2007 // Emit aliasing label for function entry point label.
2008 for (const GlobalAlias *Alias : GOAliasMap[F]) {
2009 MCSymbol *Sym = getSymbol(Alias);
2010 OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
2011 emitVisibility(Sym, Alias->getVisibility());
2012 emitLinkage(Alias, Sym);
2013 OutStreamer->emitLabel(Sym);
2014 }
2015 }
2016}
2017
2018char SystemZAsmPrinter::ID = 0;
2019
2020INITIALIZE_PASS(SystemZAsmPrinter, "systemz-asm-printer",
2021 "SystemZ Assembly Printer", false, false)
2022
2023// Force static initialization.
2024extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
2025LLVMInitializeSystemZAsmPrinter() {
2027}
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:853
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:614
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.
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
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:228
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:714
bool hasExternalLinkage() const
LLVM_ABI const GlobalObject * getAliaseeObject() const
Definition Globals.cpp:505
bool hasInitializer() const
Definitions have initializers, declarations don't.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:66
unsigned getAssemblerDialect() const
Definition MCAsmInfo.h:580
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.
const TargetRegisterInfo * getTargetRegisterInfo() const
iterator find(const KeyT &Key)
Definition MapVector.h:156
iterator end()
Definition MapVector.h:69
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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
Get the string size.
Definition StringRef.h:144
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)
const LibcallLoweringInfo & getLibcallLoweringInfo() const
virtual Value * getSDagStackGuard(const Module &M, const LibcallLoweringInfo &Libcalls) const
Return the variable that's previously inserted by insertSSPDeclarations, if any, otherwise return nul...
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:631
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:1251
@ SHT_PROGBITS
Definition ELF.h:1150
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:558
@ Length
Definition DWP.cpp:558
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:547
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...