LLVM 20.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"
40#include <cassert>
41#include <cstdint>
42#include <mutex>
43#include <new>
44#include <string>
45#include <unordered_map>
46
47using namespace llvm;
48
49#define GET_INSTRINFO_MC_DESC
50#define ENABLE_INSTR_PREDICATE_VERIFIER
51#include "HexagonGenInstrInfo.inc"
52
53#define GET_SUBTARGETINFO_MC_DESC
54#include "HexagonGenSubtargetInfo.inc"
55
56#define GET_REGINFO_MC_DESC
57#include "HexagonGenRegisterInfo.inc"
58
60 ("mno-compound",
61 cl::desc("Disable looking for compound instructions for Hexagon"));
62
64 ("mno-pairing",
65 cl::desc("Disable looking for duplex instructions for Hexagon"));
66
67namespace { // These flags are to be deprecated
68cl::opt<bool> MV5("mv5", cl::Hidden, cl::desc("Build for Hexagon V5"),
69 cl::init(false));
70cl::opt<bool> MV55("mv55", cl::Hidden, cl::desc("Build for Hexagon V55"),
71 cl::init(false));
72cl::opt<bool> MV60("mv60", cl::Hidden, cl::desc("Build for Hexagon V60"),
73 cl::init(false));
74cl::opt<bool> MV62("mv62", cl::Hidden, cl::desc("Build for Hexagon V62"),
75 cl::init(false));
76cl::opt<bool> MV65("mv65", cl::Hidden, cl::desc("Build for Hexagon V65"),
77 cl::init(false));
78cl::opt<bool> MV66("mv66", cl::Hidden, cl::desc("Build for Hexagon V66"),
79 cl::init(false));
80cl::opt<bool> MV67("mv67", cl::Hidden, cl::desc("Build for Hexagon V67"),
81 cl::init(false));
82cl::opt<bool> MV67T("mv67t", cl::Hidden, cl::desc("Build for Hexagon V67T"),
83 cl::init(false));
84cl::opt<bool> MV68("mv68", cl::Hidden, cl::desc("Build for Hexagon V68"),
85 cl::init(false));
86cl::opt<bool> MV69("mv69", cl::Hidden, cl::desc("Build for Hexagon V69"),
87 cl::init(false));
88cl::opt<bool> MV71("mv71", cl::Hidden, cl::desc("Build for Hexagon V71"),
89 cl::init(false));
90cl::opt<bool> MV71T("mv71t", cl::Hidden, cl::desc("Build for Hexagon V71T"),
91 cl::init(false));
92cl::opt<bool> MV73("mv73", cl::Hidden, cl::desc("Build for Hexagon V73"),
93 cl::init(false));
94cl::opt<bool> MV75("mv75", cl::Hidden, cl::desc("Build for Hexagon V75"),
95 cl::init(false));
96cl::opt<bool> MV79("mv79", cl::Hidden, cl::desc("Build for Hexagon V79"),
97 cl::init(false));
98} // namespace
99
101 "mhvx", cl::desc("Enable Hexagon Vector eXtensions"),
102 cl::values(clEnumValN(Hexagon::ArchEnum::V60, "v60", "Build for HVX v60"),
103 clEnumValN(Hexagon::ArchEnum::V62, "v62", "Build for HVX v62"),
104 clEnumValN(Hexagon::ArchEnum::V65, "v65", "Build for HVX v65"),
105 clEnumValN(Hexagon::ArchEnum::V66, "v66", "Build for HVX v66"),
106 clEnumValN(Hexagon::ArchEnum::V67, "v67", "Build for HVX v67"),
107 clEnumValN(Hexagon::ArchEnum::V68, "v68", "Build for HVX v68"),
108 clEnumValN(Hexagon::ArchEnum::V69, "v69", "Build for HVX v69"),
109 clEnumValN(Hexagon::ArchEnum::V71, "v71", "Build for HVX v71"),
110 clEnumValN(Hexagon::ArchEnum::V73, "v73", "Build for HVX v73"),
111 clEnumValN(Hexagon::ArchEnum::V75, "v75", "Build for HVX v75"),
112 clEnumValN(Hexagon::ArchEnum::V79, "v79", "Build for HVX v79"),
113 // Sentinel for no value specified.
114 clEnumValN(Hexagon::ArchEnum::Generic, "", "")),
115 // Sentinel for flag not present.
116 cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional);
117
118static cl::opt<bool>
120 cl::desc("Disable Hexagon Vector eXtensions"));
121
122static cl::opt<bool>
124 cl::desc("Enable HVX IEEE floating point extensions"));
126 ("mcabac", cl::desc("tbd"), cl::init(false));
127
128static StringRef DefaultArch = "hexagonv60";
129
131 if (MV5)
132 return "hexagonv5";
133 if (MV55)
134 return "hexagonv55";
135 if (MV60)
136 return "hexagonv60";
137 if (MV62)
138 return "hexagonv62";
139 if (MV65)
140 return "hexagonv65";
141 if (MV66)
142 return "hexagonv66";
143 if (MV67)
144 return "hexagonv67";
145 if (MV67T)
146 return "hexagonv67t";
147 if (MV68)
148 return "hexagonv68";
149 if (MV69)
150 return "hexagonv69";
151 if (MV71)
152 return "hexagonv71";
153 if (MV71T)
154 return "hexagonv71t";
155 if (MV73)
156 return "hexagonv73";
157 if (MV75)
158 return "hexagonv75";
159 if (MV79)
160 return "hexagonv79";
161
162 return "";
163}
164
167 if (!ArchV.empty() && !CPU.empty()) {
168 // Tiny cores have a "t" suffix that is discarded when creating a secondary
169 // non-tiny subtarget. See: addArchSubtarget
170 std::pair<StringRef, StringRef> ArchP = ArchV.split('t');
171 std::pair<StringRef, StringRef> CPUP = CPU.split('t');
172 if (ArchP.first != CPUP.first)
173 report_fatal_error("conflicting architectures specified.");
174 return CPU;
175 }
176 if (ArchV.empty()) {
177 if (CPU.empty())
178 CPU = DefaultArch;
179 return CPU;
180 }
181 return ArchV;
182}
183
184unsigned llvm::HexagonGetLastSlot() { return HexagonItinerariesV5FU::SLOT3; }
185
186unsigned llvm::HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes) {
187 enum {
188 CVI_NONE = 0,
189 CVI_XLANE = 1 << 0,
190 CVI_SHIFT = 1 << 1,
191 CVI_MPY0 = 1 << 2,
192 CVI_MPY1 = 1 << 3,
193 CVI_ZW = 1 << 4
194 };
195
196 if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
197 ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
198 return (*Lanes = 4, CVI_XLANE);
199 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
200 ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
201 return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
202 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
203 return (*Lanes = 2, CVI_MPY0);
204 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
205 return (*Lanes = 2, CVI_XLANE);
206 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
207 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
208 ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
209 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
210 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
211 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
212 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
213 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
214 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
215 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
216 return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
217 else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
218 return (*Lanes = 1, CVI_ZW);
219 else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
220 return (*Lanes = 1, CVI_XLANE);
221 else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
222 return (*Lanes = 1, CVI_SHIFT);
223
224 return (*Lanes = 0, CVI_NONE);
225}
226
227
228namespace llvm {
229namespace HexagonFUnits {
230bool isSlot0Only(unsigned units) {
231 return HexagonItinerariesV62FU::SLOT0 == units;
232}
233} // namespace HexagonFUnits
234} // namespace llvm
235
236namespace {
237
238class HexagonTargetAsmStreamer : public HexagonTargetStreamer {
240
241public:
242 HexagonTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
243 MCInstPrinter &IP)
244 : HexagonTargetStreamer(S), OS(OS) {}
245
246 void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
247 const MCInst &Inst, const MCSubtargetInfo &STI,
248 raw_ostream &OS) override {
251 std::string Buffer;
252 {
253 raw_string_ostream TempStream(Buffer);
254 InstPrinter.printInst(&Inst, Address, "", STI, TempStream);
255 }
256 StringRef Contents(Buffer);
257 auto PacketBundle = Contents.rsplit('\n');
258 auto HeadTail = PacketBundle.first.split('\n');
259 StringRef Separator = "\n";
260 StringRef Indent = "\t";
261 OS << "\t{\n";
262 while (!HeadTail.first.empty()) {
263 StringRef InstTxt;
264 auto Duplex = HeadTail.first.split('\v');
265 if (!Duplex.second.empty()) {
266 OS << Indent << Duplex.first << Separator;
267 InstTxt = Duplex.second;
268 } else if (!HeadTail.first.trim().starts_with("immext")) {
269 InstTxt = Duplex.first;
270 }
271 if (!InstTxt.empty())
272 OS << Indent << InstTxt << Separator;
273 HeadTail = HeadTail.second.split('\n');
274 }
275
277 OS << "\n\t} :mem_noshuf" << PacketBundle.second;
278 else
279 OS << "\t}" << PacketBundle.second;
280 }
281
282 void finish() override { finishAttributeSection(); }
283
284 void finishAttributeSection() override {}
285
286 void emitAttribute(unsigned Attribute, unsigned Value) override {
287 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value);
288 if (getStreamer().isVerboseAsm()) {
291 if (!Name.empty())
292 OS << "\t// " << Name;
293 }
294 OS << "\n";
295 }
296};
297
298class HexagonTargetELFStreamer : public HexagonTargetStreamer {
299public:
301 return static_cast<MCELFStreamer &>(Streamer);
302 }
303 HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
305 getStreamer().getWriter().setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI));
306 }
307
309 unsigned ByteAlignment,
310 unsigned AccessSize) override {
311 HexagonMCELFStreamer &HexagonELFStreamer =
312 static_cast<HexagonMCELFStreamer &>(getStreamer());
313 HexagonELFStreamer.HexagonMCEmitCommonSymbol(
314 Symbol, Size, Align(ByteAlignment), AccessSize);
315 }
316
318 unsigned ByteAlignment,
319 unsigned AccessSize) override {
320 HexagonMCELFStreamer &HexagonELFStreamer =
321 static_cast<HexagonMCELFStreamer &>(getStreamer());
322 HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
323 Symbol, Size, Align(ByteAlignment), AccessSize);
324 }
325
326 void finish() override { finishAttributeSection(); }
327
328 void reset() override { AttributeSection = nullptr; }
329
330private:
331 MCSection *AttributeSection = nullptr;
332
333 void finishAttributeSection() override {
335 if (S.Contents.empty())
336 return;
337
338 S.emitAttributesSection("hexagon", ".hexagon.attributes",
339 ELF::SHT_HEXAGON_ATTRIBUTES, AttributeSection);
340 }
341
343 getStreamer().setAttributeItem(Attribute, Value,
344 /*OverwriteExisting=*/true);
345 }
346};
347
348} // end anonymous namespace
349
351 MCInstrInfo *X = new MCInstrInfo();
352 InitHexagonMCInstrInfo(X);
353 return X;
354}
355
358 InitHexagonMCRegisterInfo(X, Hexagon::R31, /*DwarfFlavour=*/0,
359 /*EHFlavour=*/0, /*PC=*/Hexagon::PC);
360 return X;
361}
362
364 const Triple &TT,
365 const MCTargetOptions &Options) {
366 MCAsmInfo *MAI = new HexagonMCAsmInfo(TT);
367
368 // VirtualFP = (R30 + #0).
370 nullptr, MRI.getDwarfRegNum(Hexagon::R30, true), 0);
371 MAI->addInitialFrameState(Inst);
372
373 return MAI;
374}
375
377 unsigned SyntaxVariant,
378 const MCAsmInfo &MAI,
379 const MCInstrInfo &MII,
380 const MCRegisterInfo &MRI)
381{
382 if (SyntaxVariant == 0)
383 return new HexagonInstPrinter(MAI, MII, MRI);
384 else
385 return nullptr;
386}
387
390 MCInstPrinter *IP) {
391 return new HexagonTargetAsmStreamer(S, OS, *IP);
392}
393
395 std::unique_ptr<MCAsmBackend> &&MAB,
396 std::unique_ptr<MCObjectWriter> &&OW,
397 std::unique_ptr<MCCodeEmitter> &&Emitter) {
398 return createHexagonELFStreamer(T, Context, std::move(MAB), std::move(OW),
399 std::move(Emitter));
400}
401
402static MCTargetStreamer *
404 return new HexagonTargetELFStreamer(S, STI);
405}
406
408 return new HexagonTargetStreamer(S);
409}
410
412 if (STI->hasFeature(F))
413 STI->ToggleFeature(F);
414}
415
417 return STI->hasFeature(F);
418}
419
420namespace {
421std::string selectHexagonFS(StringRef CPU, StringRef FS) {
423 if (!FS.empty())
424 Result.push_back(FS);
425
426 switch (EnableHVX) {
427 case Hexagon::ArchEnum::V5:
428 case Hexagon::ArchEnum::V55:
429 break;
430 case Hexagon::ArchEnum::V60:
431 Result.push_back("+hvxv60");
432 break;
433 case Hexagon::ArchEnum::V62:
434 Result.push_back("+hvxv62");
435 break;
436 case Hexagon::ArchEnum::V65:
437 Result.push_back("+hvxv65");
438 break;
439 case Hexagon::ArchEnum::V66:
440 Result.push_back("+hvxv66");
441 break;
442 case Hexagon::ArchEnum::V67:
443 Result.push_back("+hvxv67");
444 break;
445 case Hexagon::ArchEnum::V68:
446 Result.push_back("+hvxv68");
447 break;
448 case Hexagon::ArchEnum::V69:
449 Result.push_back("+hvxv69");
450 break;
451 case Hexagon::ArchEnum::V71:
452 Result.push_back("+hvxv71");
453 break;
454 case Hexagon::ArchEnum::V73:
455 Result.push_back("+hvxv73");
456 break;
457 case Hexagon::ArchEnum::V75:
458 Result.push_back("+hvxv75");
459 break;
460 case Hexagon::ArchEnum::V79:
461 Result.push_back("+hvxv79");
462 break;
463
464 case Hexagon::ArchEnum::Generic: {
465 Result.push_back(StringSwitch<StringRef>(CPU)
466 .Case("hexagonv60", "+hvxv60")
467 .Case("hexagonv62", "+hvxv62")
468 .Case("hexagonv65", "+hvxv65")
469 .Case("hexagonv66", "+hvxv66")
470 .Case("hexagonv67", "+hvxv67")
471 .Case("hexagonv67t", "+hvxv67")
472 .Case("hexagonv68", "+hvxv68")
473 .Case("hexagonv69", "+hvxv69")
474 .Case("hexagonv71", "+hvxv71")
475 .Case("hexagonv71t", "+hvxv71")
476 .Case("hexagonv73", "+hvxv73")
477 .Case("hexagonv75", "+hvxv75")
478 .Case("hexagonv79", "+hvxv79"));
479 break;
480 }
481 case Hexagon::ArchEnum::NoArch:
482 // Sentinel if -mhvx isn't specified
483 break;
484 }
485 if (EnableHvxIeeeFp)
486 Result.push_back("+hvx-ieee-fp");
488 Result.push_back("+cabac");
489
490 return join(Result.begin(), Result.end(), ",");
491}
492}
493
494static bool isCPUValid(StringRef CPU) {
495 return Hexagon::getCpu(CPU).has_value();
496}
497
498namespace {
499std::pair<std::string, std::string> selectCPUAndFS(StringRef CPU,
500 StringRef FS) {
501 std::pair<std::string, std::string> Result;
502 Result.first = std::string(Hexagon_MC::selectHexagonCPU(CPU));
503 Result.second = selectHexagonFS(Result.first, FS);
504 return Result;
505}
506std::mutex ArchSubtargetMutex;
507std::unordered_map<std::string, std::unique_ptr<MCSubtargetInfo const>>
508 ArchSubtarget;
509} // namespace
510
511MCSubtargetInfo const *
513 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
514 auto Existing = ArchSubtarget.find(std::string(STI->getCPU()));
515 if (Existing == ArchSubtarget.end())
516 return nullptr;
517 return Existing->second.get();
518}
519
521 using namespace Hexagon;
522 // Make sure that +hvx-length turns hvx on, and that "hvx" alone
523 // turns on hvxvNN, corresponding to the existing ArchVNN.
524 FeatureBitset FB = S;
525 unsigned CpuArch = ArchV5;
526 for (unsigned F :
527 {ArchV79, ArchV75, ArchV73, ArchV71, ArchV69, ArchV68, ArchV67, ArchV66,
528 ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) {
529 if (!FB.test(F))
530 continue;
531 CpuArch = F;
532 break;
533 }
534 bool UseHvx = false;
535 for (unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
536 if (!FB.test(F))
537 continue;
538 UseHvx = true;
539 break;
540 }
541 bool HasHvxVer = false;
542 for (unsigned F :
543 {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, ExtensionHVXV66,
544 ExtensionHVXV67, ExtensionHVXV68, ExtensionHVXV69, ExtensionHVXV71,
545 ExtensionHVXV73, ExtensionHVXV75, ExtensionHVXV79}) {
546 if (!FB.test(F))
547 continue;
548 HasHvxVer = true;
549 UseHvx = true;
550 break;
551 }
552
553 if (!UseHvx || HasHvxVer)
554 return FB;
555
556 // HasHvxVer is false, and UseHvx is true.
557 switch (CpuArch) {
558 case ArchV79:
559 FB.set(ExtensionHVXV79);
560 [[fallthrough]];
561 case ArchV75:
562 FB.set(ExtensionHVXV75);
563 [[fallthrough]];
564 case ArchV73:
565 FB.set(ExtensionHVXV73);
566 [[fallthrough]];
567 case ArchV71:
568 FB.set(ExtensionHVXV71);
569 [[fallthrough]];
570 case ArchV69:
571 FB.set(ExtensionHVXV69);
572 [[fallthrough]];
573 case ArchV68:
574 FB.set(ExtensionHVXV68);
575 [[fallthrough]];
576 case ArchV67:
577 FB.set(ExtensionHVXV67);
578 [[fallthrough]];
579 case ArchV66:
580 FB.set(ExtensionHVXV66);
581 [[fallthrough]];
582 case ArchV65:
583 FB.set(ExtensionHVXV65);
584 [[fallthrough]];
585 case ArchV62:
586 FB.set(ExtensionHVXV62);
587 [[fallthrough]];
588 case ArchV60:
589 FB.set(ExtensionHVXV60);
590 break;
591 }
592 return FB;
593}
594
596 StringRef CPU,
597 StringRef FS) {
598 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
599 StringRef CPUName = Features.first;
600 StringRef ArchFS = Features.second;
601
602 MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(
603 TT, CPUName, /*TuneCPU*/ CPUName, ArchFS);
604 if (X != nullptr && (CPUName == "hexagonv67t" || CPUName == "hexagon71t"))
605 addArchSubtarget(X, ArchFS);
606
607 if (CPU == "help")
608 exit(0);
609
610 if (!isCPUValid(CPUName.str())) {
611 errs() << "error: invalid CPU \"" << CPUName.str().c_str()
612 << "\" specified\n";
613 return nullptr;
614 }
615
616 // Add qfloat subtarget feature by default to v68 and above
617 // unless explicitely disabled
618 if (checkFeature(X, Hexagon::ExtensionHVXV68) &&
619 !ArchFS.contains("-hvx-qfloat")) {
620 llvm::FeatureBitset Features = X->getFeatureBits();
621 X->setFeatureBits(Features.set(Hexagon::ExtensionHVXQFloat));
622 }
623
625 llvm::FeatureBitset Features = X->getFeatureBits();
626 X->setFeatureBits(Features.reset(Hexagon::FeatureDuplex));
627 }
628
629 X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
630
631 // The Z-buffer instructions are grandfathered in for current
632 // architectures but omitted for new ones. Future instruction
633 // sets may introduce new/conflicting z-buffer instructions.
634 const bool ZRegOnDefault =
635 (CPUName == "hexagonv67") || (CPUName == "hexagonv66");
636 if (ZRegOnDefault) {
637 llvm::FeatureBitset Features = X->getFeatureBits();
638 X->setFeatureBits(Features.set(Hexagon::ExtensionZReg));
639 }
640
641 return X;
642}
643
645 assert(STI != nullptr);
646 if (STI->getCPU().contains("t")) {
647 auto ArchSTI = createHexagonMCSubtargetInfo(
648 STI->getTargetTriple(),
649 STI->getCPU().substr(0, STI->getCPU().size() - 1), FS);
650 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
651 ArchSubtarget[std::string(STI->getCPU())] =
652 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
653 }
654}
655
656std::optional<unsigned>
658 for (auto Arch : {Hexagon::ExtensionHVXV79, Hexagon::ExtensionHVXV75,
659 Hexagon::ExtensionHVXV73, Hexagon::ExtensionHVXV71,
660 Hexagon::ExtensionHVXV69, Hexagon::ExtensionHVXV68,
661 Hexagon::ExtensionHVXV67, Hexagon::ExtensionHVXV66,
662 Hexagon::ExtensionHVXV65, Hexagon::ExtensionHVXV62,
663 Hexagon::ExtensionHVXV60})
664 if (Features.test(Arch))
665 return Arch;
666 return {};
667}
668
669unsigned Hexagon_MC::getArchVersion(const FeatureBitset &Features) {
670 for (auto Arch :
671 {Hexagon::ArchV79, Hexagon::ArchV75, Hexagon::ArchV73, Hexagon::ArchV71,
672 Hexagon::ArchV69, Hexagon::ArchV68, Hexagon::ArchV67, Hexagon::ArchV66,
673 Hexagon::ArchV65, Hexagon::ArchV62, Hexagon::ArchV60, Hexagon::ArchV55,
674 Hexagon::ArchV5})
675 if (Features.test(Arch))
676 return Arch;
677 llvm_unreachable("Expected arch v5-v79");
678 return 0;
679}
680
682 return StringSwitch<unsigned>(STI.getCPU())
698 .Case("hexagonv79", llvm::ELF::EF_HEXAGON_MACH_V79);
699}
700
702 return ArrayRef(VectRegRev);
703}
704
705namespace {
706class HexagonMCInstrAnalysis : public MCInstrAnalysis {
707public:
708 HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {}
709
710 bool isUnconditionalBranch(MCInst const &Inst) const override {
711 //assert(!HexagonMCInstrInfo::isBundle(Inst));
713 }
714
715 bool isConditionalBranch(MCInst const &Inst) const override {
716 //assert(!HexagonMCInstrInfo::isBundle(Inst));
718 }
719
720 bool evaluateBranch(MCInst const &Inst, uint64_t Addr,
721 uint64_t Size, uint64_t &Target) const override {
722 if (!(isCall(Inst) || isUnconditionalBranch(Inst) ||
723 isConditionalBranch(Inst)))
724 return false;
725
726 //assert(!HexagonMCInstrInfo::isBundle(Inst));
727 if (!HexagonMCInstrInfo::isExtendable(*Info, Inst))
728 return false;
729 auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst));
730 assert(Extended.isExpr());
731 int64_t Value;
732 if (!Extended.getExpr()->evaluateAsAbsolute(Value))
733 return false;
734 Target = Value;
735 return true;
736 }
737};
738}
739
741 return new HexagonMCInstrAnalysis(Info);
742}
743
744// Force static initialization.
746 // Register the MC asm info.
748
749 // Register the MC instruction info.
752
753 // Register the MC register info.
756
757 // Register the MC subtarget info.
760
761 // Register the MC Code Emitter
764
765 // Register the asm backend
768
769 // Register the MC instruction analyzer.
772
773 // Register the obj streamer
775
776 // Register the obj target streamer
779
780 // Register the asm streamer
783
784 // Register the null streamer
787
788 // Register the MC Inst Printer
791}
unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:686
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:282
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
dxil DXContainer Global Emitter
uint64_t Addr
std::string Name
uint64_t Size
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)
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)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonTargetMC()
static MCRegisterInfo * createHexagonMCRegisterInfo(const Triple &TT)
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 StringRef DefaultArch
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)
#define HEXAGON_PACKET_SIZE
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
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:56
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition: MCAsmInfo.cpp:75
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:575
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:185
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:26
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:36
Streaming machine code generation interface.
Definition: MCStreamer.h:213
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:41
Target specific streamer interface.
Definition: MCStreamer.h:94
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address, const MCInst &Inst, const MCSubtargetInfo &STI, raw_ostream &OS)
MCStreamer & getStreamer()
Definition: MCStreamer.h:102
MCStreamer & Streamer
Definition: MCStreamer.h:96
bool empty() const
Definition: SmallVector.h:81
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:700
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:229
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:571
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:150
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition: StringRef.h:424
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
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:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
@ SHT_HEXAGON_ATTRIBUTES
Definition: ELF.h:1180
@ EF_HEXAGON_MACH_V5
Definition: ELF.h:619
@ EF_HEXAGON_MACH_V79
Definition: ELF.h:633
@ EF_HEXAGON_MACH_V71T
Definition: ELF.h:630
@ EF_HEXAGON_MACH_V67T
Definition: ELF.h:626
@ EF_HEXAGON_MACH_V65
Definition: ELF.h:623
@ EF_HEXAGON_MACH_V67
Definition: ELF.h:625
@ EF_HEXAGON_MACH_V62
Definition: ELF.h:622
@ EF_HEXAGON_MACH_V73
Definition: ELF.h:631
@ EF_HEXAGON_MACH_V71
Definition: ELF.h:629
@ EF_HEXAGON_MACH_V68
Definition: ELF.h:627
@ EF_HEXAGON_MACH_V66
Definition: ELF.h:624
@ EF_HEXAGON_MACH_V55
Definition: ELF.h:620
@ EF_HEXAGON_MACH_V60
Definition: ELF.h:621
@ EF_HEXAGON_MACH_V75
Definition: ELF.h:632
@ EF_HEXAGON_MACH_V69
Definition: ELF.h:628
const TagNameMap & getHexagonAttributeTags()
bool isSlot0Only(unsigned units)
size_t bundleSize(MCInst const &MCI)
bool isMemReorderDisabled(MCInst const &MCI)
bool isBundle(MCInst const &MCI)
bool isExtendable(MCInstrInfo const &MCII, 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:211
@ ValueOptional
Definition: CommandLine.h:130
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:711
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
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)