LLVM  10.0.0
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"
17 #include "SystemZMCInstLower.h"
19 #include "llvm/BinaryFormat/ELF.h"
22 #include "llvm/IR/Mangler.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCInstBuilder.h"
25 #include "llvm/MC/MCSectionELF.h"
26 #include "llvm/MC/MCStreamer.h"
28 
29 using namespace llvm;
30 
31 // Return an RI instruction like MI with opcode Opcode, but with the
32 // GR64 register operands turned into GR32s.
33 static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode) {
34  if (MI->isCompare())
35  return MCInstBuilder(Opcode)
37  .addImm(MI->getOperand(1).getImm());
38  else
39  return MCInstBuilder(Opcode)
42  .addImm(MI->getOperand(2).getImm());
43 }
44 
45 // Return an RI instruction like MI with opcode Opcode, but with the
46 // GR64 register operands turned into GRH32s.
47 static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode) {
48  if (MI->isCompare())
49  return MCInstBuilder(Opcode)
51  .addImm(MI->getOperand(1).getImm());
52  else
53  return MCInstBuilder(Opcode)
56  .addImm(MI->getOperand(2).getImm());
57 }
58 
59 // Return an RI instruction like MI with opcode Opcode, but with the
60 // R2 register turned into a GR64.
61 static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode) {
62  return MCInstBuilder(Opcode)
63  .addReg(MI->getOperand(0).getReg())
64  .addReg(MI->getOperand(1).getReg())
65  .addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()))
66  .addImm(MI->getOperand(3).getImm())
67  .addImm(MI->getOperand(4).getImm())
68  .addImm(MI->getOperand(5).getImm());
69 }
70 
72  StringRef Name = "__tls_get_offset";
73  return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
75  Context);
76 }
77 
79  StringRef Name = "_GLOBAL_OFFSET_TABLE_";
80  return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
82  Context);
83 }
84 
85 // MI is an instruction that accepts an optional alignment hint,
86 // and which was already lowered to LoweredMI. If the alignment
87 // of the original memory operand is known, update LoweredMI to
88 // an instruction with the corresponding hint set.
89 static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI,
90  unsigned Opcode) {
91  if (!MI->hasOneMemOperand())
92  return;
93  const MachineMemOperand *MMO = *MI->memoperands_begin();
94  unsigned AlignmentHint = 0;
95  if (MMO->getAlignment() >= 16)
96  AlignmentHint = 4;
97  else if (MMO->getAlignment() >= 8)
98  AlignmentHint = 3;
99  if (AlignmentHint == 0)
100  return;
101 
102  LoweredMI.setOpcode(Opcode);
103  LoweredMI.addOperand(MCOperand::createImm(AlignmentHint));
104 }
105 
106 // MI loads the high part of a vector from memory. Return an instruction
107 // that uses replicating vector load Opcode to do the same thing.
108 static MCInst lowerSubvectorLoad(const MachineInstr *MI, unsigned Opcode) {
109  return MCInstBuilder(Opcode)
111  .addReg(MI->getOperand(1).getReg())
112  .addImm(MI->getOperand(2).getImm())
113  .addReg(MI->getOperand(3).getReg());
114 }
115 
116 // MI stores the high part of a vector to memory. Return an instruction
117 // that uses elemental vector store Opcode to do the same thing.
118 static MCInst lowerSubvectorStore(const MachineInstr *MI, unsigned Opcode) {
119  return MCInstBuilder(Opcode)
121  .addReg(MI->getOperand(1).getReg())
122  .addImm(MI->getOperand(2).getImm())
123  .addReg(MI->getOperand(3).getReg())
124  .addImm(0);
125 }
126 
129  MCInst LoweredMI;
130  switch (MI->getOpcode()) {
131  case SystemZ::Return:
132  LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D);
133  break;
134 
135  case SystemZ::CondReturn:
136  LoweredMI = MCInstBuilder(SystemZ::BCR)
137  .addImm(MI->getOperand(0).getImm())
138  .addImm(MI->getOperand(1).getImm())
139  .addReg(SystemZ::R14D);
140  break;
141 
142  case SystemZ::CRBReturn:
143  LoweredMI = MCInstBuilder(SystemZ::CRB)
144  .addReg(MI->getOperand(0).getReg())
145  .addReg(MI->getOperand(1).getReg())
146  .addImm(MI->getOperand(2).getImm())
147  .addReg(SystemZ::R14D)
148  .addImm(0);
149  break;
150 
151  case SystemZ::CGRBReturn:
152  LoweredMI = MCInstBuilder(SystemZ::CGRB)
153  .addReg(MI->getOperand(0).getReg())
154  .addReg(MI->getOperand(1).getReg())
155  .addImm(MI->getOperand(2).getImm())
156  .addReg(SystemZ::R14D)
157  .addImm(0);
158  break;
159 
160  case SystemZ::CIBReturn:
161  LoweredMI = MCInstBuilder(SystemZ::CIB)
162  .addReg(MI->getOperand(0).getReg())
163  .addImm(MI->getOperand(1).getImm())
164  .addImm(MI->getOperand(2).getImm())
165  .addReg(SystemZ::R14D)
166  .addImm(0);
167  break;
168 
169  case SystemZ::CGIBReturn:
170  LoweredMI = MCInstBuilder(SystemZ::CGIB)
171  .addReg(MI->getOperand(0).getReg())
172  .addImm(MI->getOperand(1).getImm())
173  .addImm(MI->getOperand(2).getImm())
174  .addReg(SystemZ::R14D)
175  .addImm(0);
176  break;
177 
178  case SystemZ::CLRBReturn:
179  LoweredMI = MCInstBuilder(SystemZ::CLRB)
180  .addReg(MI->getOperand(0).getReg())
181  .addReg(MI->getOperand(1).getReg())
182  .addImm(MI->getOperand(2).getImm())
183  .addReg(SystemZ::R14D)
184  .addImm(0);
185  break;
186 
187  case SystemZ::CLGRBReturn:
188  LoweredMI = MCInstBuilder(SystemZ::CLGRB)
189  .addReg(MI->getOperand(0).getReg())
190  .addReg(MI->getOperand(1).getReg())
191  .addImm(MI->getOperand(2).getImm())
192  .addReg(SystemZ::R14D)
193  .addImm(0);
194  break;
195 
196  case SystemZ::CLIBReturn:
197  LoweredMI = MCInstBuilder(SystemZ::CLIB)
198  .addReg(MI->getOperand(0).getReg())
199  .addImm(MI->getOperand(1).getImm())
200  .addImm(MI->getOperand(2).getImm())
201  .addReg(SystemZ::R14D)
202  .addImm(0);
203  break;
204 
205  case SystemZ::CLGIBReturn:
206  LoweredMI = MCInstBuilder(SystemZ::CLGIB)
207  .addReg(MI->getOperand(0).getReg())
208  .addImm(MI->getOperand(1).getImm())
209  .addImm(MI->getOperand(2).getImm())
210  .addReg(SystemZ::R14D)
211  .addImm(0);
212  break;
213 
214  case SystemZ::CallBRASL:
215  LoweredMI = MCInstBuilder(SystemZ::BRASL)
216  .addReg(SystemZ::R14D)
217  .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
218  break;
219 
220  case SystemZ::CallBASR:
221  LoweredMI = MCInstBuilder(SystemZ::BASR)
222  .addReg(SystemZ::R14D)
223  .addReg(MI->getOperand(0).getReg());
224  break;
225 
226  case SystemZ::CallJG:
227  LoweredMI = MCInstBuilder(SystemZ::JG)
228  .addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
229  break;
230 
231  case SystemZ::CallBRCL:
232  LoweredMI = MCInstBuilder(SystemZ::BRCL)
233  .addImm(MI->getOperand(0).getImm())
234  .addImm(MI->getOperand(1).getImm())
235  .addExpr(Lower.getExpr(MI->getOperand(2), MCSymbolRefExpr::VK_PLT));
236  break;
237 
238  case SystemZ::CallBR:
239  LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R1D);
240  break;
241 
242  case SystemZ::CallBCR:
243  LoweredMI = MCInstBuilder(SystemZ::BCR)
244  .addImm(MI->getOperand(0).getImm())
245  .addImm(MI->getOperand(1).getImm())
246  .addReg(SystemZ::R1D);
247  break;
248 
249  case SystemZ::CRBCall:
250  LoweredMI = MCInstBuilder(SystemZ::CRB)
251  .addReg(MI->getOperand(0).getReg())
252  .addReg(MI->getOperand(1).getReg())
253  .addImm(MI->getOperand(2).getImm())
254  .addReg(SystemZ::R1D)
255  .addImm(0);
256  break;
257 
258  case SystemZ::CGRBCall:
259  LoweredMI = MCInstBuilder(SystemZ::CGRB)
260  .addReg(MI->getOperand(0).getReg())
261  .addReg(MI->getOperand(1).getReg())
262  .addImm(MI->getOperand(2).getImm())
263  .addReg(SystemZ::R1D)
264  .addImm(0);
265  break;
266 
267  case SystemZ::CIBCall:
268  LoweredMI = MCInstBuilder(SystemZ::CIB)
269  .addReg(MI->getOperand(0).getReg())
270  .addImm(MI->getOperand(1).getImm())
271  .addImm(MI->getOperand(2).getImm())
272  .addReg(SystemZ::R1D)
273  .addImm(0);
274  break;
275 
276  case SystemZ::CGIBCall:
277  LoweredMI = MCInstBuilder(SystemZ::CGIB)
278  .addReg(MI->getOperand(0).getReg())
279  .addImm(MI->getOperand(1).getImm())
280  .addImm(MI->getOperand(2).getImm())
281  .addReg(SystemZ::R1D)
282  .addImm(0);
283  break;
284 
285  case SystemZ::CLRBCall:
286  LoweredMI = MCInstBuilder(SystemZ::CLRB)
287  .addReg(MI->getOperand(0).getReg())
288  .addReg(MI->getOperand(1).getReg())
289  .addImm(MI->getOperand(2).getImm())
290  .addReg(SystemZ::R1D)
291  .addImm(0);
292  break;
293 
294  case SystemZ::CLGRBCall:
295  LoweredMI = MCInstBuilder(SystemZ::CLGRB)
296  .addReg(MI->getOperand(0).getReg())
297  .addReg(MI->getOperand(1).getReg())
298  .addImm(MI->getOperand(2).getImm())
299  .addReg(SystemZ::R1D)
300  .addImm(0);
301  break;
302 
303  case SystemZ::CLIBCall:
304  LoweredMI = MCInstBuilder(SystemZ::CLIB)
305  .addReg(MI->getOperand(0).getReg())
306  .addImm(MI->getOperand(1).getImm())
307  .addImm(MI->getOperand(2).getImm())
308  .addReg(SystemZ::R1D)
309  .addImm(0);
310  break;
311 
312  case SystemZ::CLGIBCall:
313  LoweredMI = MCInstBuilder(SystemZ::CLGIB)
314  .addReg(MI->getOperand(0).getReg())
315  .addImm(MI->getOperand(1).getImm())
316  .addImm(MI->getOperand(2).getImm())
317  .addReg(SystemZ::R1D)
318  .addImm(0);
319  break;
320 
321  case SystemZ::TLS_GDCALL:
322  LoweredMI = MCInstBuilder(SystemZ::BRASL)
323  .addReg(SystemZ::R14D)
326  break;
327 
328  case SystemZ::TLS_LDCALL:
329  LoweredMI = MCInstBuilder(SystemZ::BRASL)
330  .addReg(SystemZ::R14D)
333  break;
334 
335  case SystemZ::GOT:
336  LoweredMI = MCInstBuilder(SystemZ::LARL)
337  .addReg(MI->getOperand(0).getReg())
338  .addExpr(getGlobalOffsetTable(MF->getContext()));
339  break;
340 
341  case SystemZ::IILF64:
342  LoweredMI = MCInstBuilder(SystemZ::IILF)
344  .addImm(MI->getOperand(2).getImm());
345  break;
346 
347  case SystemZ::IIHF64:
348  LoweredMI = MCInstBuilder(SystemZ::IIHF)
350  .addImm(MI->getOperand(2).getImm());
351  break;
352 
353  case SystemZ::RISBHH:
354  case SystemZ::RISBHL:
355  LoweredMI = lowerRIEfLow(MI, SystemZ::RISBHG);
356  break;
357 
358  case SystemZ::RISBLH:
359  case SystemZ::RISBLL:
360  LoweredMI = lowerRIEfLow(MI, SystemZ::RISBLG);
361  break;
362 
363  case SystemZ::VLVGP32:
364  LoweredMI = MCInstBuilder(SystemZ::VLVGP)
365  .addReg(MI->getOperand(0).getReg())
366  .addReg(SystemZMC::getRegAsGR64(MI->getOperand(1).getReg()))
368  break;
369 
370  case SystemZ::VLR32:
371  case SystemZ::VLR64:
372  LoweredMI = MCInstBuilder(SystemZ::VLR)
375  break;
376 
377  case SystemZ::VL:
378  Lower.lower(MI, LoweredMI);
379  lowerAlignmentHint(MI, LoweredMI, SystemZ::VLAlign);
380  break;
381 
382  case SystemZ::VST:
383  Lower.lower(MI, LoweredMI);
384  lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTAlign);
385  break;
386 
387  case SystemZ::VLM:
388  Lower.lower(MI, LoweredMI);
389  lowerAlignmentHint(MI, LoweredMI, SystemZ::VLMAlign);
390  break;
391 
392  case SystemZ::VSTM:
393  Lower.lower(MI, LoweredMI);
394  lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTMAlign);
395  break;
396 
397  case SystemZ::VL32:
398  LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPF);
399  break;
400 
401  case SystemZ::VL64:
402  LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPG);
403  break;
404 
405  case SystemZ::VST32:
406  LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEF);
407  break;
408 
409  case SystemZ::VST64:
410  LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEG);
411  break;
412 
413  case SystemZ::LFER:
414  LoweredMI = MCInstBuilder(SystemZ::VLGVF)
417  .addReg(0).addImm(0);
418  break;
419 
420  case SystemZ::LEFR:
421  LoweredMI = MCInstBuilder(SystemZ::VLVGF)
424  .addReg(MI->getOperand(1).getReg())
425  .addReg(0).addImm(0);
426  break;
427 
428 #define LOWER_LOW(NAME) \
429  case SystemZ::NAME##64: LoweredMI = lowerRILow(MI, SystemZ::NAME); break
430 
431  LOWER_LOW(IILL);
432  LOWER_LOW(IILH);
433  LOWER_LOW(TMLL);
434  LOWER_LOW(TMLH);
435  LOWER_LOW(NILL);
436  LOWER_LOW(NILH);
437  LOWER_LOW(NILF);
438  LOWER_LOW(OILL);
439  LOWER_LOW(OILH);
440  LOWER_LOW(OILF);
441  LOWER_LOW(XILF);
442 
443 #undef LOWER_LOW
444 
445 #define LOWER_HIGH(NAME) \
446  case SystemZ::NAME##64: LoweredMI = lowerRIHigh(MI, SystemZ::NAME); break
447 
448  LOWER_HIGH(IIHL);
449  LOWER_HIGH(IIHH);
450  LOWER_HIGH(TMHL);
451  LOWER_HIGH(TMHH);
452  LOWER_HIGH(NIHL);
453  LOWER_HIGH(NIHH);
454  LOWER_HIGH(NIHF);
455  LOWER_HIGH(OIHL);
456  LOWER_HIGH(OIHH);
457  LOWER_HIGH(OIHF);
458  LOWER_HIGH(XIHF);
459 
460 #undef LOWER_HIGH
461 
462  case SystemZ::Serialize:
464  LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
465  .addImm(14).addReg(SystemZ::R0D);
466  else
467  LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
468  .addImm(15).addReg(SystemZ::R0D);
469  break;
470 
471  // Emit nothing here but a comment if we can.
472  case SystemZ::MemBarrier:
473  OutStreamer->emitRawComment("MEMBARRIER");
474  return;
475 
476  // We want to emit "j .+2" for traps, jumping to the relative immediate field
477  // of the jump instruction, which is an illegal instruction. We cannot emit a
478  // "." symbol, so create and emit a temp label before the instruction and use
479  // that instead.
480  case SystemZ::Trap: {
482  OutStreamer->EmitLabel(DotSym);
483 
484  const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(DotSym, OutContext);
485  const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
486  LoweredMI = MCInstBuilder(SystemZ::J)
487  .addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
488  }
489  break;
490 
491  // Conditional traps will create a branch on condition instruction that jumps
492  // to the relative immediate field of the jump instruction. (eg. "jo .+2")
493  case SystemZ::CondTrap: {
495  OutStreamer->EmitLabel(DotSym);
496 
497  const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(DotSym, OutContext);
498  const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
499  LoweredMI = MCInstBuilder(SystemZ::BRC)
500  .addImm(MI->getOperand(0).getImm())
501  .addImm(MI->getOperand(1).getImm())
502  .addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
503  }
504  break;
505 
506  case TargetOpcode::FENTRY_CALL:
507  LowerFENTRY_CALL(*MI, Lower);
508  return;
509 
510  case TargetOpcode::STACKMAP:
511  LowerSTACKMAP(*MI);
512  return;
513 
514  case TargetOpcode::PATCHPOINT:
515  LowerPATCHPOINT(*MI, Lower);
516  return;
517 
518  default:
519  Lower.lower(MI, LoweredMI);
520  break;
521  }
522  EmitToStreamer(*OutStreamer, LoweredMI);
523 }
524 
525 
526 // Emit the largest nop instruction smaller than or equal to NumBytes
527 // bytes. Return the size of nop emitted.
529  unsigned NumBytes, const MCSubtargetInfo &STI) {
530  if (NumBytes < 2) {
531  llvm_unreachable("Zero nops?");
532  return 0;
533  }
534  else if (NumBytes < 4) {
535  OutStreamer.EmitInstruction(MCInstBuilder(SystemZ::BCRAsm)
536  .addImm(0).addReg(SystemZ::R0D), STI);
537  return 2;
538  }
539  else if (NumBytes < 6) {
540  OutStreamer.EmitInstruction(MCInstBuilder(SystemZ::BCAsm)
541  .addImm(0).addReg(0).addImm(0).addReg(0),
542  STI);
543  return 4;
544  }
545  else {
546  MCSymbol *DotSym = OutContext.createTempSymbol();
547  const MCSymbolRefExpr *Dot = MCSymbolRefExpr::create(DotSym, OutContext);
548  OutStreamer.EmitLabel(DotSym);
549  OutStreamer.EmitInstruction(MCInstBuilder(SystemZ::BRCLAsm)
550  .addImm(0).addExpr(Dot), STI);
551  return 6;
552  }
553 }
554 
555 void SystemZAsmPrinter::LowerFENTRY_CALL(const MachineInstr &MI,
557  MCContext &Ctx = MF->getContext();
558  if (MF->getFunction().hasFnAttribute("mrecord-mcount")) {
560  OutStreamer->PushSection();
561  OutStreamer->SwitchSection(
562  Ctx.getELFSection("__mcount_loc", ELF::SHT_PROGBITS, ELF::SHF_ALLOC));
563  OutStreamer->EmitSymbolValue(DotSym, 8);
564  OutStreamer->PopSection();
565  OutStreamer->EmitLabel(DotSym);
566  }
567 
568  if (MF->getFunction().hasFnAttribute("mnop-mcount")) {
569  EmitNop(Ctx, *OutStreamer, 6, getSubtargetInfo());
570  return;
571  }
572 
573  MCSymbol *fentry = Ctx.getOrCreateSymbol("__fentry__");
574  const MCSymbolRefExpr *Op =
576  OutStreamer->EmitInstruction(MCInstBuilder(SystemZ::BRASL)
577  .addReg(SystemZ::R0D).addExpr(Op), getSubtargetInfo());
578 }
579 
580 void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
581  const SystemZInstrInfo *TII =
582  static_cast<const SystemZInstrInfo *>(MF->getSubtarget().getInstrInfo());
583 
584  unsigned NumNOPBytes = MI.getOperand(1).getImm();
585 
586  auto &Ctx = OutStreamer->getContext();
587  MCSymbol *MILabel = Ctx.createTempSymbol();
588  OutStreamer->EmitLabel(MILabel);
589 
590  SM.recordStackMap(*MILabel, MI);
591  assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!");
592 
593  // Scan ahead to trim the shadow.
594  unsigned ShadowBytes = 0;
595  const MachineBasicBlock &MBB = *MI.getParent();
597  ++MII;
598  while (ShadowBytes < NumNOPBytes) {
599  if (MII == MBB.end() ||
600  MII->getOpcode() == TargetOpcode::PATCHPOINT ||
601  MII->getOpcode() == TargetOpcode::STACKMAP)
602  break;
603  ShadowBytes += TII->getInstSizeInBytes(*MII);
604  if (MII->isCall())
605  break;
606  ++MII;
607  }
608 
609  // Emit nops.
610  while (ShadowBytes < NumNOPBytes)
611  ShadowBytes += EmitNop(OutContext, *OutStreamer, NumNOPBytes - ShadowBytes,
612  getSubtargetInfo());
613 }
614 
615 // Lower a patchpoint of the form:
616 // [<def>], <id>, <numBytes>, <target>, <numArgs>
617 void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
618  SystemZMCInstLower &Lower) {
619  auto &Ctx = OutStreamer->getContext();
620  MCSymbol *MILabel = Ctx.createTempSymbol();
621  OutStreamer->EmitLabel(MILabel);
622 
623  SM.recordPatchPoint(*MILabel, MI);
624  PatchPointOpers Opers(&MI);
625 
626  unsigned EncodedBytes = 0;
627  const MachineOperand &CalleeMO = Opers.getCallTarget();
628 
629  if (CalleeMO.isImm()) {
630  uint64_t CallTarget = CalleeMO.getImm();
631  if (CallTarget) {
632  unsigned ScratchIdx = -1;
633  unsigned ScratchReg = 0;
634  do {
635  ScratchIdx = Opers.getNextScratchIdx(ScratchIdx + 1);
636  ScratchReg = MI.getOperand(ScratchIdx).getReg();
637  } while (ScratchReg == SystemZ::R0D);
638 
639  // Materialize the call target address
640  EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::LLILF)
641  .addReg(ScratchReg)
642  .addImm(CallTarget & 0xFFFFFFFF));
643  EncodedBytes += 6;
644  if (CallTarget >> 32) {
645  EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::IIHF)
646  .addReg(ScratchReg)
647  .addImm(CallTarget >> 32));
648  EncodedBytes += 6;
649  }
650 
651  EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BASR)
652  .addReg(SystemZ::R14D)
653  .addReg(ScratchReg));
654  EncodedBytes += 2;
655  }
656  } else if (CalleeMO.isGlobal()) {
657  const MCExpr *Expr = Lower.getExpr(CalleeMO, MCSymbolRefExpr::VK_PLT);
658  EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
659  .addReg(SystemZ::R14D)
660  .addExpr(Expr));
661  EncodedBytes += 6;
662  }
663 
664  // Emit padding.
665  unsigned NumBytes = Opers.getNumPatchBytes();
666  assert(NumBytes >= EncodedBytes &&
667  "Patchpoint can't request size less than the length of a call.");
668  assert((NumBytes - EncodedBytes) % 2 == 0 &&
669  "Invalid number of NOP bytes requested!");
670  while (EncodedBytes < NumBytes)
671  EncodedBytes += EmitNop(OutContext, *OutStreamer, NumBytes - EncodedBytes,
672  getSubtargetInfo());
673 }
674 
675 // Convert a SystemZ-specific constant pool modifier into the associated
676 // MCSymbolRefExpr variant kind.
679  switch (Modifier) {
684  }
685  llvm_unreachable("Invalid SystemCPModifier!");
686 }
687 
690  auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
691 
692  const MCExpr *Expr =
693  MCSymbolRefExpr::create(getSymbol(ZCPV->getGlobalValue()),
694  getModifierVariantKind(ZCPV->getModifier()),
695  OutContext);
696  uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
697 
698  OutStreamer->EmitValue(Expr, Size);
699 }
700 
701 bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
702  const char *ExtraCode,
703  raw_ostream &OS) {
704  if (ExtraCode)
705  return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
707  MCOperand MO(Lower.lowerOperand(MI->getOperand(OpNo)));
709  return false;
710 }
711 
713  unsigned OpNo,
714  const char *ExtraCode,
715  raw_ostream &OS) {
717  MI->getOperand(OpNo + 1).getImm(),
718  MI->getOperand(OpNo + 2).getReg(), OS);
719  return false;
720 }
721 
723  emitStackMaps(SM);
724 }
725 
726 // Force static initialization.
729 }
#define LOWER_LOW(NAME)
void EmitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
unsigned getNextScratchIdx(unsigned StartIdx=0) const
Get the next scratch register operand index.
Definition: StackMaps.cpp:69
LLVMContext & Context
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:95
static void printAddress(unsigned Base, int64_t Disp, unsigned Index, raw_ostream &O)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:329
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:90
bool hasFastSerialization() const
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:228
static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer, unsigned NumBytes, const MCSubtargetInfo &STI)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI, unsigned Opcode)
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:98
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
static MCInst lowerSubvectorLoad(const MachineInstr *MI, unsigned Opcode)
A description of a memory reference used in the backend.
unsigned getRegAsGRH32(unsigned Reg)
const HexagonInstrInfo * TII
unsigned getRegAsGR32(unsigned Reg)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:169
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override
Context object for machine code objects.
Definition: MCContext.h:65
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
virtual const TargetInstrInfo * getInstrInfo() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:467
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
Definition: MCInstBuilder.h:49
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
Definition: MCExpr.cpp:169
MCOperand lowerOperand(const MachineOperand &MO) const
MCContext & getContext() const
static MCInst lowerSubvectorStore(const MachineInstr *MI, unsigned Opcode)
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...
Streaming machine code generation interface.
Definition: MCStreamer.h:197
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
Definition: MCInstBuilder.h:31
Control flow instructions. These all have token chains.
Definition: ISDOpcodes.h:687
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:226
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:86
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool isCompare(QueryType Type=IgnoreBundle) const
Return true if this instruction is a comparison.
Definition: MachineInstr.h:743
static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode)
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:486
static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode)
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
Definition: MachineInstr.h:582
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Definition: MCInstBuilder.h:37
MI-level patchpoint operands.
Definition: StackMaps.h:76
void emitStackMaps(StackMaps &SM)
Emit the stack maps.
Abstract base class for all machine specific constantpool value subclasses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t getAlignment() const
Return the minimum known alignment in bytes of the actual memory reference.
static const MCSymbolRefExpr * getTLSGetOffset(MCContext &Context)
void recordPatchPoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a patchpoint instruction.
Definition: StackMaps.cpp:372
void setOpcode(unsigned Op)
Definition: MCInst.h:171
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
Definition: MachineInstr.h:567
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:449
MachineOperand class - Representation of each machine instruction operand.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:233
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...
static MCSymbolRefExpr::VariantKind getModifierVariantKind(SystemZCP::SystemZCPModifier Modifier)
unsigned getRegAsGR64(unsigned Reg)
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:130
unsigned getRegAsVR128(unsigned Reg)
int64_t getImm() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode)
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:271
Target & getTheSystemZTarget()
Representation of each machine instruction.
Definition: MachineInstr.h:63
unsigned getInstSizeInBytes(const MachineInstr &MI) const override
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:130
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 EmitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
static const MCSymbolRefExpr * getGlobalOffsetTable(MCContext &Context)
Generic base class for all target subtargets.
uint32_t Size
Definition: Profile.cpp:46
uint32_t getNumPatchBytes() const
Return the number of patchable bytes the given patchpoint should emit.
Definition: StackMaps.h:104
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:424
static void printOperand(const MCOperand &MO, const MCAsmInfo *MAI, raw_ostream &O)
#define LOWER_HIGH(NAME)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSystemZAsmPrinter()
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:400
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
A SystemZ-specific constant pool value.
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:218
void recordStackMap(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a stackmap instruction.
Definition: StackMaps.cpp:362
IRTranslator LLVM IR MI
const MachineOperand & getCallTarget() const
Returns the target of the underlying call.
Definition: StackMaps.h:109
void addOperand(const MCOperand &Op)
Definition: MCInst.h:184
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:431
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:122
const MCExpr * getExpr(const MachineOperand &MO, MCSymbolRefExpr::VariantKind Kind) const