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