| Craig Topper | f3f6650 | 2012-03-17 09:39:20 +0000 | [diff] [blame] | 1 | //===-- HexagonMCTargetDesc.cpp - Hexagon Target Descriptions -------------===// |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +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 | // |
| Craig Topper | bc3168b | 2012-03-17 09:28:37 +0000 | [diff] [blame] | 10 | // This file provides Hexagon specific target descriptions. |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Eugene Zelenko | 401f381 | 2016-12-17 01:29:35 +0000 | [diff] [blame] | 14 | #include "Hexagon.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 15 | #include "HexagonTargetStreamer.h" |
| Colin LeMahieu | ff06261 | 2014-11-20 21:56:35 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/HexagonInstPrinter.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 17 | #include "MCTargetDesc/HexagonMCAsmInfo.h" |
| 18 | #include "MCTargetDesc/HexagonMCELFStreamer.h" |
| Eugene Zelenko | 5015689 | 2016-12-17 01:17:18 +0000 | [diff] [blame] | 19 | #include "MCTargetDesc/HexagonMCInstrInfo.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 20 | #include "MCTargetDesc/HexagonMCTargetDesc.h" |
| 21 | #include "llvm/ADT/StringRef.h" |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCContext.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCDwarf.h" |
| Colin LeMahieu | 2c76920 | 2014-11-06 17:05:51 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCELFStreamer.h" |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 25 | #include "llvm/MC/MCInstrAnalysis.h" |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCInstrInfo.h" |
| 27 | #include "llvm/MC/MCRegisterInfo.h" |
| Jyotsna Verma | 7503a62 | 2013-02-20 16:13:27 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCStreamer.h" |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCSubtargetInfo.h" |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 30 | #include "llvm/Support/ELF.h" |
| Craig Topper | c4965bc | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 31 | #include "llvm/Support/ErrorHandling.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 33 | #include "llvm/Support/TargetRegistry.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 34 | #include <cassert> |
| 35 | #include <cstdint> |
| 36 | #include <new> |
| 37 | #include <string> |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 38 | |
| Chandler Carruth | d174b72 | 2014-04-22 02:03:14 +0000 | [diff] [blame] | 39 | using namespace llvm; |
| 40 | |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 41 | #define GET_INSTRINFO_MC_DESC |
| 42 | #include "HexagonGenInstrInfo.inc" |
| 43 | |
| 44 | #define GET_SUBTARGETINFO_MC_DESC |
| 45 | #include "HexagonGenSubtargetInfo.inc" |
| 46 | |
| 47 | #define GET_REGINFO_MC_DESC |
| 48 | #include "HexagonGenRegisterInfo.inc" |
| 49 | |
| Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 50 | cl::opt<bool> llvm::HexagonDisableCompound |
| 51 | ("mno-compound", |
| 52 | cl::desc("Disable looking for compound instructions for Hexagon")); |
| 53 | |
| 54 | cl::opt<bool> llvm::HexagonDisableDuplex |
| 55 | ("mno-pairing", |
| 56 | cl::desc("Disable looking for duplex instructions for Hexagon")); |
| 57 | |
| Krzysztof Parzyszek | 64d4e2b | 2016-04-20 21:17:40 +0000 | [diff] [blame] | 58 | static cl::opt<bool> HexagonV4ArchVariant("mv4", cl::Hidden, cl::init(false), |
| 59 | cl::desc("Build for Hexagon V4")); |
| 60 | |
| 61 | static cl::opt<bool> HexagonV5ArchVariant("mv5", cl::Hidden, cl::init(false), |
| 62 | cl::desc("Build for Hexagon V5")); |
| 63 | |
| 64 | static cl::opt<bool> HexagonV55ArchVariant("mv55", cl::Hidden, cl::init(false), |
| 65 | cl::desc("Build for Hexagon V55")); |
| 66 | |
| 67 | static cl::opt<bool> HexagonV60ArchVariant("mv60", cl::Hidden, cl::init(false), |
| 68 | cl::desc("Build for Hexagon V60")); |
| 69 | |
| Krzysztof Parzyszek | 64d4e2b | 2016-04-20 21:17:40 +0000 | [diff] [blame] | 70 | static StringRef DefaultArch = "hexagonv60"; |
| 71 | |
| 72 | static StringRef HexagonGetArchVariant() { |
| 73 | if (HexagonV4ArchVariant) |
| 74 | return "hexagonv4"; |
| 75 | if (HexagonV5ArchVariant) |
| 76 | return "hexagonv5"; |
| 77 | if (HexagonV55ArchVariant) |
| 78 | return "hexagonv55"; |
| 79 | if (HexagonV60ArchVariant) |
| 80 | return "hexagonv60"; |
| 81 | return ""; |
| 82 | } |
| 83 | |
| Krzysztof Parzyszek | 75e74ee | 2016-08-19 14:09:47 +0000 | [diff] [blame] | 84 | StringRef Hexagon_MC::selectHexagonCPU(const Triple &TT, StringRef CPU) { |
| Krzysztof Parzyszek | 64d4e2b | 2016-04-20 21:17:40 +0000 | [diff] [blame] | 85 | StringRef ArchV = HexagonGetArchVariant(); |
| 86 | if (!ArchV.empty() && !CPU.empty()) { |
| 87 | if (ArchV != CPU) |
| 88 | report_fatal_error("conflicting architectures specified."); |
| 89 | return CPU; |
| 90 | } |
| 91 | if (ArchV.empty()) { |
| 92 | if (CPU.empty()) |
| 93 | CPU = DefaultArch; |
| 94 | return CPU; |
| 95 | } |
| 96 | return ArchV; |
| Krzysztof Parzyszek | 759a7d0 | 2015-12-14 15:03:54 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 99 | unsigned HexagonGetLastSlot() { |
| 100 | return HexagonItinerariesV4FU::SLOT3; |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 103 | |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 104 | namespace { |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 105 | |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 106 | class HexagonTargetAsmStreamer : public HexagonTargetStreamer { |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 107 | public: |
| 108 | HexagonTargetAsmStreamer(MCStreamer &S, |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 109 | formatted_raw_ostream &OS, |
| 110 | bool isVerboseAsm, |
| 111 | MCInstPrinter &IP) |
| Colin LeMahieu | fa38972 | 2015-06-18 21:03:13 +0000 | [diff] [blame] | 112 | : HexagonTargetStreamer(S) {} |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 113 | |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 114 | void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, |
| 115 | const MCInst &Inst, const MCSubtargetInfo &STI) override { |
| 116 | assert(HexagonMCInstrInfo::isBundle(Inst)); |
| 117 | assert(HexagonMCInstrInfo::bundleSize(Inst) <= HEXAGON_PACKET_SIZE); |
| 118 | std::string Buffer; |
| 119 | { |
| 120 | raw_string_ostream TempStream(Buffer); |
| 121 | InstPrinter.printInst(&Inst, TempStream, "", STI); |
| 122 | } |
| 123 | StringRef Contents(Buffer); |
| 124 | auto PacketBundle = Contents.rsplit('\n'); |
| 125 | auto HeadTail = PacketBundle.first.split('\n'); |
| Colin LeMahieu | b7a5f9f | 2015-11-10 00:22:00 +0000 | [diff] [blame] | 126 | StringRef Separator = "\n"; |
| 127 | StringRef Indent = "\t\t"; |
| 128 | OS << "\t{\n"; |
| 129 | while (!HeadTail.first.empty()) { |
| 130 | StringRef InstTxt; |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 131 | auto Duplex = HeadTail.first.split('\v'); |
| Colin LeMahieu | b7a5f9f | 2015-11-10 00:22:00 +0000 | [diff] [blame] | 132 | if (!Duplex.second.empty()) { |
| 133 | OS << Indent << Duplex.first << Separator; |
| 134 | InstTxt = Duplex.second; |
| 135 | } else if (!HeadTail.first.trim().startswith("immext")) { |
| 136 | InstTxt = Duplex.first; |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 137 | } |
| Colin LeMahieu | b7a5f9f | 2015-11-10 00:22:00 +0000 | [diff] [blame] | 138 | if (!InstTxt.empty()) |
| 139 | OS << Indent << InstTxt << Separator; |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 140 | HeadTail = HeadTail.second.split('\n'); |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 141 | } |
| Colin LeMahieu | b7a5f9f | 2015-11-10 00:22:00 +0000 | [diff] [blame] | 142 | OS << "\t}" << PacketBundle.second; |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 143 | } |
| 144 | }; |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 145 | |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 146 | class HexagonTargetELFStreamer : public HexagonTargetStreamer { |
| 147 | public: |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 148 | MCELFStreamer &getStreamer() { |
| 149 | return static_cast<MCELFStreamer &>(Streamer); |
| 150 | } |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 151 | HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI) |
| 152 | : HexagonTargetStreamer(S) { |
| 153 | MCAssembler &MCA = getStreamer().getAssembler(); |
| 154 | MCA.setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI)); |
| 155 | } |
| 156 | |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 157 | |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 158 | void EmitCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size, |
| 159 | unsigned ByteAlignment, |
| 160 | unsigned AccessSize) override { |
| 161 | HexagonMCELFStreamer &HexagonELFStreamer = |
| 162 | static_cast<HexagonMCELFStreamer &>(getStreamer()); |
| 163 | HexagonELFStreamer.HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment, |
| 164 | AccessSize); |
| 165 | } |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 166 | |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 167 | void EmitLocalCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size, |
| 168 | unsigned ByteAlignment, |
| 169 | unsigned AccessSize) override { |
| 170 | HexagonMCELFStreamer &HexagonELFStreamer = |
| 171 | static_cast<HexagonMCELFStreamer &>(getStreamer()); |
| 172 | HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol( |
| 173 | Symbol, Size, ByteAlignment, AccessSize); |
| 174 | } |
| 175 | }; |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 176 | |
| 177 | } // end anonymous namespace |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 178 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 179 | llvm::MCInstrInfo *llvm::createHexagonMCInstrInfo() { |
| 180 | MCInstrInfo *X = new MCInstrInfo(); |
| 181 | InitHexagonMCInstrInfo(X); |
| 182 | return X; |
| 183 | } |
| 184 | |
| 185 | static MCRegisterInfo *createHexagonMCRegisterInfo(const Triple &TT) { |
| 186 | MCRegisterInfo *X = new MCRegisterInfo(); |
| 187 | InitHexagonMCRegisterInfo(X, Hexagon::R31); |
| 188 | return X; |
| 189 | } |
| 190 | |
| Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 191 | static MCAsmInfo *createHexagonMCAsmInfo(const MCRegisterInfo &MRI, |
| Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 192 | const Triple &TT) { |
| Rafael Espindola | 140a837 | 2013-05-10 18:16:59 +0000 | [diff] [blame] | 193 | MCAsmInfo *MAI = new HexagonMCAsmInfo(TT); |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 194 | |
| 195 | // VirtualFP = (R30 + #0). |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 196 | MCCFIInstruction Inst = |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 197 | MCCFIInstruction::createDefCfa(nullptr, |
| 198 | MRI.getDwarfRegNum(Hexagon::R30, true), 0); |
| Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 199 | MAI->addInitialFrameState(Inst); |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 200 | |
| 201 | return MAI; |
| 202 | } |
| 203 | |
| Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 204 | static MCInstPrinter *createHexagonMCInstPrinter(const Triple &T, |
| Eric Christopher | f801940 | 2015-03-31 00:10:04 +0000 | [diff] [blame] | 205 | unsigned SyntaxVariant, |
| Sid Manning | 12cd21a | 2014-10-15 18:27:40 +0000 | [diff] [blame] | 206 | const MCAsmInfo &MAI, |
| 207 | const MCInstrInfo &MII, |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 208 | const MCRegisterInfo &MRI) |
| 209 | { |
| Eric Christopher | fbe80f5 | 2015-04-09 19:20:37 +0000 | [diff] [blame] | 210 | if (SyntaxVariant == 0) |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 211 | return new HexagonInstPrinter(MAI, MII, MRI); |
| Eric Christopher | fbe80f5 | 2015-04-09 19:20:37 +0000 | [diff] [blame] | 212 | else |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 213 | return nullptr; |
| 214 | } |
| 215 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 216 | static MCTargetStreamer * |
| 217 | createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, |
| 218 | MCInstPrinter *IP, bool IsVerboseAsm) { |
| 219 | return new HexagonTargetAsmStreamer(S, OS, IsVerboseAsm, *IP); |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 222 | static MCStreamer *createMCStreamer(Triple const &T, |
| 223 | MCContext &Context, |
| 224 | MCAsmBackend &MAB, |
| 225 | raw_pwrite_stream &OS, |
| 226 | MCCodeEmitter *Emitter, |
| 227 | bool RelaxAll) { |
| 228 | return createHexagonELFStreamer(T, Context, MAB, OS, Emitter); |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static MCTargetStreamer * |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 232 | createHexagonObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) { |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 233 | return new HexagonTargetELFStreamer(S, STI); |
| Sid Manning | 12cd21a | 2014-10-15 18:27:40 +0000 | [diff] [blame] | 234 | } |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 235 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 236 | static void LLVM_ATTRIBUTE_UNUSED clearFeature(MCSubtargetInfo* STI, uint64_t F) { |
| 237 | uint64_t FB = STI->getFeatureBits().to_ullong(); |
| 238 | if (FB & (1ULL << F)) |
| 239 | STI->ToggleFeature(F); |
| 240 | } |
| 241 | |
| 242 | static bool LLVM_ATTRIBUTE_UNUSED checkFeature(MCSubtargetInfo* STI, uint64_t F) { |
| 243 | uint64_t FB = STI->getFeatureBits().to_ullong(); |
| 244 | return (FB & (1ULL << F)) != 0; |
| 245 | } |
| 246 | |
| 247 | StringRef Hexagon_MC::ParseHexagonTriple(const Triple &TT, StringRef CPU) { |
| 248 | StringRef CPUName = Hexagon_MC::selectHexagonCPU(TT, CPU); |
| 249 | StringRef FS = ""; |
| 250 | if (CPUName.equals_lower("hexagonv60")) |
| 251 | FS = "+hvx"; |
| 252 | return FS; |
| 253 | } |
| 254 | |
| 255 | static bool isCPUValid(std::string CPU) |
| 256 | { |
| 257 | std::vector<std::string> table |
| 258 | { |
| 259 | "hexagonv4", |
| 260 | "hexagonv5", |
| 261 | "hexagonv55", |
| 262 | "hexagonv60", |
| 263 | }; |
| 264 | |
| 265 | return std::find(table.begin(), table.end(), CPU) != table.end(); |
| 266 | } |
| 267 | |
| 268 | MCSubtargetInfo *Hexagon_MC::createHexagonMCSubtargetInfo(const Triple &TT, |
| 269 | StringRef CPU, |
| 270 | StringRef FS) { |
| 271 | StringRef ArchFS = (FS.size()) ? FS : Hexagon_MC::ParseHexagonTriple(TT, CPU); |
| 272 | StringRef CPUName = Hexagon_MC::selectHexagonCPU(TT, CPU); |
| 273 | if (!isCPUValid(CPUName.str())) |
| 274 | { |
| 275 | errs() << "error: invalid CPU \"" << CPUName.str().c_str() << "\" specified\n"; |
| 276 | return nullptr; |
| 277 | } |
| 278 | |
| 279 | MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(TT, CPUName, ArchFS); |
| 280 | if (X->getFeatureBits()[Hexagon::ExtensionHVXDbl]) { |
| 281 | llvm::FeatureBitset Features = X->getFeatureBits(); |
| 282 | X->setFeatureBits(Features.set(Hexagon::ExtensionHVX)); |
| 283 | } |
| 284 | return X; |
| 285 | } |
| 286 | |
| 287 | unsigned Hexagon_MC::GetELFFlags(const MCSubtargetInfo &STI) { |
| 288 | static std::map<StringRef,unsigned> ElfFlags = { |
| 289 | {"hexagonv4", ELF::EF_HEXAGON_MACH_V4}, |
| 290 | {"hexagonv5", ELF::EF_HEXAGON_MACH_V5}, |
| 291 | {"hexagonv55", ELF::EF_HEXAGON_MACH_V55}, |
| 292 | {"hexagonv60", ELF::EF_HEXAGON_MACH_V60}, |
| 293 | }; |
| 294 | |
| 295 | auto F = ElfFlags.find(STI.getCPU()); |
| 296 | assert(F != ElfFlags.end() && "Unrecognized Architecture"); |
| 297 | return F->second; |
| 298 | } |
| 299 | |
| 300 | namespace { |
| 301 | class HexagonMCInstrAnalysis : public MCInstrAnalysis { |
| 302 | public: |
| 303 | HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {} |
| 304 | |
| 305 | bool isUnconditionalBranch(MCInst const &Inst) const override { |
| 306 | //assert(!HexagonMCInstrInfo::isBundle(Inst)); |
| 307 | return MCInstrAnalysis::isUnconditionalBranch(Inst); |
| 308 | } |
| 309 | |
| 310 | bool isConditionalBranch(MCInst const &Inst) const override { |
| 311 | //assert(!HexagonMCInstrInfo::isBundle(Inst)); |
| 312 | return MCInstrAnalysis::isConditionalBranch(Inst); |
| 313 | } |
| 314 | |
| 315 | bool evaluateBranch(MCInst const &Inst, uint64_t Addr, |
| 316 | uint64_t Size, uint64_t &Target) const override { |
| 317 | //assert(!HexagonMCInstrInfo::isBundle(Inst)); |
| 318 | if(!HexagonMCInstrInfo::isExtendable(*Info, Inst)) |
| 319 | return false; |
| 320 | auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst)); |
| 321 | assert(Extended.isExpr()); |
| 322 | int64_t Value; |
| 323 | if(!Extended.getExpr()->evaluateAsAbsolute(Value)) |
| 324 | return false; |
| 325 | Target = Value; |
| 326 | return true; |
| 327 | } |
| 328 | }; |
| 329 | } |
| 330 | |
| 331 | static MCInstrAnalysis *createHexagonMCInstrAnalysis(const MCInstrInfo *Info) { |
| 332 | return new HexagonMCInstrAnalysis(Info); |
| 333 | } |
| 334 | |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 335 | // Force static initialization. |
| 336 | extern "C" void LLVMInitializeHexagonTargetMC() { |
| 337 | // Register the MC asm info. |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 338 | RegisterMCAsmInfoFn X(getTheHexagonTarget(), createHexagonMCAsmInfo); |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 339 | |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 340 | // Register the MC instruction info. |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 341 | TargetRegistry::RegisterMCInstrInfo(getTheHexagonTarget(), |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 342 | createHexagonMCInstrInfo); |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 343 | |
| 344 | // Register the MC register info. |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 345 | TargetRegistry::RegisterMCRegInfo(getTheHexagonTarget(), |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 346 | createHexagonMCRegisterInfo); |
| 347 | |
| 348 | // Register the MC subtarget info. |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 349 | TargetRegistry::RegisterMCSubtargetInfo(getTheHexagonTarget(), |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 350 | Hexagon_MC::createHexagonMCSubtargetInfo); |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 351 | |
| 352 | // Register the MC Code Emitter |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 353 | TargetRegistry::RegisterMCCodeEmitter(getTheHexagonTarget(), |
| Sid Manning | 7da3f9a | 2014-10-03 13:18:11 +0000 | [diff] [blame] | 354 | createHexagonMCCodeEmitter); |
| Sid Manning | 12cd21a | 2014-10-15 18:27:40 +0000 | [diff] [blame] | 355 | |
| Colin LeMahieu | a675077 | 2015-06-03 17:34:16 +0000 | [diff] [blame] | 356 | // Register the asm backend |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 357 | TargetRegistry::RegisterMCAsmBackend(getTheHexagonTarget(), |
| Colin LeMahieu | a675077 | 2015-06-03 17:34:16 +0000 | [diff] [blame] | 358 | createHexagonAsmBackend); |
| 359 | |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 360 | |
| 361 | // Register the MC instruction analyzer. |
| 362 | TargetRegistry::RegisterMCInstrAnalysis(getTheHexagonTarget(), |
| 363 | createHexagonMCInstrAnalysis); |
| 364 | |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 365 | // Register the obj streamer |
| Krzysztof Parzyszek | 8cdfe8e | 2017-02-06 19:35:46 +0000 | [diff] [blame^] | 366 | TargetRegistry::RegisterELFStreamer(getTheHexagonTarget(), |
| 367 | createMCStreamer); |
| 368 | |
| 369 | // Register the obj target streamer |
| 370 | TargetRegistry::RegisterObjectTargetStreamer(getTheHexagonTarget(), |
| 371 | createHexagonObjectTargetStreamer); |
| Colin LeMahieu | be99a02 | 2015-06-17 03:06:16 +0000 | [diff] [blame] | 372 | |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 373 | // Register the asm streamer |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 374 | TargetRegistry::RegisterAsmTargetStreamer(getTheHexagonTarget(), |
| Colin LeMahieu | d215875 | 2015-06-18 20:43:50 +0000 | [diff] [blame] | 375 | createMCAsmTargetStreamer); |
| 376 | |
| Sid Manning | 12cd21a | 2014-10-15 18:27:40 +0000 | [diff] [blame] | 377 | // Register the MC Inst Printer |
| Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 378 | TargetRegistry::RegisterMCInstPrinter(getTheHexagonTarget(), |
| Sid Manning | 12cd21a | 2014-10-15 18:27:40 +0000 | [diff] [blame] | 379 | createHexagonMCInstPrinter); |
| Tony Linthicum | b3705e0 | 2011-12-15 22:29:08 +0000 | [diff] [blame] | 380 | } |