LLVM  5.0.0
HexagonAsmPrinter.cpp
Go to the documentation of this file.
1 //===-- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly --===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to Hexagon assembly language. This printer is
12 // the output mechanism used by `llc'.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #include "HexagonAsmPrinter.h"
17 #include "Hexagon.h"
19 #include "HexagonSubtarget.h"
20 #include "HexagonTargetMachine.h"
24 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/BinaryFormat/ELF.h"
32 #include "llvm/IR/Constants.h"
33 #include "llvm/IR/DataLayout.h"
34 #include "llvm/IR/DerivedTypes.h"
35 #include "llvm/IR/Mangler.h"
36 #include "llvm/IR/Module.h"
37 #include "llvm/MC/MCAsmInfo.h"
38 #include "llvm/MC/MCContext.h"
39 #include "llvm/MC/MCExpr.h"
40 #include "llvm/MC/MCInst.h"
41 #include "llvm/MC/MCSection.h"
42 #include "llvm/MC/MCSectionELF.h"
43 #include "llvm/MC/MCStreamer.h"
44 #include "llvm/MC/MCSymbol.h"
46 #include "llvm/Support/Debug.h"
47 #include "llvm/Support/Format.h"
55 
56 using namespace llvm;
57 
58 namespace llvm {
59  void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
60  MCInst &MCB, HexagonAsmPrinter &AP);
61 }
62 
63 #define DEBUG_TYPE "asm-printer"
64 
66  "hexagon-align-calls", cl::Hidden, cl::init(true),
67  cl::desc("Insert falign after call instruction for Hexagon target"));
68 
69 // Given a scalar register return its pair.
70 inline static unsigned getHexagonRegisterPair(unsigned Reg,
71  const MCRegisterInfo *RI) {
72  assert(Hexagon::IntRegsRegClass.contains(Reg));
73  MCSuperRegIterator SR(Reg, RI, false);
74  unsigned Pair = *SR;
75  assert(Hexagon::DoubleRegsRegClass.contains(Pair));
76  return Pair;
77 }
78 
80  std::unique_ptr<MCStreamer> Streamer)
81  : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr) {}
82 
83 void HexagonAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
84  raw_ostream &O) {
85  const MachineOperand &MO = MI->getOperand(OpNo);
86 
87  switch (MO.getType()) {
88  default: llvm_unreachable ("<unknown operand type>");
91  return;
93  O << MO.getImm();
94  return;
96  MO.getMBB()->getSymbol()->print(O, MAI);
97  return;
99  GetCPISymbol(MO.getIndex())->print(O, MAI);
100  return;
102  // Computing the address of a global symbol, not calling it.
103  getSymbol(MO.getGlobal())->print(O, MAI);
104  printOffset(MO.getOffset(), O);
105  return;
106  }
107 }
108 
109 //
110 // isBlockOnlyReachableByFallthrough - We need to override this since the
111 // default AsmPrinter does not print labels for any basic block that
112 // is only reachable by a fall through. That works for all cases except
113 // for the case in which the basic block is reachable by a fall through but
114 // through an indirect from a jump table. In this case, the jump table
115 // will contain a label not defined by AsmPrinter.
116 //
119  if (MBB->hasAddressTaken())
120  return false;
122 }
123 
124 
125 /// PrintAsmOperand - Print out an operand for an inline asm expression.
126 ///
128  unsigned AsmVariant,
129  const char *ExtraCode,
130  raw_ostream &OS) {
131  // Does this asm operand have a single letter operand modifier?
132  if (ExtraCode && ExtraCode[0]) {
133  if (ExtraCode[1] != 0)
134  return true; // Unknown modifier.
135 
136  switch (ExtraCode[0]) {
137  default:
138  // See if this is a generic print operand
139  return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS);
140  case 'c': // Don't print "$" before a global var name or constant.
141  // Hexagon never has a prefix.
142  printOperand(MI, OpNo, OS);
143  return false;
144  case 'L':
145  case 'H': { // The highest-numbered register of a pair.
146  const MachineOperand &MO = MI->getOperand(OpNo);
147  const MachineFunction &MF = *MI->getParent()->getParent();
148  const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
149  if (!MO.isReg())
150  return true;
151  unsigned RegNumber = MO.getReg();
152  // This should be an assert in the frontend.
153  if (Hexagon::DoubleRegsRegClass.contains(RegNumber))
154  RegNumber = TRI->getSubReg(RegNumber, ExtraCode[0] == 'L' ?
155  Hexagon::isub_lo :
156  Hexagon::isub_hi);
157  OS << HexagonInstPrinter::getRegisterName(RegNumber);
158  return false;
159  }
160  case 'I':
161  // Write 'i' if an integer constant, otherwise nothing. Used to print
162  // addi vs add, etc.
163  if (MI->getOperand(OpNo).isImm())
164  OS << "i";
165  return false;
166  }
167  }
168 
169  printOperand(MI, OpNo, OS);
170  return false;
171 }
172 
174  unsigned OpNo, unsigned AsmVariant,
175  const char *ExtraCode,
176  raw_ostream &O) {
177  if (ExtraCode && ExtraCode[0])
178  return true; // Unknown modifier.
179 
180  const MachineOperand &Base = MI->getOperand(OpNo);
181  const MachineOperand &Offset = MI->getOperand(OpNo+1);
182 
183  if (Base.isReg())
184  printOperand(MI, OpNo, O);
185  else
186  llvm_unreachable("Unimplemented");
187 
188  if (Offset.isImm()) {
189  if (Offset.getImm())
190  O << " + #" << Offset.getImm();
191  }
192  else
193  llvm_unreachable("Unimplemented");
194 
195  return false;
196 }
197 
199  MCStreamer &OutStreamer, const MCOperand &Imm,
200  int AlignSize) {
201  MCSymbol *Sym;
202  int64_t Value;
203  if (Imm.getExpr()->evaluateAsAbsolute(Value)) {
204  StringRef sectionPrefix;
205  std::string ImmString;
206  StringRef Name;
207  if (AlignSize == 8) {
208  Name = ".CONST_0000000000000000";
209  sectionPrefix = ".gnu.linkonce.l8";
210  ImmString = utohexstr(Value);
211  } else {
212  Name = ".CONST_00000000";
213  sectionPrefix = ".gnu.linkonce.l4";
214  ImmString = utohexstr(static_cast<uint32_t>(Value));
215  }
216 
217  std::string symbolName = // Yes, leading zeros are kept.
218  Name.drop_back(ImmString.size()).str() + ImmString;
219  std::string sectionName = sectionPrefix.str() + symbolName;
220 
221  MCSectionELF *Section = OutStreamer.getContext().getELFSection(
223  OutStreamer.SwitchSection(Section);
224 
225  Sym = AP.OutContext.getOrCreateSymbol(Twine(symbolName));
226  if (Sym->isUndefined()) {
227  OutStreamer.EmitLabel(Sym);
228  OutStreamer.EmitSymbolAttribute(Sym, MCSA_Global);
229  OutStreamer.EmitIntValue(Value, AlignSize);
230  OutStreamer.EmitCodeAlignment(AlignSize);
231  }
232  } else {
233  assert(Imm.isExpr() && "Expected expression and found none");
234  const MachineOperand &MO = MI.getOperand(1);
235  assert(MO.isGlobal() || MO.isCPI() || MO.isJTI());
236  MCSymbol *MOSymbol = nullptr;
237  if (MO.isGlobal())
238  MOSymbol = AP.getSymbol(MO.getGlobal());
239  else if (MO.isCPI())
240  MOSymbol = AP.GetCPISymbol(MO.getIndex());
241  else if (MO.isJTI())
242  MOSymbol = AP.GetJTISymbol(MO.getIndex());
243  else
244  llvm_unreachable("Unknown operand type!");
245 
246  StringRef SymbolName = MOSymbol->getName();
247  std::string LitaName = ".CONST_" + SymbolName.str();
248 
249  MCSectionELF *Section = OutStreamer.getContext().getELFSection(
251 
252  OutStreamer.SwitchSection(Section);
253  Sym = AP.OutContext.getOrCreateSymbol(Twine(LitaName));
254  if (Sym->isUndefined()) {
255  OutStreamer.EmitLabel(Sym);
256  OutStreamer.EmitSymbolAttribute(Sym, MCSA_Local);
257  OutStreamer.EmitValue(Imm.getExpr(), AlignSize);
258  OutStreamer.EmitCodeAlignment(AlignSize);
259  }
260  }
261  return Sym;
262 }
263 
264 static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo,
265  unsigned VectorSize, MCContext &Ctx) {
266  MCInst T;
267  T.setOpcode(Inst.getOpcode());
268  for (unsigned i = 0, n = Inst.getNumOperands(); i != n; ++i) {
269  if (i != OpNo) {
270  T.addOperand(Inst.getOperand(i));
271  continue;
272  }
273  MCOperand &ImmOp = Inst.getOperand(i);
274  const auto *HE = static_cast<const HexagonMCExpr*>(ImmOp.getExpr());
275  int32_t V = cast<MCConstantExpr>(HE->getExpr())->getValue();
276  auto *NewCE = MCConstantExpr::create(V / int32_t(VectorSize), Ctx);
277  auto *NewHE = HexagonMCExpr::create(NewCE, Ctx);
279  }
280  return T;
281 }
282 
284  const MachineInstr &MI) {
285  MCInst &MappedInst = static_cast <MCInst &>(Inst);
286  const MCRegisterInfo *RI = OutStreamer->getContext().getRegisterInfo();
287  const MachineFunction &MF = *MI.getParent()->getParent();
288  const auto &HST = MF.getSubtarget<HexagonSubtarget>();
289  const auto &VecRC = HST.useHVXSglOps() ? Hexagon::VectorRegsRegClass
290  : Hexagon::VectorRegs128BRegClass;
291  unsigned VectorSize = HST.getRegisterInfo()->getSpillSize(VecRC);
292 
293  switch (Inst.getOpcode()) {
294  default: return;
295 
296  case Hexagon::A2_iconst: {
297  Inst.setOpcode(Hexagon::A2_addi);
298  MCOperand Reg = Inst.getOperand(0);
299  MCOperand S16 = Inst.getOperand(1);
302  Inst.clear();
303  Inst.addOperand(Reg);
304  Inst.addOperand(MCOperand::createReg(Hexagon::R0));
305  Inst.addOperand(S16);
306  break;
307  }
308 
309  case Hexagon::A2_tfrf: {
310  Inst.setOpcode(Hexagon::A2_paddif);
312  break;
313  }
314 
315  case Hexagon::A2_tfrt: {
316  Inst.setOpcode(Hexagon::A2_paddit);
318  break;
319  }
320 
321  case Hexagon::A2_tfrfnew: {
322  Inst.setOpcode(Hexagon::A2_paddifnew);
324  break;
325  }
326 
327  case Hexagon::A2_tfrtnew: {
328  Inst.setOpcode(Hexagon::A2_padditnew);
330  break;
331  }
332 
333  case Hexagon::A2_zxtb: {
334  Inst.setOpcode(Hexagon::A2_andir);
336  break;
337  }
338 
339  // "$dst = CONST64(#$src1)",
340  case Hexagon::CONST64:
341  if (!OutStreamer->hasRawTextSupport()) {
342  const MCOperand &Imm = MappedInst.getOperand(1);
343  MCSectionSubPair Current = OutStreamer->getCurrentSection();
344 
345  MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 8);
346 
347  OutStreamer->SwitchSection(Current.first, Current.second);
348  MCInst TmpInst;
349  MCOperand &Reg = MappedInst.getOperand(0);
350  TmpInst.setOpcode(Hexagon::L2_loadrdgp);
351  TmpInst.addOperand(Reg);
354  MappedInst = TmpInst;
355 
356  }
357  break;
358  case Hexagon::CONST32:
359  if (!OutStreamer->hasRawTextSupport()) {
360  MCOperand &Imm = MappedInst.getOperand(1);
361  MCSectionSubPair Current = OutStreamer->getCurrentSection();
362  MCSymbol *Sym = smallData(*this, MI, *OutStreamer, Imm, 4);
363  OutStreamer->SwitchSection(Current.first, Current.second);
364  MCInst TmpInst;
365  MCOperand &Reg = MappedInst.getOperand(0);
366  TmpInst.setOpcode(Hexagon::L2_loadrigp);
367  TmpInst.addOperand(Reg);
370  MappedInst = TmpInst;
371  }
372  break;
373 
374  // C2_pxfer_map maps to C2_or instruction. Though, it's possible to use
375  // C2_or during instruction selection itself but it results
376  // into suboptimal code.
377  case Hexagon::C2_pxfer_map: {
378  MCOperand &Ps = Inst.getOperand(1);
379  MappedInst.setOpcode(Hexagon::C2_or);
380  MappedInst.addOperand(Ps);
381  return;
382  }
383 
384  // Vector reduce complex multiply by scalar, Rt & 1 map to :hi else :lo
385  // The insn is mapped from the 4 operand to the 3 operand raw form taking
386  // 3 register pairs.
387  case Hexagon::M2_vrcmpys_acc_s1: {
388  MCOperand &Rt = Inst.getOperand(3);
389  assert (Rt.isReg() && "Expected register and none was found");
390  unsigned Reg = RI->getEncodingValue(Rt.getReg());
391  if (Reg & 1)
392  MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
393  else
394  MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
395  Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
396  return;
397  }
398  case Hexagon::M2_vrcmpys_s1: {
399  MCOperand &Rt = Inst.getOperand(2);
400  assert (Rt.isReg() && "Expected register and none was found");
401  unsigned Reg = RI->getEncodingValue(Rt.getReg());
402  if (Reg & 1)
403  MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_h);
404  else
405  MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_l);
406  Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
407  return;
408  }
409 
410  case Hexagon::M2_vrcmpys_s1rp: {
411  MCOperand &Rt = Inst.getOperand(2);
412  assert (Rt.isReg() && "Expected register and none was found");
413  unsigned Reg = RI->getEncodingValue(Rt.getReg());
414  if (Reg & 1)
415  MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
416  else
417  MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
418  Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
419  return;
420  }
421 
422  case Hexagon::A4_boundscheck: {
423  MCOperand &Rs = Inst.getOperand(1);
424  assert (Rs.isReg() && "Expected register and none was found");
425  unsigned Reg = RI->getEncodingValue(Rs.getReg());
426  if (Reg & 1) // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2
427  MappedInst.setOpcode(Hexagon::A4_boundscheck_hi);
428  else // raw:lo
429  MappedInst.setOpcode(Hexagon::A4_boundscheck_lo);
430  Rs.setReg(getHexagonRegisterPair(Rs.getReg(), RI));
431  return;
432  }
433  case Hexagon::PS_call_nr:
434  Inst.setOpcode(Hexagon::J2_call);
435  break;
436  case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
437  MCOperand &MO = MappedInst.getOperand(2);
438  int64_t Imm;
439  MCExpr const *Expr = MO.getExpr();
440  bool Success = Expr->evaluateAsAbsolute(Imm);
441  assert (Success && "Expected immediate and none was found");
442  (void)Success;
443  MCInst TmpInst;
444  if (Imm == 0) {
445  TmpInst.setOpcode(Hexagon::S2_vsathub);
446  TmpInst.addOperand(MappedInst.getOperand(0));
447  TmpInst.addOperand(MappedInst.getOperand(1));
448  MappedInst = TmpInst;
449  return;
450  }
451  TmpInst.setOpcode(Hexagon::S5_asrhub_rnd_sat);
452  TmpInst.addOperand(MappedInst.getOperand(0));
453  TmpInst.addOperand(MappedInst.getOperand(1));
454  const MCExpr *One = MCConstantExpr::create(1, OutContext);
455  const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
456  TmpInst.addOperand(
458  MappedInst = TmpInst;
459  return;
460  }
461  case Hexagon::S5_vasrhrnd_goodsyntax:
462  case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
463  MCOperand &MO2 = MappedInst.getOperand(2);
464  MCExpr const *Expr = MO2.getExpr();
465  int64_t Imm;
466  bool Success = Expr->evaluateAsAbsolute(Imm);
467  assert (Success && "Expected immediate and none was found");
468  (void)Success;
469  MCInst TmpInst;
470  if (Imm == 0) {
471  TmpInst.setOpcode(Hexagon::A2_combinew);
472  TmpInst.addOperand(MappedInst.getOperand(0));
473  MCOperand &MO1 = MappedInst.getOperand(1);
474  unsigned High = RI->getSubReg(MO1.getReg(), Hexagon::isub_hi);
475  unsigned Low = RI->getSubReg(MO1.getReg(), Hexagon::isub_lo);
476  // Add a new operand for the second register in the pair.
477  TmpInst.addOperand(MCOperand::createReg(High));
478  TmpInst.addOperand(MCOperand::createReg(Low));
479  MappedInst = TmpInst;
480  return;
481  }
482 
483  if (Inst.getOpcode() == Hexagon::S2_asr_i_p_rnd_goodsyntax)
484  TmpInst.setOpcode(Hexagon::S2_asr_i_p_rnd);
485  else
486  TmpInst.setOpcode(Hexagon::S5_vasrhrnd);
487  TmpInst.addOperand(MappedInst.getOperand(0));
488  TmpInst.addOperand(MappedInst.getOperand(1));
489  const MCExpr *One = MCConstantExpr::create(1, OutContext);
490  const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
491  TmpInst.addOperand(
493  MappedInst = TmpInst;
494  return;
495  }
496  // if ("#u5==0") Assembler mapped to: "Rd=Rs"; else Rd=asr(Rs,#u5-1):rnd
497  case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
498  MCOperand &MO = Inst.getOperand(2);
499  MCExpr const *Expr = MO.getExpr();
500  int64_t Imm;
501  bool Success = Expr->evaluateAsAbsolute(Imm);
502  assert (Success && "Expected immediate and none was found");
503  (void)Success;
504  MCInst TmpInst;
505  if (Imm == 0) {
506  TmpInst.setOpcode(Hexagon::A2_tfr);
507  TmpInst.addOperand(MappedInst.getOperand(0));
508  TmpInst.addOperand(MappedInst.getOperand(1));
509  MappedInst = TmpInst;
510  return;
511  }
512  TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd);
513  TmpInst.addOperand(MappedInst.getOperand(0));
514  TmpInst.addOperand(MappedInst.getOperand(1));
515  const MCExpr *One = MCConstantExpr::create(1, OutContext);
516  const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
517  TmpInst.addOperand(
519  MappedInst = TmpInst;
520  return;
521  }
522 
523  // Translate a "$Rdd = #imm" to "$Rdd = combine(#[-1,0], #imm)"
524  case Hexagon::A2_tfrpi: {
525  MCInst TmpInst;
526  MCOperand &Rdd = MappedInst.getOperand(0);
527  MCOperand &MO = MappedInst.getOperand(1);
528 
529  TmpInst.setOpcode(Hexagon::A2_combineii);
530  TmpInst.addOperand(Rdd);
531  int64_t Imm;
532  bool Success = MO.getExpr()->evaluateAsAbsolute(Imm);
533  if (Success && Imm < 0) {
534  const MCExpr *MOne = MCConstantExpr::create(-1, OutContext);
536  } else {
539  }
540  TmpInst.addOperand(MO);
541  MappedInst = TmpInst;
542  return;
543  }
544  // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)"
545  case Hexagon::A2_tfrp: {
546  MCOperand &MO = MappedInst.getOperand(1);
547  unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
548  unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
549  MO.setReg(High);
550  // Add a new operand for the second register in the pair.
551  MappedInst.addOperand(MCOperand::createReg(Low));
552  MappedInst.setOpcode(Hexagon::A2_combinew);
553  return;
554  }
555 
556  case Hexagon::A2_tfrpt:
557  case Hexagon::A2_tfrpf: {
558  MCOperand &MO = MappedInst.getOperand(2);
559  unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
560  unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
561  MO.setReg(High);
562  // Add a new operand for the second register in the pair.
563  MappedInst.addOperand(MCOperand::createReg(Low));
564  MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrpt)
565  ? Hexagon::C2_ccombinewt
566  : Hexagon::C2_ccombinewf);
567  return;
568  }
569  case Hexagon::A2_tfrptnew:
570  case Hexagon::A2_tfrpfnew: {
571  MCOperand &MO = MappedInst.getOperand(2);
572  unsigned High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
573  unsigned Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
574  MO.setReg(High);
575  // Add a new operand for the second register in the pair.
576  MappedInst.addOperand(MCOperand::createReg(Low));
577  MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrptnew)
578  ? Hexagon::C2_ccombinewnewt
579  : Hexagon::C2_ccombinewnewf);
580  return;
581  }
582 
583  case Hexagon::M2_mpysmi: {
584  MCOperand &Imm = MappedInst.getOperand(2);
585  MCExpr const *Expr = Imm.getExpr();
586  int64_t Value;
587  bool Success = Expr->evaluateAsAbsolute(Value);
588  assert(Success);
589  (void)Success;
590  if (Value < 0 && Value > -256) {
591  MappedInst.setOpcode(Hexagon::M2_mpysin);
594  } else
595  MappedInst.setOpcode(Hexagon::M2_mpysip);
596  return;
597  }
598 
599  case Hexagon::A2_addsp: {
600  MCOperand &Rt = Inst.getOperand(1);
601  assert (Rt.isReg() && "Expected register and none was found");
602  unsigned Reg = RI->getEncodingValue(Rt.getReg());
603  if (Reg & 1)
604  MappedInst.setOpcode(Hexagon::A2_addsph);
605  else
606  MappedInst.setOpcode(Hexagon::A2_addspl);
607  Rt.setReg(getHexagonRegisterPair(Rt.getReg(), RI));
608  return;
609  }
610  case Hexagon::V6_vd0:
611  case Hexagon::V6_vd0_128B: {
612  MCInst TmpInst;
613  assert (Inst.getOperand(0).isReg() &&
614  "Expected register and none was found");
615 
616  TmpInst.setOpcode(Hexagon::V6_vxor);
617  TmpInst.addOperand(Inst.getOperand(0));
618  TmpInst.addOperand(Inst.getOperand(0));
619  TmpInst.addOperand(Inst.getOperand(0));
620  MappedInst = TmpInst;
621  return;
622  }
623 
624  case Hexagon::V6_vL32Ub_pi:
625  case Hexagon::V6_vL32b_cur_pi:
626  case Hexagon::V6_vL32b_nt_cur_pi:
627  case Hexagon::V6_vL32b_pi:
628  case Hexagon::V6_vL32b_nt_pi:
629  case Hexagon::V6_vL32b_nt_tmp_pi:
630  case Hexagon::V6_vL32b_tmp_pi:
631  case Hexagon::V6_vL32Ub_pi_128B:
632  case Hexagon::V6_vL32b_cur_pi_128B:
633  case Hexagon::V6_vL32b_nt_cur_pi_128B:
634  case Hexagon::V6_vL32b_pi_128B:
635  case Hexagon::V6_vL32b_nt_pi_128B:
636  case Hexagon::V6_vL32b_nt_tmp_pi_128B:
637  case Hexagon::V6_vL32b_tmp_pi_128B:
638  MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
639  return;
640 
641  case Hexagon::V6_vL32Ub_ai:
642  case Hexagon::V6_vL32b_ai:
643  case Hexagon::V6_vL32b_cur_ai:
644  case Hexagon::V6_vL32b_nt_ai:
645  case Hexagon::V6_vL32b_nt_cur_ai:
646  case Hexagon::V6_vL32b_nt_tmp_ai:
647  case Hexagon::V6_vL32b_tmp_ai:
648  case Hexagon::V6_vL32Ub_ai_128B:
649  case Hexagon::V6_vL32b_ai_128B:
650  case Hexagon::V6_vL32b_cur_ai_128B:
651  case Hexagon::V6_vL32b_nt_ai_128B:
652  case Hexagon::V6_vL32b_nt_cur_ai_128B:
653  case Hexagon::V6_vL32b_nt_tmp_ai_128B:
654  case Hexagon::V6_vL32b_tmp_ai_128B:
655  MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
656  return;
657 
658  case Hexagon::V6_vS32Ub_pi:
659  case Hexagon::V6_vS32b_new_pi:
660  case Hexagon::V6_vS32b_nt_new_pi:
661  case Hexagon::V6_vS32b_nt_pi:
662  case Hexagon::V6_vS32b_pi:
663  case Hexagon::V6_vS32Ub_pi_128B:
664  case Hexagon::V6_vS32b_new_pi_128B:
665  case Hexagon::V6_vS32b_nt_new_pi_128B:
666  case Hexagon::V6_vS32b_nt_pi_128B:
667  case Hexagon::V6_vS32b_pi_128B:
668  MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
669  return;
670 
671  case Hexagon::V6_vS32Ub_ai:
672  case Hexagon::V6_vS32b_ai:
673  case Hexagon::V6_vS32b_new_ai:
674  case Hexagon::V6_vS32b_nt_ai:
675  case Hexagon::V6_vS32b_nt_new_ai:
676  case Hexagon::V6_vS32Ub_ai_128B:
677  case Hexagon::V6_vS32b_ai_128B:
678  case Hexagon::V6_vS32b_new_ai_128B:
679  case Hexagon::V6_vS32b_nt_ai_128B:
680  case Hexagon::V6_vS32b_nt_new_ai_128B:
681  MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
682  return;
683 
684  case Hexagon::V6_vL32b_cur_npred_pi:
685  case Hexagon::V6_vL32b_cur_pred_pi:
686  case Hexagon::V6_vL32b_npred_pi:
687  case Hexagon::V6_vL32b_nt_cur_npred_pi:
688  case Hexagon::V6_vL32b_nt_cur_pred_pi:
689  case Hexagon::V6_vL32b_nt_npred_pi:
690  case Hexagon::V6_vL32b_nt_pred_pi:
691  case Hexagon::V6_vL32b_nt_tmp_npred_pi:
692  case Hexagon::V6_vL32b_nt_tmp_pred_pi:
693  case Hexagon::V6_vL32b_pred_pi:
694  case Hexagon::V6_vL32b_tmp_npred_pi:
695  case Hexagon::V6_vL32b_tmp_pred_pi:
696  case Hexagon::V6_vL32b_cur_npred_pi_128B:
697  case Hexagon::V6_vL32b_cur_pred_pi_128B:
698  case Hexagon::V6_vL32b_npred_pi_128B:
699  case Hexagon::V6_vL32b_nt_cur_npred_pi_128B:
700  case Hexagon::V6_vL32b_nt_cur_pred_pi_128B:
701  case Hexagon::V6_vL32b_nt_npred_pi_128B:
702  case Hexagon::V6_vL32b_nt_pred_pi_128B:
703  case Hexagon::V6_vL32b_nt_tmp_npred_pi_128B:
704  case Hexagon::V6_vL32b_nt_tmp_pred_pi_128B:
705  case Hexagon::V6_vL32b_pred_pi_128B:
706  case Hexagon::V6_vL32b_tmp_npred_pi_128B:
707  case Hexagon::V6_vL32b_tmp_pred_pi_128B:
708  MappedInst = ScaleVectorOffset(Inst, 4, VectorSize, OutContext);
709  return;
710 
711  case Hexagon::V6_vL32b_cur_npred_ai:
712  case Hexagon::V6_vL32b_cur_pred_ai:
713  case Hexagon::V6_vL32b_npred_ai:
714  case Hexagon::V6_vL32b_nt_cur_npred_ai:
715  case Hexagon::V6_vL32b_nt_cur_pred_ai:
716  case Hexagon::V6_vL32b_nt_npred_ai:
717  case Hexagon::V6_vL32b_nt_pred_ai:
718  case Hexagon::V6_vL32b_nt_tmp_npred_ai:
719  case Hexagon::V6_vL32b_nt_tmp_pred_ai:
720  case Hexagon::V6_vL32b_pred_ai:
721  case Hexagon::V6_vL32b_tmp_npred_ai:
722  case Hexagon::V6_vL32b_tmp_pred_ai:
723  case Hexagon::V6_vL32b_cur_npred_ai_128B:
724  case Hexagon::V6_vL32b_cur_pred_ai_128B:
725  case Hexagon::V6_vL32b_npred_ai_128B:
726  case Hexagon::V6_vL32b_nt_cur_npred_ai_128B:
727  case Hexagon::V6_vL32b_nt_cur_pred_ai_128B:
728  case Hexagon::V6_vL32b_nt_npred_ai_128B:
729  case Hexagon::V6_vL32b_nt_pred_ai_128B:
730  case Hexagon::V6_vL32b_nt_tmp_npred_ai_128B:
731  case Hexagon::V6_vL32b_nt_tmp_pred_ai_128B:
732  case Hexagon::V6_vL32b_pred_ai_128B:
733  case Hexagon::V6_vL32b_tmp_npred_ai_128B:
734  case Hexagon::V6_vL32b_tmp_pred_ai_128B:
735  MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
736  return;
737 
738  case Hexagon::V6_vS32Ub_npred_pi:
739  case Hexagon::V6_vS32Ub_pred_pi:
740  case Hexagon::V6_vS32b_new_npred_pi:
741  case Hexagon::V6_vS32b_new_pred_pi:
742  case Hexagon::V6_vS32b_npred_pi:
743  case Hexagon::V6_vS32b_nqpred_pi:
744  case Hexagon::V6_vS32b_nt_new_npred_pi:
745  case Hexagon::V6_vS32b_nt_new_pred_pi:
746  case Hexagon::V6_vS32b_nt_npred_pi:
747  case Hexagon::V6_vS32b_nt_nqpred_pi:
748  case Hexagon::V6_vS32b_nt_pred_pi:
749  case Hexagon::V6_vS32b_nt_qpred_pi:
750  case Hexagon::V6_vS32b_pred_pi:
751  case Hexagon::V6_vS32b_qpred_pi:
752  case Hexagon::V6_vS32Ub_npred_pi_128B:
753  case Hexagon::V6_vS32Ub_pred_pi_128B:
754  case Hexagon::V6_vS32b_new_npred_pi_128B:
755  case Hexagon::V6_vS32b_new_pred_pi_128B:
756  case Hexagon::V6_vS32b_npred_pi_128B:
757  case Hexagon::V6_vS32b_nqpred_pi_128B:
758  case Hexagon::V6_vS32b_nt_new_npred_pi_128B:
759  case Hexagon::V6_vS32b_nt_new_pred_pi_128B:
760  case Hexagon::V6_vS32b_nt_npred_pi_128B:
761  case Hexagon::V6_vS32b_nt_nqpred_pi_128B:
762  case Hexagon::V6_vS32b_nt_pred_pi_128B:
763  case Hexagon::V6_vS32b_nt_qpred_pi_128B:
764  case Hexagon::V6_vS32b_pred_pi_128B:
765  case Hexagon::V6_vS32b_qpred_pi_128B:
766  MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
767  return;
768 
769  case Hexagon::V6_vS32Ub_npred_ai:
770  case Hexagon::V6_vS32Ub_pred_ai:
771  case Hexagon::V6_vS32b_new_npred_ai:
772  case Hexagon::V6_vS32b_new_pred_ai:
773  case Hexagon::V6_vS32b_npred_ai:
774  case Hexagon::V6_vS32b_nqpred_ai:
775  case Hexagon::V6_vS32b_nt_new_npred_ai:
776  case Hexagon::V6_vS32b_nt_new_pred_ai:
777  case Hexagon::V6_vS32b_nt_npred_ai:
778  case Hexagon::V6_vS32b_nt_nqpred_ai:
779  case Hexagon::V6_vS32b_nt_pred_ai:
780  case Hexagon::V6_vS32b_nt_qpred_ai:
781  case Hexagon::V6_vS32b_pred_ai:
782  case Hexagon::V6_vS32b_qpred_ai:
783  case Hexagon::V6_vS32Ub_npred_ai_128B:
784  case Hexagon::V6_vS32Ub_pred_ai_128B:
785  case Hexagon::V6_vS32b_new_npred_ai_128B:
786  case Hexagon::V6_vS32b_new_pred_ai_128B:
787  case Hexagon::V6_vS32b_npred_ai_128B:
788  case Hexagon::V6_vS32b_nqpred_ai_128B:
789  case Hexagon::V6_vS32b_nt_new_npred_ai_128B:
790  case Hexagon::V6_vS32b_nt_new_pred_ai_128B:
791  case Hexagon::V6_vS32b_nt_npred_ai_128B:
792  case Hexagon::V6_vS32b_nt_nqpred_ai_128B:
793  case Hexagon::V6_vS32b_nt_pred_ai_128B:
794  case Hexagon::V6_vS32b_nt_qpred_ai_128B:
795  case Hexagon::V6_vS32b_pred_ai_128B:
796  case Hexagon::V6_vS32b_qpred_ai_128B:
797  MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
798  return;
799  }
800 }
801 
802 
803 /// printMachineInstruction -- Print out a single Hexagon MI in Darwin syntax to
804 /// the current output stream.
805 ///
808  const MCInstrInfo &MCII = *Subtarget->getInstrInfo();
809 
810  if (MI->isBundle()) {
811  const MachineBasicBlock* MBB = MI->getParent();
813 
814  for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
815  if (!MII->isDebugValue() && !MII->isImplicitDef())
816  HexagonLowerToMC(MCII, &*MII, MCB, *this);
817  }
818  else
819  HexagonLowerToMC(MCII, MI, MCB, *this);
820 
822  MCII, *Subtarget, OutStreamer->getContext(), MCB, nullptr);
823  assert(Ok);
824  (void)Ok;
825  if(HexagonMCInstrInfo::bundleSize(MCB) == 0)
826  return;
827  OutStreamer->EmitInstruction(MCB, getSubtargetInfo());
828 }
829 
832 }
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const GlobalValue * getGlobal() const
instr_iterator instr_end()
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:305
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:420
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
void clear()
Definition: MCInst.h:182
bool isReg() const
Definition: MCInst.h:58
MachineBasicBlock * getMBB() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:88
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
static cl::opt< bool > AlignCalls("hexagon-align-calls", cl::Hidden, cl::init(true), cl::desc("Insert falign after call instruction for Hexagon target"))
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
MachineBasicBlock reference.
static MCSymbol * smallData(AsmPrinter &AP, const MachineInstr &MI, MCStreamer &OutStreamer, const MCOperand &Imm, int AlignSize)
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:204
uint64_t High
return AArch64::GPR64RegClass contains(Reg)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
MCSuperRegIterator enumerates all super-registers of Reg.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Reg
All possible values of the reg field in the ModR/M byte.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
.local (ELF)
Definition: MCDirectives.h:35
MCContext & getContext() const
Definition: MCStreamer.h:226
Context object for machine code objects.
Definition: MCContext.h:59
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:528
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:65
#define T
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker)
int64_t getImm() const
HexagonAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:93
void EmitInstruction(const MachineInstr *MI) override
printMachineInstruction – Print out a single Hexagon MI in Darwin syntax to the current output stream...
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:124
const char * Name
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:139
static unsigned getHexagonRegisterPair(unsigned Reg, const MCRegisterInfo *RI)
bool isBundle() const
Definition: MachineInstr.h:819
const MCExpr * getExpr() const
Definition: MCInst.h:96
void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI, MCInst &MCB, HexagonAsmPrinter &AP)
void HexagonProcessInstruction(MCInst &Inst, const MachineInstr &MBB)
Address of a global value.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
Streaming machine code generation interface.
Definition: MCStreamer.h:167
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:854
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
unsigned getSubReg(unsigned Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:76
bool isExpr() const
Definition: MCInst.h:61
virtual bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
int64_t getOffset() const
Return the offset from the symbol in this operand.
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
self_iterator getIterator()
Definition: ilist_node.h:82
static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo, unsigned VectorSize, MCContext &Ctx)
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.h:369
void LLVMInitializeHexagonAsmPrinter()
void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O)
void setOpcode(unsigned Op)
Definition: MCInst.h:167
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS) override
PrintAsmOperand - Print out an operand for an inline asm expression.
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:51
MachineOperand class - Representation of each machine instruction operand.
Module.h This file contains the declarations for the Module class.
virtual void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
Definition: MCStreamer.cpp:845
unsigned getOpcode() const
Definition: MCInst.h:168
llvm_unreachable("Unknown RegBank!")
#define Success
Representation of each machine instruction.
Definition: MachineInstr.h:59
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
.type _foo,
Definition: MCDirectives.h:30
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:121
unsigned getNumOperands() const
Definition: MCInst.h:175
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
static volatile int Zero
void setMustNotExtend(MCExpr const &Expr, bool Val=true)
size_t bundleSize(MCInst const &MCI)
static std::string utohexstr(uint64_t X, bool LowerCase=false)
Definition: StringExtras.h:62
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
void setReg(unsigned Reg)
Set the register number.
Definition: MCInst.h:71
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:379
LLVM Value Representation.
Definition: Value.h:73
static char const * getRegisterName(unsigned RegNo)
const HexagonInstrInfo * getInstrInfo() const override
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:301
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
IRTranslator LLVM IR MI
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:177
virtual void print(raw_ostream &O, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:117
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const override
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition: StringRef.h:654
Address of indexed Constant in Constant Pool.
void setS27_2_reloc(MCExpr const &Expr, bool Val=true)
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
Instructions::const_iterator const_instr_iterator
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:159
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:173
Target & getTheHexagonTarget()
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:260
void setExpr(const MCExpr *Val)
Definition: MCInst.h:101