LLVM 24.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/StringMap.h"
23#include "llvm/ADT/StringRef.h"
26#include "llvm/MC/MCAssembler.h"
28#include "llvm/MC/MCContext.h"
29#include "llvm/MC/MCDwarf.h"
33#include "llvm/MC/MCInstrInfo.h"
35#include "llvm/MC/MCStreamer.h"
42#include <cassert>
43#include <cstdint>
44#include <mutex>
45#include <new>
46#include <string>
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));
99cl::opt<bool> MV81("mv81", cl::Hidden, cl::desc("Build for Hexagon V81"),
100 cl::init(false));
101cl::opt<bool> MV83("mv83", cl::Hidden, cl::desc("Build for Hexagon V83"),
102 cl::init(false));
103cl::opt<bool> MV85("mv85", cl::Hidden, cl::desc("Build for Hexagon V85"),
104 cl::init(false));
105} // namespace
106
108 "mhvx", cl::desc("Enable Hexagon Vector eXtensions"),
109 cl::values(clEnumValN(Hexagon::ArchEnum::V60, "v60", "Build for HVX v60"),
110 clEnumValN(Hexagon::ArchEnum::V62, "v62", "Build for HVX v62"),
111 clEnumValN(Hexagon::ArchEnum::V65, "v65", "Build for HVX v65"),
112 clEnumValN(Hexagon::ArchEnum::V66, "v66", "Build for HVX v66"),
113 clEnumValN(Hexagon::ArchEnum::V67, "v67", "Build for HVX v67"),
114 clEnumValN(Hexagon::ArchEnum::V68, "v68", "Build for HVX v68"),
115 clEnumValN(Hexagon::ArchEnum::V69, "v69", "Build for HVX v69"),
116 clEnumValN(Hexagon::ArchEnum::V71, "v71", "Build for HVX v71"),
117 clEnumValN(Hexagon::ArchEnum::V73, "v73", "Build for HVX v73"),
118 clEnumValN(Hexagon::ArchEnum::V75, "v75", "Build for HVX v75"),
119 clEnumValN(Hexagon::ArchEnum::V79, "v79", "Build for HVX v79"),
120 clEnumValN(Hexagon::ArchEnum::V81, "v81", "Build for HVX v81"),
121 clEnumValN(Hexagon::ArchEnum::V83, "v83", "Build for HVX v83"),
122 clEnumValN(Hexagon::ArchEnum::V85, "v85", "Build for HVX v85"),
123 // Sentinel for no value specified.
125 // Sentinel for flag not present.
127
128static cl::opt<bool>
130 cl::desc("Disable Hexagon Vector eXtensions"));
131
133 cl::desc("Enable Hexagon Matrix eXtensions"));
134
135static cl::opt<bool>
137 cl::desc("Enable HVX IEEE floating point extensions"));
139 ("mcabac", cl::desc("tbd"), cl::init(false));
140static cl::opt<bool> EnableHLX("mhlx", cl::desc("Enable Hexagon HLX"));
141
142static constexpr StringRef DefaultArch = "hexagonv68";
143
145 if (MV5)
146 return "hexagonv5";
147 if (MV55)
148 return "hexagonv55";
149 if (MV60)
150 return "hexagonv60";
151 if (MV62)
152 return "hexagonv62";
153 if (MV65)
154 return "hexagonv65";
155 if (MV66)
156 return "hexagonv66";
157 if (MV67)
158 return "hexagonv67";
159 if (MV67T)
160 return "hexagonv67t";
161 if (MV68)
162 return "hexagonv68";
163 if (MV69)
164 return "hexagonv69";
165 if (MV71)
166 return "hexagonv71";
167 if (MV71T)
168 return "hexagonv71t";
169 if (MV73)
170 return "hexagonv73";
171 if (MV75)
172 return "hexagonv75";
173 if (MV79)
174 return "hexagonv79";
175 if (MV81)
176 return "hexagonv81";
177 if (MV83)
178 return "hexagonv83";
179 if (MV85)
180 return "hexagonv85";
181
182 return "";
183}
184
187 if (!ArchV.empty() && !CPU.empty()) {
188 // Tiny cores have a "t" suffix that is discarded when creating a secondary
189 // non-tiny subtarget. See: addArchSubtarget
190 std::pair<StringRef, StringRef> ArchP = ArchV.split('t');
191 std::pair<StringRef, StringRef> CPUP = CPU.split('t');
192 if (ArchP.first != CPUP.first)
193 report_fatal_error("conflicting architectures specified.");
194 return CPU;
195 }
196 if (ArchV.empty()) {
197 if (CPU.empty())
198 CPU = DefaultArch;
199 return CPU;
200 }
201 return ArchV;
202}
203
204unsigned llvm::HexagonGetLastSlot() { return HexagonItinerariesV5FU::SLOT3; }
205
206unsigned llvm::HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes) {
207 enum {
208 CVI_NONE = 0,
209 CVI_XLANE = 1 << 0,
210 CVI_SHIFT = 1 << 1,
211 CVI_MPY0 = 1 << 2,
212 CVI_MPY1 = 1 << 3,
213 CVI_ZW = 1 << 4
214 };
215
216 if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
217 ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
218 return (*Lanes = 4, CVI_XLANE);
219 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
220 ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
221 return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
222 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
223 return (*Lanes = 2, CVI_MPY0);
224 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
225 return (*Lanes = 2, CVI_XLANE);
226 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
227 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
228 ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
229 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
230 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
231 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
232 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
233 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
234 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
235 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
236 return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
237 else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
238 return (*Lanes = 1, CVI_ZW);
239 else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
240 return (*Lanes = 1, CVI_XLANE);
241 else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
242 return (*Lanes = 1, CVI_SHIFT);
243
244 return (*Lanes = 0, CVI_NONE);
245}
246
247
248namespace llvm {
249namespace HexagonFUnits {
250bool isSlot0Only(unsigned units) {
251 return HexagonItinerariesV62FU::SLOT0 == units;
252}
253} // namespace HexagonFUnits
254} // namespace llvm
255
256namespace {
257
258class HexagonTargetAsmStreamer : public HexagonTargetStreamer {
259 formatted_raw_ostream &OS;
260
261public:
262 HexagonTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
263 MCInstPrinter &IP)
264 : HexagonTargetStreamer(S), OS(OS) {}
265
266 void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
267 const MCInst &Inst, const MCSubtargetInfo &STI,
268 raw_ostream &OS) override {
271 std::string Buffer;
272 {
273 raw_string_ostream TempStream(Buffer);
274 for (auto &I : HexagonMCInstrInfo::bundleInstructions(Inst)) {
275 InstPrinter.printInst(I.getInst(), Address, "", STI, TempStream);
276 TempStream << "\n";
277 }
278 }
279
280 std::string LoopString = "";
281 bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(Inst);
282 bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(Inst);
283 if (IsLoop0) {
284 LoopString += (IsLoop1 ? " :endloop01" : " :endloop0");
285 } else if (IsLoop1) {
286 LoopString += " :endloop1";
287 }
288
289 StringRef Contents(Buffer);
290 auto PacketBundle = Contents.rsplit('\n');
291 auto HeadTail = PacketBundle.first.split('\n');
292 StringRef Separator = "\n";
293 StringRef Indent = "\t";
294 OS << "\t{\n";
295 while (!HeadTail.first.empty()) {
296 StringRef InstTxt;
297 auto Duplex = HeadTail.first.split('\v');
298 if (!Duplex.second.empty()) {
299 OS << Indent << Duplex.first << Separator;
300 InstTxt = Duplex.second;
301 } else if (!HeadTail.first.trim().starts_with("immext")) {
302 InstTxt = Duplex.first;
303 }
304 if (!InstTxt.empty())
305 OS << Indent << InstTxt << Separator;
306 HeadTail = HeadTail.second.split('\n');
307 }
308
310 OS << "\n\t} :mem_noshuf" << LoopString;
311 else
312 OS << "\t}" << LoopString;
313 }
314
315 void finish() override { finishAttributeSection(); }
316
317 void finishAttributeSection() override {}
318
319 void emitAttribute(unsigned Attribute, unsigned Value) override {
320 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value);
321 if (getStreamer().isVerboseAsm()) {
324 if (!Name.empty())
325 OS << "\t// " << Name;
326 }
327 OS << "\n";
328 }
329};
330
331class HexagonTargetELFStreamer : public HexagonTargetStreamer {
332public:
333 MCELFStreamer &getStreamer() {
334 return static_cast<MCELFStreamer &>(Streamer);
335 }
336 HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
337 : HexagonTargetStreamer(S) {
338 getStreamer().getWriter().setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI));
339 }
340
341 void emitCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size,
342 unsigned ByteAlignment,
343 unsigned AccessSize) override {
344 HexagonMCELFStreamer &HexagonELFStreamer =
345 static_cast<HexagonMCELFStreamer &>(getStreamer());
346 HexagonELFStreamer.HexagonMCEmitCommonSymbol(
347 Symbol, Size, Align(ByteAlignment), AccessSize);
348 }
349
350 void emitLocalCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size,
351 unsigned ByteAlignment,
352 unsigned AccessSize) override {
353 HexagonMCELFStreamer &HexagonELFStreamer =
354 static_cast<HexagonMCELFStreamer &>(getStreamer());
355 HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
356 Symbol, Size, Align(ByteAlignment), AccessSize);
357 }
358
359 void finish() override { finishAttributeSection(); }
360
361 void reset() override { AttributeSection = nullptr; }
362
363private:
364 MCSection *AttributeSection = nullptr;
365
366 void finishAttributeSection() override {
367 MCELFStreamer &S = getStreamer();
368 if (S.Contents.empty())
369 return;
370
371 S.emitAttributesSection("hexagon", ".hexagon.attributes",
372 ELF::SHT_HEXAGON_ATTRIBUTES, AttributeSection);
373 }
374
375 void emitAttribute(uint32_t Attribute, uint32_t Value) override {
376 getStreamer().setAttributeItem(Attribute, Value,
377 /*OverwriteExisting=*/true);
378 }
379};
380
381} // end anonymous namespace
382
384 MCInstrInfo *X = new MCInstrInfo();
385 InitHexagonMCInstrInfo(X);
386 return X;
387}
388
391 InitHexagonMCRegisterInfo(X, Hexagon::R31, /*DwarfFlavour=*/0,
392 /*EHFlavour=*/0, /*PC=*/Hexagon::PC);
393 return X;
394}
395
397 const Triple &TT,
398 const MCTargetOptions &Options) {
399 MCAsmInfo *MAI = new HexagonMCAsmInfo(TT, Options);
400
401 // VirtualFP = (R30 + #0).
403 nullptr, MRI.getDwarfRegNum(Hexagon::R30, true), 0);
404 MAI->addInitialFrameState(Inst);
405
406 return MAI;
407}
408
410 unsigned SyntaxVariant,
411 const MCAsmInfo &MAI,
412 const MCInstrInfo &MII,
413 const MCRegisterInfo &MRI)
414{
415 if (SyntaxVariant == 0)
416 return new HexagonInstPrinter(MAI, MII, MRI);
417 else
418 return nullptr;
419}
420
423 MCInstPrinter *IP) {
424 return new HexagonTargetAsmStreamer(S, OS, *IP);
425}
426
428 std::unique_ptr<MCAsmBackend> &&MAB,
429 std::unique_ptr<MCObjectWriter> &&OW,
430 std::unique_ptr<MCCodeEmitter> &&Emitter) {
431 return createHexagonELFStreamer(T, Context, std::move(MAB), std::move(OW),
432 std::move(Emitter));
433}
434
435static MCTargetStreamer *
437 return new HexagonTargetELFStreamer(S, STI);
438}
439
443
444[[maybe_unused]] static void clearFeature(MCSubtargetInfo *STI, uint64_t F) {
445 if (STI->hasFeature(F))
446 STI->ToggleFeature(F);
447}
448
449[[maybe_unused]] static bool checkFeature(MCSubtargetInfo *STI, uint64_t F) {
450 return STI->hasFeature(F);
451}
452
453namespace {
454std::string selectHexagonFS(StringRef CPU, StringRef FS) {
456 if (!FS.empty())
457 Result.push_back(FS);
458
459 if (EnableHMX)
460 Result.push_back("+hmx");
461
462 switch (EnableHVX) {
465 break;
467 Result.push_back("+hvxv60");
468 break;
470 Result.push_back("+hvxv62");
471 break;
473 Result.push_back("+hvxv65");
474 break;
476 Result.push_back("+hvxv66");
477 break;
479 Result.push_back("+hvxv67");
480 break;
482 Result.push_back("+hvxv68");
483 break;
485 Result.push_back("+hvxv69");
486 break;
488 Result.push_back("+hvxv71");
489 break;
491 Result.push_back("+hvxv73");
492 break;
494 Result.push_back("+hvxv75");
495 break;
497 Result.push_back("+hvxv79");
498 break;
500 Result.push_back("+hvxv81");
501 break;
503 Result.push_back("+hvxv83");
504 break;
506 Result.push_back("+hvxv85");
507 break;
508
510 Result.push_back(StringSwitch<StringRef>(CPU)
511 .Case("hexagonv60", "+hvxv60")
512 .Case("hexagonv62", "+hvxv62")
513 .Case("hexagonv65", "+hvxv65")
514 .Case("hexagonv66", "+hvxv66")
515 .Case("hexagonv67", "+hvxv67")
516 .Case("hexagonv67t", "+hvxv67")
517 .Case("hexagonv68", "+hvxv68")
518 .Case("hexagonv69", "+hvxv69")
519 .Case("hexagonv71", "+hvxv71")
520 .Case("hexagonv71t", "+hvxv71")
521 .Case("hexagonv73", "+hvxv73")
522 .Case("hexagonv75", "+hvxv75")
523 .Case("hexagonv79", "+hvxv79")
524 .Case("hexagonv81", "+hvxv81")
525 .Case("hexagonv83", "+hvxv83")
526 .Case("hexagonv85", "+hvxv85"));
527 break;
528 }
530 // Sentinel if -mhvx isn't specified
531 break;
532 }
533 if (EnableHvxIeeeFp)
534 Result.push_back("+hvx-ieee-fp");
536 Result.push_back("+cabac");
537 if (EnableHLX)
538 Result.push_back("+hlx");
539
540 return join(Result.begin(), Result.end(), ",");
541}
542}
543
544static bool isCPUValid(StringRef CPU) {
545 return Hexagon::getCpu(CPU).has_value();
546}
547
548namespace {
549std::pair<std::string, std::string> selectCPUAndFS(StringRef CPU,
550 StringRef FS) {
551 std::pair<std::string, std::string> Result;
552 Result.first = std::string(Hexagon_MC::selectHexagonCPU(CPU));
553 Result.second = selectHexagonFS(Result.first, FS);
554 return Result;
555}
556std::mutex ArchSubtargetMutex;
558} // namespace
559
560MCSubtargetInfo const *
562 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
563 auto Existing = ArchSubtarget.find(STI->getCPU());
564 if (Existing == ArchSubtarget.end())
565 return nullptr;
566 return Existing->second.get();
567}
568
570 using namespace Hexagon;
571 // Make sure that +hvx-length turns hvx on, and that "hvx" alone
572 // turns on hvxvNN, corresponding to the existing ArchVNN.
573 FeatureBitset FB = S;
574 unsigned CpuArch = ArchV5;
575 for (unsigned F : {ArchV85, ArchV83, ArchV81, ArchV79, ArchV75, ArchV73,
576 ArchV71, ArchV69, ArchV68, ArchV67, ArchV66, ArchV65,
577 ArchV62, ArchV60, ArchV55, ArchV5}) {
578 if (!FB.test(F))
579 continue;
580 CpuArch = F;
581 break;
582 }
583 bool UseHvx = false;
584 for (unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
585 if (!FB.test(F))
586 continue;
587 UseHvx = true;
588 break;
589 }
590 bool HasHvxVer = false;
591 for (unsigned F :
592 {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, ExtensionHVXV66,
593 ExtensionHVXV67, ExtensionHVXV68, ExtensionHVXV69, ExtensionHVXV71,
594 ExtensionHVXV73, ExtensionHVXV75, ExtensionHVXV79, ExtensionHVXV81,
595 ExtensionHVXV83, ExtensionHVXV85}) {
596 if (!FB.test(F))
597 continue;
598 HasHvxVer = true;
599 UseHvx = true;
600 break;
601 }
602
603 if (!UseHvx || HasHvxVer)
604 return FB;
605
606 // HasHvxVer is false, and UseHvx is true.
607 switch (CpuArch) {
608 case ArchV85:
609 FB.set(ExtensionHVXV85);
610 [[fallthrough]];
611 case ArchV83:
612 FB.set(ExtensionHVXV83);
613 [[fallthrough]];
614 case ArchV81:
615 FB.set(ExtensionHVXV81);
616 [[fallthrough]];
617 case ArchV79:
618 FB.set(ExtensionHVXV79);
619 [[fallthrough]];
620 case ArchV75:
621 FB.set(ExtensionHVXV75);
622 [[fallthrough]];
623 case ArchV73:
624 FB.set(ExtensionHVXV73);
625 [[fallthrough]];
626 case ArchV71:
627 FB.set(ExtensionHVXV71);
628 [[fallthrough]];
629 case ArchV69:
630 FB.set(ExtensionHVXV69);
631 [[fallthrough]];
632 case ArchV68:
633 FB.set(ExtensionHVXV68);
634 [[fallthrough]];
635 case ArchV67:
636 FB.set(ExtensionHVXV67);
637 [[fallthrough]];
638 case ArchV66:
639 FB.set(ExtensionHVXV66);
640 [[fallthrough]];
641 case ArchV65:
642 FB.set(ExtensionHVXV65);
643 [[fallthrough]];
644 case ArchV62:
645 FB.set(ExtensionHVXV62);
646 [[fallthrough]];
647 case ArchV60:
648 FB.set(ExtensionHVXV60);
649 break;
650 }
651 return FB;
652}
653
655 StringRef CPU,
656 StringRef FS) {
657 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
658 StringRef CPUName = Features.first;
659 StringRef ArchFS = Features.second;
660
661 MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(
662 TT, CPUName, /*TuneCPU*/ CPUName, ArchFS);
663 if (X != nullptr && (CPUName == "hexagonv67t" || CPUName == "hexagon71t"))
664 addArchSubtarget(X, ArchFS);
665
666 if (CPU == "help")
667 exit(0);
668
669 if (!isCPUValid(CPUName.str())) {
670 errs() << "error: invalid CPU \"" << CPUName.str().c_str()
671 << "\" specified\n";
672 return nullptr;
673 }
674
675 // Add qfloat subtarget feature by default to v68 and above
676 // unless explicitly disabled
677 if (checkFeature(X, Hexagon::ExtensionHVXV68) &&
678 !ArchFS.contains("-hvx-qfloat")) {
679 llvm::FeatureBitset Features = X->getFeatureBits();
680 X->setFeatureBits(Features.set(Hexagon::ExtensionHVXQFloat));
681 }
682
684 llvm::FeatureBitset Features = X->getFeatureBits();
685 X->setFeatureBits(Features.reset(Hexagon::FeatureDuplex));
686 }
687
688 X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
689
690 // The Z-buffer instructions are grandfathered in for current
691 // architectures but omitted for new ones. Future instruction
692 // sets may introduce new/conflicting z-buffer instructions.
693 const bool ZRegOnDefault =
694 (CPUName == "hexagonv67") || (CPUName == "hexagonv66");
695 if (ZRegOnDefault) {
696 llvm::FeatureBitset Features = X->getFeatureBits();
697 X->setFeatureBits(Features.set(Hexagon::ExtensionZReg));
698 }
699
700 return X;
701}
702
704 assert(STI != nullptr);
705 if (STI->getCPU().contains("t")) {
706 auto ArchSTI = createHexagonMCSubtargetInfo(STI->getTargetTriple(),
707 STI->getCPU().drop_back(), FS);
708 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
709 ArchSubtarget[STI->getCPU()] =
710 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
711 }
712}
713
714std::optional<unsigned>
716 for (auto Arch : {Hexagon::ExtensionHVXV85, Hexagon::ExtensionHVXV83,
717 Hexagon::ExtensionHVXV81, Hexagon::ExtensionHVXV79,
718 Hexagon::ExtensionHVXV75, Hexagon::ExtensionHVXV73,
719 Hexagon::ExtensionHVXV71, Hexagon::ExtensionHVXV69,
720 Hexagon::ExtensionHVXV68, Hexagon::ExtensionHVXV67,
721 Hexagon::ExtensionHVXV66, Hexagon::ExtensionHVXV65,
722 Hexagon::ExtensionHVXV62, Hexagon::ExtensionHVXV60})
723 if (Features.test(Arch))
724 return Arch;
725 return {};
726}
727
728unsigned Hexagon_MC::getArchVersion(const FeatureBitset &Features) {
729 for (auto Arch :
730 {Hexagon::ArchV85, Hexagon::ArchV83, Hexagon::ArchV81, Hexagon::ArchV79,
731 Hexagon::ArchV75, Hexagon::ArchV73, Hexagon::ArchV71, Hexagon::ArchV69,
732 Hexagon::ArchV68, Hexagon::ArchV67, Hexagon::ArchV66, Hexagon::ArchV65,
733 Hexagon::ArchV62, Hexagon::ArchV60, Hexagon::ArchV55, Hexagon::ArchV5})
734 if (Features.test(Arch))
735 return Arch;
736 llvm_unreachable("Expected arch v5-v85");
737 return 0;
738}
739
762
764 const auto &RC = getHexagonMCRegisterClass(Hexagon::VectRegRevRegClassID);
765 return ArrayRef(RC.begin(), RC.end());
766}
767
768namespace {
769class HexagonMCInstrAnalysis : public MCInstrAnalysis {
770public:
771 HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {}
772
773 bool isUnconditionalBranch(MCInst const &Inst) const override {
774 //assert(!HexagonMCInstrInfo::isBundle(Inst));
776 }
777
778 bool isConditionalBranch(MCInst const &Inst) const override {
779 //assert(!HexagonMCInstrInfo::isBundle(Inst));
781 }
782
783 bool evaluateBranch(MCInst const &Inst, uint64_t Addr,
784 uint64_t Size, uint64_t &Target) const override {
785 if (!(isCall(Inst) || isUnconditionalBranch(Inst) ||
786 isConditionalBranch(Inst)))
787 return false;
788
789 //assert(!HexagonMCInstrInfo::isBundle(Inst));
790 if (!HexagonMCInstrInfo::isExtendable(*Info, Inst))
791 return false;
792 auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst));
793 assert(Extended.isExpr());
794 int64_t Value;
795 if (!Extended.getExpr()->evaluateAsAbsolute(Value))
796 return false;
797 Target = Value;
798 return true;
799 }
800
801 uint32_t getValueFromMask(uint32_t Instruction, uint32_t Mask) const {
802 uint32_t Result = 0;
803 uint32_t Offset = 0;
804 while (Mask) {
805 if (Instruction & (Mask & -Mask))
806 Result |= (1 << Offset);
807 Mask &= (Mask - 1);
808 ++Offset;
809 }
810 return Result;
811 }
812
813 std::vector<std::pair<uint64_t, uint64_t>>
814 findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
815 const MCSubtargetInfo &STI) const override {
816 // Do a lightweight parsing of PLT entries.
817 std::vector<std::pair<uint64_t, uint64_t>> Result;
818 for (uint64_t Byte = 0x0, End = PltContents.size(); Byte < End; Byte += 4) {
819 // Recognize immext(##gotpltn)
820 uint32_t ImmExt = support::endian::read32le(PltContents.data() + Byte);
821 if ((ImmExt & 0x00004000) != 0x00004000)
822 continue;
823 uint32_t LoadGotPlt =
824 support::endian::read32le(PltContents.data() + Byte + 4);
825 if ((LoadGotPlt & 0x6a49c00c) != 0x6a49c00c)
826 continue;
827 uint32_t Address = (getValueFromMask(ImmExt, 0xfff3fff) << 6) +
828 getValueFromMask(LoadGotPlt, 0x1f80) + PltSectionVA +
829 Byte;
830 Result.emplace_back(PltSectionVA + Byte, Address);
831 }
832 return Result;
833 }
834};
835} // namespace
836
838 return new HexagonMCInstrAnalysis(Info);
839}
840
841// Force static initialization.
844 // Register the MC asm info.
846
847 // Register the MC instruction info.
850
851 // Register the MC register info.
854
855 // Register the MC subtarget info.
858
859 // Register the MC Code Emitter
862
863 // Register the asm backend
866
867 // Register the MC instruction analyzer.
870
871 // Register the obj streamer
873
874 // Register the obj target streamer
877
878 // Register the asm streamer
881
882 // Register the null streamer
885
886 // Register the MC Inst Printer
889}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
uint64_t uint64_t
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static MCTargetStreamer * createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint)
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
dxil container DXContainer Global Emitter
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 cl::opt< bool > EnableHLX("mhlx", cl::desc("Enable Hexagon HLX"))
static MCInstPrinter * createHexagonMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
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 cl::opt< bool > EnableHMX("mhmx", cl::desc("Enable Hexagon Matrix eXtensions"))
static MCRegisterInfo * createHexagonMCRegisterInfo(const Triple &TT)
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 void clearFeature(MCSubtargetInfo *STI, uint64_t F)
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::V81, "v81", "Build for HVX v81"), clEnumValN(Hexagon::ArchEnum::V83, "v83", "Build for HVX v83"), clEnumValN(Hexagon::ArchEnum::V85, "v85", "Build for HVX v85"), clEnumValN(Hexagon::ArchEnum::Generic, "", "")), cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional)
static bool 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:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
MachineRegisterInfo & MRI
This file contains some functions that are useful when dealing with strings.
std::unique_ptr< MCStreamer > && Streamer
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
const T * data() const
Definition ArrayRef.h:138
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)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition MCAsmInfo.cpp:43
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:628
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...
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 bool isUnconditionalBranch(const MCInst &Inst) const
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...
Streaming machine code generation interface.
Definition MCStreamer.h:222
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
StringRef getCPU() const
const FeatureBitset & ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
Target specific streamer interface.
Definition MCStreamer.h:95
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:446
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
Definition StringRef.h:642
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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.
LLVM_ABI StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
@ EF_HEXAGON_MACH_V5
Definition ELF.h:469
@ EF_HEXAGON_MACH_V79
Definition ELF.h:487
@ EF_HEXAGON_MACH_V71T
Definition ELF.h:482
@ EF_HEXAGON_MACH_V67T
Definition ELF.h:477
@ EF_HEXAGON_MACH_V65
Definition ELF.h:474
@ EF_HEXAGON_MACH_V67
Definition ELF.h:476
@ EF_HEXAGON_MACH_V62
Definition ELF.h:473
@ EF_HEXAGON_MACH_V85
Definition ELF.h:490
@ EF_HEXAGON_MACH_V73
Definition ELF.h:484
@ EF_HEXAGON_MACH_V71
Definition ELF.h:481
@ EF_HEXAGON_MACH_V68
Definition ELF.h:479
@ EF_HEXAGON_MACH_V66
Definition ELF.h:475
@ EF_HEXAGON_MACH_V55
Definition ELF.h:470
@ EF_HEXAGON_MACH_V81
Definition ELF.h:488
@ EF_HEXAGON_MACH_V60
Definition ELF.h:471
@ EF_HEXAGON_MACH_V83
Definition ELF.h:489
@ EF_HEXAGON_MACH_V75
Definition ELF.h:485
@ EF_HEXAGON_MACH_V69
Definition ELF.h:480
@ SHT_HEXAGON_ATTRIBUTES
Definition ELF.h:1054
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)
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
uint32_t read32le(const void *P)
Definition Endian.h:412
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
unsigned HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes)
cl::opt< bool > HexagonDisableCompound
MCCodeEmitter * createHexagonMCCodeEmitter(const MCInstrInfo &MCII, MCContext &MCT)
unsigned HexagonGetLastSlot()
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
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:163
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
MCInstrInfo * createHexagonMCInstrInfo()
ArrayRef(const T &OneElt) -> ArrayRef< T >
MCStreamer * createHexagonELFStreamer(Triple const &TT, MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > CE)
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
cl::opt< bool > HexagonDisableDuplex
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)