LLVM 24.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"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/Twine.h"
37#include "llvm/IR/Module.h"
38#include "llvm/MC/MCContext.h"
40#include "llvm/MC/MCExpr.h"
41#include "llvm/MC/MCInst.h"
44#include "llvm/MC/MCStreamer.h"
45#include "llvm/MC/MCSymbol.h"
52#include <cassert>
53#include <cstdint>
54#include <string>
55
56using namespace llvm;
57
58namespace llvm {
59
60void HexagonLowerToMC(const MCInstrInfo &MCII, const MachineInstr *MI,
61 MCInst &MCB, HexagonAsmPrinter &AP);
62
63} // end namespace llvm
64
65#define DEBUG_TYPE "asm-printer"
66
67// Given a scalar register return its pair.
68inline static unsigned getHexagonRegisterPair(unsigned Reg,
69 const MCRegisterInfo *RI) {
70 assert(Hexagon::IntRegsRegClass.contains(Reg));
71 unsigned Pair = *RI->superregs(Reg).begin();
72 assert(Hexagon::DoubleRegsRegClass.contains(Pair));
73 return Pair;
74}
75
77 raw_ostream &O) {
78 const MachineOperand &MO = MI->getOperand(OpNo);
79
80 switch (MO.getType()) {
81 default:
82 llvm_unreachable ("<unknown operand type>");
85 return;
87 O << MO.getImm();
88 return;
90 MO.getMBB()->getSymbol()->print(O, MAI);
91 return;
93 GetCPISymbol(MO.getIndex())->print(O, MAI);
94 return;
96 PrintSymbolOperand(MO, O);
97 return;
98 }
99}
100
101// isBlockOnlyReachableByFallthrough - We need to override this since the
102// default AsmPrinter does not print labels for any basic block that
103// is only reachable by a fall through. That works for all cases except
104// for the case in which the basic block is reachable by a fall through but
105// through an indirect from a jump table. In this case, the jump table
106// will contain a label not defined by AsmPrinter.
108 const MachineBasicBlock *MBB) const {
109 if (MBB->hasAddressTaken())
110 return false;
112}
113
114/// PrintAsmOperand - Print out an operand for an inline asm expression.
116 const char *ExtraCode,
117 raw_ostream &OS) {
118 // Does this asm operand have a single letter operand modifier?
119 if (ExtraCode && ExtraCode[0]) {
120 if (ExtraCode[1] != 0)
121 return true; // Unknown modifier.
122
123 switch (ExtraCode[0]) {
124 default:
125 // See if this is a generic print operand
126 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
127 case 'L':
128 case 'H': { // The highest-numbered register of a pair.
129 const MachineOperand &MO = MI->getOperand(OpNo);
130 const MachineFunction &MF = *MI->getParent()->getParent();
131 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
132 if (!MO.isReg())
133 return true;
134 Register RegNumber = MO.getReg();
135 // This should be an assert in the frontend.
136 if (Hexagon::DoubleRegsRegClass.contains(RegNumber))
137 RegNumber = TRI->getSubReg(RegNumber, ExtraCode[0] == 'L' ?
138 Hexagon::isub_lo :
139 Hexagon::isub_hi);
141 return false;
142 }
143 case 'I':
144 // Write 'i' if an integer constant, otherwise nothing. Used to print
145 // addi vs add, etc.
146 if (MI->getOperand(OpNo).isImm())
147 OS << "i";
148 return false;
149 }
150 }
151
152 printOperand(MI, OpNo, OS);
153 return false;
154}
155
157 unsigned OpNo,
158 const char *ExtraCode,
159 raw_ostream &O) {
160 if (ExtraCode && ExtraCode[0])
161 return true; // Unknown modifier.
162
163 const MachineOperand &Base = MI->getOperand(OpNo);
164 const MachineOperand &Offset = MI->getOperand(OpNo+1);
165
166 if (Base.isReg())
167 printOperand(MI, OpNo, O);
168 else
169 llvm_unreachable("Unimplemented");
170
171 if (Offset.isImm()) {
172 if (Offset.getImm())
173 O << "+#" << Offset.getImm();
174 } else {
175 llvm_unreachable("Unimplemented");
176 }
177
178 return false;
179}
180
182 MCStreamer &OutStreamer, const MCOperand &Imm,
183 int AlignSize, const MCSubtargetInfo& STI) {
184 MCSymbol *Sym;
185 int64_t Value;
186 if (Imm.getExpr()->evaluateAsAbsolute(Value)) {
187 StringRef sectionPrefix;
188 std::string ImmString;
189 StringRef Name;
190 if (AlignSize == 8) {
191 Name = ".CONST_0000000000000000";
192 sectionPrefix = ".gnu.linkonce.l8";
193 ImmString = utohexstr(Value);
194 } else {
195 Name = ".CONST_00000000";
196 sectionPrefix = ".gnu.linkonce.l4";
197 ImmString = utohexstr(static_cast<uint32_t>(Value));
198 }
199
200 std::string symbolName = // Yes, leading zeros are kept.
201 Name.drop_back(ImmString.size()).str() + ImmString;
202 std::string sectionName = sectionPrefix.str() + symbolName;
203
204 MCSectionELF *Section = OutStreamer.getContext().getELFSection(
206 OutStreamer.switchSection(Section);
207
208 Sym = AP.OutContext.getOrCreateSymbol(Twine(symbolName));
209 if (Sym->isUndefined()) {
210 OutStreamer.emitLabel(Sym);
211 OutStreamer.emitSymbolAttribute(Sym, MCSA_Global);
212 OutStreamer.emitIntValue(Value, AlignSize);
213 OutStreamer.emitCodeAlignment(Align(AlignSize), STI);
214 }
215 } else {
216 assert(Imm.isExpr() && "Expected expression and found none");
217 const MachineOperand &MO = MI.getOperand(1);
218 assert(MO.isGlobal() || MO.isCPI() || MO.isJTI());
219 MCSymbol *MOSymbol = nullptr;
220 if (MO.isGlobal())
221 MOSymbol = AP.getSymbol(MO.getGlobal());
222 else if (MO.isCPI())
223 MOSymbol = AP.GetCPISymbol(MO.getIndex());
224 else if (MO.isJTI())
225 MOSymbol = AP.GetJTISymbol(MO.getIndex());
226 else
227 llvm_unreachable("Unknown operand type!");
228
229 StringRef SymbolName = MOSymbol->getName();
230 std::string LitaName = ".CONST_" + SymbolName.str();
231
232 MCSectionELF *Section = OutStreamer.getContext().getELFSection(
234
235 OutStreamer.switchSection(Section);
236 Sym = AP.OutContext.getOrCreateSymbol(Twine(LitaName));
237 if (Sym->isUndefined()) {
238 OutStreamer.emitLabel(Sym);
239 OutStreamer.emitSymbolAttribute(Sym, MCSA_Local);
240 OutStreamer.emitValue(Imm.getExpr(), AlignSize);
241 OutStreamer.emitCodeAlignment(Align(AlignSize), STI);
242 }
243 }
244 return Sym;
245}
246
247static MCInst ScaleVectorOffset(MCInst &Inst, unsigned OpNo,
248 unsigned VectorSize, MCContext &Ctx) {
249 MCInst T;
250 T.setOpcode(Inst.getOpcode());
251 for (unsigned i = 0, n = Inst.getNumOperands(); i != n; ++i) {
252 if (i != OpNo) {
253 T.addOperand(Inst.getOperand(i));
254 continue;
255 }
256 MCOperand &ImmOp = Inst.getOperand(i);
257 const auto *HE = static_cast<const HexagonMCExpr*>(ImmOp.getExpr());
258 int32_t V = cast<MCConstantExpr>(HE->getExpr())->getValue();
259 auto *NewCE = MCConstantExpr::create(V / int32_t(VectorSize), Ctx);
260 auto *NewHE = HexagonMCExpr::create(NewCE, Ctx);
261 T.addOperand(MCOperand::createExpr(NewHE));
262 }
263 return T;
264}
265
267 const MachineInstr &MI) {
268 MCInst &MappedInst = static_cast <MCInst &>(Inst);
269 const MCRegisterInfo *RI = OutStreamer->getContext().getRegisterInfo();
270 const MachineFunction &MF = *MI.getParent()->getParent();
271 auto &HRI = *MF.getSubtarget<HexagonSubtarget>().getRegisterInfo();
272 unsigned VectorSize = HRI.getRegSizeInBits(Hexagon::HvxVRRegClass) / 8;
273
274 switch (Inst.getOpcode()) {
275 default:
276 return;
277
278 case Hexagon::A2_iconst: {
279 Inst.setOpcode(Hexagon::A2_addi);
280 MCOperand Reg = Inst.getOperand(0);
281 MCOperand S16 = Inst.getOperand(1);
284 Inst.clear();
285 Inst.addOperand(Reg);
286 Inst.addOperand(MCOperand::createReg(Hexagon::R0));
287 Inst.addOperand(S16);
288 break;
289 }
290
291 case Hexagon::A2_tfrf: {
293 Inst.setOpcode(Hexagon::A2_paddif);
295 break;
296 }
297
298 case Hexagon::A2_tfrt: {
300 Inst.setOpcode(Hexagon::A2_paddit);
302 break;
303 }
304
305 case Hexagon::A2_tfrfnew: {
307 Inst.setOpcode(Hexagon::A2_paddifnew);
309 break;
310 }
311
312 case Hexagon::A2_tfrtnew: {
314 Inst.setOpcode(Hexagon::A2_padditnew);
316 break;
317 }
318
319 case Hexagon::A2_zxtb: {
321 Inst.setOpcode(Hexagon::A2_andir);
323 break;
324 }
325
326 // "$dst = CONST64(#$src1)",
327 case Hexagon::CONST64:
328 if (!OutStreamer->hasRawTextSupport()) {
329 const MCOperand &Imm = MappedInst.getOperand(1);
330 MCSectionSubPair Current = OutStreamer->getCurrentSection();
331
332 MCSymbol *Sym =
334
335 OutStreamer->switchSection(Current.first, Current.second);
336 MCInst TmpInst;
337 MCOperand &Reg = MappedInst.getOperand(0);
338 TmpInst.setOpcode(Hexagon::L2_loadrdgp);
339 TmpInst.addOperand(Reg);
342 MappedInst = TmpInst;
343
344 }
345 break;
346 case Hexagon::CONST32:
347 if (!OutStreamer->hasRawTextSupport()) {
348 MCOperand &Imm = MappedInst.getOperand(1);
349 MCSectionSubPair Current = OutStreamer->getCurrentSection();
350 MCSymbol *Sym =
352 OutStreamer->switchSection(Current.first, Current.second);
353 MCInst TmpInst;
354 MCOperand &Reg = MappedInst.getOperand(0);
355 TmpInst.setOpcode(Hexagon::L2_loadrigp);
356 TmpInst.addOperand(Reg);
359 MappedInst = TmpInst;
360 }
361 break;
362
363 // C2_pxfer_map maps to C2_or instruction. Though, it's possible to use
364 // C2_or during instruction selection itself but it results
365 // into suboptimal code.
366 case Hexagon::C2_pxfer_map: {
367 MCOperand &Ps = Inst.getOperand(1);
368 MappedInst.setOpcode(Hexagon::C2_or);
369 MappedInst.addOperand(Ps);
370 return;
371 }
372
373 // Vector reduce complex multiply by scalar, Rt & 1 map to :hi else :lo
374 // The insn is mapped from the 4 operand to the 3 operand raw form taking
375 // 3 register pairs.
376 case Hexagon::M2_vrcmpys_acc_s1: {
377 MCOperand &Rt = Inst.getOperand(3);
378 assert(Rt.isReg() && "Expected register and none was found");
379 unsigned Reg = RI->getEncodingValue(Rt.getReg());
380 if (Reg & 1)
381 MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_h);
382 else
383 MappedInst.setOpcode(Hexagon::M2_vrcmpys_acc_s1_l);
385 return;
386 }
387 case Hexagon::M2_vrcmpys_s1: {
388 MCOperand &Rt = Inst.getOperand(2);
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_s1_h);
393 else
394 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1_l);
396 return;
397 }
398
399 case Hexagon::M2_vrcmpys_s1rp: {
400 MCOperand &Rt = Inst.getOperand(2);
401 assert(Rt.isReg() && "Expected register and none was found");
402 unsigned Reg = RI->getEncodingValue(Rt.getReg());
403 if (Reg & 1)
404 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_h);
405 else
406 MappedInst.setOpcode(Hexagon::M2_vrcmpys_s1rp_l);
408 return;
409 }
410
411 case Hexagon::A4_boundscheck: {
412 MCOperand &Rs = Inst.getOperand(1);
413 assert(Rs.isReg() && "Expected register and none was found");
414 unsigned Reg = RI->getEncodingValue(Rs.getReg());
415 if (Reg & 1) // Odd mapped to raw:hi, regpair is rodd:odd-1, like r3:2
416 MappedInst.setOpcode(Hexagon::A4_boundscheck_hi);
417 else // raw:lo
418 MappedInst.setOpcode(Hexagon::A4_boundscheck_lo);
420 return;
421 }
422
423 case Hexagon::PS_call_nr:
424 Inst.setOpcode(Hexagon::J2_call);
425 break;
426
427 case Hexagon::PS_readcr:
428 Inst.setOpcode(Hexagon::A2_tfrcrr);
429 break;
430
431 case Hexagon::PS_readcr64:
432 Inst.setOpcode(Hexagon::A4_tfrcpp);
433 break;
434
435 case Hexagon::S5_asrhub_rnd_sat_goodsyntax: {
436 MCOperand &MO = MappedInst.getOperand(2);
437 int64_t Imm;
438 MCExpr const *Expr = MO.getExpr();
439 bool Success = Expr->evaluateAsAbsolute(Imm);
440 assert(Success && "Expected immediate and none was found");
441 (void)Success;
442 MCInst TmpInst;
443 if (Imm == 0) {
444 TmpInst.setOpcode(Hexagon::S2_vsathub);
445 TmpInst.addOperand(MappedInst.getOperand(0));
446 TmpInst.addOperand(MappedInst.getOperand(1));
447 MappedInst = TmpInst;
448 return;
449 }
450 TmpInst.setOpcode(Hexagon::S5_asrhub_rnd_sat);
451 TmpInst.addOperand(MappedInst.getOperand(0));
452 TmpInst.addOperand(MappedInst.getOperand(1));
454 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
455 TmpInst.addOperand(
457 MappedInst = TmpInst;
458 return;
459 }
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 MCRegister High = RI->getSubReg(MO1.getReg(), Hexagon::isub_hi);
475 MCRegister Low = RI->getSubReg(MO1.getReg(), Hexagon::isub_lo);
476 // Add a new operand for the second register in the pair.
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));
490 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
491 TmpInst.addOperand(
493 MappedInst = TmpInst;
494 return;
495 }
496
497 // if ("#u5==0") Assembler mapped to: "Rd=Rs"; else Rd=asr(Rs,#u5-1):rnd
498 case Hexagon::S2_asr_i_r_rnd_goodsyntax: {
499 MCOperand &MO = Inst.getOperand(2);
500 MCExpr const *Expr = MO.getExpr();
501 int64_t Imm;
502 bool Success = Expr->evaluateAsAbsolute(Imm);
503 assert(Success && "Expected immediate and none was found");
504 (void)Success;
505 MCInst TmpInst;
506 if (Imm == 0) {
507 TmpInst.setOpcode(Hexagon::A2_tfr);
508 TmpInst.addOperand(MappedInst.getOperand(0));
509 TmpInst.addOperand(MappedInst.getOperand(1));
510 MappedInst = TmpInst;
511 return;
512 }
513 TmpInst.setOpcode(Hexagon::S2_asr_i_r_rnd);
514 TmpInst.addOperand(MappedInst.getOperand(0));
515 TmpInst.addOperand(MappedInst.getOperand(1));
517 const MCExpr *Sub = MCBinaryExpr::createSub(Expr, One, OutContext);
518 TmpInst.addOperand(
520 MappedInst = TmpInst;
521 return;
522 }
523
524 // Translate a "$Rdd = #imm" to "$Rdd = combine(#[-1,0], #imm)"
525 case Hexagon::A2_tfrpi: {
526 MCInst TmpInst;
527 MCOperand &Rdd = MappedInst.getOperand(0);
528 MCOperand &MO = MappedInst.getOperand(1);
529
530 TmpInst.setOpcode(Hexagon::A2_combineii);
531 TmpInst.addOperand(Rdd);
532 int64_t Imm;
533 bool Success = MO.getExpr()->evaluateAsAbsolute(Imm);
534 if (Success && Imm < 0) {
535 const MCExpr *MOne = MCConstantExpr::create(-1, OutContext);
538 } else {
542 }
543 TmpInst.addOperand(MO);
544 MappedInst = TmpInst;
545 return;
546 }
547
548 // Translate a "$Rdd = $Rss" to "$Rdd = combine($Rs, $Rt)"
549 case Hexagon::A2_tfrp: {
550 MCOperand &MO = MappedInst.getOperand(1);
551 MCRegister High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
552 MCRegister Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
553 MO.setReg(High);
554 // Add a new operand for the second register in the pair.
556 MappedInst.setOpcode(Hexagon::A2_combinew);
557 return;
558 }
559
560 case Hexagon::A2_tfrpt:
561 case Hexagon::A2_tfrpf: {
562 MCOperand &MO = MappedInst.getOperand(2);
563 MCRegister High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
564 MCRegister Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
565 MO.setReg(High);
566 // Add a new operand for the second register in the pair.
568 MappedInst.setOpcode((Inst.getOpcode() == Hexagon::A2_tfrpt)
569 ? Hexagon::C2_ccombinewt
570 : Hexagon::C2_ccombinewf);
571 return;
572 }
573
574 case Hexagon::A2_tfrptnew:
575 case Hexagon::A2_tfrpfnew: {
576 MCOperand &MO = MappedInst.getOperand(2);
577 MCRegister High = RI->getSubReg(MO.getReg(), Hexagon::isub_hi);
578 MCRegister Low = RI->getSubReg(MO.getReg(), Hexagon::isub_lo);
579 MO.setReg(High);
580 // Add a new operand for the second register in the pair.
582 MappedInst.setOpcode(Inst.getOpcode() == Hexagon::A2_tfrptnew
583 ? Hexagon::C2_ccombinewnewt
584 : Hexagon::C2_ccombinewnewf);
585 return;
586 }
587
588 case Hexagon::M2_mpysmi: {
589 MCOperand &Imm = MappedInst.getOperand(2);
590 MCExpr const *Expr = Imm.getExpr();
591 int64_t Value;
592 bool Success = Expr->evaluateAsAbsolute(Value);
594 (void)Success;
595 if (Value < 0 && Value > -256) {
596 MappedInst.setOpcode(Hexagon::M2_mpysin);
599 } else
600 MappedInst.setOpcode(Hexagon::M2_mpysip);
601 return;
602 }
603
604 case Hexagon::A2_addsp: {
605 MCOperand &Rt = Inst.getOperand(1);
606 assert(Rt.isReg() && "Expected register and none was found");
607 unsigned Reg = RI->getEncodingValue(Rt.getReg());
608 if (Reg & 1)
609 MappedInst.setOpcode(Hexagon::A2_addsph);
610 else
611 MappedInst.setOpcode(Hexagon::A2_addspl);
613 return;
614 }
615
616 case Hexagon::V6_vd0: {
617 MCInst TmpInst;
618 assert(Inst.getOperand(0).isReg() &&
619 "Expected register and none was found");
620
621 TmpInst.setOpcode(Hexagon::V6_vxor);
622 TmpInst.addOperand(Inst.getOperand(0));
623 TmpInst.addOperand(Inst.getOperand(0));
624 TmpInst.addOperand(Inst.getOperand(0));
625 MappedInst = TmpInst;
626 return;
627 }
628
629 case Hexagon::V6_vdd0: {
630 MCInst TmpInst;
631 assert (Inst.getOperand(0).isReg() &&
632 "Expected register and none was found");
633
634 TmpInst.setOpcode(Hexagon::V6_vsubw_dv);
635 TmpInst.addOperand(Inst.getOperand(0));
636 TmpInst.addOperand(Inst.getOperand(0));
637 TmpInst.addOperand(Inst.getOperand(0));
638 MappedInst = TmpInst;
639 return;
640 }
641
642 case Hexagon::V6_vL32Ub_pi:
643 case Hexagon::V6_vL32b_cur_pi:
644 case Hexagon::V6_vL32b_nt_cur_pi:
645 case Hexagon::V6_vL32b_pi:
646 case Hexagon::V6_vL32b_nt_pi:
647 case Hexagon::V6_vL32b_nt_tmp_pi:
648 case Hexagon::V6_vL32b_tmp_pi:
649 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
650 return;
651
652 case Hexagon::V6_vL32Ub_ai:
653 case Hexagon::V6_vL32b_ai:
654 case Hexagon::V6_vL32b_cur_ai:
655 case Hexagon::V6_vL32b_nt_ai:
656 case Hexagon::V6_vL32b_nt_cur_ai:
657 case Hexagon::V6_vL32b_nt_tmp_ai:
658 case Hexagon::V6_vL32b_tmp_ai:
659 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
660 return;
661
662 case Hexagon::V6_vS32Ub_pi:
663 case Hexagon::V6_vS32b_new_pi:
664 case Hexagon::V6_vS32b_nt_new_pi:
665 case Hexagon::V6_vS32b_nt_pi:
666 case Hexagon::V6_vS32b_pi:
667 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
668 return;
669
670 case Hexagon::V6_vS32Ub_ai:
671 case Hexagon::V6_vS32b_ai:
672 case Hexagon::V6_vS32b_new_ai:
673 case Hexagon::V6_vS32b_nt_ai:
674 case Hexagon::V6_vS32b_nt_new_ai:
675 MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
676 return;
677
678 case Hexagon::V6_vL32b_cur_npred_pi:
679 case Hexagon::V6_vL32b_cur_pred_pi:
680 case Hexagon::V6_vL32b_npred_pi:
681 case Hexagon::V6_vL32b_nt_cur_npred_pi:
682 case Hexagon::V6_vL32b_nt_cur_pred_pi:
683 case Hexagon::V6_vL32b_nt_npred_pi:
684 case Hexagon::V6_vL32b_nt_pred_pi:
685 case Hexagon::V6_vL32b_nt_tmp_npred_pi:
686 case Hexagon::V6_vL32b_nt_tmp_pred_pi:
687 case Hexagon::V6_vL32b_pred_pi:
688 case Hexagon::V6_vL32b_tmp_npred_pi:
689 case Hexagon::V6_vL32b_tmp_pred_pi:
690 MappedInst = ScaleVectorOffset(Inst, 4, VectorSize, OutContext);
691 return;
692
693 case Hexagon::V6_vL32b_cur_npred_ai:
694 case Hexagon::V6_vL32b_cur_pred_ai:
695 case Hexagon::V6_vL32b_npred_ai:
696 case Hexagon::V6_vL32b_nt_cur_npred_ai:
697 case Hexagon::V6_vL32b_nt_cur_pred_ai:
698 case Hexagon::V6_vL32b_nt_npred_ai:
699 case Hexagon::V6_vL32b_nt_pred_ai:
700 case Hexagon::V6_vL32b_nt_tmp_npred_ai:
701 case Hexagon::V6_vL32b_nt_tmp_pred_ai:
702 case Hexagon::V6_vL32b_pred_ai:
703 case Hexagon::V6_vL32b_tmp_npred_ai:
704 case Hexagon::V6_vL32b_tmp_pred_ai:
705 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
706 return;
707
708 case Hexagon::V6_vS32Ub_npred_pi:
709 case Hexagon::V6_vS32Ub_pred_pi:
710 case Hexagon::V6_vS32b_new_npred_pi:
711 case Hexagon::V6_vS32b_new_pred_pi:
712 case Hexagon::V6_vS32b_npred_pi:
713 case Hexagon::V6_vS32b_nqpred_pi:
714 case Hexagon::V6_vS32b_nt_new_npred_pi:
715 case Hexagon::V6_vS32b_nt_new_pred_pi:
716 case Hexagon::V6_vS32b_nt_npred_pi:
717 case Hexagon::V6_vS32b_nt_nqpred_pi:
718 case Hexagon::V6_vS32b_nt_pred_pi:
719 case Hexagon::V6_vS32b_nt_qpred_pi:
720 case Hexagon::V6_vS32b_pred_pi:
721 case Hexagon::V6_vS32b_qpred_pi:
722 MappedInst = ScaleVectorOffset(Inst, 3, VectorSize, OutContext);
723 return;
724
725 case Hexagon::V6_vS32Ub_npred_ai:
726 case Hexagon::V6_vS32Ub_pred_ai:
727 case Hexagon::V6_vS32b_new_npred_ai:
728 case Hexagon::V6_vS32b_new_pred_ai:
729 case Hexagon::V6_vS32b_npred_ai:
730 case Hexagon::V6_vS32b_nqpred_ai:
731 case Hexagon::V6_vS32b_nt_new_npred_ai:
732 case Hexagon::V6_vS32b_nt_new_pred_ai:
733 case Hexagon::V6_vS32b_nt_npred_ai:
734 case Hexagon::V6_vS32b_nt_nqpred_ai:
735 case Hexagon::V6_vS32b_nt_pred_ai:
736 case Hexagon::V6_vS32b_nt_qpred_ai:
737 case Hexagon::V6_vS32b_pred_ai:
738 case Hexagon::V6_vS32b_qpred_ai:
739 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
740 return;
741
742 // V65+
743 case Hexagon::V6_vS32b_srls_ai:
744 MappedInst = ScaleVectorOffset(Inst, 1, VectorSize, OutContext);
745 return;
746
747 case Hexagon::V6_vS32b_srls_pi:
748 MappedInst = ScaleVectorOffset(Inst, 2, VectorSize, OutContext);
749 return;
750 }
751}
752
753/// Print out a single Hexagon MI to the current output stream.
755 Hexagon_MC::verifyInstructionPredicates(MI->getOpcode(),
756 getSubtargetInfo().getFeatureBits());
757
758 MCInst MCB;
759 MCB.setOpcode(Hexagon::BUNDLE);
761 const MCInstrInfo &MCII = *Subtarget->getInstrInfo();
762
763 if (MI->isBundle()) {
764 const MachineBasicBlock* MBB = MI->getParent();
765 MachineBasicBlock::const_instr_iterator MII = MI->getIterator();
766
767 for (++MII; MII != MBB->instr_end() && MII->isInsideBundle(); ++MII)
768 if (!MII->isDebugInstr() && !MII->isImplicitDef() &&
769 MII->getOpcode() != TargetOpcode::FREEZE)
770 HexagonLowerToMC(MCII, &*MII, MCB, *this);
771 } else {
772 HexagonLowerToMC(MCII, MI, MCB, *this);
773 }
774
775 const MachineFunction &MF = *MI->getParent()->getParent();
776 const auto &HII = *MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
777 if (MI->isBundle() && HII.getBundleNoShuf(*MI))
779
780 MCContext &Ctx = OutStreamer->getContext();
781 bool Ok = HexagonMCInstrInfo::canonicalizePacket(MCII, *Subtarget, Ctx,
782 MCB, nullptr);
783 assert(Ok); (void)Ok;
784 if (HexagonMCInstrInfo::bundleSize(MCB) == 0)
785 return;
786 OutStreamer->emitInstruction(MCB, getSubtargetInfo());
787}
788
790 if (M.getTargetTriple().isOSBinFormatELF())
791 emitAttributes();
792}
793
796 static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
797 if (M.getTargetTriple().isOSBinFormatELF())
799}
800
801void HexagonAsmPrinter::emitAttributes() {
803 static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
805}
806
808 bool Typed) {
809 auto &O = *OutStreamer;
810 MCSymbol *CurSled = OutContext.createTempSymbol("xray_sled_", true);
811 O.emitLabel(CurSled);
812
813 auto *Sym = MCSymbolRefExpr::create(
814 OutContext.getOrCreateSymbol(Typed ? "__xray_TypedEvent"
815 : "__xray_CustomEvent"),
816 OutContext);
817
818 // The sled structure:
819 // .Lxray_sled_N:
820 // { jump .Lend } -- disabled (patched to nop when enabled)
821 // <save args, move operands, call handler, restore args>
822 // .Lend:
823
824 MCSymbol *EndSled = OutContext.createTempSymbol();
825
826 // Packet 1: jump over the sled (disabled state).
827 MCInst *JumpInst = OutContext.createMCInst();
828 JumpInst->setOpcode(Hexagon::J2_jump);
831
832 MCInst JumpPacket;
833 JumpPacket.setOpcode(Hexagon::BUNDLE);
834 JumpPacket.addOperand(MCOperand::createImm(0));
835 JumpPacket.addOperand(MCOperand::createInst(JumpInst));
836 EmitToStreamer(O, JumpPacket);
837
838 // Packet 2: allocframe to save LR:FP.
839 MCInst *AllocInst = OutContext.createMCInst();
840 AllocInst->setOpcode(Hexagon::S2_allocframe);
841 AllocInst->addOperand(MCOperand::createReg(Hexagon::R29));
842 AllocInst->addOperand(MCOperand::createReg(Hexagon::R30));
845
846 MCInst AllocPacket;
847 AllocPacket.setOpcode(Hexagon::BUNDLE);
848 AllocPacket.addOperand(MCOperand::createImm(0));
849 AllocPacket.addOperand(MCOperand::createInst(AllocInst));
850 EmitToStreamer(O, AllocPacket);
851
852 // Save argument registers and set up call arguments.
853 // Custom event: 2 operands (ptr, size) in MI operands 0,1 -> r0, r1
854 // Typed event: 3 operands (type, ptr, size) in MI operands 0,1,2 ->
855 // r0,r1,r2
856 unsigned NumArgs = Typed ? 3 : 2;
857
858 // Save the original argument registers onto the stack.
859 // Packet 3: Allocate space and save r0.
860 MCInst *SubSpInst = OutContext.createMCInst();
861 SubSpInst->setOpcode(Hexagon::A2_addi);
862 SubSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
863 SubSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
865 MCConstantExpr::create(-(int64_t)(NumArgs * 4), OutContext),
866 OutContext)));
867
868 MCInst SubSpPacket;
869 SubSpPacket.setOpcode(Hexagon::BUNDLE);
870 SubSpPacket.addOperand(MCOperand::createImm(0));
871 SubSpPacket.addOperand(MCOperand::createInst(SubSpInst));
872 EmitToStreamer(O, SubSpPacket);
873
874 // Save each argument register.
875 for (unsigned I = 0; I < NumArgs; ++I) {
876 MCInst *StoreInst = OutContext.createMCInst();
877 StoreInst->setOpcode(Hexagon::S2_storeri_io);
878 StoreInst->addOperand(MCOperand::createReg(Hexagon::R29));
881 StoreInst->addOperand(MCOperand::createReg(Hexagon::R0 + I));
882
883 MCInst StorePacket;
884 StorePacket.setOpcode(Hexagon::BUNDLE);
885 StorePacket.addOperand(MCOperand::createImm(0));
887 EmitToStreamer(O, StorePacket);
888 }
889
890 // Move operands into argument registers (r0, r1, [r2]).
891 // The XRay intrinsic uses i64 for size (and type) parameters. On 32-bit
892 // Hexagon these are in DoubleRegs (register pairs). The runtime handler
893 // expects 32-bit arguments, so extract the low sub-register.
894 //
895 // NOTE: Moves are always emitted (even identity moves like r0 = r0) so that
896 // the sled has a fixed size. The runtime patching code relies on the sled
897 // being a known number of words to encode the correct jump offset for the
898 // disabled state.
899 //
900 // NOTE: When source registers alias destination registers in a conflicting
901 // order (e.g., src0 in r1 and src1 in r0), the sequential moves can produce
902 // incorrect results. This is the same limitation as AArch64's implementation
903 // and is unlikely in practice since the register allocator rarely produces
904 // such assignments for XRay event intrinsics.
905 const auto &HRI = *MF->getSubtarget<HexagonSubtarget>().getRegisterInfo();
906 for (unsigned I = 0; I < NumArgs; ++I) {
907 Register SrcReg = MI.getOperand(I).getReg();
908 if (Hexagon::DoubleRegsRegClass.contains(SrcReg))
909 SrcReg = HRI.getSubReg(SrcReg, Hexagon::isub_lo);
910
911 MCInst *MovInst = OutContext.createMCInst();
912 MovInst->setOpcode(Hexagon::A2_tfr);
913 MovInst->addOperand(MCOperand::createReg(Hexagon::R0 + I));
914 MovInst->addOperand(MCOperand::createReg(SrcReg));
915
916 MCInst MovPacket;
917 MovPacket.setOpcode(Hexagon::BUNDLE);
918 MovPacket.addOperand(MCOperand::createImm(0));
919 MovPacket.addOperand(MCOperand::createInst(MovInst));
920 EmitToStreamer(O, MovPacket);
921 }
922
923 // Call the handler.
924 MCInst *CallInst = OutContext.createMCInst();
925 CallInst->setOpcode(Hexagon::J2_call);
926 CallInst->addOperand(
928
929 MCInst CallPacket;
930 CallPacket.setOpcode(Hexagon::BUNDLE);
931 CallPacket.addOperand(MCOperand::createImm(0));
933 EmitToStreamer(O, CallPacket);
934
935 // Restore argument registers.
936 for (unsigned I = 0; I < NumArgs; ++I) {
937 MCInst *LoadInst = OutContext.createMCInst();
938 LoadInst->setOpcode(Hexagon::L2_loadri_io);
939 LoadInst->addOperand(MCOperand::createReg(Hexagon::R0 + I));
940 LoadInst->addOperand(MCOperand::createReg(Hexagon::R29));
943
944 MCInst LoadPacket;
945 LoadPacket.setOpcode(Hexagon::BUNDLE);
946 LoadPacket.addOperand(MCOperand::createImm(0));
948 EmitToStreamer(O, LoadPacket);
949 }
950
951 // Deallocate saved argument space.
952 MCInst *AddSpInst = OutContext.createMCInst();
953 AddSpInst->setOpcode(Hexagon::A2_addi);
954 AddSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
955 AddSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
958
959 MCInst AddSpPacket;
960 AddSpPacket.setOpcode(Hexagon::BUNDLE);
961 AddSpPacket.addOperand(MCOperand::createImm(0));
962 AddSpPacket.addOperand(MCOperand::createInst(AddSpInst));
963 EmitToStreamer(O, AddSpPacket);
964
965 // Deallocframe to restore LR:FP.
966 MCInst *DeallocInst = OutContext.createMCInst();
967 DeallocInst->setOpcode(Hexagon::L2_deallocframe);
968 DeallocInst->addOperand(MCOperand::createReg(Hexagon::D15));
969 DeallocInst->addOperand(MCOperand::createReg(Hexagon::R30));
970
971 MCInst DeallocPacket;
972 DeallocPacket.setOpcode(Hexagon::BUNDLE);
973 DeallocPacket.addOperand(MCOperand::createImm(0));
974 DeallocPacket.addOperand(MCOperand::createInst(DeallocInst));
975 EmitToStreamer(O, DeallocPacket);
976
977 OutStreamer->emitLabel(EndSled);
978 recordSled(CurSled, MI,
980}
981
983 Register AddrReg = MI.getOperand(0).getReg();
984 const int64_t Type = MI.getOperand(1).getImm();
985 [[maybe_unused]] MachineBasicBlock::const_instr_iterator NextI =
986 std::next(MI.getIterator());
987 assert(NextI != MI.getParent()->instr_end() && NextI->isCall() &&
988 "KCFI_CHECK not followed by a call instruction");
989 assert(NextI->getOperand(0).getReg() == AddrReg &&
990 "KCFI_CHECK call target doesn't match call operand");
991
992 // Scratch registers for the compare. Default to R6/R7 (caller-saved,
993 // in GeneralSubRegs for potential compounding). If AddrReg conflicts,
994 // fall back through other caller-saved registers.
995 unsigned ScratchRegs[] = {Hexagon::R6, Hexagon::R7};
996 unsigned NextReg = Hexagon::R8;
997 for (auto &Reg : ScratchRegs) {
998 if (Reg != AddrReg)
999 continue;
1000 if (NextReg == AddrReg)
1001 ++NextReg;
1002 Reg = NextReg++;
1003 }
1004 unsigned LoadReg = ScratchRegs[0];
1005 unsigned TypeReg = ScratchRegs[1];
1006 unsigned PredReg = Hexagon::P0;
1007
1008 // Adjust for patchable-function-prefix (nop padding before the function).
1009 int64_t PrefixNops = MI.getMF()->getFunction().getFnAttributeAsParsedInteger(
1010 "patchable-function-prefix");
1011 int64_t Offset = -(PrefixNops * 4 + 4);
1012
1013 // Emit the KCFI check sequence.
1014 //
1015 // Packet 1: load the type hash and materialize the expected hash together.
1016 // The load offset only leaves its field for an implausible
1017 // patchable-function-prefix, but extend it rather than truncate.
1018 // { r_load = memw(r_addr + #offset); r_type = ##expected_hash }
1019 MCInst *LoadInst = OutContext.createMCInst();
1020 LoadInst->setOpcode(Hexagon::L2_loadri_io);
1021 LoadInst->addOperand(MCOperand::createReg(LoadReg));
1022 LoadInst->addOperand(MCOperand::createReg(AddrReg));
1025
1026 MCInst *TypeInst = OutContext.createMCInst();
1027 TypeInst->setOpcode(Hexagon::A2_tfrsi);
1028 TypeInst->addOperand(MCOperand::createReg(TypeReg));
1029 auto *TypeExpr = HexagonMCExpr::create(
1031 HexagonMCInstrInfo::setMustExtend(*TypeExpr, true);
1032 TypeInst->addOperand(MCOperand::createExpr(TypeExpr));
1033
1034 // setMustExtend() only records that an operand needs an extender; the
1035 // extender still has to be inserted, and slot assignment has to place it
1036 // ahead of what it extends. HexagonLowerToMC()/emitInstruction() do both
1037 // for the MachineInstr stream; packets built here get neither.
1038 const MCInstrInfo &MCII = *Subtarget->getInstrInfo();
1039
1040 // Slot assignment is required for correctness, not just density: an extender
1041 // encoded after its instruction is not a legal packet. Passing a checker
1042 // (rather than nullptr) is what makes the assert meaningful.
1043 auto EmitPacket = [&](MCInst &MCB) {
1044 HexagonMCChecker Checker(OutContext, MCII, *Subtarget, MCB,
1045 *OutContext.getRegisterInfo(),
1046 /*ReportErrors=*/false);
1047 [[maybe_unused]] bool Ok = HexagonMCInstrInfo::canonicalizePacket(
1048 MCII, *Subtarget, OutContext, MCB, &Checker);
1049 assert(Ok && "KCFI packet failed MC canonicalization");
1051 };
1052
1053 MCInst LoadTypePacket;
1054 LoadTypePacket.setOpcode(Hexagon::BUNDLE);
1055 LoadTypePacket.addOperand(MCOperand::createImm(0));
1056 HexagonMCInstrInfo::extendIfNeeded(OutContext, MCII, LoadTypePacket,
1057 *LoadInst);
1058 LoadTypePacket.addOperand(MCOperand::createInst(LoadInst));
1059 HexagonMCInstrInfo::extendIfNeeded(OutContext, MCII, LoadTypePacket,
1060 *TypeInst);
1061 LoadTypePacket.addOperand(MCOperand::createInst(TypeInst));
1062 EmitPacket(LoadTypePacket);
1063
1064 // Packet 3: Compare and branch if equal.
1065 // { p0 = cmp.eq(r_load, r_type); if (p0.new) jump:t .Lpass }
1066 MCSymbol *Pass = OutContext.createTempSymbol();
1067
1068 MCInst *CmpInst = OutContext.createMCInst();
1069 CmpInst->setOpcode(Hexagon::C2_cmpeq);
1070 CmpInst->addOperand(MCOperand::createReg(PredReg));
1071 CmpInst->addOperand(MCOperand::createReg(LoadReg));
1072 CmpInst->addOperand(MCOperand::createReg(TypeReg));
1073
1074 MCInst *JumpInst = OutContext.createMCInst();
1075 JumpInst->setOpcode(Hexagon::J2_jumptnewpt);
1076 JumpInst->addOperand(MCOperand::createReg(PredReg));
1079
1080 MCInst CmpJmpPacket;
1081 CmpJmpPacket.setOpcode(Hexagon::BUNDLE);
1082 CmpJmpPacket.addOperand(MCOperand::createImm(0));
1084 CmpJmpPacket.addOperand(MCOperand::createInst(JumpInst));
1085 EmitPacket(CmpJmpPacket);
1086
1087 // Packet 4: Crash on mismatch via misaligned load.
1088 // Use the same mechanism as llvm.trap (PS_crash): a doubleword load from
1089 // a misaligned address is guaranteed to fault in all execution modes,
1090 // including kernel/monitor mode where trap0 may not generate a useful
1091 // exception.
1092 MCSymbol *TrapLabel = OutContext.createTempSymbol();
1093 OutStreamer->emitLabel(TrapLabel);
1094
1095 MCInst *CrashInst = OutContext.createMCInst();
1096 CrashInst->setOpcode(Hexagon::PS_loadrdabs);
1097 CrashInst->addOperand(MCOperand::createReg(Hexagon::D13));
1098 auto *CrashExpr = HexagonMCExpr::create(
1100 HexagonMCInstrInfo::setMustExtend(*CrashExpr, true);
1101 CrashInst->addOperand(MCOperand::createExpr(CrashExpr));
1102
1103 MCInst CrashPacket;
1104 CrashPacket.setOpcode(Hexagon::BUNDLE);
1105 CrashPacket.addOperand(MCOperand::createImm(0));
1106 HexagonMCInstrInfo::extendIfNeeded(OutContext, MCII, CrashPacket, *CrashInst);
1107 CrashPacket.addOperand(MCOperand::createInst(CrashInst));
1108 EmitPacket(CrashPacket);
1109
1110 emitKCFITrapEntry(*MI.getMF(), TrapLabel);
1111 OutStreamer->emitLabel(Pass);
1112}
1113
1115 static const int8_t NoopsInSledCount = 6;
1116 // We want to emit the following pattern:
1117 //
1118 // .L_xray_sled_N:
1119 // <xray_sled_base>:
1120 // { jump .Ltmp0 }
1121 // { nop }
1122 // { nop }
1123 // { nop }
1124 // { nop }
1125 // { nop }
1126 // { nop }
1127 // .Ltmp0:
1128 //
1129 // We need the 6 nop words because at runtime, we'd be patching over the
1130 // full 7 words with the following pattern:
1131 //
1132 // <xray_sled_n>:
1133 // { allocframe(#0) }
1134 // { immext(#...) // upper 26-bits of func id
1135 // r7 = ##... // lower 6-bits of func id
1136 // immext(#...) // upper 26-bits of trampoline
1137 // r6 = ##... } // lower 6-bits of trampoline
1138 // { callr r6 }
1139 // { deallocframe }
1140 //
1141 // allocframe saves r31:30 (LR:FP) before the call, and deallocframe
1142 // restores them after the trampoline returns, ensuring the caller's
1143 // return address in r31 is preserved across the sled.
1144 //
1145 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1146 OutStreamer->emitLabel(CurSled);
1147
1148 MCInst *SledJump = new (OutContext) MCInst();
1149 SledJump->setOpcode(Hexagon::J2_jump);
1150 auto PostSled = OutContext.createTempSymbol();
1153
1154 // Emit "jump PostSled" instruction, which jumps over the nop series.
1155 MCInst SledJumpPacket;
1156 SledJumpPacket.setOpcode(Hexagon::BUNDLE);
1157 SledJumpPacket.addOperand(MCOperand::createImm(0));
1158 SledJumpPacket.addOperand(MCOperand::createInst(SledJump));
1159
1160 EmitToStreamer(*OutStreamer, SledJumpPacket);
1161
1162 // FIXME: this will emit individual packets, we should
1163 // special-case this and combine them into a single packet.
1164 emitNops(NoopsInSledCount);
1165
1166 OutStreamer->emitLabel(PostSled);
1167 recordSled(CurSled, MI, Kind, 2);
1168}
1169
1173
1177
1181
1182char HexagonAsmPrinter::ID = 0;
1183
1184INITIALIZE_PASS(HexagonAsmPrinter, "hexagon-asm-printer",
1185 "Hexagon Assembly Printer", false, false)
1186
1187extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1188LLVMInitializeHexagonAsmPrinter() {
1190}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t Imm
constexpr LLT S16
MachineBasicBlock & MBB
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
#define LLVM_ABI
Definition Compiler.h:211
#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
Module.h This file contains the declarations for the Module class.
#define I(x, y, z)
Definition MD5.cpp:57
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:479
This file contains some functions that are useful when dealing with strings.
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:95
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:98
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.
void emitKCFITrapEntry(const MachineFunction &MF, const MCSymbol *Symbol)
MachineFunction * MF
The current machine function.
Definition AsmPrinter.h:113
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:105
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition AsmPrinter.h:110
const MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:101
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
This class represents a function call, abstracting a target machine's calling convention.
This class is the base class for the comparison instructions.
Definition InstrTypes.h:728
void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI)
void LowerPATCHABLE_EVENT_CALL(const MachineInstr &MI, bool Typed)
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 LowerKCFI_CHECK(const MachineInstr &MI)
void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O)
void HexagonProcessInstruction(MCInst &Inst, const MachineInstr &MBB)
static char const * getRegisterName(MCRegister Reg)
Check for a valid bundle.
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
void emitTargetAttributes(const MCSubtargetInfo &STI)
An instruction for reading from memory.
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
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:552
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:222
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
MCContext & getContext() const
Definition MCStreamer.h:330
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 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:213
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:60
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:268
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:68
Pass interface - Implemented by all 'passes'.
Definition Pass.h:97
Wrapper class representing virtual and physical registers.
Definition Register.h:20
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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:1098
@ SHF_WRITE
Definition ELF.h:1095
@ SHT_PROGBITS
Definition ELF.h:996
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)
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
void setMustExtend(MCExpr const &Expr, bool Val=true)
This is an optimization pass for GlobalISel generic memory operations.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
Definition Threading.h:280
@ Offset
Definition DWP.cpp:577
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
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:68
@ 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,...