| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 1 | //===-- HexagonMCCodeEmitter.cpp - Hexagon Target Descriptions ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "Hexagon.h" |
| 11 | #include "MCTargetDesc/HexagonBaseInfo.h" |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 12 | #include "MCTargetDesc/HexagonFixupKinds.h" |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 13 | #include "MCTargetDesc/HexagonMCCodeEmitter.h" |
| Colin LeMahieu | af304e5 | 2015-02-19 19:00:00 +0000 | [diff] [blame] | 14 | #include "MCTargetDesc/HexagonMCInstrInfo.h" |
| Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/HexagonMCTargetDesc.h" |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 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" |
| Benjamin Kramer | 50e2a29 | 2015-06-04 15:03:02 +0000 | [diff] [blame] | 25 | #include "llvm/Support/EndianStream.h" |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 26 | #include "llvm/Support/raw_ostream.h" |
| 27 | |
| 28 | #define DEBUG_TYPE "mccodeemitter" |
| 29 | |
| 30 | using namespace llvm; |
| 31 | using namespace Hexagon; |
| 32 | |
| 33 | STATISTIC(MCNumEmitted, "Number of MC instructions emitted"); |
| 34 | |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 35 | HexagonMCCodeEmitter::HexagonMCCodeEmitter(MCInstrInfo const &aMII, |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 36 | MCContext &aMCT) |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 37 | : MCT(aMCT), MCII(aMII), Addend(new unsigned(0)), |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 38 | Extended(new bool(false)), CurrentBundle(new MCInst const *), |
| 39 | CurrentIndex(new size_t(0)) {} |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 40 | |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 41 | uint32_t HexagonMCCodeEmitter::parseBits(size_t Last, |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 42 | MCInst const &MCB, |
| 43 | MCInst const &MCI) const { |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 44 | bool Duplex = HexagonMCInstrInfo::isDuplex(MCII, MCI); |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 45 | if (*CurrentIndex == 0) { |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 46 | if (HexagonMCInstrInfo::isInnerLoop(MCB)) { |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 47 | assert(!Duplex); |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 48 | assert(*CurrentIndex != Last); |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 49 | return HexagonII::INST_PARSE_LOOP_END; |
| 50 | } |
| 51 | } |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 52 | if (*CurrentIndex == 1) { |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 53 | if (HexagonMCInstrInfo::isOuterLoop(MCB)) { |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 54 | assert(!Duplex); |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 55 | assert(*CurrentIndex != Last); |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 56 | return HexagonII::INST_PARSE_LOOP_END; |
| 57 | } |
| 58 | } |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 59 | if (Duplex) { |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 60 | assert(*CurrentIndex == Last); |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 61 | return HexagonII::INST_PARSE_DUPLEX; |
| 62 | } |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 63 | if(*CurrentIndex == Last) |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 64 | return HexagonII::INST_PARSE_PACKET_END; |
| 65 | return HexagonII::INST_PARSE_NOT_END; |
| 66 | } |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 67 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 68 | /// EncodeInstruction - Emit the bundle |
| 69 | void HexagonMCCodeEmitter::encodeInstruction(const MCInst &MI, raw_ostream &OS, |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 70 | SmallVectorImpl<MCFixup> &Fixups, |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 71 | const MCSubtargetInfo &STI) const { |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 72 | MCInst &HMB = const_cast<MCInst &>(MI); |
| 73 | |
| 74 | assert(HexagonMCInstrInfo::isBundle(HMB)); |
| 75 | DEBUG(dbgs() << "Encoding bundle\n";); |
| 76 | *Addend = 0; |
| 77 | *Extended = false; |
| 78 | *CurrentBundle = &MI; |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 79 | *CurrentIndex = 0; |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 80 | size_t Last = HexagonMCInstrInfo::bundleSize(HMB) - 1; |
| 81 | for (auto &I : HexagonMCInstrInfo::bundleInstructions(HMB)) { |
| 82 | MCInst &HMI = const_cast<MCInst &>(*I.getInst()); |
| Daniel Sanders | 72db2a3 | 2016-11-19 13:05:44 +0000 | [diff] [blame] | 83 | verifyInstructionPredicates(HMI, |
| 84 | computeAvailableFeatures(STI.getFeatureBits())); |
| 85 | |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 86 | EncodeSingleInstruction(HMI, OS, Fixups, STI, |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 87 | parseBits(Last, HMB, HMI)); |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 88 | *Extended = HexagonMCInstrInfo::isImmext(HMI); |
| 89 | *Addend += HEXAGON_INSTR_SIZE; |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 90 | ++*CurrentIndex; |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 91 | } |
| 92 | return; |
| 93 | } |
| 94 | |
| Krzysztof Parzyszek | e737b86 | 2016-04-28 15:54:48 +0000 | [diff] [blame] | 95 | static bool RegisterMatches(unsigned Consumer, unsigned Producer, |
| 96 | unsigned Producer2) { |
| 97 | if (Consumer == Producer) |
| 98 | return true; |
| 99 | if (Consumer == Producer2) |
| 100 | return true; |
| 101 | // Calculate if we're a single vector consumer referencing a double producer |
| 102 | if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15) |
| 103 | if (Consumer >= Hexagon::V0 && Consumer <= Hexagon::V31) |
| 104 | return ((Consumer - Hexagon::V0) >> 1) == (Producer - Hexagon::W0); |
| 105 | return false; |
| 106 | } |
| 107 | |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 108 | /// EncodeSingleInstruction - Emit a single |
| 109 | void HexagonMCCodeEmitter::EncodeSingleInstruction( |
| 110 | const MCInst &MI, raw_ostream &OS, SmallVectorImpl<MCFixup> &Fixups, |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 111 | const MCSubtargetInfo &STI, uint32_t Parse) const { |
| 112 | assert(!HexagonMCInstrInfo::isBundle(MI)); |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 113 | uint64_t Binary; |
| 114 | |
| 115 | // Pseudo instructions don't get encoded and shouldn't be here |
| 116 | // in the first place! |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 117 | assert(!HexagonMCInstrInfo::getDesc(MCII, MI).isPseudo() && |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 118 | "pseudo-instruction found"); |
| 119 | DEBUG(dbgs() << "Encoding insn" |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 120 | " `" << HexagonMCInstrInfo::getName(MCII, MI) << "'" |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 121 | "\n"); |
| 122 | |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 123 | Binary = getBinaryCodeForInstr(MI, Fixups, STI); |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 124 | // Check for unimplemented instructions. Immediate extenders |
| 125 | // are encoded as zero, so they need to be accounted for. |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 126 | if (!Binary && |
| 127 | MI.getOpcode() != DuplexIClass0 && |
| 128 | MI.getOpcode() != A4_ext) { |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 129 | DEBUG(dbgs() << "Unimplemented inst: " |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 130 | " `" << HexagonMCInstrInfo::getName(MCII, MI) << "'" |
| Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 131 | "\n"); |
| 132 | llvm_unreachable("Unimplemented Instruction"); |
| 133 | } |
| 134 | Binary |= Parse; |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 135 | |
| 136 | // if we need to emit a duplexed instruction |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 137 | if (MI.getOpcode() >= Hexagon::DuplexIClass0 && |
| 138 | MI.getOpcode() <= Hexagon::DuplexIClassF) { |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 139 | assert(Parse == HexagonII::INST_PARSE_DUPLEX && |
| 140 | "Emitting duplex without duplex parse bits"); |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 141 | unsigned dupIClass = MI.getOpcode() - Hexagon::DuplexIClass0; |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 142 | // 29 is the bit position. |
| 143 | // 0b1110 =0xE bits are masked off and down shifted by 1 bit. |
| 144 | // Last bit is moved to bit position 13 |
| 145 | Binary = ((dupIClass & 0xE) << (29 - 1)) | ((dupIClass & 0x1) << 13); |
| 146 | |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 147 | const MCInst *subInst0 = MI.getOperand(0).getInst(); |
| 148 | const MCInst *subInst1 = MI.getOperand(1).getInst(); |
| Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 149 | |
| 150 | // get subinstruction slot 0 |
| 151 | unsigned subInstSlot0Bits = getBinaryCodeForInstr(*subInst0, Fixups, STI); |
| 152 | // get subinstruction slot 1 |
| 153 | unsigned subInstSlot1Bits = getBinaryCodeForInstr(*subInst1, Fixups, STI); |
| 154 | |
| 155 | Binary |= subInstSlot0Bits | (subInstSlot1Bits << 16); |
| 156 | } |
| Benjamin Kramer | 50e2a29 | 2015-06-04 15:03:02 +0000 | [diff] [blame] | 157 | support::endian::Writer<support::little>(OS).write<uint32_t>(Binary); |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 158 | ++MCNumEmitted; |
| 159 | } |
| 160 | |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 161 | namespace { |
| 162 | void raise_relocation_error(unsigned bits, unsigned kind) { |
| 163 | std::string Text; |
| 164 | { |
| 165 | llvm::raw_string_ostream Stream(Text); |
| 166 | Stream << "Unrecognized relocation combination bits: " << bits |
| 167 | << " kind: " << kind; |
| 168 | } |
| 169 | report_fatal_error(Text); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /// getFixupNoBits - Some insns are not extended and thus have no |
| 174 | /// bits. These cases require a more brute force method for determining |
| 175 | /// the correct relocation. |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 176 | Hexagon::Fixups HexagonMCCodeEmitter::getFixupNoBits( |
| 177 | MCInstrInfo const &MCII, const MCInst &MI, const MCOperand &MO, |
| 178 | const MCSymbolRefExpr::VariantKind kind) const { |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 179 | const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MI); |
| 180 | unsigned insnType = llvm::HexagonMCInstrInfo::getType(MCII, MI); |
| 181 | |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 182 | if (insnType == HexagonII::TypeEXTENDER) { |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 183 | switch (kind) { |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 184 | case MCSymbolRefExpr::VK_GOTREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 185 | return Hexagon::fixup_Hexagon_GOTREL_32_6_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 186 | case MCSymbolRefExpr::VK_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 187 | return Hexagon::fixup_Hexagon_GOT_32_6_X; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 188 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 189 | return Hexagon::fixup_Hexagon_TPREL_32_6_X; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 190 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 191 | return Hexagon::fixup_Hexagon_DTPREL_32_6_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 192 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 193 | return Hexagon::fixup_Hexagon_GD_GOT_32_6_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 194 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 195 | return Hexagon::fixup_Hexagon_LD_GOT_32_6_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 196 | case MCSymbolRefExpr::VK_Hexagon_IE: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 197 | return Hexagon::fixup_Hexagon_IE_32_6_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 198 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 199 | return Hexagon::fixup_Hexagon_IE_GOT_32_6_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 200 | case MCSymbolRefExpr::VK_Hexagon_PCREL: |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 201 | return Hexagon::fixup_Hexagon_B32_PCREL_X; |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame^] | 202 | case MCSymbolRefExpr::VK_Hexagon_GD_PLT: |
| 203 | return Hexagon::fixup_Hexagon_GD_PLT_B32_PCREL_X; |
| 204 | case MCSymbolRefExpr::VK_Hexagon_LD_PLT: |
| 205 | return Hexagon::fixup_Hexagon_LD_PLT_B32_PCREL_X; |
| 206 | |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 207 | case MCSymbolRefExpr::VK_None: { |
| 208 | auto Insts = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); |
| Krzysztof Parzyszek | e17b0bf | 2017-02-02 20:21:56 +0000 | [diff] [blame] | 209 | for (auto I = Insts.begin(), N = Insts.end(); I != N; ++I) { |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 210 | if (I->getInst() == &MI) { |
| Krzysztof Parzyszek | e17b0bf | 2017-02-02 20:21:56 +0000 | [diff] [blame] | 211 | const MCInst &NextI = *(I+1)->getInst(); |
| 212 | const MCInstrDesc &D = HexagonMCInstrInfo::getDesc(MCII, NextI); |
| 213 | if (D.isBranch() || D.isCall() || |
| 214 | HexagonMCInstrInfo::getType(MCII, NextI) == HexagonII::TypeCR) |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 215 | return Hexagon::fixup_Hexagon_B32_PCREL_X; |
| Krzysztof Parzyszek | e17b0bf | 2017-02-02 20:21:56 +0000 | [diff] [blame] | 216 | return Hexagon::fixup_Hexagon_32_6_X; |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 217 | } |
| Krzysztof Parzyszek | e17b0bf | 2017-02-02 20:21:56 +0000 | [diff] [blame] | 218 | } |
| Krzysztof Parzyszek | 357b048 | 2017-02-02 19:58:22 +0000 | [diff] [blame] | 219 | raise_relocation_error(0, kind); |
| 220 | } |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 221 | default: |
| 222 | raise_relocation_error(0, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 223 | } |
| 224 | } else if (MCID.isBranch()) |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 225 | return Hexagon::fixup_Hexagon_B13_PCREL; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 226 | |
| 227 | switch (MCID.getOpcode()) { |
| 228 | case Hexagon::HI: |
| 229 | case Hexagon::A2_tfrih: |
| 230 | switch (kind) { |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 231 | case MCSymbolRefExpr::VK_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 232 | return Hexagon::fixup_Hexagon_GOT_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 233 | case MCSymbolRefExpr::VK_GOTREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 234 | return Hexagon::fixup_Hexagon_GOTREL_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 235 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 236 | return Hexagon::fixup_Hexagon_GD_GOT_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 237 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 238 | return Hexagon::fixup_Hexagon_LD_GOT_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 239 | case MCSymbolRefExpr::VK_Hexagon_IE: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 240 | return Hexagon::fixup_Hexagon_IE_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 241 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 242 | return Hexagon::fixup_Hexagon_IE_GOT_HI16; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 243 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 244 | return Hexagon::fixup_Hexagon_TPREL_HI16; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 245 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 246 | return Hexagon::fixup_Hexagon_DTPREL_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 247 | case MCSymbolRefExpr::VK_None: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 248 | return Hexagon::fixup_Hexagon_HI16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 249 | default: |
| 250 | raise_relocation_error(0, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | case Hexagon::LO: |
| 254 | case Hexagon::A2_tfril: |
| 255 | switch (kind) { |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 256 | case MCSymbolRefExpr::VK_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 257 | return Hexagon::fixup_Hexagon_GOT_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 258 | case MCSymbolRefExpr::VK_GOTREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 259 | return Hexagon::fixup_Hexagon_GOTREL_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 260 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 261 | return Hexagon::fixup_Hexagon_GD_GOT_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 262 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 263 | return Hexagon::fixup_Hexagon_LD_GOT_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 264 | case MCSymbolRefExpr::VK_Hexagon_IE: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 265 | return Hexagon::fixup_Hexagon_IE_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 266 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 267 | return Hexagon::fixup_Hexagon_IE_GOT_LO16; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 268 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 269 | return Hexagon::fixup_Hexagon_TPREL_LO16; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 270 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 271 | return Hexagon::fixup_Hexagon_DTPREL_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 272 | case MCSymbolRefExpr::VK_None: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 273 | return Hexagon::fixup_Hexagon_LO16; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 274 | default: |
| 275 | raise_relocation_error(0, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | // The only relocs left should be GP relative: |
| 279 | default: |
| 280 | if (MCID.mayStore() || MCID.mayLoad()) { |
| Chad Rosier | c00ab4f | 2016-02-18 17:49:57 +0000 | [diff] [blame] | 281 | for (const MCPhysReg *ImpUses = MCID.getImplicitUses(); *ImpUses; |
| 282 | ++ImpUses) { |
| Krzysztof Parzyszek | bc17b68 | 2016-01-11 15:51:53 +0000 | [diff] [blame] | 283 | if (*ImpUses != Hexagon::GP) |
| 284 | continue; |
| 285 | switch (HexagonMCInstrInfo::getAccessSize(MCII, MI)) { |
| 286 | case HexagonII::MemAccessSize::ByteAccess: |
| 287 | return fixup_Hexagon_GPREL16_0; |
| 288 | case HexagonII::MemAccessSize::HalfWordAccess: |
| 289 | return fixup_Hexagon_GPREL16_1; |
| 290 | case HexagonII::MemAccessSize::WordAccess: |
| 291 | return fixup_Hexagon_GPREL16_2; |
| 292 | case HexagonII::MemAccessSize::DoubleWordAccess: |
| 293 | return fixup_Hexagon_GPREL16_3; |
| 294 | default: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 295 | raise_relocation_error(0, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 296 | } |
| 297 | } |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 298 | } |
| 299 | raise_relocation_error(0, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 300 | } |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 301 | llvm_unreachable("Relocation exit not taken"); |
| 302 | } |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 303 | |
| Colin LeMahieu | a071a8e | 2015-06-15 21:52:13 +0000 | [diff] [blame] | 304 | namespace llvm { |
| 305 | extern const MCInstrDesc HexagonInsts[]; |
| 306 | } |
| 307 | |
| 308 | namespace { |
| 309 | bool isPCRel (unsigned Kind) { |
| 310 | switch(Kind){ |
| 311 | case fixup_Hexagon_B22_PCREL: |
| 312 | case fixup_Hexagon_B15_PCREL: |
| 313 | case fixup_Hexagon_B7_PCREL: |
| 314 | case fixup_Hexagon_B13_PCREL: |
| 315 | case fixup_Hexagon_B9_PCREL: |
| 316 | case fixup_Hexagon_B32_PCREL_X: |
| 317 | case fixup_Hexagon_B22_PCREL_X: |
| 318 | case fixup_Hexagon_B15_PCREL_X: |
| 319 | case fixup_Hexagon_B13_PCREL_X: |
| 320 | case fixup_Hexagon_B9_PCREL_X: |
| 321 | case fixup_Hexagon_B7_PCREL_X: |
| 322 | case fixup_Hexagon_32_PCREL: |
| 323 | case fixup_Hexagon_PLT_B22_PCREL: |
| 324 | case fixup_Hexagon_GD_PLT_B22_PCREL: |
| 325 | case fixup_Hexagon_LD_PLT_B22_PCREL: |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame^] | 326 | case fixup_Hexagon_GD_PLT_B22_PCREL_X: |
| 327 | case fixup_Hexagon_LD_PLT_B22_PCREL_X: |
| Colin LeMahieu | a071a8e | 2015-06-15 21:52:13 +0000 | [diff] [blame] | 328 | case fixup_Hexagon_6_PCREL_X: |
| 329 | return true; |
| 330 | default: |
| 331 | return false; |
| 332 | } |
| 333 | } |
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 334 | } |
| Colin LeMahieu | a071a8e | 2015-06-15 21:52:13 +0000 | [diff] [blame] | 335 | |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 336 | unsigned HexagonMCCodeEmitter::getExprOpValue(const MCInst &MI, |
| 337 | const MCOperand &MO, |
| 338 | const MCExpr *ME, |
| 339 | SmallVectorImpl<MCFixup> &Fixups, |
| 340 | const MCSubtargetInfo &STI) const |
| 341 | |
| 342 | { |
| Colin LeMahieu | 98c8e07 | 2016-02-15 18:42:07 +0000 | [diff] [blame] | 343 | if (isa<HexagonMCExpr>(ME)) |
| 344 | ME = &HexagonMCInstrInfo::getExpr(*ME); |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 345 | int64_t Value; |
| 346 | if (ME->evaluateAsAbsolute(Value)) |
| 347 | return Value; |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 348 | assert(ME->getKind() == MCExpr::SymbolRef || |
| 349 | ME->getKind() == MCExpr::Binary); |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 350 | if (ME->getKind() == MCExpr::Binary) { |
| 351 | MCBinaryExpr const *Binary = cast<MCBinaryExpr>(ME); |
| 352 | getExprOpValue(MI, MO, Binary->getLHS(), Fixups, STI); |
| 353 | getExprOpValue(MI, MO, Binary->getRHS(), Fixups, STI); |
| Colin LeMahieu | a071a8e | 2015-06-15 21:52:13 +0000 | [diff] [blame] | 354 | return 0; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 355 | } |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 356 | Hexagon::Fixups FixupKind = |
| 357 | Hexagon::Fixups(Hexagon::fixup_Hexagon_TPREL_LO16); |
| 358 | const MCSymbolRefExpr *MCSRE = static_cast<const MCSymbolRefExpr *>(ME); |
| 359 | const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MI); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 360 | unsigned bits = HexagonMCInstrInfo::getExtentBits(MCII, MI) - |
| 361 | HexagonMCInstrInfo::getExtentAlignment(MCII, MI); |
| 362 | const MCSymbolRefExpr::VariantKind kind = MCSRE->getKind(); |
| 363 | |
| 364 | DEBUG(dbgs() << "----------------------------------------\n"); |
| 365 | DEBUG(dbgs() << "Opcode Name: " << HexagonMCInstrInfo::getName(MCII, MI) |
| 366 | << "\n"); |
| Colin LeMahieu | 6efd273 | 2015-05-01 21:30:22 +0000 | [diff] [blame] | 367 | DEBUG(dbgs() << "Opcode: " << MCID.getOpcode() << "\n"); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 368 | DEBUG(dbgs() << "Relocation bits: " << bits << "\n"); |
| 369 | DEBUG(dbgs() << "Addend: " << *Addend << "\n"); |
| 370 | DEBUG(dbgs() << "----------------------------------------\n"); |
| 371 | |
| 372 | switch (bits) { |
| 373 | default: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 374 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 375 | case 32: |
| 376 | switch (kind) { |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 377 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 378 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_DTPREL_32_6_X |
| 379 | : Hexagon::fixup_Hexagon_DTPREL_32; |
| 380 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 381 | case MCSymbolRefExpr::VK_GOT: |
| 382 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_GOT_32_6_X |
| 383 | : Hexagon::fixup_Hexagon_GOT_32; |
| 384 | break; |
| 385 | case MCSymbolRefExpr::VK_GOTREL: |
| 386 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_GOTREL_32_6_X |
| 387 | : Hexagon::fixup_Hexagon_GOTREL_32; |
| 388 | break; |
| 389 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| 390 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_GD_GOT_32_6_X |
| 391 | : Hexagon::fixup_Hexagon_GD_GOT_32; |
| 392 | break; |
| 393 | case MCSymbolRefExpr::VK_Hexagon_IE: |
| 394 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_IE_32_6_X |
| 395 | : Hexagon::fixup_Hexagon_IE_32; |
| 396 | break; |
| 397 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| 398 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_IE_GOT_32_6_X |
| 399 | : Hexagon::fixup_Hexagon_IE_GOT_32; |
| 400 | break; |
| 401 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| 402 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_LD_GOT_32_6_X |
| 403 | : Hexagon::fixup_Hexagon_LD_GOT_32; |
| 404 | break; |
| 405 | case MCSymbolRefExpr::VK_Hexagon_PCREL: |
| 406 | FixupKind = Hexagon::fixup_Hexagon_32_PCREL; |
| 407 | break; |
| 408 | case MCSymbolRefExpr::VK_None: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 409 | FixupKind = |
| 410 | *Extended ? Hexagon::fixup_Hexagon_32_6_X : Hexagon::fixup_Hexagon_32; |
| 411 | break; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 412 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 413 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_TPREL_32_6_X |
| 414 | : Hexagon::fixup_Hexagon_TPREL_32; |
| 415 | break; |
| 416 | default: |
| 417 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 418 | } |
| 419 | break; |
| 420 | |
| 421 | case 22: |
| 422 | switch (kind) { |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 423 | case MCSymbolRefExpr::VK_Hexagon_GD_PLT: |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame^] | 424 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_GD_PLT_B22_PCREL_X |
| 425 | : Hexagon::fixup_Hexagon_GD_PLT_B22_PCREL; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 426 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 427 | case MCSymbolRefExpr::VK_Hexagon_LD_PLT: |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame^] | 428 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_LD_PLT_B22_PCREL_X |
| 429 | : Hexagon::fixup_Hexagon_LD_PLT_B22_PCREL; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 430 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 431 | case MCSymbolRefExpr::VK_None: |
| 432 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_B22_PCREL_X |
| 433 | : Hexagon::fixup_Hexagon_B22_PCREL; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 434 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 435 | case MCSymbolRefExpr::VK_PLT: |
| 436 | FixupKind = Hexagon::fixup_Hexagon_PLT_B22_PCREL; |
| 437 | break; |
| 438 | default: |
| 439 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 440 | } |
| 441 | break; |
| 442 | |
| 443 | case 16: |
| 444 | if (*Extended) { |
| 445 | switch (kind) { |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 446 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 447 | FixupKind = Hexagon::fixup_Hexagon_DTPREL_16_X; |
| 448 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 449 | case MCSymbolRefExpr::VK_GOT: |
| 450 | FixupKind = Hexagon::fixup_Hexagon_GOT_16_X; |
| 451 | break; |
| 452 | case MCSymbolRefExpr::VK_GOTREL: |
| 453 | FixupKind = Hexagon::fixup_Hexagon_GOTREL_16_X; |
| 454 | break; |
| 455 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| 456 | FixupKind = Hexagon::fixup_Hexagon_GD_GOT_16_X; |
| 457 | break; |
| 458 | case MCSymbolRefExpr::VK_Hexagon_IE: |
| 459 | FixupKind = Hexagon::fixup_Hexagon_IE_16_X; |
| 460 | break; |
| 461 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| 462 | FixupKind = Hexagon::fixup_Hexagon_IE_GOT_16_X; |
| 463 | break; |
| 464 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| 465 | FixupKind = Hexagon::fixup_Hexagon_LD_GOT_16_X; |
| 466 | break; |
| 467 | case MCSymbolRefExpr::VK_None: |
| 468 | FixupKind = Hexagon::fixup_Hexagon_16_X; |
| 469 | break; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 470 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 471 | FixupKind = Hexagon::fixup_Hexagon_TPREL_16_X; |
| 472 | break; |
| 473 | default: |
| 474 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 475 | } |
| 476 | } else |
| 477 | switch (kind) { |
| Colin LeMahieu | ecef1d9 | 2016-02-16 20:38:17 +0000 | [diff] [blame] | 478 | case MCSymbolRefExpr::VK_None: { |
| 479 | if (HexagonMCInstrInfo::s23_2_reloc(*MO.getExpr())) |
| 480 | FixupKind = Hexagon::fixup_Hexagon_23_REG; |
| 481 | else |
| Krzysztof Parzyszek | d0d42f0 | 2017-02-02 20:35:12 +0000 | [diff] [blame] | 482 | if (MCID.mayStore() || MCID.mayLoad()) { |
| 483 | for (const MCPhysReg *ImpUses = MCID.getImplicitUses(); *ImpUses; |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 484 | ++ImpUses) { |
| Krzysztof Parzyszek | d0d42f0 | 2017-02-02 20:35:12 +0000 | [diff] [blame] | 485 | if (*ImpUses != Hexagon::GP) |
| 486 | continue; |
| 487 | switch (HexagonMCInstrInfo::getAccessSize(MCII, MI)) { |
| 488 | case HexagonII::MemAccessSize::ByteAccess: |
| 489 | FixupKind = fixup_Hexagon_GPREL16_0; |
| 490 | break; |
| 491 | case HexagonII::MemAccessSize::HalfWordAccess: |
| 492 | FixupKind = fixup_Hexagon_GPREL16_1; |
| 493 | break; |
| 494 | case HexagonII::MemAccessSize::WordAccess: |
| 495 | FixupKind = fixup_Hexagon_GPREL16_2; |
| 496 | break; |
| 497 | case HexagonII::MemAccessSize::DoubleWordAccess: |
| 498 | FixupKind = fixup_Hexagon_GPREL16_3; |
| 499 | break; |
| 500 | default: |
| 501 | raise_relocation_error(bits, kind); |
| 502 | } |
| 503 | } |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 504 | } else |
| Krzysztof Parzyszek | d0d42f0 | 2017-02-02 20:35:12 +0000 | [diff] [blame] | 505 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | ecef1d9 | 2016-02-16 20:38:17 +0000 | [diff] [blame] | 506 | break; |
| 507 | } |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 508 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 509 | FixupKind = Hexagon::fixup_Hexagon_DTPREL_16; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 510 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 511 | case MCSymbolRefExpr::VK_GOTREL: |
| 512 | if (MCID.getOpcode() == Hexagon::HI) |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 513 | FixupKind = Hexagon::fixup_Hexagon_GOTREL_HI16; |
| 514 | else |
| 515 | FixupKind = Hexagon::fixup_Hexagon_GOTREL_LO16; |
| 516 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 517 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 518 | FixupKind = Hexagon::fixup_Hexagon_GD_GOT_16; |
| 519 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 520 | case MCSymbolRefExpr::VK_Hexagon_GPREL: |
| 521 | FixupKind = Hexagon::fixup_Hexagon_GPREL16_0; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 522 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 523 | case MCSymbolRefExpr::VK_Hexagon_HI16: |
| 524 | FixupKind = Hexagon::fixup_Hexagon_HI16; |
| 525 | break; |
| 526 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 527 | FixupKind = Hexagon::fixup_Hexagon_IE_GOT_16; |
| 528 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 529 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| 530 | FixupKind = Hexagon::fixup_Hexagon_LD_GOT_16; |
| 531 | break; |
| 532 | case MCSymbolRefExpr::VK_Hexagon_LO16: |
| 533 | FixupKind = Hexagon::fixup_Hexagon_LO16; |
| 534 | break; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 535 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 536 | FixupKind = Hexagon::fixup_Hexagon_TPREL_16; |
| 537 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 538 | default: |
| 539 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 540 | } |
| 541 | break; |
| 542 | |
| 543 | case 15: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 544 | switch (kind) { |
| 545 | case MCSymbolRefExpr::VK_None: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 546 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_B15_PCREL_X |
| 547 | : Hexagon::fixup_Hexagon_B15_PCREL; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 548 | break; |
| 549 | default: |
| 550 | raise_relocation_error(bits, kind); |
| 551 | } |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case 13: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 555 | switch (kind) { |
| 556 | case MCSymbolRefExpr::VK_None: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 557 | FixupKind = Hexagon::fixup_Hexagon_B13_PCREL; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 558 | break; |
| 559 | default: |
| 560 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 561 | } |
| 562 | break; |
| 563 | |
| 564 | case 12: |
| 565 | if (*Extended) |
| 566 | switch (kind) { |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 567 | // There isn't a GOT_12_X, both 11_X and 16_X resolve to 6/26 |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 568 | case MCSymbolRefExpr::VK_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 569 | FixupKind = Hexagon::fixup_Hexagon_GOT_16_X; |
| 570 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 571 | case MCSymbolRefExpr::VK_GOTREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 572 | FixupKind = Hexagon::fixup_Hexagon_GOTREL_16_X; |
| 573 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 574 | case MCSymbolRefExpr::VK_None: |
| 575 | FixupKind = Hexagon::fixup_Hexagon_12_X; |
| 576 | break; |
| 577 | default: |
| 578 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 579 | } |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 580 | else |
| 581 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 582 | break; |
| 583 | |
| 584 | case 11: |
| 585 | if (*Extended) |
| 586 | switch (kind) { |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 587 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 588 | FixupKind = Hexagon::fixup_Hexagon_DTPREL_11_X; |
| 589 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 590 | case MCSymbolRefExpr::VK_GOT: |
| 591 | FixupKind = Hexagon::fixup_Hexagon_GOT_11_X; |
| 592 | break; |
| 593 | case MCSymbolRefExpr::VK_GOTREL: |
| 594 | FixupKind = Hexagon::fixup_Hexagon_GOTREL_11_X; |
| 595 | break; |
| 596 | case MCSymbolRefExpr::VK_Hexagon_GD_GOT: |
| 597 | FixupKind = Hexagon::fixup_Hexagon_GD_GOT_11_X; |
| 598 | break; |
| 599 | case MCSymbolRefExpr::VK_Hexagon_IE_GOT: |
| 600 | FixupKind = Hexagon::fixup_Hexagon_IE_GOT_11_X; |
| 601 | break; |
| 602 | case MCSymbolRefExpr::VK_Hexagon_LD_GOT: |
| 603 | FixupKind = Hexagon::fixup_Hexagon_LD_GOT_11_X; |
| 604 | break; |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame^] | 605 | case MCSymbolRefExpr::VK_Hexagon_GD_PLT: |
| 606 | FixupKind = Hexagon::fixup_Hexagon_GD_PLT_B22_PCREL_X; |
| 607 | break; |
| 608 | case MCSymbolRefExpr::VK_Hexagon_LD_PLT: |
| 609 | FixupKind = Hexagon::fixup_Hexagon_LD_PLT_B22_PCREL_X; |
| 610 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 611 | case MCSymbolRefExpr::VK_None: |
| 612 | FixupKind = Hexagon::fixup_Hexagon_11_X; |
| 613 | break; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 614 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 615 | FixupKind = Hexagon::fixup_Hexagon_TPREL_11_X; |
| 616 | break; |
| 617 | default: |
| 618 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 619 | } |
| 620 | else { |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 621 | switch (kind) { |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 622 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 623 | FixupKind = Hexagon::fixup_Hexagon_TPREL_11_X; |
| 624 | break; |
| 625 | default: |
| 626 | raise_relocation_error(bits, kind); |
| 627 | } |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 628 | } |
| 629 | break; |
| 630 | |
| 631 | case 10: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 632 | if (*Extended) { |
| 633 | switch (kind) { |
| 634 | case MCSymbolRefExpr::VK_None: |
| 635 | FixupKind = Hexagon::fixup_Hexagon_10_X; |
| 636 | break; |
| 637 | default: |
| 638 | raise_relocation_error(bits, kind); |
| 639 | } |
| 640 | } else |
| 641 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 642 | break; |
| 643 | |
| 644 | case 9: |
| 645 | if (MCID.isBranch() || |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 646 | (HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCR)) |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 647 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_B9_PCREL_X |
| 648 | : Hexagon::fixup_Hexagon_B9_PCREL; |
| 649 | else if (*Extended) |
| 650 | FixupKind = Hexagon::fixup_Hexagon_9_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 651 | else |
| 652 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 653 | break; |
| 654 | |
| 655 | case 8: |
| 656 | if (*Extended) |
| 657 | FixupKind = Hexagon::fixup_Hexagon_8_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 658 | else |
| 659 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case 7: |
| 663 | if (MCID.isBranch() || |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 664 | (HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCR)) |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 665 | FixupKind = *Extended ? Hexagon::fixup_Hexagon_B7_PCREL_X |
| 666 | : Hexagon::fixup_Hexagon_B7_PCREL; |
| 667 | else if (*Extended) |
| 668 | FixupKind = Hexagon::fixup_Hexagon_7_X; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 669 | else |
| 670 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 671 | break; |
| 672 | |
| 673 | case 6: |
| 674 | if (*Extended) { |
| 675 | switch (kind) { |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 676 | case MCSymbolRefExpr::VK_DTPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 677 | FixupKind = Hexagon::fixup_Hexagon_DTPREL_16_X; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 678 | break; |
| 679 | // This is part of an extender, GOT_11 is a |
| 680 | // Word32_U6 unsigned/truncated reloc. |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 681 | case MCSymbolRefExpr::VK_GOT: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 682 | FixupKind = Hexagon::fixup_Hexagon_GOT_11_X; |
| 683 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 684 | case MCSymbolRefExpr::VK_GOTREL: |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 685 | FixupKind = Hexagon::fixup_Hexagon_GOTREL_11_X; |
| 686 | break; |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 687 | case MCSymbolRefExpr::VK_Hexagon_PCREL: |
| 688 | FixupKind = Hexagon::fixup_Hexagon_6_PCREL_X; |
| 689 | break; |
| Colin LeMahieu | 0e05192 | 2016-02-10 18:32:01 +0000 | [diff] [blame] | 690 | case MCSymbolRefExpr::VK_TPREL: |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 691 | FixupKind = Hexagon::fixup_Hexagon_TPREL_16_X; |
| 692 | break; |
| 693 | case MCSymbolRefExpr::VK_None: |
| 694 | FixupKind = Hexagon::fixup_Hexagon_6_X; |
| 695 | break; |
| 696 | default: |
| 697 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 698 | } |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 699 | } else |
| 700 | raise_relocation_error(bits, kind); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case 0: |
| 704 | FixupKind = getFixupNoBits(MCII, MI, MO, kind); |
| 705 | break; |
| 706 | } |
| 707 | |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 708 | MCExpr const *FixupExpression = |
| 709 | (*Addend > 0 && isPCRel(FixupKind)) |
| 710 | ? MCBinaryExpr::createAdd(MO.getExpr(), |
| 711 | MCConstantExpr::create(*Addend, MCT), MCT) |
| 712 | : MO.getExpr(); |
| Colin LeMahieu | a071a8e | 2015-06-15 21:52:13 +0000 | [diff] [blame] | 713 | |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 714 | MCFixup fixup = MCFixup::create(*Addend, FixupExpression, |
| Colin LeMahieu | a071a8e | 2015-06-15 21:52:13 +0000 | [diff] [blame] | 715 | MCFixupKind(FixupKind), MI.getLoc()); |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 716 | Fixups.push_back(fixup); |
| 717 | // All of the information is in the fixup. |
| Colin LeMahieu | 1c79d9b | 2016-02-09 19:18:02 +0000 | [diff] [blame] | 718 | return 0; |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 721 | unsigned |
| 722 | HexagonMCCodeEmitter::getMachineOpValue(MCInst const &MI, MCOperand const &MO, |
| 723 | SmallVectorImpl<MCFixup> &Fixups, |
| 724 | MCSubtargetInfo const &STI) const { |
| Simon Pilgrim | ee6ef4d | 2017-02-19 00:03:46 +0000 | [diff] [blame] | 725 | #ifndef NDEBUG |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame] | 726 | size_t OperandNumber = ~0U; |
| 727 | for (unsigned i = 0, n = MI.getNumOperands(); i < n; ++i) |
| 728 | if (&MI.getOperand(i) == &MO) { |
| 729 | OperandNumber = i; |
| 730 | break; |
| 731 | } |
| 732 | assert((OperandNumber != ~0U) && "Operand not found"); |
| Simon Pilgrim | ee6ef4d | 2017-02-19 00:03:46 +0000 | [diff] [blame] | 733 | #endif |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 734 | |
| 735 | if (HexagonMCInstrInfo::isNewValue(MCII, MI) && |
| 736 | &MO == &MI.getOperand(HexagonMCInstrInfo::getNewValueOp(MCII, MI))) { |
| 737 | // Calculate the new value distance to the associated producer |
| 738 | MCOperand const &MCO = |
| 739 | MI.getOperand(HexagonMCInstrInfo::getNewValueOp(MCII, MI)); |
| 740 | unsigned SOffset = 0; |
| 741 | unsigned VOffset = 0; |
| 742 | unsigned Register = MCO.getReg(); |
| 743 | unsigned Register1; |
| 744 | unsigned Register2; |
| 745 | auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); |
| 746 | auto i = Instructions.begin() + *CurrentIndex - 1; |
| 747 | for (;; --i) { |
| 748 | assert(i != Instructions.begin() - 1 && "Couldn't find producer"); |
| 749 | MCInst const &Inst = *i->getInst(); |
| 750 | if (HexagonMCInstrInfo::isImmext(Inst)) |
| 751 | continue; |
| 752 | ++SOffset; |
| 753 | if (HexagonMCInstrInfo::isVector(MCII, Inst)) |
| 754 | // Vector instructions don't count scalars |
| 755 | ++VOffset; |
| 756 | Register1 = |
| 757 | HexagonMCInstrInfo::hasNewValue(MCII, Inst) |
| 758 | ? HexagonMCInstrInfo::getNewValueOperand(MCII, Inst).getReg() |
| 759 | : static_cast<unsigned>(Hexagon::NoRegister); |
| 760 | Register2 = |
| 761 | HexagonMCInstrInfo::hasNewValue2(MCII, Inst) |
| 762 | ? HexagonMCInstrInfo::getNewValueOperand2(MCII, Inst).getReg() |
| 763 | : static_cast<unsigned>(Hexagon::NoRegister); |
| 764 | if (!RegisterMatches(Register, Register1, Register2)) |
| 765 | // This isn't the register we're looking for |
| 766 | continue; |
| 767 | if (!HexagonMCInstrInfo::isPredicated(MCII, Inst)) |
| 768 | // Producer is unpredicated |
| 769 | break; |
| 770 | assert(HexagonMCInstrInfo::isPredicated(MCII, MI) && |
| 771 | "Unpredicated consumer depending on predicated producer"); |
| 772 | if (HexagonMCInstrInfo::isPredicatedTrue(MCII, Inst) == |
| 773 | HexagonMCInstrInfo::isPredicatedTrue(MCII, MI)) |
| 774 | // Producer predicate sense matched ours |
| 775 | break; |
| 776 | } |
| 777 | // Hexagon PRM 10.11 Construct Nt from distance |
| 778 | unsigned Offset = |
| 779 | HexagonMCInstrInfo::isVector(MCII, MI) ? VOffset : SOffset; |
| 780 | Offset <<= 1; |
| 781 | Offset |= |
| 782 | HexagonMCInstrInfo::SubregisterBit(Register, Register1, Register2); |
| 783 | return Offset; |
| 784 | } |
| Krzysztof Parzyszek | c6f1e1a | 2016-03-21 20:13:33 +0000 | [diff] [blame] | 785 | assert(!MO.isImm()); |
| 786 | if (MO.isReg()) { |
| 787 | unsigned Reg = MO.getReg(); |
| Krzysztof Parzyszek | bc4dc9b | 2017-02-02 15:32:26 +0000 | [diff] [blame] | 788 | if (HexagonMCInstrInfo::isSubInstruction(MI) || |
| 789 | llvm::HexagonMCInstrInfo::getType(MCII, MI) == HexagonII::TypeCJ) |
| Krzysztof Parzyszek | c6f1e1a | 2016-03-21 20:13:33 +0000 | [diff] [blame] | 790 | return HexagonMCInstrInfo::getDuplexRegisterNumbering(Reg); |
| 791 | switch(MI.getOpcode()){ |
| 792 | case Hexagon::A2_tfrrcr: |
| 793 | case Hexagon::A2_tfrcrr: |
| 794 | if(Reg == Hexagon::M0) |
| 795 | Reg = Hexagon::C6; |
| 796 | if(Reg == Hexagon::M1) |
| 797 | Reg = Hexagon::C7; |
| 798 | } |
| 799 | return MCT.getRegisterInfo()->getEncodingValue(Reg); |
| 800 | } |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 801 | |
| Colin LeMahieu | b662565 | 2015-05-01 21:14:21 +0000 | [diff] [blame] | 802 | return getExprOpValue(MI, MO, MO.getExpr(), Fixups, STI); |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 805 | MCCodeEmitter *llvm::createHexagonMCCodeEmitter(MCInstrInfo const &MII, |
| 806 | MCRegisterInfo const &MRI, |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 807 | MCContext &MCT) { |
| Eric Christopher | 0169e42 | 2015-03-10 22:03:14 +0000 | [diff] [blame] | 808 | return new HexagonMCCodeEmitter(MII, MCT); |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| Daniel Sanders | 72db2a3 | 2016-11-19 13:05:44 +0000 | [diff] [blame] | 811 | #define ENABLE_INSTR_PREDICATE_VERIFIER |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 812 | #include "HexagonGenMCCodeEmitter.inc" |