1 //===-- HexagonMCCodeEmitter.cpp - Hexagon Target Descriptions ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "MCTargetDesc/HexagonBaseInfo.h"
12 #include "MCTargetDesc/HexagonFixupKinds.h"
13 #include "MCTargetDesc/HexagonMCCodeEmitter.h"
14 #include "MCTargetDesc/HexagonMCInstrInfo.h"
15 #include "MCTargetDesc/HexagonMCTargetDesc.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/MC/MCCodeEmitter.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/EndianStream.h"
26 #include "llvm/Support/raw_ostream.h"
28 #define DEBUG_TYPE "mccodeemitter"
31 using namespace Hexagon;
33 STATISTIC(MCNumEmitted, "Number of MC instructions emitted");
35 HexagonMCCodeEmitter::HexagonMCCodeEmitter(MCInstrInfo const &aMII,
37 : MCT(aMCT), MCII(aMII), Addend(new unsigned(0)),
38 Extended(new bool(false)), CurrentBundle(new MCInst const *) {}
40 uint32_t HexagonMCCodeEmitter::parseBits(size_t Instruction, size_t Last,
42 MCInst const &MCI) const {
43 bool Duplex = HexagonMCInstrInfo::isDuplex(MCII, MCI);
44 if (Instruction == 0) {
45 if (HexagonMCInstrInfo::isInnerLoop(MCB)) {
47 assert(Instruction != Last);
48 return HexagonII::INST_PARSE_LOOP_END;
51 if (Instruction == 1) {
52 if (HexagonMCInstrInfo::isOuterLoop(MCB)) {
54 assert(Instruction != Last);
55 return HexagonII::INST_PARSE_LOOP_END;
59 assert(Instruction == Last);
60 return HexagonII::INST_PARSE_DUPLEX;
62 if(Instruction == Last)
63 return HexagonII::INST_PARSE_PACKET_END;
64 return HexagonII::INST_PARSE_NOT_END;
67 void HexagonMCCodeEmitter::encodeInstruction(MCInst const &MI, raw_ostream &OS,
68 SmallVectorImpl<MCFixup> &Fixups,
69 MCSubtargetInfo const &STI) const {
70 MCInst &HMB = const_cast<MCInst &>(MI);
72 assert(HexagonMCInstrInfo::isBundle(HMB));
73 DEBUG(dbgs() << "Encoding bundle\n";);
77 size_t Instruction = 0;
78 size_t Last = HexagonMCInstrInfo::bundleSize(HMB) - 1;
79 for (auto &I : HexagonMCInstrInfo::bundleInstructions(HMB)) {
80 MCInst &HMI = const_cast<MCInst &>(*I.getInst());
81 EncodeSingleInstruction(HMI, OS, Fixups, STI,
82 parseBits(Instruction, Last, HMB, HMI),
84 *Extended = HexagonMCInstrInfo::isImmext(HMI);
85 *Addend += HEXAGON_INSTR_SIZE;
91 /// EncodeSingleInstruction - Emit a single
92 void HexagonMCCodeEmitter::EncodeSingleInstruction(
93 const MCInst &MI, raw_ostream &OS, SmallVectorImpl<MCFixup> &Fixups,
94 const MCSubtargetInfo &STI, uint32_t Parse, size_t Index) const {
96 assert(!HexagonMCInstrInfo::isBundle(HMB));
99 // Pseudo instructions don't get encoded and shouldn't be here
100 // in the first place!
101 assert(!HexagonMCInstrInfo::getDesc(MCII, HMB).isPseudo() &&
102 "pseudo-instruction found");
103 DEBUG(dbgs() << "Encoding insn"
104 " `" << HexagonMCInstrInfo::getName(MCII, HMB) << "'"
107 if (HexagonMCInstrInfo::isNewValue(MCII, HMB)) {
108 // Calculate the new value distance to the associated producer
110 HMB.getOperand(HexagonMCInstrInfo::getNewValueOp(MCII, HMB));
111 unsigned SOffset = 0;
112 unsigned Register = MCO.getReg();
114 auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle);
115 auto i = Instructions.begin() + Index - 1;
117 assert(i != Instructions.begin() - 1 && "Couldn't find producer");
118 MCInst const &Inst = *i->getInst();
119 if (HexagonMCInstrInfo::isImmext(Inst))
123 HexagonMCInstrInfo::hasNewValue(MCII, Inst)
124 ? HexagonMCInstrInfo::getNewValueOperand(MCII, Inst).getReg()
125 : static_cast<unsigned>(Hexagon::NoRegister);
126 if (Register != Register1)
127 // This isn't the register we're looking for
129 if (!HexagonMCInstrInfo::isPredicated(MCII, Inst))
130 // Producer is unpredicated
132 assert(HexagonMCInstrInfo::isPredicated(MCII, HMB) &&
133 "Unpredicated consumer depending on predicated producer");
134 if (HexagonMCInstrInfo::isPredicatedTrue(MCII, Inst) ==
135 HexagonMCInstrInfo::isPredicatedTrue(MCII, HMB))
136 // Producer predicate sense matched ours
139 // Hexagon PRM 10.11 Construct Nt from distance
140 unsigned Offset = SOffset;
142 MCO.setReg(Offset + Hexagon::R0);
145 Binary = getBinaryCodeForInstr(HMB, Fixups, STI);
146 // Check for unimplemented instructions. Immediate extenders
147 // are encoded as zero, so they need to be accounted for.
149 ((HMB.getOpcode() != DuplexIClass0) && (HMB.getOpcode() != A4_ext) &&
150 (HMB.getOpcode() != A4_ext_b) && (HMB.getOpcode() != A4_ext_c) &&
151 (HMB.getOpcode() != A4_ext_g))) {
152 // Use a A2_nop for unimplemented instructions.
153 DEBUG(dbgs() << "Unimplemented inst: "
154 " `" << HexagonMCInstrInfo::getName(MCII, HMB) << "'"
156 llvm_unreachable("Unimplemented Instruction");
160 // if we need to emit a duplexed instruction
161 if (HMB.getOpcode() >= Hexagon::DuplexIClass0 &&
162 HMB.getOpcode() <= Hexagon::DuplexIClassF) {
163 assert(Parse == HexagonII::INST_PARSE_DUPLEX &&
164 "Emitting duplex without duplex parse bits");
166 switch (HMB.getOpcode()) {
167 case Hexagon::DuplexIClass0:
170 case Hexagon::DuplexIClass1:
173 case Hexagon::DuplexIClass2:
176 case Hexagon::DuplexIClass3:
179 case Hexagon::DuplexIClass4:
182 case Hexagon::DuplexIClass5:
185 case Hexagon::DuplexIClass6:
188 case Hexagon::DuplexIClass7:
191 case Hexagon::DuplexIClass8:
194 case Hexagon::DuplexIClass9:
197 case Hexagon::DuplexIClassA:
200 case Hexagon::DuplexIClassB:
203 case Hexagon::DuplexIClassC:
206 case Hexagon::DuplexIClassD:
209 case Hexagon::DuplexIClassE:
212 case Hexagon::DuplexIClassF:
216 llvm_unreachable("Unimplemented DuplexIClass");
219 // 29 is the bit position.
220 // 0b1110 =0xE bits are masked off and down shifted by 1 bit.
221 // Last bit is moved to bit position 13
222 Binary = ((dupIClass & 0xE) << (29 - 1)) | ((dupIClass & 0x1) << 13);
224 const MCInst *subInst0 = HMB.getOperand(0).getInst();
225 const MCInst *subInst1 = HMB.getOperand(1).getInst();
227 // get subinstruction slot 0
228 unsigned subInstSlot0Bits = getBinaryCodeForInstr(*subInst0, Fixups, STI);
229 // get subinstruction slot 1
230 unsigned subInstSlot1Bits = getBinaryCodeForInstr(*subInst1, Fixups, STI);
232 Binary |= subInstSlot0Bits | (subInstSlot1Bits << 16);
234 support::endian::Writer<support::little>(OS).write<uint32_t>(Binary);
238 static Hexagon::Fixups getFixupNoBits(MCInstrInfo const &MCII, const MCInst &MI,
240 const MCSymbolRefExpr::VariantKind kind) {
241 const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MI);
242 unsigned insnType = llvm::HexagonMCInstrInfo::getType(MCII, MI);
244 if (insnType == HexagonII::TypePREFIX) {
246 case llvm::MCSymbolRefExpr::VK_GOTOFF:
247 return Hexagon::fixup_Hexagon_GOTREL_32_6_X;
248 case llvm::MCSymbolRefExpr::VK_GOT:
249 return Hexagon::fixup_Hexagon_GOT_32_6_X;
250 case llvm::MCSymbolRefExpr::VK_TPREL:
251 return Hexagon::fixup_Hexagon_TPREL_32_6_X;
252 case llvm::MCSymbolRefExpr::VK_DTPREL:
253 return Hexagon::fixup_Hexagon_DTPREL_32_6_X;
254 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
255 return Hexagon::fixup_Hexagon_GD_GOT_32_6_X;
256 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
257 return Hexagon::fixup_Hexagon_LD_GOT_32_6_X;
258 case llvm::MCSymbolRefExpr::VK_Hexagon_IE:
259 return Hexagon::fixup_Hexagon_IE_32_6_X;
260 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
261 return Hexagon::fixup_Hexagon_IE_GOT_32_6_X;
264 return Hexagon::fixup_Hexagon_B32_PCREL_X;
266 return Hexagon::fixup_Hexagon_32_6_X;
268 } else if (MCID.isBranch())
269 return (Hexagon::fixup_Hexagon_B13_PCREL);
271 switch (MCID.getOpcode()) {
273 case Hexagon::A2_tfrih:
275 case llvm::MCSymbolRefExpr::VK_GOT:
276 return Hexagon::fixup_Hexagon_GOT_HI16;
277 case llvm::MCSymbolRefExpr::VK_GOTOFF:
278 return Hexagon::fixup_Hexagon_GOTREL_HI16;
279 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
280 return Hexagon::fixup_Hexagon_GD_GOT_HI16;
281 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
282 return Hexagon::fixup_Hexagon_LD_GOT_HI16;
283 case llvm::MCSymbolRefExpr::VK_Hexagon_IE:
284 return Hexagon::fixup_Hexagon_IE_HI16;
285 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
286 return Hexagon::fixup_Hexagon_IE_GOT_HI16;
287 case llvm::MCSymbolRefExpr::VK_TPREL:
288 return Hexagon::fixup_Hexagon_TPREL_HI16;
289 case llvm::MCSymbolRefExpr::VK_DTPREL:
290 return Hexagon::fixup_Hexagon_DTPREL_HI16;
292 return Hexagon::fixup_Hexagon_HI16;
296 case Hexagon::A2_tfril:
298 case llvm::MCSymbolRefExpr::VK_GOT:
299 return Hexagon::fixup_Hexagon_GOT_LO16;
300 case llvm::MCSymbolRefExpr::VK_GOTOFF:
301 return Hexagon::fixup_Hexagon_GOTREL_LO16;
302 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
303 return Hexagon::fixup_Hexagon_GD_GOT_LO16;
304 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
305 return Hexagon::fixup_Hexagon_LD_GOT_LO16;
306 case llvm::MCSymbolRefExpr::VK_Hexagon_IE:
307 return Hexagon::fixup_Hexagon_IE_LO16;
308 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
309 return Hexagon::fixup_Hexagon_IE_GOT_LO16;
310 case llvm::MCSymbolRefExpr::VK_TPREL:
311 return Hexagon::fixup_Hexagon_TPREL_LO16;
312 case llvm::MCSymbolRefExpr::VK_DTPREL:
313 return Hexagon::fixup_Hexagon_DTPREL_LO16;
315 return Hexagon::fixup_Hexagon_LO16;
318 // The only relocs left should be GP relative:
320 if (MCID.mayStore() || MCID.mayLoad()) {
321 for (const uint16_t *ImpUses = MCID.getImplicitUses(); *ImpUses;
323 if (*ImpUses == Hexagon::GP) {
324 switch (HexagonMCInstrInfo::getAccessSize(MCII, MI)) {
325 case HexagonII::MemAccessSize::ByteAccess:
326 return fixup_Hexagon_GPREL16_0;
327 case HexagonII::MemAccessSize::HalfWordAccess:
328 return fixup_Hexagon_GPREL16_1;
329 case HexagonII::MemAccessSize::WordAccess:
330 return fixup_Hexagon_GPREL16_2;
331 case HexagonII::MemAccessSize::DoubleWordAccess:
332 return fixup_Hexagon_GPREL16_3;
334 llvm_unreachable("unhandled fixup");
339 llvm_unreachable("unhandled fixup");
342 return LastTargetFixupKind;
346 extern const MCInstrDesc HexagonInsts[];
350 bool isPCRel (unsigned Kind) {
352 case fixup_Hexagon_B22_PCREL:
353 case fixup_Hexagon_B15_PCREL:
354 case fixup_Hexagon_B7_PCREL:
355 case fixup_Hexagon_B13_PCREL:
356 case fixup_Hexagon_B9_PCREL:
357 case fixup_Hexagon_B32_PCREL_X:
358 case fixup_Hexagon_B22_PCREL_X:
359 case fixup_Hexagon_B15_PCREL_X:
360 case fixup_Hexagon_B13_PCREL_X:
361 case fixup_Hexagon_B9_PCREL_X:
362 case fixup_Hexagon_B7_PCREL_X:
363 case fixup_Hexagon_32_PCREL:
364 case fixup_Hexagon_PLT_B22_PCREL:
365 case fixup_Hexagon_GD_PLT_B22_PCREL:
366 case fixup_Hexagon_LD_PLT_B22_PCREL:
367 case fixup_Hexagon_6_PCREL_X:
375 unsigned HexagonMCCodeEmitter::getExprOpValue(const MCInst &MI,
378 SmallVectorImpl<MCFixup> &Fixups,
379 const MCSubtargetInfo &STI) const
384 if (ME->evaluateAsAbsolute(Res))
387 MCExpr::ExprKind MK = ME->getKind();
388 if (MK == MCExpr::Constant) {
389 return cast<MCConstantExpr>(ME)->getValue();
391 if (MK == MCExpr::Binary) {
393 Res = getExprOpValue(MI, MO, cast<MCBinaryExpr>(ME)->getLHS(), Fixups, STI);
395 getExprOpValue(MI, MO, cast<MCBinaryExpr>(ME)->getRHS(), Fixups, STI);
399 assert(MK == MCExpr::SymbolRef);
401 Hexagon::Fixups FixupKind =
402 Hexagon::Fixups(Hexagon::fixup_Hexagon_TPREL_LO16);
403 const MCSymbolRefExpr *MCSRE = static_cast<const MCSymbolRefExpr *>(ME);
404 const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MI);
405 unsigned bits = HexagonMCInstrInfo::getExtentBits(MCII, MI) -
406 HexagonMCInstrInfo::getExtentAlignment(MCII, MI);
407 const MCSymbolRefExpr::VariantKind kind = MCSRE->getKind();
409 DEBUG(dbgs() << "----------------------------------------\n");
410 DEBUG(dbgs() << "Opcode Name: " << HexagonMCInstrInfo::getName(MCII, MI)
412 DEBUG(dbgs() << "Opcode: " << MCID.getOpcode() << "\n");
413 DEBUG(dbgs() << "Relocation bits: " << bits << "\n");
414 DEBUG(dbgs() << "Addend: " << *Addend << "\n");
415 DEBUG(dbgs() << "----------------------------------------\n");
419 DEBUG(dbgs() << "unrecognized bit count of " << bits << '\n');
424 case llvm::MCSymbolRefExpr::VK_Hexagon_PCREL:
425 FixupKind = Hexagon::fixup_Hexagon_32_PCREL;
427 case llvm::MCSymbolRefExpr::VK_GOT:
428 FixupKind = *Extended ? Hexagon::fixup_Hexagon_GOT_32_6_X
429 : Hexagon::fixup_Hexagon_GOT_32;
431 case llvm::MCSymbolRefExpr::VK_GOTOFF:
432 FixupKind = *Extended ? Hexagon::fixup_Hexagon_GOTREL_32_6_X
433 : Hexagon::fixup_Hexagon_GOTREL_32;
435 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
436 FixupKind = *Extended ? Hexagon::fixup_Hexagon_GD_GOT_32_6_X
437 : Hexagon::fixup_Hexagon_GD_GOT_32;
439 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
440 FixupKind = *Extended ? Hexagon::fixup_Hexagon_LD_GOT_32_6_X
441 : Hexagon::fixup_Hexagon_LD_GOT_32;
443 case llvm::MCSymbolRefExpr::VK_Hexagon_IE:
444 FixupKind = *Extended ? Hexagon::fixup_Hexagon_IE_32_6_X
445 : Hexagon::fixup_Hexagon_IE_32;
447 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
448 FixupKind = *Extended ? Hexagon::fixup_Hexagon_IE_GOT_32_6_X
449 : Hexagon::fixup_Hexagon_IE_GOT_32;
451 case llvm::MCSymbolRefExpr::VK_TPREL:
452 FixupKind = *Extended ? Hexagon::fixup_Hexagon_TPREL_32_6_X
453 : Hexagon::fixup_Hexagon_TPREL_32;
455 case llvm::MCSymbolRefExpr::VK_DTPREL:
456 FixupKind = *Extended ? Hexagon::fixup_Hexagon_DTPREL_32_6_X
457 : Hexagon::fixup_Hexagon_DTPREL_32;
461 *Extended ? Hexagon::fixup_Hexagon_32_6_X : Hexagon::fixup_Hexagon_32;
468 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_PLT:
469 FixupKind = Hexagon::fixup_Hexagon_GD_PLT_B22_PCREL;
471 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_PLT:
472 FixupKind = Hexagon::fixup_Hexagon_LD_PLT_B22_PCREL;
475 if (MCID.isBranch() || MCID.isCall()) {
476 FixupKind = *Extended ? Hexagon::fixup_Hexagon_B22_PCREL_X
477 : Hexagon::fixup_Hexagon_B22_PCREL;
479 errs() << "unrecognized relocation, bits: " << bits << "\n";
480 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
490 FixupKind = Hexagon::fixup_Hexagon_16_X;
492 case llvm::MCSymbolRefExpr::VK_GOT:
493 FixupKind = Hexagon::fixup_Hexagon_GOT_16_X;
495 case llvm::MCSymbolRefExpr::VK_GOTOFF:
496 FixupKind = Hexagon::fixup_Hexagon_GOTREL_16_X;
498 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
499 FixupKind = Hexagon::fixup_Hexagon_GD_GOT_16_X;
501 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
502 FixupKind = Hexagon::fixup_Hexagon_LD_GOT_16_X;
504 case llvm::MCSymbolRefExpr::VK_Hexagon_IE:
505 FixupKind = Hexagon::fixup_Hexagon_IE_16_X;
507 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
508 FixupKind = Hexagon::fixup_Hexagon_IE_GOT_16_X;
510 case llvm::MCSymbolRefExpr::VK_TPREL:
511 FixupKind = Hexagon::fixup_Hexagon_TPREL_16_X;
513 case llvm::MCSymbolRefExpr::VK_DTPREL:
514 FixupKind = Hexagon::fixup_Hexagon_DTPREL_16_X;
520 errs() << "unrecognized relocation, bits " << bits << "\n";
521 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
523 case llvm::MCSymbolRefExpr::VK_GOTOFF:
524 if ((MCID.getOpcode() == Hexagon::HI) ||
525 (MCID.getOpcode() == Hexagon::LO_H))
526 FixupKind = Hexagon::fixup_Hexagon_GOTREL_HI16;
528 FixupKind = Hexagon::fixup_Hexagon_GOTREL_LO16;
530 case llvm::MCSymbolRefExpr::VK_Hexagon_GPREL:
531 FixupKind = Hexagon::fixup_Hexagon_GPREL16_0;
533 case llvm::MCSymbolRefExpr::VK_Hexagon_LO16:
534 FixupKind = Hexagon::fixup_Hexagon_LO16;
536 case llvm::MCSymbolRefExpr::VK_Hexagon_HI16:
537 FixupKind = Hexagon::fixup_Hexagon_HI16;
539 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
540 FixupKind = Hexagon::fixup_Hexagon_GD_GOT_16;
542 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
543 FixupKind = Hexagon::fixup_Hexagon_LD_GOT_16;
545 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
546 FixupKind = Hexagon::fixup_Hexagon_IE_GOT_16;
548 case llvm::MCSymbolRefExpr::VK_TPREL:
549 FixupKind = Hexagon::fixup_Hexagon_TPREL_16;
551 case llvm::MCSymbolRefExpr::VK_DTPREL:
552 FixupKind = Hexagon::fixup_Hexagon_DTPREL_16;
558 if (MCID.isBranch() || MCID.isCall())
559 FixupKind = *Extended ? Hexagon::fixup_Hexagon_B15_PCREL_X
560 : Hexagon::fixup_Hexagon_B15_PCREL;
565 FixupKind = Hexagon::fixup_Hexagon_B13_PCREL;
567 errs() << "unrecognized relocation, bits " << bits << "\n";
568 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
576 FixupKind = Hexagon::fixup_Hexagon_12_X;
578 // There isn't a GOT_12_X, both 11_X and 16_X resolve to 6/26
579 case llvm::MCSymbolRefExpr::VK_GOT:
580 FixupKind = Hexagon::fixup_Hexagon_GOT_16_X;
582 case llvm::MCSymbolRefExpr::VK_GOTOFF:
583 FixupKind = Hexagon::fixup_Hexagon_GOTREL_16_X;
587 errs() << "unrecognized relocation, bits " << bits << "\n";
588 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
596 FixupKind = Hexagon::fixup_Hexagon_11_X;
598 case llvm::MCSymbolRefExpr::VK_GOT:
599 FixupKind = Hexagon::fixup_Hexagon_GOT_11_X;
601 case llvm::MCSymbolRefExpr::VK_GOTOFF:
602 FixupKind = Hexagon::fixup_Hexagon_GOTREL_11_X;
604 case llvm::MCSymbolRefExpr::VK_Hexagon_GD_GOT:
605 FixupKind = Hexagon::fixup_Hexagon_GD_GOT_11_X;
607 case llvm::MCSymbolRefExpr::VK_Hexagon_LD_GOT:
608 FixupKind = Hexagon::fixup_Hexagon_LD_GOT_11_X;
610 case llvm::MCSymbolRefExpr::VK_Hexagon_IE_GOT:
611 FixupKind = Hexagon::fixup_Hexagon_IE_GOT_11_X;
613 case llvm::MCSymbolRefExpr::VK_TPREL:
614 FixupKind = Hexagon::fixup_Hexagon_TPREL_11_X;
616 case llvm::MCSymbolRefExpr::VK_DTPREL:
617 FixupKind = Hexagon::fixup_Hexagon_DTPREL_11_X;
621 errs() << "unrecognized relocation, bits " << bits << "\n";
622 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
628 FixupKind = Hexagon::fixup_Hexagon_10_X;
632 if (MCID.isBranch() ||
633 (llvm::HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCR))
634 FixupKind = *Extended ? Hexagon::fixup_Hexagon_B9_PCREL_X
635 : Hexagon::fixup_Hexagon_B9_PCREL;
637 FixupKind = Hexagon::fixup_Hexagon_9_X;
639 errs() << "unrecognized relocation, bits " << bits << "\n";
640 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
646 FixupKind = Hexagon::fixup_Hexagon_8_X;
648 errs() << "unrecognized relocation, bits " << bits << "\n";
649 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
654 if (MCID.isBranch() ||
655 (llvm::HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCR))
656 FixupKind = *Extended ? Hexagon::fixup_Hexagon_B7_PCREL_X
657 : Hexagon::fixup_Hexagon_B7_PCREL;
659 FixupKind = Hexagon::fixup_Hexagon_7_X;
661 errs() << "unrecognized relocation, bits " << bits << "\n";
662 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
670 FixupKind = Hexagon::fixup_Hexagon_6_X;
672 case llvm::MCSymbolRefExpr::VK_Hexagon_PCREL:
673 FixupKind = Hexagon::fixup_Hexagon_6_PCREL_X;
675 // This is part of an extender, GOT_11 is a
676 // Word32_U6 unsigned/truncated reloc.
677 case llvm::MCSymbolRefExpr::VK_GOT:
678 FixupKind = Hexagon::fixup_Hexagon_GOT_11_X;
680 case llvm::MCSymbolRefExpr::VK_GOTOFF:
681 FixupKind = Hexagon::fixup_Hexagon_GOTREL_11_X;
685 errs() << "unrecognized relocation, bits " << bits << "\n";
686 errs() << "name = " << HexagonMCInstrInfo::getName(MCII, MI) << "\n";
691 FixupKind = getFixupNoBits(MCII, MI, MO, kind);
695 MCExpr const *FixupExpression = (*Addend > 0 && isPCRel(FixupKind)) ?
696 MCBinaryExpr::createAdd(MO.getExpr(),
697 MCConstantExpr::create(*Addend, MCT), MCT) :
700 MCFixup fixup = MCFixup::create(*Addend, FixupExpression,
701 MCFixupKind(FixupKind), MI.getLoc());
702 Fixups.push_back(fixup);
703 // All of the information is in the fixup.
708 HexagonMCCodeEmitter::getMachineOpValue(MCInst const &MI, MCOperand const &MO,
709 SmallVectorImpl<MCFixup> &Fixups,
710 MCSubtargetInfo const &STI) const {
712 return MCT.getRegisterInfo()->getEncodingValue(MO.getReg());
714 return static_cast<unsigned>(MO.getImm());
718 return getExprOpValue(MI, MO, MO.getExpr(), Fixups, STI);
721 MCCodeEmitter *llvm::createHexagonMCCodeEmitter(MCInstrInfo const &MII,
722 MCRegisterInfo const &MRI,
724 return new HexagonMCCodeEmitter(MII, MCT);
727 #include "HexagonGenMCCodeEmitter.inc"