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 {
539 const MCExpr *Zero = MCConstantExpr::create(0, OutContext);
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 HexagonLowerToMC(MCII, &*MII, MCB, *this);
770 } else {
771 HexagonLowerToMC(MCII, MI, MCB, *this);
772 }
773
774 const MachineFunction &MF = *MI->getParent()->getParent();
775 const auto &HII = *MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
776 if (MI->isBundle() && HII.getBundleNoShuf(*MI))
778
779 MCContext &Ctx = OutStreamer->getContext();
780 bool Ok = HexagonMCInstrInfo::canonicalizePacket(MCII, *Subtarget, Ctx,
781 MCB, nullptr);
782 assert(Ok); (void)Ok;
783 if (HexagonMCInstrInfo::bundleSize(MCB) == 0)
784 return;
785 OutStreamer->emitInstruction(MCB, getSubtargetInfo());
786}
787
789 if (M.getTargetTriple().isOSBinFormatELF())
790 emitAttributes();
791}
792
795 static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
796 if (M.getTargetTriple().isOSBinFormatELF())
798}
799
800void HexagonAsmPrinter::emitAttributes() {
802 static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
804}
805
807 bool Typed) {
808 auto &O = *OutStreamer;
809 MCSymbol *CurSled = OutContext.createTempSymbol("xray_sled_", true);
810 O.emitLabel(CurSled);
811
812 auto *Sym = MCSymbolRefExpr::create(
813 OutContext.getOrCreateSymbol(Typed ? "__xray_TypedEvent"
814 : "__xray_CustomEvent"),
815 OutContext);
816
817 // The sled structure:
818 // .Lxray_sled_N:
819 // { jump .Lend } -- disabled (patched to nop when enabled)
820 // <save args, move operands, call handler, restore args>
821 // .Lend:
822
823 MCSymbol *EndSled = OutContext.createTempSymbol();
824
825 // Packet 1: jump over the sled (disabled state).
826 MCInst *JumpInst = OutContext.createMCInst();
827 JumpInst->setOpcode(Hexagon::J2_jump);
830
831 MCInst JumpPacket;
832 JumpPacket.setOpcode(Hexagon::BUNDLE);
833 JumpPacket.addOperand(MCOperand::createImm(0));
834 JumpPacket.addOperand(MCOperand::createInst(JumpInst));
835 EmitToStreamer(O, JumpPacket);
836
837 // Packet 2: allocframe to save LR:FP.
838 MCInst *AllocInst = OutContext.createMCInst();
839 AllocInst->setOpcode(Hexagon::S2_allocframe);
840 AllocInst->addOperand(MCOperand::createReg(Hexagon::R29));
841 AllocInst->addOperand(MCOperand::createReg(Hexagon::R30));
844
845 MCInst AllocPacket;
846 AllocPacket.setOpcode(Hexagon::BUNDLE);
847 AllocPacket.addOperand(MCOperand::createImm(0));
848 AllocPacket.addOperand(MCOperand::createInst(AllocInst));
849 EmitToStreamer(O, AllocPacket);
850
851 // Save argument registers and set up call arguments.
852 // Custom event: 2 operands (ptr, size) in MI operands 0,1 -> r0, r1
853 // Typed event: 3 operands (type, ptr, size) in MI operands 0,1,2 ->
854 // r0,r1,r2
855 unsigned NumArgs = Typed ? 3 : 2;
856
857 // Save the original argument registers onto the stack.
858 // Packet 3: Allocate space and save r0.
859 MCInst *SubSpInst = OutContext.createMCInst();
860 SubSpInst->setOpcode(Hexagon::A2_addi);
861 SubSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
862 SubSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
864 MCConstantExpr::create(-(int64_t)(NumArgs * 4), OutContext),
865 OutContext)));
866
867 MCInst SubSpPacket;
868 SubSpPacket.setOpcode(Hexagon::BUNDLE);
869 SubSpPacket.addOperand(MCOperand::createImm(0));
870 SubSpPacket.addOperand(MCOperand::createInst(SubSpInst));
871 EmitToStreamer(O, SubSpPacket);
872
873 // Save each argument register.
874 for (unsigned I = 0; I < NumArgs; ++I) {
875 MCInst *StoreInst = OutContext.createMCInst();
876 StoreInst->setOpcode(Hexagon::S2_storeri_io);
877 StoreInst->addOperand(MCOperand::createReg(Hexagon::R29));
880 StoreInst->addOperand(MCOperand::createReg(Hexagon::R0 + I));
881
882 MCInst StorePacket;
883 StorePacket.setOpcode(Hexagon::BUNDLE);
884 StorePacket.addOperand(MCOperand::createImm(0));
886 EmitToStreamer(O, StorePacket);
887 }
888
889 // Move operands into argument registers (r0, r1, [r2]).
890 // The XRay intrinsic uses i64 for size (and type) parameters. On 32-bit
891 // Hexagon these are in DoubleRegs (register pairs). The runtime handler
892 // expects 32-bit arguments, so extract the low sub-register.
893 //
894 // NOTE: Moves are always emitted (even identity moves like r0 = r0) so that
895 // the sled has a fixed size. The runtime patching code relies on the sled
896 // being a known number of words to encode the correct jump offset for the
897 // disabled state.
898 //
899 // NOTE: When source registers alias destination registers in a conflicting
900 // order (e.g., src0 in r1 and src1 in r0), the sequential moves can produce
901 // incorrect results. This is the same limitation as AArch64's implementation
902 // and is unlikely in practice since the register allocator rarely produces
903 // such assignments for XRay event intrinsics.
904 const auto &HRI = *MF->getSubtarget<HexagonSubtarget>().getRegisterInfo();
905 for (unsigned I = 0; I < NumArgs; ++I) {
906 Register SrcReg = MI.getOperand(I).getReg();
907 if (Hexagon::DoubleRegsRegClass.contains(SrcReg))
908 SrcReg = HRI.getSubReg(SrcReg, Hexagon::isub_lo);
909
910 MCInst *MovInst = OutContext.createMCInst();
911 MovInst->setOpcode(Hexagon::A2_tfr);
912 MovInst->addOperand(MCOperand::createReg(Hexagon::R0 + I));
913 MovInst->addOperand(MCOperand::createReg(SrcReg));
914
915 MCInst MovPacket;
916 MovPacket.setOpcode(Hexagon::BUNDLE);
917 MovPacket.addOperand(MCOperand::createImm(0));
918 MovPacket.addOperand(MCOperand::createInst(MovInst));
919 EmitToStreamer(O, MovPacket);
920 }
921
922 // Call the handler.
923 MCInst *CallInst = OutContext.createMCInst();
924 CallInst->setOpcode(Hexagon::J2_call);
925 CallInst->addOperand(
927
928 MCInst CallPacket;
929 CallPacket.setOpcode(Hexagon::BUNDLE);
930 CallPacket.addOperand(MCOperand::createImm(0));
932 EmitToStreamer(O, CallPacket);
933
934 // Restore argument registers.
935 for (unsigned I = 0; I < NumArgs; ++I) {
936 MCInst *LoadInst = OutContext.createMCInst();
937 LoadInst->setOpcode(Hexagon::L2_loadri_io);
938 LoadInst->addOperand(MCOperand::createReg(Hexagon::R0 + I));
939 LoadInst->addOperand(MCOperand::createReg(Hexagon::R29));
942
943 MCInst LoadPacket;
944 LoadPacket.setOpcode(Hexagon::BUNDLE);
945 LoadPacket.addOperand(MCOperand::createImm(0));
947 EmitToStreamer(O, LoadPacket);
948 }
949
950 // Deallocate saved argument space.
951 MCInst *AddSpInst = OutContext.createMCInst();
952 AddSpInst->setOpcode(Hexagon::A2_addi);
953 AddSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
954 AddSpInst->addOperand(MCOperand::createReg(Hexagon::R29));
957
958 MCInst AddSpPacket;
959 AddSpPacket.setOpcode(Hexagon::BUNDLE);
960 AddSpPacket.addOperand(MCOperand::createImm(0));
961 AddSpPacket.addOperand(MCOperand::createInst(AddSpInst));
962 EmitToStreamer(O, AddSpPacket);
963
964 // Deallocframe to restore LR:FP.
965 MCInst *DeallocInst = OutContext.createMCInst();
966 DeallocInst->setOpcode(Hexagon::L2_deallocframe);
967 DeallocInst->addOperand(MCOperand::createReg(Hexagon::D15));
968 DeallocInst->addOperand(MCOperand::createReg(Hexagon::R30));
969
970 MCInst DeallocPacket;
971 DeallocPacket.setOpcode(Hexagon::BUNDLE);
972 DeallocPacket.addOperand(MCOperand::createImm(0));
973 DeallocPacket.addOperand(MCOperand::createInst(DeallocInst));
974 EmitToStreamer(O, DeallocPacket);
975
976 OutStreamer->emitLabel(EndSled);
977 recordSled(CurSled, MI,
979}
980
982 Register AddrReg = MI.getOperand(0).getReg();
983 const int64_t Type = MI.getOperand(1).getImm();
984 [[maybe_unused]] MachineBasicBlock::const_instr_iterator NextI =
985 std::next(MI.getIterator());
986 assert(NextI != MI.getParent()->instr_end() && NextI->isCall() &&
987 "KCFI_CHECK not followed by a call instruction");
988 assert(NextI->getOperand(0).getReg() == AddrReg &&
989 "KCFI_CHECK call target doesn't match call operand");
990
991 // Scratch registers for the compare. Default to R6/R7 (caller-saved,
992 // in GeneralSubRegs for potential compounding). If AddrReg conflicts,
993 // fall back through other caller-saved registers.
994 unsigned ScratchRegs[] = {Hexagon::R6, Hexagon::R7};
995 unsigned NextReg = Hexagon::R8;
996 for (auto &Reg : ScratchRegs) {
997 if (Reg != AddrReg)
998 continue;
999 if (NextReg == AddrReg)
1000 ++NextReg;
1001 Reg = NextReg++;
1002 }
1003 unsigned LoadReg = ScratchRegs[0];
1004 unsigned TypeReg = ScratchRegs[1];
1005 unsigned PredReg = Hexagon::P0;
1006
1007 // Adjust for patchable-function-prefix (nop padding before the function).
1008 int64_t PrefixNops = MI.getMF()->getFunction().getFnAttributeAsParsedInteger(
1009 "patchable-function-prefix");
1010 int64_t Offset = -(PrefixNops * 4 + 4);
1011
1012 // Emit the KCFI check sequence.
1013 //
1014 // Packet 1: load the type hash and materialize the expected hash together.
1015 // The load offset only leaves its field for an implausible
1016 // patchable-function-prefix, but extend it rather than truncate.
1017 // { r_load = memw(r_addr + #offset); r_type = ##expected_hash }
1018 MCInst *LoadInst = OutContext.createMCInst();
1019 LoadInst->setOpcode(Hexagon::L2_loadri_io);
1020 LoadInst->addOperand(MCOperand::createReg(LoadReg));
1021 LoadInst->addOperand(MCOperand::createReg(AddrReg));
1024
1025 MCInst *TypeInst = OutContext.createMCInst();
1026 TypeInst->setOpcode(Hexagon::A2_tfrsi);
1027 TypeInst->addOperand(MCOperand::createReg(TypeReg));
1028 auto *TypeExpr = HexagonMCExpr::create(
1030 HexagonMCInstrInfo::setMustExtend(*TypeExpr, true);
1031 TypeInst->addOperand(MCOperand::createExpr(TypeExpr));
1032
1033 // setMustExtend() only records that an operand needs an extender; the
1034 // extender still has to be inserted, and slot assignment has to place it
1035 // ahead of what it extends. HexagonLowerToMC()/emitInstruction() do both
1036 // for the MachineInstr stream; packets built here get neither.
1037 const MCInstrInfo &MCII = *Subtarget->getInstrInfo();
1038
1039 // Slot assignment is required for correctness, not just density: an extender
1040 // encoded after its instruction is not a legal packet. Passing a checker
1041 // (rather than nullptr) is what makes the assert meaningful.
1042 auto EmitPacket = [&](MCInst &MCB) {
1043 HexagonMCChecker Checker(OutContext, MCII, *Subtarget, MCB,
1044 *OutContext.getRegisterInfo(),
1045 /*ReportErrors=*/false);
1046 [[maybe_unused]] bool Ok = HexagonMCInstrInfo::canonicalizePacket(
1047 MCII, *Subtarget, OutContext, MCB, &Checker);
1048 assert(Ok && "KCFI packet failed MC canonicalization");
1050 };
1051
1052 MCInst LoadTypePacket;
1053 LoadTypePacket.setOpcode(Hexagon::BUNDLE);
1054 LoadTypePacket.addOperand(MCOperand::createImm(0));
1055 HexagonMCInstrInfo::extendIfNeeded(OutContext, MCII, LoadTypePacket,
1056 *LoadInst);
1057 LoadTypePacket.addOperand(MCOperand::createInst(LoadInst));
1058 HexagonMCInstrInfo::extendIfNeeded(OutContext, MCII, LoadTypePacket,
1059 *TypeInst);
1060 LoadTypePacket.addOperand(MCOperand::createInst(TypeInst));
1061 EmitPacket(LoadTypePacket);
1062
1063 // Packet 3: Compare and branch if equal.
1064 // { p0 = cmp.eq(r_load, r_type); if (p0.new) jump:t .Lpass }
1065 MCSymbol *Pass = OutContext.createTempSymbol();
1066
1067 MCInst *CmpInst = OutContext.createMCInst();
1068 CmpInst->setOpcode(Hexagon::C2_cmpeq);
1069 CmpInst->addOperand(MCOperand::createReg(PredReg));
1070 CmpInst->addOperand(MCOperand::createReg(LoadReg));
1071 CmpInst->addOperand(MCOperand::createReg(TypeReg));
1072
1073 MCInst *JumpInst = OutContext.createMCInst();
1074 JumpInst->setOpcode(Hexagon::J2_jumptnewpt);
1075 JumpInst->addOperand(MCOperand::createReg(PredReg));
1078
1079 MCInst CmpJmpPacket;
1080 CmpJmpPacket.setOpcode(Hexagon::BUNDLE);
1081 CmpJmpPacket.addOperand(MCOperand::createImm(0));
1083 CmpJmpPacket.addOperand(MCOperand::createInst(JumpInst));
1084 EmitPacket(CmpJmpPacket);
1085
1086 // Packet 4: Crash on mismatch via misaligned load.
1087 // Use the same mechanism as llvm.trap (PS_crash): a doubleword load from
1088 // a misaligned address is guaranteed to fault in all execution modes,
1089 // including kernel/monitor mode where trap0 may not generate a useful
1090 // exception.
1091 MCSymbol *TrapLabel = OutContext.createTempSymbol();
1092 OutStreamer->emitLabel(TrapLabel);
1093
1094 MCInst *CrashInst = OutContext.createMCInst();
1095 CrashInst->setOpcode(Hexagon::PS_loadrdabs);
1096 CrashInst->addOperand(MCOperand::createReg(Hexagon::D13));
1097 auto *CrashExpr = HexagonMCExpr::create(
1099 HexagonMCInstrInfo::setMustExtend(*CrashExpr, true);
1100 CrashInst->addOperand(MCOperand::createExpr(CrashExpr));
1101
1102 MCInst CrashPacket;
1103 CrashPacket.setOpcode(Hexagon::BUNDLE);
1104 CrashPacket.addOperand(MCOperand::createImm(0));
1105 HexagonMCInstrInfo::extendIfNeeded(OutContext, MCII, CrashPacket, *CrashInst);
1106 CrashPacket.addOperand(MCOperand::createInst(CrashInst));
1107 EmitPacket(CrashPacket);
1108
1109 emitKCFITrapEntry(*MI.getMF(), TrapLabel);
1110 OutStreamer->emitLabel(Pass);
1111}
1112
1114 static const int8_t NoopsInSledCount = 6;
1115 // We want to emit the following pattern:
1116 //
1117 // .L_xray_sled_N:
1118 // <xray_sled_base>:
1119 // { jump .Ltmp0 }
1120 // { nop }
1121 // { nop }
1122 // { nop }
1123 // { nop }
1124 // { nop }
1125 // { nop }
1126 // .Ltmp0:
1127 //
1128 // We need the 6 nop words because at runtime, we'd be patching over the
1129 // full 7 words with the following pattern:
1130 //
1131 // <xray_sled_n>:
1132 // { allocframe(#0) }
1133 // { immext(#...) // upper 26-bits of func id
1134 // r7 = ##... // lower 6-bits of func id
1135 // immext(#...) // upper 26-bits of trampoline
1136 // r6 = ##... } // lower 6-bits of trampoline
1137 // { callr r6 }
1138 // { deallocframe }
1139 //
1140 // allocframe saves r31:30 (LR:FP) before the call, and deallocframe
1141 // restores them after the trampoline returns, ensuring the caller's
1142 // return address in r31 is preserved across the sled.
1143 //
1144 auto CurSled = OutContext.createTempSymbol("xray_sled_", true);
1145 OutStreamer->emitLabel(CurSled);
1146
1147 MCInst *SledJump = new (OutContext) MCInst();
1148 SledJump->setOpcode(Hexagon::J2_jump);
1149 auto PostSled = OutContext.createTempSymbol();
1152
1153 // Emit "jump PostSled" instruction, which jumps over the nop series.
1154 MCInst SledJumpPacket;
1155 SledJumpPacket.setOpcode(Hexagon::BUNDLE);
1156 SledJumpPacket.addOperand(MCOperand::createImm(0));
1157 SledJumpPacket.addOperand(MCOperand::createInst(SledJump));
1158
1159 EmitToStreamer(*OutStreamer, SledJumpPacket);
1160
1161 // FIXME: this will emit individual packets, we should
1162 // special-case this and combine them into a single packet.
1163 emitNops(NoopsInSledCount);
1164
1165 OutStreamer->emitLabel(PostSled);
1166 recordSled(CurSled, MI, Kind, 2);
1167}
1168
1172
1176
1180
1181char HexagonAsmPrinter::ID = 0;
1182
1183INITIALIZE_PASS(HexagonAsmPrinter, "hexagon-asm-printer",
1184 "Hexagon Assembly Printer", false, false)
1185
1186extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
1187LLVMInitializeHexagonAsmPrinter() {
1189}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned Imm
constexpr LLT S16
MachineBasicBlock & MBB
#define X(NUM, ENUM, NAME)
Definition ELF.h:857
#define LLVM_ABI
Definition Compiler.h:215
#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:484
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: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.
void emitKCFITrapEntry(const MachineFunction &MF, const MCSymbol *Symbol)
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 MCAsmInfo & MAI
Target Asm Printer information.
Definition AsmPrinter.h:97
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:550
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
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:326
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: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: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:99
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:1259
@ SHF_WRITE
Definition ELF.h:1256
@ SHT_PROGBITS
Definition ELF.h:1157
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,...