LLVM 22.0.0git
HexagonMCTargetDesc.cpp
Go to the documentation of this file.
1//===-- HexagonMCTargetDesc.cpp - Hexagon Target Descriptions -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides Hexagon specific target descriptions.
10//
11//===----------------------------------------------------------------------===//
12
14#include "HexagonDepArch.h"
22#include "llvm/ADT/StringRef.h"
25#include "llvm/MC/MCAssembler.h"
27#include "llvm/MC/MCContext.h"
28#include "llvm/MC/MCDwarf.h"
32#include "llvm/MC/MCInstrInfo.h"
34#include "llvm/MC/MCStreamer.h"
41#include <cassert>
42#include <cstdint>
43#include <mutex>
44#include <new>
45#include <string>
46#include <unordered_map>
47
48using namespace llvm;
49
50#define GET_INSTRINFO_MC_DESC
51#define ENABLE_INSTR_PREDICATE_VERIFIER
52#include "HexagonGenInstrInfo.inc"
53
54#define GET_SUBTARGETINFO_MC_DESC
55#include "HexagonGenSubtargetInfo.inc"
56
57#define GET_REGINFO_MC_DESC
58#include "HexagonGenRegisterInfo.inc"
59
61 ("mno-compound",
62 cl::desc("Disable looking for compound instructions for Hexagon"));
63
65 ("mno-pairing",
66 cl::desc("Disable looking for duplex instructions for Hexagon"));
67
68namespace { // These flags are to be deprecated
69cl::opt<bool> MV5("mv5", cl::Hidden, cl::desc("Build for Hexagon V5"),
70 cl::init(false));
71cl::opt<bool> MV55("mv55", cl::Hidden, cl::desc("Build for Hexagon V55"),
72 cl::init(false));
73cl::opt<bool> MV60("mv60", cl::Hidden, cl::desc("Build for Hexagon V60"),
74 cl::init(false));
75cl::opt<bool> MV62("mv62", cl::Hidden, cl::desc("Build for Hexagon V62"),
76 cl::init(false));
77cl::opt<bool> MV65("mv65", cl::Hidden, cl::desc("Build for Hexagon V65"),
78 cl::init(false));
79cl::opt<bool> MV66("mv66", cl::Hidden, cl::desc("Build for Hexagon V66"),
80 cl::init(false));
81cl::opt<bool> MV67("mv67", cl::Hidden, cl::desc("Build for Hexagon V67"),
82 cl::init(false));
83cl::opt<bool> MV67T("mv67t", cl::Hidden, cl::desc("Build for Hexagon V67T"),
84 cl::init(false));
85cl::opt<bool> MV68("mv68", cl::Hidden, cl::desc("Build for Hexagon V68"),
86 cl::init(false));
87cl::opt<bool> MV69("mv69", cl::Hidden, cl::desc("Build for Hexagon V69"),
88 cl::init(false));
89cl::opt<bool> MV71("mv71", cl::Hidden, cl::desc("Build for Hexagon V71"),
90 cl::init(false));
91cl::opt<bool> MV71T("mv71t", cl::Hidden, cl::desc("Build for Hexagon V71T"),
92 cl::init(false));
93cl::opt<bool> MV73("mv73", cl::Hidden, cl::desc("Build for Hexagon V73"),
94 cl::init(false));
95cl::opt<bool> MV75("mv75", cl::Hidden, cl::desc("Build for Hexagon V75"),
96 cl::init(false));
97cl::opt<bool> MV79("mv79", cl::Hidden, cl::desc("Build for Hexagon V79"),
98 cl::init(false));
99} // namespace
100
102 "mhvx", cl::desc("Enable Hexagon Vector eXtensions"),
103 cl::values(clEnumValN(Hexagon::ArchEnum::V60, "v60", "Build for HVX v60"),
104 clEnumValN(Hexagon::ArchEnum::V62, "v62", "Build for HVX v62"),
105 clEnumValN(Hexagon::ArchEnum::V65, "v65", "Build for HVX v65"),
106 clEnumValN(Hexagon::ArchEnum::V66, "v66", "Build for HVX v66"),
107 clEnumValN(Hexagon::ArchEnum::V67, "v67", "Build for HVX v67"),
108 clEnumValN(Hexagon::ArchEnum::V68, "v68", "Build for HVX v68"),
109 clEnumValN(Hexagon::ArchEnum::V69, "v69", "Build for HVX v69"),
110 clEnumValN(Hexagon::ArchEnum::V71, "v71", "Build for HVX v71"),
111 clEnumValN(Hexagon::ArchEnum::V73, "v73", "Build for HVX v73"),
112 clEnumValN(Hexagon::ArchEnum::V75, "v75", "Build for HVX v75"),
113 clEnumValN(Hexagon::ArchEnum::V79, "v79", "Build for HVX v79"),
114 // Sentinel for no value specified.
115 clEnumValN(Hexagon::ArchEnum::Generic, "", "")),
116 // Sentinel for flag not present.
117 cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional);
118
119static cl::opt<bool>
121 cl::desc("Disable Hexagon Vector eXtensions"));
122
123static cl::opt<bool>
125 cl::desc("Enable HVX IEEE floating point extensions"));
127 ("mcabac", cl::desc("tbd"), cl::init(false));
128
129static constexpr StringRef DefaultArch = "hexagonv68";
130
132 if (MV5)
133 return "hexagonv5";
134 if (MV55)
135 return "hexagonv55";
136 if (MV60)
137 return "hexagonv60";
138 if (MV62)
139 return "hexagonv62";
140 if (MV65)
141 return "hexagonv65";
142 if (MV66)
143 return "hexagonv66";
144 if (MV67)
145 return "hexagonv67";
146 if (MV67T)
147 return "hexagonv67t";
148 if (MV68)
149 return "hexagonv68";
150 if (MV69)
151 return "hexagonv69";
152 if (MV71)
153 return "hexagonv71";
154 if (MV71T)
155 return "hexagonv71t";
156 if (MV73)
157 return "hexagonv73";
158 if (MV75)
159 return "hexagonv75";
160 if (MV79)
161 return "hexagonv79";
162
163 return "";
164}
165
168 if (!ArchV.empty() && !CPU.empty()) {
169 // Tiny cores have a "t" suffix that is discarded when creating a secondary
170 // non-tiny subtarget. See: addArchSubtarget
171 std::pair<StringRef, StringRef> ArchP = ArchV.split('t');
172 std::pair<StringRef, StringRef> CPUP = CPU.split('t');
173 if (ArchP.first != CPUP.first)
174 report_fatal_error("conflicting architectures specified.");
175 return CPU;
176 }
177 if (ArchV.empty()) {
178 if (CPU.empty())
179 CPU = DefaultArch;
180 return CPU;
181 }
182 return ArchV;
183}
184
185unsigned llvm::HexagonGetLastSlot() { return HexagonItinerariesV5FU::SLOT3; }
186
187unsigned llvm::HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes) {
188 enum {
189 CVI_NONE = 0,
190 CVI_XLANE = 1 << 0,
191 CVI_SHIFT = 1 << 1,
192 CVI_MPY0 = 1 << 2,
193 CVI_MPY1 = 1 << 3,
194 CVI_ZW = 1 << 4
195 };
196
197 if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
198 ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
199 return (*Lanes = 4, CVI_XLANE);
200 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
201 ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
202 return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
203 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
204 return (*Lanes = 2, CVI_MPY0);
205 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
206 return (*Lanes = 2, CVI_XLANE);
207 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
208 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
209 ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
210 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
211 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
212 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
213 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
214 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
215 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
216 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
217 return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
218 else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
219 return (*Lanes = 1, CVI_ZW);
220 else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
221 return (*Lanes = 1, CVI_XLANE);
222 else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
223 return (*Lanes = 1, CVI_SHIFT);
224
225 return (*Lanes = 0, CVI_NONE);
226}
227
228
229namespace llvm {
230namespace HexagonFUnits {
231bool isSlot0Only(unsigned units) {
232 return HexagonItinerariesV62FU::SLOT0 == units;
233}
234} // namespace HexagonFUnits
235} // namespace llvm
236
237namespace {
238
239class HexagonTargetAsmStreamer : public HexagonTargetStreamer {
241
242public:
243 HexagonTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
244 MCInstPrinter &IP)
245 : HexagonTargetStreamer(S), OS(OS) {}
246
247 void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
248 const MCInst &Inst, const MCSubtargetInfo &STI,
249 raw_ostream &OS) override {
252 std::string Buffer;
253 {
254 raw_string_ostream TempStream(Buffer);
255 for (auto &I : HexagonMCInstrInfo::bundleInstructions(Inst)) {
256 InstPrinter.printInst(I.getInst(), Address, "", STI, TempStream);
257 TempStream << "\n";
258 }
259 }
260
261 std::string LoopString = "";
262 bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(Inst);
263 bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(Inst);
264 if (IsLoop0) {
265 LoopString += (IsLoop1 ? " :endloop01" : " :endloop0");
266 } else if (IsLoop1) {
267 LoopString += " :endloop1";
268 }
269
270 StringRef Contents(Buffer);
271 auto PacketBundle = Contents.rsplit('\n');
272 auto HeadTail = PacketBundle.first.split('\n');
273 StringRef Separator = "\n";
274 StringRef Indent = "\t";
275 OS << "\t{\n";
276 while (!HeadTail.first.empty()) {
277 StringRef InstTxt;
278 auto Duplex = HeadTail.first.split('\v');
279 if (!Duplex.second.empty()) {
280 OS << Indent << Duplex.first << Separator;
281 InstTxt = Duplex.second;
282 } else if (!HeadTail.first.trim().starts_with("immext")) {
283 InstTxt = Duplex.first;
284 }
285 if (!InstTxt.empty())
286 OS << Indent << InstTxt << Separator;
287 HeadTail = HeadTail.second.split('\n');
288 }
289
291 OS << "\n\t} :mem_noshuf" << LoopString;
292 else
293 OS << "\t}" << LoopString;
294 }
295
296 void finish() override { finishAttributeSection(); }
297
298 void finishAttributeSection() override {}
299
300 void emitAttribute(unsigned Attribute, unsigned Value) override {
301 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value);
302 if (getStreamer().isVerboseAsm()) {
305 if (!Name.empty())
306 OS << "\t// " << Name;
307 }
308 OS << "\n";
309 }
310};
311
312class HexagonTargetELFStreamer : public HexagonTargetStreamer {
313public:
315 return static_cast<MCELFStreamer &>(Streamer);
316 }
317 HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
319 getStreamer().getWriter().setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI));
320 }
321
323 unsigned ByteAlignment,
324 unsigned AccessSize) override {
325 HexagonMCELFStreamer &HexagonELFStreamer =
326 static_cast<HexagonMCELFStreamer &>(getStreamer());
327 HexagonELFStreamer.HexagonMCEmitCommonSymbol(
328 Symbol, Size, Align(ByteAlignment), AccessSize);
329 }
330
332 unsigned ByteAlignment,
333 unsigned AccessSize) override {
334 HexagonMCELFStreamer &HexagonELFStreamer =
335 static_cast<HexagonMCELFStreamer &>(getStreamer());
336 HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
337 Symbol, Size, Align(ByteAlignment), AccessSize);
338 }
339
340 void finish() override { finishAttributeSection(); }
341
342 void reset() override { AttributeSection = nullptr; }
343
344private:
345 MCSection *AttributeSection = nullptr;
346
347 void finishAttributeSection() override {
349 if (S.Contents.empty())
350 return;
351
352 S.emitAttributesSection("hexagon", ".hexagon.attributes",
353 ELF::SHT_HEXAGON_ATTRIBUTES, AttributeSection);
354 }
355
357 getStreamer().setAttributeItem(Attribute, Value,
358 /*OverwriteExisting=*/true);
359 }
360};
361
362} // end anonymous namespace
363
365 MCInstrInfo *X = new MCInstrInfo();
366 InitHexagonMCInstrInfo(X);
367 return X;
368}
369
372 InitHexagonMCRegisterInfo(X, Hexagon::R31, /*DwarfFlavour=*/0,
373 /*EHFlavour=*/0, /*PC=*/Hexagon::PC);
374 return X;
375}
376
378 const Triple &TT,
379 const MCTargetOptions &Options) {
380 MCAsmInfo *MAI = new HexagonMCAsmInfo(TT);
381
382 // VirtualFP = (R30 + #0).
384 nullptr, MRI.getDwarfRegNum(Hexagon::R30, true), 0);
385 MAI->addInitialFrameState(Inst);
386
387 return MAI;
388}
389
391 unsigned SyntaxVariant,
392 const MCAsmInfo &MAI,
393 const MCInstrInfo &MII,
394 const MCRegisterInfo &MRI)
395{
396 if (SyntaxVariant == 0)
397 return new HexagonInstPrinter(MAI, MII, MRI);
398 else
399 return nullptr;
400}
401
404 MCInstPrinter *IP) {
405 return new HexagonTargetAsmStreamer(S, OS, *IP);
406}
407
409 std::unique_ptr<MCAsmBackend> &&MAB,
410 std::unique_ptr<MCObjectWriter> &&OW,
411 std::unique_ptr<MCCodeEmitter> &&Emitter) {
412 return createHexagonELFStreamer(T, Context, std::move(MAB), std::move(OW),
413 std::move(Emitter));
414}
415
416static MCTargetStreamer *
418 return new HexagonTargetELFStreamer(S, STI);
419}
420
422 return new HexagonTargetStreamer(S);
423}
424
426 if (STI->hasFeature(F))
427 STI->ToggleFeature(F);
428}
429
431 return STI->hasFeature(F);
432}
433
434namespace {
435std::string selectHexagonFS(StringRef CPU, StringRef FS) {
437 if (!FS.empty())
438 Result.push_back(FS);
439
440 switch (EnableHVX) {
441 case Hexagon::ArchEnum::V5:
442 case Hexagon::ArchEnum::V55:
443 break;
444 case Hexagon::ArchEnum::V60:
445 Result.push_back("+hvxv60");
446 break;
447 case Hexagon::ArchEnum::V62:
448 Result.push_back("+hvxv62");
449 break;
450 case Hexagon::ArchEnum::V65:
451 Result.push_back("+hvxv65");
452 break;
453 case Hexagon::ArchEnum::V66:
454 Result.push_back("+hvxv66");
455 break;
456 case Hexagon::ArchEnum::V67:
457 Result.push_back("+hvxv67");
458 break;
459 case Hexagon::ArchEnum::V68:
460 Result.push_back("+hvxv68");
461 break;
462 case Hexagon::ArchEnum::V69:
463 Result.push_back("+hvxv69");
464 break;
465 case Hexagon::ArchEnum::V71:
466 Result.push_back("+hvxv71");
467 break;
468 case Hexagon::ArchEnum::V73:
469 Result.push_back("+hvxv73");
470 break;
471 case Hexagon::ArchEnum::V75:
472 Result.push_back("+hvxv75");
473 break;
474 case Hexagon::ArchEnum::V79:
475 Result.push_back("+hvxv79");
476 break;
477
478 case Hexagon::ArchEnum::Generic: {
479 Result.push_back(StringSwitch<StringRef>(CPU)
480 .Case("hexagonv60", "+hvxv60")
481 .Case("hexagonv62", "+hvxv62")
482 .Case("hexagonv65", "+hvxv65")
483 .Case("hexagonv66", "+hvxv66")
484 .Case("hexagonv67", "+hvxv67")
485 .Case("hexagonv67t", "+hvxv67")
486 .Case("hexagonv68", "+hvxv68")
487 .Case("hexagonv69", "+hvxv69")
488 .Case("hexagonv71", "+hvxv71")
489 .Case("hexagonv71t", "+hvxv71")
490 .Case("hexagonv73", "+hvxv73")
491 .Case("hexagonv75", "+hvxv75")
492 .Case("hexagonv79", "+hvxv79"));
493 break;
494 }
495 case Hexagon::ArchEnum::NoArch:
496 // Sentinel if -mhvx isn't specified
497 break;
498 }
499 if (EnableHvxIeeeFp)
500 Result.push_back("+hvx-ieee-fp");
502 Result.push_back("+cabac");
503
504 return join(Result.begin(), Result.end(), ",");
505}
506}
507
508static bool isCPUValid(StringRef CPU) {
509 return Hexagon::getCpu(CPU).has_value();
510}
511
512namespace {
513std::pair<std::string, std::string> selectCPUAndFS(StringRef CPU,
514 StringRef FS) {
515 std::pair<std::string, std::string> Result;
516 Result.first = std::string(Hexagon_MC::selectHexagonCPU(CPU));
517 Result.second = selectHexagonFS(Result.first, FS);
518 return Result;
519}
520std::mutex ArchSubtargetMutex;
521std::unordered_map<std::string, std::unique_ptr<MCSubtargetInfo const>>
522 ArchSubtarget;
523} // namespace
524
525MCSubtargetInfo const *
527 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
528 auto Existing = ArchSubtarget.find(std::string(STI->getCPU()));
529 if (Existing == ArchSubtarget.end())
530 return nullptr;
531 return Existing->second.get();
532}
533
535 using namespace Hexagon;
536 // Make sure that +hvx-length turns hvx on, and that "hvx" alone
537 // turns on hvxvNN, corresponding to the existing ArchVNN.
538 FeatureBitset FB = S;
539 unsigned CpuArch = ArchV5;
540 for (unsigned F :
541 {ArchV79, ArchV75, ArchV73, ArchV71, ArchV69, ArchV68, ArchV67, ArchV66,
542 ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) {
543 if (!FB.test(F))
544 continue;
545 CpuArch = F;
546 break;
547 }
548 bool UseHvx = false;
549 for (unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
550 if (!FB.test(F))
551 continue;
552 UseHvx = true;
553 break;
554 }
555 bool HasHvxVer = false;
556 for (unsigned F :
557 {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, ExtensionHVXV66,
558 ExtensionHVXV67, ExtensionHVXV68, ExtensionHVXV69, ExtensionHVXV71,
559 ExtensionHVXV73, ExtensionHVXV75, ExtensionHVXV79}) {
560 if (!FB.test(F))
561 continue;
562 HasHvxVer = true;
563 UseHvx = true;
564 break;
565 }
566
567 if (!UseHvx || HasHvxVer)
568 return FB;
569
570 // HasHvxVer is false, and UseHvx is true.
571 switch (CpuArch) {
572 case ArchV79:
573 FB.set(ExtensionHVXV79);
574 [[fallthrough]];
575 case ArchV75:
576 FB.set(ExtensionHVXV75);
577 [[fallthrough]];
578 case ArchV73:
579 FB.set(ExtensionHVXV73);
580 [[fallthrough]];
581 case ArchV71:
582 FB.set(ExtensionHVXV71);
583 [[fallthrough]];
584 case ArchV69:
585 FB.set(ExtensionHVXV69);
586 [[fallthrough]];
587 case ArchV68:
588 FB.set(ExtensionHVXV68);
589 [[fallthrough]];
590 case ArchV67:
591 FB.set(ExtensionHVXV67);
592 [[fallthrough]];
593 case ArchV66:
594 FB.set(ExtensionHVXV66);
595 [[fallthrough]];
596 case ArchV65:
597 FB.set(ExtensionHVXV65);
598 [[fallthrough]];
599 case ArchV62:
600 FB.set(ExtensionHVXV62);
601 [[fallthrough]];
602 case ArchV60:
603 FB.set(ExtensionHVXV60);
604 break;
605 }
606 return FB;
607}
608
610 StringRef CPU,
611 StringRef FS) {
612 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
613 StringRef CPUName = Features.first;
614 StringRef ArchFS = Features.second;
615
616 MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(
617 TT, CPUName, /*TuneCPU*/ CPUName, ArchFS);
618 if (X != nullptr && (CPUName == "hexagonv67t" || CPUName == "hexagon71t"))
619 addArchSubtarget(X, ArchFS);
620
621 if (CPU == "help")
622 exit(0);
623
624 if (!isCPUValid(CPUName.str())) {
625 errs() << "error: invalid CPU \"" << CPUName.str().c_str()
626 << "\" specified\n";
627 return nullptr;
628 }
629
630 // Add qfloat subtarget feature by default to v68 and above
631 // unless explicitly disabled
632 if (checkFeature(X, Hexagon::ExtensionHVXV68) &&
633 !ArchFS.contains("-hvx-qfloat")) {
634 llvm::FeatureBitset Features = X->getFeatureBits();
635 X->setFeatureBits(Features.set(Hexagon::ExtensionHVXQFloat));
636 }
637
639 llvm::FeatureBitset Features = X->getFeatureBits();
640 X->setFeatureBits(Features.reset(Hexagon::FeatureDuplex));
641 }
642
643 X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
644
645 // The Z-buffer instructions are grandfathered in for current
646 // architectures but omitted for new ones. Future instruction
647 // sets may introduce new/conflicting z-buffer instructions.
648 const bool ZRegOnDefault =
649 (CPUName == "hexagonv67") || (CPUName == "hexagonv66");
650 if (ZRegOnDefault) {
651 llvm::FeatureBitset Features = X->getFeatureBits();
652 X->setFeatureBits(Features.set(Hexagon::ExtensionZReg));
653 }
654
655 return X;
656}
657
659 assert(STI != nullptr);
660 if (STI->getCPU().contains("t")) {
661 auto ArchSTI = createHexagonMCSubtargetInfo(STI->getTargetTriple(),
662 STI->getCPU().drop_back(), FS);
663 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
664 ArchSubtarget[std::string(STI->getCPU())] =
665 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
666 }
667}
668
669std::optional<unsigned>
671 for (auto Arch : {Hexagon::ExtensionHVXV79, Hexagon::ExtensionHVXV75,
672 Hexagon::ExtensionHVXV73, Hexagon::ExtensionHVXV71,
673 Hexagon::ExtensionHVXV69, Hexagon::ExtensionHVXV68,
674 Hexagon::ExtensionHVXV67, Hexagon::ExtensionHVXV66,
675 Hexagon::ExtensionHVXV65, Hexagon::ExtensionHVXV62,
676 Hexagon::ExtensionHVXV60})
677 if (Features.test(Arch))
678 return Arch;
679 return {};
680}
681
682unsigned Hexagon_MC::getArchVersion(const FeatureBitset &Features) {
683 for (auto Arch :
684 {Hexagon::ArchV79, Hexagon::ArchV75, Hexagon::ArchV73, Hexagon::ArchV71,
685 Hexagon::ArchV69, Hexagon::ArchV68, Hexagon::ArchV67, Hexagon::ArchV66,
686 Hexagon::ArchV65, Hexagon::ArchV62, Hexagon::ArchV60, Hexagon::ArchV55,
687 Hexagon::ArchV5})
688 if (Features.test(Arch))
689 return Arch;
690 llvm_unreachable("Expected arch v5-v79");
691 return 0;
692}
693
695 return StringSwitch<unsigned>(STI.getCPU())
711 .Case("hexagonv79", llvm::ELF::EF_HEXAGON_MACH_V79);
712}
713
715 return ArrayRef(VectRegRev);
716}
717
718namespace {
719class HexagonMCInstrAnalysis : public MCInstrAnalysis {
720public:
721 HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {}
722
723 bool isUnconditionalBranch(MCInst const &Inst) const override {
724 //assert(!HexagonMCInstrInfo::isBundle(Inst));
726 }
727
728 bool isConditionalBranch(MCInst const &Inst) const override {
729 //assert(!HexagonMCInstrInfo::isBundle(Inst));
731 }
732
733 bool evaluateBranch(MCInst const &Inst, uint64_t Addr,
734 uint64_t Size, uint64_t &Target) const override {
735 if (!(isCall(Inst) || isUnconditionalBranch(Inst) ||
736 isConditionalBranch(Inst)))
737 return false;
738
739 //assert(!HexagonMCInstrInfo::isBundle(Inst));
740 if (!HexagonMCInstrInfo::isExtendable(*Info, Inst))
741 return false;
742 auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst));
743 assert(Extended.isExpr());
744 int64_t Value;
745 if (!Extended.getExpr()->evaluateAsAbsolute(Value))
746 return false;
747 Target = Value;
748 return true;
749 }
750
751 uint32_t getValueFromMask(uint32_t Instruction, uint32_t Mask) const {
752 uint32_t Result = 0;
753 uint32_t Offset = 0;
754 while (Mask) {
755 if (Instruction & (Mask & -Mask))
756 Result |= (1 << Offset);
757 Mask &= (Mask - 1);
758 ++Offset;
759 }
760 return Result;
761 }
762
763 std::vector<std::pair<uint64_t, uint64_t>>
764 findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
765 const MCSubtargetInfo &STI) const override {
766 // Do a lightweight parsing of PLT entries.
767 std::vector<std::pair<uint64_t, uint64_t>> Result;
768 for (uint64_t Byte = 0x0, End = PltContents.size(); Byte < End; Byte += 4) {
769 // Recognize immext(##gotpltn)
770 uint32_t ImmExt = support::endian::read32le(PltContents.data() + Byte);
771 if ((ImmExt & 0x00004000) != 0x00004000)
772 continue;
773 uint32_t LoadGotPlt =
774 support::endian::read32le(PltContents.data() + Byte + 4);
775 if ((LoadGotPlt & 0x6a49c00c) != 0x6a49c00c)
776 continue;
777 uint32_t Address = (getValueFromMask(ImmExt, 0xfff3fff) << 6) +
778 getValueFromMask(LoadGotPlt, 0x1f80) + PltSectionVA +
779 Byte;
780 Result.emplace_back(PltSectionVA + Byte, Address);
781 }
782 return Result;
783 }
784};
785} // namespace
786
788 return new HexagonMCInstrAnalysis(Info);
789}
790
791// Force static initialization.
794 // Register the MC asm info.
796
797 // Register the MC instruction info.
800
801 // Register the MC register info.
804
805 // Register the MC subtarget info.
808
809 // Register the MC Code Emitter
812
813 // Register the asm backend
816
817 // Register the MC instruction analyzer.
820
821 // Register the obj streamer
823
824 // Register the obj target streamer
827
828 // Register the asm streamer
831
832 // Register the null streamer
835
836 // Register the MC Inst Printer
839}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:687
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:298
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
dxil DXContainer Global Emitter
uint64_t Addr
std::string Name
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static cl::opt< bool > EnableHexagonCabac("mcabac", cl::desc("tbd"), cl::init(false))
static MCTargetStreamer * createHexagonNullTargetStreamer(MCStreamer &S)
static MCTargetStreamer * createHexagonObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
static MCTargetStreamer * createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *IP)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonTargetMC()
static MCInstrAnalysis * createHexagonMCInstrAnalysis(const MCInstrInfo *Info)
static MCInstPrinter * createHexagonMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static void LLVM_ATTRIBUTE_UNUSED clearFeature(MCSubtargetInfo *STI, uint64_t F)
static cl::opt< bool > DisableHVX("mno-hvx", cl::Hidden, cl::desc("Disable Hexagon Vector eXtensions"))
static MCStreamer * createMCStreamer(Triple const &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static bool isCPUValid(StringRef CPU)
static MCRegisterInfo * createHexagonMCRegisterInfo(const Triple &TT)
static cl::opt< Hexagon::ArchEnum > EnableHVX("mhvx", cl::desc("Enable Hexagon Vector eXtensions"), cl::values(clEnumValN(Hexagon::ArchEnum::V60, "v60", "Build for HVX v60"), clEnumValN(Hexagon::ArchEnum::V62, "v62", "Build for HVX v62"), clEnumValN(Hexagon::ArchEnum::V65, "v65", "Build for HVX v65"), clEnumValN(Hexagon::ArchEnum::V66, "v66", "Build for HVX v66"), clEnumValN(Hexagon::ArchEnum::V67, "v67", "Build for HVX v67"), clEnumValN(Hexagon::ArchEnum::V68, "v68", "Build for HVX v68"), clEnumValN(Hexagon::ArchEnum::V69, "v69", "Build for HVX v69"), clEnumValN(Hexagon::ArchEnum::V71, "v71", "Build for HVX v71"), clEnumValN(Hexagon::ArchEnum::V73, "v73", "Build for HVX v73"), clEnumValN(Hexagon::ArchEnum::V75, "v75", "Build for HVX v75"), clEnumValN(Hexagon::ArchEnum::V79, "v79", "Build for HVX v79"), clEnumValN(Hexagon::ArchEnum::Generic, "", "")), cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional)
static cl::opt< bool > EnableHvxIeeeFp("mhvx-ieee-fp", cl::Hidden, cl::desc("Enable HVX IEEE floating point extensions"))
static MCAsmInfo * createHexagonMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options)
static StringRef HexagonGetArchVariant()
static bool LLVM_ATTRIBUTE_UNUSED checkFeature(MCSubtargetInfo *STI, uint64_t F)
static constexpr StringRef DefaultArch
#define HEXAGON_PACKET_SIZE
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
raw_pwrite_stream & OS
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
const T * data() const
Definition: ArrayRef.h:144
Container class for subtarget features.
constexpr FeatureBitset & reset(unsigned I)
constexpr bool test(unsigned I) const
FeatureBitset & set()
Prints bundles as a newline separated list of individual instructions Duplexes are separated by a ver...
void HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment, unsigned AccessSize)
void HexagonMCEmitCommonSymbol(MCSymbol *Symbol, uint64_t Size, Align ByteAlignment, unsigned AccessSize)
virtual void emitCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, unsigned AccessGranularity)
virtual void emitLocalCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlign, unsigned AccessGranularity)
virtual void emitAttribute(unsigned Attribute, unsigned Value)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:74
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition: MCDwarf.h:585
Context object for machine code objects.
Definition: MCContext.h:83
SmallVector< AttributeItem, 64 > Contents
void emitAttributesSection(StringRef Vendor, const Twine &Section, unsigned Type, MCSection *&AttributeSection)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:46
virtual void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS)=0
Print the specified MCInst to the specified raw_ostream.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
virtual std::vector< std::pair< uint64_t, uint64_t > > findPltEntries(uint64_t PltSectionVA, ArrayRef< uint8_t > PltContents, const MCSubtargetInfo &STI) const
Returns (PLT virtual address, GOT virtual address) pairs for PLT entries.
virtual bool isCall(const MCInst &Inst) const
virtual bool isUnconditionalBranch(const MCInst &Inst) const
virtual bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size, uint64_t &Target) const
Given a branch instruction try to get the address the branch targets.
virtual bool isConditionalBranch(const MCInst &Inst) const
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:27
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
StringRef getCPU() const
FeatureBitset ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Target specific streamer interface.
Definition: MCStreamer.h:93
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address, const MCInst &Inst, const MCSubtargetInfo &STI, raw_ostream &OS)
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
MCStreamer & Streamer
Definition: MCStreamer.h:95
bool empty() const
Definition: SmallVector.h:82
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:434
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition: StringRef.h:626
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:68
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
LLVM Value Representation.
Definition: Value.h:75
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:126
LLVM_ABI StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
@ EF_HEXAGON_MACH_V5
Definition: ELF.h:659
@ EF_HEXAGON_MACH_V79
Definition: ELF.h:677
@ EF_HEXAGON_MACH_V71T
Definition: ELF.h:672
@ EF_HEXAGON_MACH_V67T
Definition: ELF.h:667
@ EF_HEXAGON_MACH_V65
Definition: ELF.h:664
@ EF_HEXAGON_MACH_V67
Definition: ELF.h:666
@ EF_HEXAGON_MACH_V62
Definition: ELF.h:663
@ EF_HEXAGON_MACH_V73
Definition: ELF.h:674
@ EF_HEXAGON_MACH_V71
Definition: ELF.h:671
@ EF_HEXAGON_MACH_V68
Definition: ELF.h:669
@ EF_HEXAGON_MACH_V66
Definition: ELF.h:665
@ EF_HEXAGON_MACH_V55
Definition: ELF.h:660
@ EF_HEXAGON_MACH_V60
Definition: ELF.h:661
@ EF_HEXAGON_MACH_V75
Definition: ELF.h:675
@ EF_HEXAGON_MACH_V69
Definition: ELF.h:670
@ SHT_HEXAGON_ATTRIBUTES
Definition: ELF.h:1227
LLVM_ABI const TagNameMap & getHexagonAttributeTags()
bool isSlot0Only(unsigned units)
bool isOuterLoop(MCInst const &MCI)
size_t bundleSize(MCInst const &MCI)
bool isMemReorderDisabled(MCInst const &MCI)
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
bool isBundle(MCInst const &MCI)
bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI)
bool isInnerLoop(MCInst const &MCI)
MCOperand const & getExtendableOperand(MCInstrInfo const &MCII, MCInst const &MCI)
llvm::ArrayRef< MCPhysReg > GetVectRegRev()
unsigned getArchVersion(const FeatureBitset &Features)
unsigned GetELFFlags(const MCSubtargetInfo &STI)
std::optional< unsigned > getHVXVersion(const FeatureBitset &Features)
MCSubtargetInfo const * getArchSubtarget(MCSubtargetInfo const *STI)
StringRef selectHexagonCPU(StringRef CPU)
void addArchSubtarget(MCSubtargetInfo const *STI, StringRef FS)
FeatureBitset completeHVXFeatures(const FeatureBitset &FB)
MCSubtargetInfo * createHexagonMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
Create a Hexagon MCSubtargetInfo instance.
std::optional< Hexagon::ArchEnum > getCpu(StringRef CPU)
@ FS
Definition: X86.h:214
@ ValueOptional
Definition: CommandLine.h:131
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:712
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
uint32_t read32le(const void *P)
Definition: Endian.h:429
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
unsigned HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes)
cl::opt< bool > HexagonDisableCompound
MCCodeEmitter * createHexagonMCCodeEmitter(const MCInstrInfo &MCII, MCContext &MCT)
unsigned HexagonGetLastSlot()
Target & getTheHexagonTarget()
MCAsmBackend * createHexagonAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MCInstrInfo * createHexagonMCInstrInfo()
MCStreamer * createHexagonELFStreamer(Triple const &TT, MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > CE)
cl::opt< bool > HexagonDisableDuplex
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
RegisterMCAsmInfoFn - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)