LLVM 23.0.0git
HexagonAsmPrinter.cpp
Go to the documentation of this file.
1//===- HexagonAsmPrinter.cpp - Print machine instrs to Hexagon assembly ---===//
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// This file contains a printer that converts from our internal representation
10// of machine-dependent LLVM code to Hexagon assembly language. This printer is
11// the output mechanism used by `llc'.
12//
13//===----------------------------------------------------------------------===//
14
15#include "HexagonAsmPrinter.h"
16#include "HexagonInstrInfo.h"
17#include "HexagonRegisterInfo.h"
18#include "HexagonSubtarget.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/ADT/Twine.h"
36#include "llvm/MC/MCContext.h"
38#include "llvm/MC/MCExpr.h"
39#include "llvm/MC/MCInst.h"
42#include "llvm/MC/MCStreamer.h"
43#include "llvm/MC/MCSymbol.h"
50#include <cassert>
51#include <cstdint>
52#include <string>
53
54using namespace llvm;
55
56namespace llvm {
57
58void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
59 MCInst &MCB, HexagonAsmPrinter &AP);
60
61} // end namespace llvm
62
63#define DEBUG_TYPE "asm-printer"
64
65// Given a scalar register return its pair.
66inline static unsigned getHexagonRegisterPair(unsigned Reg,
67 const MCRegisterInfo *RI) {
68 assert(Hexagon::IntRegsRegClass.contains(Reg));
69 unsigned Pair = *RI->superregs(Reg).begin();
70 assert(Hexagon::DoubleRegsRegClass.contains(Pair));
71 return Pair;
72}
73
75 raw_ostream &O) {
76 const MachineOperand &MO = MI->getOperand(OpNo);
77
78 switch (MO.getType()) {
79 default:
80 llvm_unreachable ("<unknown operand type>");
83 return;
85 O << MO.getImm();
86 return;
88 MO.getMBB()->getSymbol()->print(O, MAI);
89 return;
91 GetCPISymbol(MO.getIndex())->print(O, MAI);
92 return;
94 PrintSymbolOperand(MO, O);
95 return;
96 }
97}
98
99// isBlockOnlyReachableByFallthrough - We need to override this since the
100// default AsmPrinter does not print labels for any basic block that
101// is only reachable by a fall through. That works for all cases except
102// for the case in which the basic block is reachable by a fall through but
103// through an indirect from a jump table. In this case, the jump table
104// will contain a label not defined by AsmPrinter.
106 const MachineBasicBlock *MBB) const {
107 if (MBB->hasAddressTaken())
108 return false;
110}
111
112/// PrintAsmOperand - Print out an operand for an inline asm expression.
114 const char *ExtraCode,
115 raw_ostream &OS) {
116 // Does this asm operand have a single letter operand modifier?
117 if (ExtraCode && ExtraCode[0]) {
118 if (ExtraCode[1] != 0)
119 return true; // Unknown modifier.
120
121 switch (ExtraCode[0]) {
122 default:
123 // See if this is a generic print operand
124 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
125 case 'L':
126 case 'H': { // The highest-numbered register of a pair.
127 const MachineOperand &MO = MI->getOperand(OpNo);
128 const MachineFunction &MF = *MI->getParent()->getParent();
129 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
130 if (!MO.isReg())
131 return true;
132 Register RegNumber = MO.getReg();
133 // This should be an assert in the frontend.
134 if (Hexagon::DoubleRegsRegClass.contains(RegNumber))
135 RegNumber = TRI->getSubReg(RegNumber, ExtraCode[0] == 'L' ?
136 Hexagon::isub_lo :
137 Hexagon::isub_hi);
139 return false;
140 }
141 case 'I':
142 // Write 'i' if an integer constant, otherwise nothing. Used to print
143 // addi vs add, etc.
144 if (MI->getOperand(OpNo).isImm())
145 OS << "i";
146 return false;
147 }
148 }
149
150 printOperand(MI, OpNo, OS);
151 return false;
152}
153
155 unsigned OpNo,
156 const char *ExtraCode,
157 raw_ostream &O) {
158 if (ExtraCode && ExtraCode[0])
159 return true; // Unknown modifier.
160
161 const MachineOperand &Base = MI->getOperand(OpNo);
162 const MachineOperand &Offset = MI->getOperand(OpNo+1);
163
164 if (Base.isReg())
165 printOperand(MI, OpNo, O);
166 else
167 llvm_unreachable("Unimplemented");
168
169 if (Offset.isImm()) {
170 if (Offset.getImm())
171 O << "+#" << Offset.getImm();
172 } else {
173 llvm_unreachable("Unimplemented");
174 }
175
176 return false;
177}
178
180 MCStreamer &OutStreamer, const MCOperand &Imm,
181 int AlignSize, const MCSubtargetInfo& STI) {
182 MCSymbol *Sym;
183 int64_t Value;
184 if (Imm.getExpr()->evaluateAsAbsolute(Value)) {
185 StringRef sectionPrefix;
186 std::string ImmString;
187 StringRef Name;
188 if (AlignSize == 8) {
189 Name = ".CONST_0000000000000000";
190 sectionPrefix = ".gnu.linkonce.l8";
191 ImmString = utohexstr(Value);
192 } else {
193 Name = ".CONST_00000000";
194 sectionPrefix = ".gnu.linkonce.l4";
195 ImmString = utohexstr(static_cast<uint32_t>(Value));
196 }
197
198 std::string symbolName = // Yes, leading zeros are kept.
199 Name.drop_back(ImmString.size()).str() + ImmString;
200 std::string sectionName = sectionPrefix.str() + symbolName;
201
202 MCSectionELF *Section = OutStreamer.getContext().getELFSection(
204 OutStreamer.switchSection(Section);
205
206 Sym = AP.OutContext.getOrCreateSymbol(Twine(symbolName));
207 if (Sym->isUndefined()) {
208 OutStreamer.emitLabel(Sym);
209 OutStreamer.emitSymbolAttribute(Sym, MCSA_Global);
210 OutStreamer.emitIntValue(Value, AlignSize);
211 OutStreamer.emitCodeAlignment(Align(AlignSize), &STI);
212 }
213 } else {
214 assert(Imm.isExpr() && "Expected expression and found none");
215 const MachineOperand &MO = MI.getOperand(1);
216 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI());
217 MCSymbol *MOSymbol = nullptr;
218 if (MO.isGlobal())
219 MOSymbol = AP.getSymbol(MO.getGlobal());
220 else if (MO.isCPI())
221 MOSymbol = AP.GetCPISymbol(MO.getIndex());
222 else if (MO.isJTI())
223 MOSymbol = AP.GetJTISymbol(MO.getIndex());
224 else
225 llvm_unreachable("Unknown operand type!");
226
227 StringRef SymbolName = MOSymbol->getName();
228 std::string LitaName = ".CONST_" + SymbolName.str();
229
230 MCSectionELF *Section = OutStreamer.getContext().getELFSection(
232
233 OutStreamer.switchSection(Section);
234 Sym = AP.OutContext.getOrCreateSymbol(Twine(LitaName));
235 if (Sym->isUndefined()) {
236 OutStreamer.emitLabel(Sym);
237 OutStreamer.emitSymbolAttribute(Sym, MCSA_Local);
238 OutStreamer.emitValue(Imm.getExpr(), AlignSize);
239 OutStreamer.emitCodeAlignment(Align(AlignSize), &STI);
240 }
241 }
242 return Sym;
243}
244
245static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo,
246 unsigned VectorSize, MCContext &Ctx) {
247 MCInst T;
248 T.setOpcode(Inst.getOpcode());
249 for (unsigned i = 0, n = Inst.getNumOperands(); i != n; ++i) {
250 if (i != OpNo) {
251 T.addOperand(Inst.getOperand(i));
252 continue;
253 }
254 MCOperand &ImmOp = Inst.getOperand(i);
255 const auto *HE = static_cast<const HexagonMCExpr*>(ImmOp.getExpr());
256 int32_t V = cast<MCConstantExpr>(HE->getExpr())->getValue();
257 auto *NewCE = MCConstantExpr::create(V / int32_t(VectorSize), Ctx);
258 auto *NewHE = HexagonMCExpr::create(NewCE, Ctx);
259 T.addOperand(MCOperand::createExpr(NewHE));
260 }
261 return T;
262}
263
265 const MachineInstr &MI) {
266 MCInst &MappedInst = static_cast <MCInst &>(Inst);
267 const MCRegisterInfo *RI = OutStreamer->getContext().getRegisterInfo();
268 const MachineFunction &MF = *MI.getParent()->getParent();
269 auto &HRI = *MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
270 unsigned VectorSize = HRI.getRegSizeInBits(Hexagon::HvxVRRegClass) / 8;
271
272 switch (Inst.getOpcode()) {
273 default:
274 return;
275
276 case Hexagon::A2_iconst: {
277 Inst.setOpcode(Hexagon::A2_addi);
278 MCOperand Reg = Inst.getOperand(0);
279 MCOperand S16 = Inst.getOperand(1);
282 Inst.clear();
283 Inst.addOperand(Reg);
284 Inst.addOperand(MCOperand::createReg(Hexagon::R0));
285 Inst.addOperand(S16);
286 break;
287 }
288
289 case Hexagon::A2_tfrf: {
291 Inst.setOpcode(Hexagon::A2_paddif);
293 break;
294 }
295
296 case Hexagon::A2_tfrt: {
298 Inst.setOpcode(Hexagon::A2_paddit);
300 break;
301 }
302
303 case Hexagon::A2_tfrfnew: {
305 Inst.setOpcode(Hexagon::A2_paddifnew);
307 break;
308 }
309
310 case Hexagon::A2_tfrtnew: {
312 Inst.setOpcode(Hexagon::A2_padditnew);
314 break;
315 }
316
317 case Hexagon::A2_zxtb: {
319 Inst.setOpcode(Hexagon::A2_andir);
321 break;
322 }
323
324 // "$dst = CONST64(#$src1)",
325 case Hexagon::CONST64:
326 if (!OutStreamer->hasRawTextSupport()) {
327 const MCOperand &Imm = MappedInst.getOperand(1);
328 MCSectionSubPair Current = OutStreamer->getCurrentSection();
329
330 MCSymbol *Sym =
331 smallData(*this, MI, *OutStreamer, Imm, 8, getSubtargetInfo());
332
333 OutStreamer->switchSection(Current.first, Current.second);
334 MCInst TmpInst;
335 MCOperand &Reg = MappedInst.getOperand(0);
336 TmpInst.setOpcode(Hexagon::L2_loadrdgp);
337 TmpInst.addOperand(Reg);
340 MappedInst = TmpInst;
341
342 }
343 break;
344 case Hexagon::CONST32:
345 if (!OutStreamer->hasRawTextSupport()) {
346 MCOperand &Imm = MappedInst.getOperand(1);
347 MCSectionSubPair Current = OutStreamer->getCurrentSection();
348 MCSymbol *Sym =
349 smallData(*this, MI, *OutStreamer, Imm, 4, getSubtargetInfo());
350 OutStreamer->switchSection(Current.first, Current.second);
351 MCInst TmpInst;
352 MCOperand &Reg = MappedInst.getOperand(0);
353 TmpInst.setOpcode(Hexagon::L2_loadrigp);
354 TmpInst.addOperand(Reg);
357 MappedInst = TmpInst;
358 }
359 break;
360
361 // C2_pxfer_map maps to C2_or instruction. Though, it's possible to use
362 // C2_or during instruction selection itself but it results
363 // into suboptimal code.
364 case Hexagon::C2_pxfer_map: {
365 MCOperand &Ps = Inst.getOperand(1);
366 MappedInst.setOpcode(Hexagon::C2_or);
367 MappedInst.addOperand(Ps);
368 return;
369 }
370
371 // Vector reduce complex multiply by scalar, Rt & 1 map to :hi else :lo
372 // The insn is mapped from the 4 operand to the 3 operand raw form taking
373 // 3 register pairs.
374 case Hexagon::M2_vrcmpys_acc_s1: {
375 MCOperand &Rt = Inst.getOperand(3);
376 assert(Rt.isReg() && "Expected register and none was found");
377 unsigned Reg = RI->getEncodingValue(Rt.getReg());
378 if (Reg & 1)
379 MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
380 else
381 MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
383 return;
384 }
385 case Hexagon::M2_vrcmpys_s1: {
386 MCOperand &Rt = Inst.getOperand(2);
387 assert(Rt.isReg() && "Expected register and none was found");
388 unsigned Reg = RI->getEncodingValue(Rt.getReg());
389 if (Reg & 1)
390 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_h);
391 else
392 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_l);
394 return;
395 }
396
397 case Hexagon::M2_vrcmpys_s1rp: {
398 MCOperand &Rt = Inst.getOperand(2);
399 assert(Rt.isReg() && "Expected register and none was found");
400 unsigned Reg = RI->getEncodingValue(Rt.getReg());
401 if (Reg & 1)
402 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
403 else
404 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
406 return;
407 }
408
409 case Hexagon::A4_boundscheck: {
410 MCOperand &Rs = Inst.getOperand(1);
411 assert(Rs.isReg() && "Expected register and none was found");
412 unsigned Reg = RI->getEncodingValue(Rs.getReg());
413 if (Reg & 1) // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2
414 MappedInst.setOpcode(Hexagon::A4_boundscheck_hi);
415 else // raw:lo
416 MappedInst.setOpcode(Hexagon::A4_boundscheck_lo);
418 return;
419 }
420
421 case Hexagon::PS_call_nr:
422 Inst.setOpcode(Hexagon::J2_call);
423 break;
424
425 case Hexagon::PS_readcr:
426 Inst.setOpcode(Hexagon::A2_tfrcrr);
427 break;
428
429 case Hexagon::PS_readcr64:
430 Inst.setOpcode(Hexagon::A4_tfrcpp);
431 break;
432
433 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
434 MCOperand &MO = MappedInst.getOperand(2);
435 int64_t Imm;
436 MCExpr const *Expr = MO.getExpr();
437 bool Success = Expr->evaluateAsAbsolute(Imm);
438 assert(Success && "Expected immediate and none was found");
439 (void)Success;
440 MCInst TmpInst;
441 if (Imm == 0) {
442 TmpInst.setOpcode(Hexagon::S2_vsathub);
443 TmpInst.addOperand(MappedInst.getOperand(0));
444 TmpInst.addOperand(MappedInst.getOperand(1));
445 MappedInst = TmpInst;
446 return;
447 }
448 TmpInst.setOpcode(Hexagon::S5_asrhub_rnd_sat);
449 TmpInst.addOperand(MappedInst.getOperand(0));
450 TmpInst.addOperand(MappedInst.getOperand(1));
452 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
453 TmpInst.addOperand(
455 MappedInst = TmpInst;
456 return;
457 }
458
459 case Hexagon::S5_vasrhrnd_goodsyntax:
460 case Hexagon::S2_asr_i_p_rnd_goodsyntax: {
461 MCOperand &MO2 = MappedInst.getOperand(2);
462 MCExpr const *Expr = MO2.getExpr();
463 int64_t Imm;
464 bool Success = Expr->evaluateAsAbsolute(Imm);
465 assert(Success && "Expected immediate and none was found");
466 (void)Success;
467 MCInst TmpInst;
468 if (Imm == 0) {
469 TmpInst.setOpcode(Hexagon::A2_combinew);
470 TmpInst.addOperand(MappedInst.getOperand(0));
471 MCOperand &MO1 = MappedInst.getOperand(1);
472 MCRegister High = RI->getSubReg(MO1.getReg(), Hexagon::isub_hi);
473 MCRegister Low = RI->getSubReg(MO1.getReg(), Hexagon::isub_lo);
474 // Add a new operand for the second register in the pair.
477 MappedInst = TmpInst;
478 return;
479 }
480
481 if (Inst.getOpcode() == Hexagon::S2_asr_i_p_rnd_goodsyntax)
482 TmpInst.setOpcode(Hexagon::S2_asr_i_p_rnd);
483 else
484 TmpInst.setOpcode(Hexagon::S5_vasrhrnd);
485 TmpInst.addOperand(MappedInst.getOperand(0));
486 TmpInst.addOperand(MappedInst.getOperand(1));
488 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
489 TmpInst.addOperand(
491 MappedInst = TmpInst;
492 return;
493 }
494
495 // if ("#u5==0") Assembler mapped to: "Rd=Rs"; else Rd=asr(Rs,#u5-1):rnd
496 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
497 MCOperand &MO = Inst.getOperand(2);
498 MCExpr const *Expr = MO.getExpr();
499 int64_t Imm;
500 bool Success = Expr->evaluateAsAbsolute(Imm);
501 assert(Success && "Expected immediate and none was found");
502 (void)Success;
503 MCInst TmpInst;
504 if (Imm == 0) {
505 TmpInst.setOpcode(Hexagon::A2_tfr);
506 TmpInst.addOperand(MappedInst.getOperand(0));
507 TmpInst.addOperand(MappedInst.getOperand(1));
508 MappedInst = TmpInst;
509 return;
510 }
511 TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd);
512 TmpInst.addOperand(MappedInst.getOperand(0));
513 TmpInst.addOperand(MappedInst.getOperand(1));
515 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
516 TmpInst.addOperand(
518 MappedInst = TmpInst;
519 return;
520 }
521
522 // Translate a "$Rdd = #imm" to "$Rdd = combine(#[-1,0], #imm)"
523 case Hexagon::A2_tfrpi: {
524 MCInst TmpInst;
525 MCOperand &Rdd = MappedInst.getOperand(0);
526 MCOperand &MO = MappedInst.getOperand(1);
527
528 TmpInst.setOpcode(Hexagon::A2_combineii);
529 TmpInst.addOperand(Rdd);
530 int64_t Imm;
531 bool Success = MO.getExpr()->evaluateAsAbsolute(Imm);
532 if (Success && Imm < 0) {
533 const MCExpr *MOne = MCConstantExpr::create(-1, OutContext);
536 } else {
537 const MCExpr *Zero = MCConstantExpr::create(0, OutContext);
540 }
541 TmpInst.addOperand(MO);
542 MappedInst = TmpInst;
543 return;
544 }
545
546 // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)"
547 case Hexagon::A2_tfrp: {
548 MCOperand &MO = MappedInst.getOperand(1);
549 MCRegister High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
550 MCRegister Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
551 MO.setReg(High);
552 // Add a new operand for the second register in the pair.
554 MappedInst.setOpcode(Hexagon::A2_combinew);
555 return;
556 }
557
558 case Hexagon::A2_tfrpt:
559 case Hexagon::A2_tfrpf: {
560 MCOperand &MO = MappedInst.getOperand(2);
561 MCRegister High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
562 MCRegister Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
563 MO.setReg(High);
564 // Add a new operand for the second register in the pair.
566 MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrpt)
567 ? Hexagon::C2_ccombinewt
568 : Hexagon::C2_ccombinewf);
569 return;
570 }
571
572 case Hexagon::A2_tfrptnew:
573 case Hexagon::A2_tfrpfnew: {
574 MCOperand &MO = MappedInst.getOperand(2);
575 MCRegister High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
576 MCRegister Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
577 MO.setReg(High);
578 // Add a new operand for the second register in the pair.
580 MappedInst.setOpcode(Inst.getOpcode() == Hexagon::A2_tfrptnew
581 ? Hexagon::C2_ccombinewnewt
582 : Hexagon::C2_ccombinewnewf);
583 return;
584 }
585
586 case Hexagon::M2_mpysmi: {
587 MCOperand &Imm = MappedInst.getOperand(2);
588 MCExpr const *Expr = Imm.getExpr();
589 int64_t Value;
590 bool Success = Expr->evaluateAsAbsolute(Value);
592 (void)Success;
593 if (Value < 0 && Value > -256) {
594 MappedInst.setOpcode(Hexagon::M2_mpysin);
595 Imm.setExpr(HexagonMCExpr::create(
597 } else
598 MappedInst.setOpcode(Hexagon::M2_mpysip);
599 return;
600 }
601
602 case Hexagon::A2_addsp: {
603 MCOperand &Rt = Inst.getOperand(1);
604 assert(Rt.isReg() && "Expected register and none was found");
605 unsigned Reg = RI->getEncodingValue(Rt.getReg());
606 if (Reg & 1)
607 MappedInst.setOpcode(Hexagon::A2_addsph);
608 else
609 MappedInst.setOpcode(Hexagon::A2_addspl);
611 return;
612 }
613
614 case Hexagon::V6_vd0: {
615 MCInst TmpInst;
616 assert(Inst.getOperand(0).isReg() &&
617 "Expected register and none was found");
618
619 TmpInst.setOpcode(Hexagon::V6_vxor);
620 TmpInst.addOperand(Inst.getOperand(0));
621 TmpInst.addOperand(Inst.getOperand(0));
622 TmpInst.addOperand(Inst.getOperand(0));
623 MappedInst = TmpInst;
624 return;
625 }
626
627 case Hexagon::V6_vdd0: {
628 MCInst TmpInst;
629 assert (Inst.getOperand(0).isReg() &&
630 "Expected register and none was found");
631
632 TmpInst.setOpcode(Hexagon::V6_vsubw_dv);
633 TmpInst.addOperand(Inst.getOperand(0));
634 TmpInst.addOperand(Inst.getOperand(0));
635 TmpInst.addOperand(Inst.getOperand(0));
636 MappedInst = TmpInst;
637 return;
638 }
639
640 case Hexagon::V6_vL32Ub_pi:
641 case Hexagon::V6_vL32b_cur_pi:
642 case Hexagon::V6_vL32b_nt_cur_pi:
643 case Hexagon::V6_vL32b_pi:
644 case Hexagon::V6_vL32b_nt_pi:
645 case Hexagon::V6_vL32b_nt_tmp_pi:
646 case Hexagon::V6_vL32b_tmp_pi:
647 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
648 return;
649
650 case Hexagon::V6_vL32Ub_ai:
651 case Hexagon::V6_vL32b_ai:
652 case Hexagon::V6_vL32b_cur_ai:
653 case Hexagon::V6_vL32b_nt_ai:
654 case Hexagon::V6_vL32b_nt_cur_ai:
655 case Hexagon::V6_vL32b_nt_tmp_ai:
656 case Hexagon::V6_vL32b_tmp_ai:
657 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
658 return;
659
660 case Hexagon::V6_vS32Ub_pi:
661 case Hexagon::V6_vS32b_new_pi:
662 case Hexagon::V6_vS32b_nt_new_pi:
663 case Hexagon::V6_vS32b_nt_pi:
664 case Hexagon::V6_vS32b_pi:
665 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
666 return;
667
668 case Hexagon::V6_vS32Ub_ai:
669 case Hexagon::V6_vS32b_ai:
670 case Hexagon::V6_vS32b_new_ai:
671 case Hexagon::V6_vS32b_nt_ai:
672 case Hexagon::V6_vS32b_nt_new_ai:
673 MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
674 return;
675
676 case Hexagon::V6_vL32b_cur_npred_pi:
677 case Hexagon::V6_vL32b_cur_pred_pi:
678 case Hexagon::V6_vL32b_npred_pi:
679 case Hexagon::V6_vL32b_nt_cur_npred_pi:
680 case Hexagon::V6_vL32b_nt_cur_pred_pi:
681 case Hexagon::V6_vL32b_nt_npred_pi:
682 case Hexagon::V6_vL32b_nt_pred_pi:
683 case Hexagon::V6_vL32b_nt_tmp_npred_pi:
684 case Hexagon::V6_vL32b_nt_tmp_pred_pi:
685 case Hexagon::V6_vL32b_pred_pi:
686 case Hexagon::V6_vL32b_tmp_npred_pi:
687 case Hexagon::V6_vL32b_tmp_pred_pi:
688 MappedInst = ScaleVectorOffset(Inst, 4, VectorSize, OutContext);
689 return;
690
691 case Hexagon::V6_vL32b_cur_npred_ai:
692 case Hexagon::V6_vL32b_cur_pred_ai:
693 case Hexagon::V6_vL32b_npred_ai:
694 case Hexagon::V6_vL32b_nt_cur_npred_ai:
695 case Hexagon::V6_vL32b_nt_cur_pred_ai:
696 case Hexagon::V6_vL32b_nt_npred_ai:
697 case Hexagon::V6_vL32b_nt_pred_ai:
698 case Hexagon::V6_vL32b_nt_tmp_npred_ai:
699 case Hexagon::V6_vL32b_nt_tmp_pred_ai:
700 case Hexagon::V6_vL32b_pred_ai:
701 case Hexagon::V6_vL32b_tmp_npred_ai:
702 case Hexagon::V6_vL32b_tmp_pred_ai:
703 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
704 return;
705
706 case Hexagon::V6_vS32Ub_npred_pi:
707 case Hexagon::V6_vS32Ub_pred_pi:
708 case Hexagon::V6_vS32b_new_npred_pi:
709 case Hexagon::V6_vS32b_new_pred_pi:
710 case Hexagon::V6_vS32b_npred_pi:
711 case Hexagon::V6_vS32b_nqpred_pi:
712 case Hexagon::V6_vS32b_nt_new_npred_pi:
713 case Hexagon::V6_vS32b_nt_new_pred_pi:
714 case Hexagon::V6_vS32b_nt_npred_pi:
715 case Hexagon::V6_vS32b_nt_nqpred_pi:
716 case Hexagon::V6_vS32b_nt_pred_pi:
717 case Hexagon::V6_vS32b_nt_qpred_pi:
718 case Hexagon::V6_vS32b_pred_pi:
719 case Hexagon::V6_vS32b_qpred_pi:
720 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
721 return;
722
723 case Hexagon::V6_vS32Ub_npred_ai:
724 case Hexagon::V6_vS32Ub_pred_ai:
725 case Hexagon::V6_vS32b_new_npred_ai:
726 case Hexagon::V6_vS32b_new_pred_ai:
727 case Hexagon::V6_vS32b_npred_ai:
728 case Hexagon::V6_vS32b_nqpred_ai:
729 case Hexagon::V6_vS32b_nt_new_npred_ai:
730 case Hexagon::V6_vS32b_nt_new_pred_ai:
731 case Hexagon::V6_vS32b_nt_npred_ai:
732 case Hexagon::V6_vS32b_nt_nqpred_ai:
733 case Hexagon::V6_vS32b_nt_pred_ai:
734 case Hexagon::V6_vS32b_nt_qpred_ai:
735 case Hexagon::V6_vS32b_pred_ai:
736 case Hexagon::V6_vS32b_qpred_ai:
737 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
738 return;
739
740 // V65+
741 case Hexagon::V6_vS32b_srls_ai:
742 MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
743 return;
744
745 case Hexagon::V6_vS32b_srls_pi:
746 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
747 return;
748 }
749}
750
751/// Print out a single Hexagon MI to the current output stream.
753 Hexagon_MC::verifyInstructionPredicates(MI->getOpcode(),
754 getSubtargetInfo().getFeatureBits());
755
756 MCInst MCB;
757 MCB.setOpcode(Hexagon::BUNDLE);
759 const MCInstrInfo &MCII = *Subtarget->getInstrInfo();
760
761 if (MI->isBundle()) {
762 const MachineBasicBlock* MBB = MI->getParent();
763 MachineBasicBlock::const_instr_iterator MII = MI->getIterator();
764
765 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
766 if (!MII->isDebugInstr() && !MII->isImplicitDef())
767 HexagonLowerToMC(MCII, &*MII, MCB, *this);
768 } else {
769 HexagonLowerToMC(MCII, MI, MCB, *this);
770 }
771
772 const MachineFunction &MF = *MI->getParent()->getParent();
773 const auto &HII = *MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
774 if (MI->isBundle() && HII.getBundleNoShuf(*MI))
776
777 MCContext &Ctx = OutStreamer->getContext();
778 bool Ok = HexagonMCInstrInfo::canonicalizePacket(MCII, *Subtarget, Ctx,
779 MCB, nullptr);
780 assert(Ok); (void)Ok;
781 if (HexagonMCInstrInfo::bundleSize(MCB) == 0)
782 return;
783 OutStreamer->emitInstruction(MCB, getSubtargetInfo());
784}
785
787 if (TM.getTargetTriple().isOSBinFormatELF())
788 emitAttributes();
789}
790
793 static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
794 if (TM.getTargetTriple().isOSBinFormatELF())
796}
797
798void HexagonAsmPrinter::emitAttributes() {
800 static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
802}
803
805 static const int8_t NoopsInSledCount = 4;
806 // We want to emit the following pattern:
807 //
808 // .L_xray_sled_N:
809 // <xray_sled_base>:
810 // { jump .Ltmp0 }
811 // { nop
812 // nop
813 // nop
814 // nop }
815 // .Ltmp0:
816 //
817 // We need the 4 nop words because at runtime, we'd be patching over the
818 // full 5 words with the following pattern:
819 //
820 // <xray_sled_n>:
821 // { immext(#...) // upper 26-bits of trampoline
822 // r6 = ##... // lower 6-bits of trampoline
823 // immext(#...) // upper 26-bits of func id
824 // r7 = ##... } // lower 6 bits of func id
825 // { callr r6 }
826 //
827 //
828 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
829 OutStreamer->emitLabel(CurSled);
830
831 MCInst *SledJump = new (OutContext) MCInst();
832 SledJump->setOpcode(Hexagon::J2_jump);
833 auto PostSled = OutContext.createTempSymbol();
836
837 // Emit "jump PostSled" instruction, which jumps over the nop series.
838 MCInst SledJumpPacket;
839 SledJumpPacket.setOpcode(Hexagon::BUNDLE);
840 SledJumpPacket.addOperand(MCOperand::createImm(0));
841 SledJumpPacket.addOperand(MCOperand::createInst(SledJump));
842
843 EmitToStreamer(*OutStreamer, SledJumpPacket);
844
845 // FIXME: this will emit individual packets, we should
846 // special-case this and combine them into a single packet.
847 emitNops(NoopsInSledCount);
848
849 OutStreamer->emitLabel(PostSled);
850 recordSled(CurSled, MI, Kind, 2);
851}
852
856
860
864
865char HexagonAsmPrinter::ID = 0;
866
867INITIALIZE_PASS(HexagonAsmPrinter, "hexagon-asm-printer",
868 "Hexagon Assembly Printer", false, false)
869
871LLVMInitializeHexagonAsmPrinter() {
873}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
constexpr LLT S16
MachineBasicBlock & MBB
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
static MCSymbol * smallData(AsmPrinter &AP, const MachineInstr &MI, MCStreamer &OutStreamer, const MCOperand &Imm, int AlignSize, const MCSubtargetInfo &STI)
static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo, unsigned VectorSize, MCContext &Ctx)
static unsigned getHexagonRegisterPair(unsigned Reg, const MCRegisterInfo *RI)
IRTranslator LLVM IR MI
Register Reg
Register const TargetRegisterInfo * TRI
#define T
uint64_t High
#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:487
This file contains some functions that are useful when dealing with strings.
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:91
MCSymbol * getSymbol(const GlobalValue *GV) const
void emitNops(unsigned N)
Emit N NOP instructions.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
Definition AsmPrinter.h:94
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition AsmPrinter.h:97
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:109
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
void recordSled(MCSymbol *Sled, const MachineInstr &MI, SledKind Kind, uint8_t Version=0)
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition AsmPrinter.h:101
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:106
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.
void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI)
void EmitSled(const MachineInstr &MI, SledKind Kind)
void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI)
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...
bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const override
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS) override
PrintAsmOperand - Print out an operand for an inline asm expression.
void emitInstruction(const MachineInstr *MI) override
Print out a single Hexagon MI to the current output stream.
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI)
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 printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O)
void HexagonProcessInstruction(MCInst &Inst, const MachineInstr &MBB)
static char const * getRegisterName(MCRegister Reg)
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
void emitTargetAttributes(const MCSubtargetInfo &STI)
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
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
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition MCContext.h:553
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
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getNumOperands() const
Definition MCInst.h:212
unsigned getOpcode() const
Definition MCInst.h:202
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
void clear()
Definition MCInst.h:223
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:40
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:166
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
void setReg(MCRegister Reg)
Set the register number.
Definition MCInst.h:79
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
static MCOperand createInst(const MCInst *Val)
Definition MCInst.h:173
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
iterator_range< MCSuperRegIterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
This represents a section on linux, lots of unix variants and some bare metal systems.
Streaming machine code generation interface.
Definition MCStreamer.h:221
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
MCContext & getContext() const
Definition MCStreamer.h:322
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
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.
virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
Generic base class for all target subtargets.
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
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition MCSymbol.cpp:59
bool isUndefined() const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition MCSymbol.h:243
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
static const MCUnaryExpr * createMinus(const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:269
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Instructions::const_iterator const_instr_iterator
Representation of each machine instruction.
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.
MachineBasicBlock * getMBB() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
Wrapper class representing virtual and physical registers.
Definition Register.h:20
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:222
const MCSubtargetInfo * getMCSubtargetInfo() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
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.
@ SHF_ALLOC
Definition ELF.h:1250
@ SHF_WRITE
Definition ELF.h:1247
@ SHT_PROGBITS
Definition ELF.h:1149
size_t bundleSize(MCInst const &MCI)
void setS27_2_reloc(MCExpr const &Expr, bool Val=true)
void setMemReorderDisabled(MCInst &MCI)
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker, bool AttemptCompatibility=false)
void setMustNotExtend(MCExpr const &Expr, bool Val=true)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:532
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
Target & getTheHexagonTarget()
void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI, MCInst &MCB, HexagonAsmPrinter &AP)
@ Success
The lock was released successfully.
@ Sub
Subtraction of integers.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
std::pair< MCSection *, uint32_t > MCSectionSubPair
Definition MCStreamer.h:67
@ MCSA_Local
.local (ELF)
@ MCSA_Global
.type _foo, @gnu_unique_object
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...