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
132static cl::opt<bool>
134 cl::desc("Enable HVX IEEE floating point extensions"));
136 ("mcabac", cl::desc("tbd"), cl::init(false));
137
138static constexpr StringRef DefaultArch = "hexagonv68";
139
141 if (MV5)
142 return "hexagonv5";
143 if (MV55)
144 return "hexagonv55";
145 if (MV60)
146 return "hexagonv60";
147 if (MV62)
148 return "hexagonv62";
149 if (MV65)
150 return "hexagonv65";
151 if (MV66)
152 return "hexagonv66";
153 if (MV67)
154 return "hexagonv67";
155 if (MV67T)
156 return "hexagonv67t";
157 if (MV68)
158 return "hexagonv68";
159 if (MV69)
160 return "hexagonv69";
161 if (MV71)
162 return "hexagonv71";
163 if (MV71T)
164 return "hexagonv71t";
165 if (MV73)
166 return "hexagonv73";
167 if (MV75)
168 return "hexagonv75";
169 if (MV79)
170 return "hexagonv79";
171 if (MV81)
172 return "hexagonv81";
173 if (MV83)
174 return "hexagonv83";
175 if (MV85)
176 return "hexagonv85";
177
178 return "";
179}
180
183 if (!ArchV.empty() && !CPU.empty()) {
184 // Tiny cores have a "t" suffix that is discarded when creating a secondary
185 // non-tiny subtarget. See: addArchSubtarget
186 std::pair<StringRef, StringRef> ArchP = ArchV.split('t');
187 std::pair<StringRef, StringRef> CPUP = CPU.split('t');
188 if (ArchP.first != CPUP.first)
189 report_fatal_error("conflicting architectures specified.");
190 return CPU;
191 }
192 if (ArchV.empty()) {
193 if (CPU.empty())
194 CPU = DefaultArch;
195 return CPU;
196 }
197 return ArchV;
198}
199
200unsigned llvm::HexagonGetLastSlot() { return HexagonItinerariesV5FU::SLOT3; }
201
202unsigned llvm::HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes) {
203 enum {
204 CVI_NONE = 0,
205 CVI_XLANE = 1 << 0,
206 CVI_SHIFT = 1 << 1,
207 CVI_MPY0 = 1 << 2,
208 CVI_MPY1 = 1 << 3,
209 CVI_ZW = 1 << 4
210 };
211
212 if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
213 ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
214 return (*Lanes = 4, CVI_XLANE);
215 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
216 ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
217 return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
218 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
219 return (*Lanes = 2, CVI_MPY0);
220 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
221 return (*Lanes = 2, CVI_XLANE);
222 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
223 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
224 ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
225 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
226 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
227 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
228 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
229 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
230 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
231 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
232 return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
233 else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
234 return (*Lanes = 1, CVI_ZW);
235 else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
236 return (*Lanes = 1, CVI_XLANE);
237 else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
238 return (*Lanes = 1, CVI_SHIFT);
239
240 return (*Lanes = 0, CVI_NONE);
241}
242
243
244namespace llvm {
245namespace HexagonFUnits {
246bool isSlot0Only(unsigned units) {
247 return HexagonItinerariesV62FU::SLOT0 == units;
248}
249} // namespace HexagonFUnits
250} // namespace llvm
251
252namespace {
253
254class HexagonTargetAsmStreamer : public HexagonTargetStreamer {
255 formatted_raw_ostream &OS;
256
257public:
258 HexagonTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
259 MCInstPrinter &IP)
260 : HexagonTargetStreamer(S), OS(OS) {}
261
262 void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
263 const MCInst &Inst, const MCSubtargetInfo &STI,
264 raw_ostream &OS) override {
267 std::string Buffer;
268 {
269 raw_string_ostream TempStream(Buffer);
270 for (auto &I : HexagonMCInstrInfo::bundleInstructions(Inst)) {
271 InstPrinter.printInst(I.getInst(), Address, "", STI, TempStream);
272 TempStream << "\n";
273 }
274 }
275
276 std::string LoopString = "";
277 bool IsLoop0 = HexagonMCInstrInfo::isInnerLoop(Inst);
278 bool IsLoop1 = HexagonMCInstrInfo::isOuterLoop(Inst);
279 if (IsLoop0) {
280 LoopString += (IsLoop1 ? " :endloop01" : " :endloop0");
281 } else if (IsLoop1) {
282 LoopString += " :endloop1";
283 }
284
285 StringRef Contents(Buffer);
286 auto PacketBundle = Contents.rsplit('\n');
287 auto HeadTail = PacketBundle.first.split('\n');
288 StringRef Separator = "\n";
289 StringRef Indent = "\t";
290 OS << "\t{\n";
291 while (!HeadTail.first.empty()) {
292 StringRef InstTxt;
293 auto Duplex = HeadTail.first.split('\v');
294 if (!Duplex.second.empty()) {
295 OS << Indent << Duplex.first << Separator;
296 InstTxt = Duplex.second;
297 } else if (!HeadTail.first.trim().starts_with("immext")) {
298 InstTxt = Duplex.first;
299 }
300 if (!InstTxt.empty())
301 OS << Indent << InstTxt << Separator;
302 HeadTail = HeadTail.second.split('\n');
303 }
304
306 OS << "\n\t} :mem_noshuf" << LoopString;
307 else
308 OS << "\t}" << LoopString;
309 }
310
311 void finish() override { finishAttributeSection(); }
312
313 void finishAttributeSection() override {}
314
315 void emitAttribute(unsigned Attribute, unsigned Value) override {
316 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value);
317 if (getStreamer().isVerboseAsm()) {
320 if (!Name.empty())
321 OS << "\t// " << Name;
322 }
323 OS << "\n";
324 }
325};
326
327class HexagonTargetELFStreamer : public HexagonTargetStreamer {
328public:
329 MCELFStreamer &getStreamer() {
330 return static_cast<MCELFStreamer &>(Streamer);
331 }
332 HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
333 : HexagonTargetStreamer(S) {
334 getStreamer().getWriter().setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI));
335 }
336
337 void emitCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size,
338 unsigned ByteAlignment,
339 unsigned AccessSize) override {
340 HexagonMCELFStreamer &HexagonELFStreamer =
341 static_cast<HexagonMCELFStreamer &>(getStreamer());
342 HexagonELFStreamer.HexagonMCEmitCommonSymbol(
343 Symbol, Size, Align(ByteAlignment), AccessSize);
344 }
345
346 void emitLocalCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size,
347 unsigned ByteAlignment,
348 unsigned AccessSize) override {
349 HexagonMCELFStreamer &HexagonELFStreamer =
350 static_cast<HexagonMCELFStreamer &>(getStreamer());
351 HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
352 Symbol, Size, Align(ByteAlignment), AccessSize);
353 }
354
355 void finish() override { finishAttributeSection(); }
356
357 void reset() override { AttributeSection = nullptr; }
358
359private:
360 MCSection *AttributeSection = nullptr;
361
362 void finishAttributeSection() override {
363 MCELFStreamer &S = getStreamer();
364 if (S.Contents.empty())
365 return;
366
367 S.emitAttributesSection("hexagon", ".hexagon.attributes",
368 ELF::SHT_HEXAGON_ATTRIBUTES, AttributeSection);
369 }
370
371 void emitAttribute(uint32_t Attribute, uint32_t Value) override {
372 getStreamer().setAttributeItem(Attribute, Value,
373 /*OverwriteExisting=*/true);
374 }
375};
376
377} // end anonymous namespace
378
380 MCInstrInfo *X = new MCInstrInfo();
381 InitHexagonMCInstrInfo(X);
382 return X;
383}
384
387 InitHexagonMCRegisterInfo(X, Hexagon::R31, /*DwarfFlavour=*/0,
388 /*EHFlavour=*/0, /*PC=*/Hexagon::PC);
389 return X;
390}
391
393 const Triple &TT,
394 const MCTargetOptions &Options) {
395 MCAsmInfo *MAI = new HexagonMCAsmInfo(TT, Options);
396
397 // VirtualFP = (R30 + #0).
399 nullptr, MRI.getDwarfRegNum(Hexagon::R30, true), 0);
400 MAI->addInitialFrameState(Inst);
401
402 return MAI;
403}
404
406 unsigned SyntaxVariant,
407 const MCAsmInfo &MAI,
408 const MCInstrInfo &MII,
409 const MCRegisterInfo &MRI)
410{
411 if (SyntaxVariant == 0)
412 return new HexagonInstPrinter(MAI, MII, MRI);
413 else
414 return nullptr;
415}
416
419 MCInstPrinter *IP) {
420 return new HexagonTargetAsmStreamer(S, OS, *IP);
421}
422
424 std::unique_ptr<MCAsmBackend> &&MAB,
425 std::unique_ptr<MCObjectWriter> &&OW,
426 std::unique_ptr<MCCodeEmitter> &&Emitter) {
427 return createHexagonELFStreamer(T, Context, std::move(MAB), std::move(OW),
428 std::move(Emitter));
429}
430
431static MCTargetStreamer *
433 return new HexagonTargetELFStreamer(S, STI);
434}
435
439
440[[maybe_unused]] static void clearFeature(MCSubtargetInfo *STI, uint64_t F) {
441 if (STI->hasFeature(F))
442 STI->ToggleFeature(F);
443}
444
445[[maybe_unused]] static bool checkFeature(MCSubtargetInfo *STI, uint64_t F) {
446 return STI->hasFeature(F);
447}
448
449namespace {
450std::string selectHexagonFS(StringRef CPU, StringRef FS) {
452 if (!FS.empty())
453 Result.push_back(FS);
454
455 switch (EnableHVX) {
458 break;
460 Result.push_back("+hvxv60");
461 break;
463 Result.push_back("+hvxv62");
464 break;
466 Result.push_back("+hvxv65");
467 break;
469 Result.push_back("+hvxv66");
470 break;
472 Result.push_back("+hvxv67");
473 break;
475 Result.push_back("+hvxv68");
476 break;
478 Result.push_back("+hvxv69");
479 break;
481 Result.push_back("+hvxv71");
482 break;
484 Result.push_back("+hvxv73");
485 break;
487 Result.push_back("+hvxv75");
488 break;
490 Result.push_back("+hvxv79");
491 break;
493 Result.push_back("+hvxv81");
494 break;
496 Result.push_back("+hvxv83");
497 break;
499 Result.push_back("+hvxv85");
500 break;
501
503 Result.push_back(StringSwitch<StringRef>(CPU)
504 .Case("hexagonv60", "+hvxv60")
505 .Case("hexagonv62", "+hvxv62")
506 .Case("hexagonv65", "+hvxv65")
507 .Case("hexagonv66", "+hvxv66")
508 .Case("hexagonv67", "+hvxv67")
509 .Case("hexagonv67t", "+hvxv67")
510 .Case("hexagonv68", "+hvxv68")
511 .Case("hexagonv69", "+hvxv69")
512 .Case("hexagonv71", "+hvxv71")
513 .Case("hexagonv71t", "+hvxv71")
514 .Case("hexagonv73", "+hvxv73")
515 .Case("hexagonv75", "+hvxv75")
516 .Case("hexagonv79", "+hvxv79")
517 .Case("hexagonv81", "+hvxv81")
518 .Case("hexagonv83", "+hvxv83")
519 .Case("hexagonv85", "+hvxv85"));
520 break;
521 }
523 // Sentinel if -mhvx isn't specified
524 break;
525 }
526 if (EnableHvxIeeeFp)
527 Result.push_back("+hvx-ieee-fp");
529 Result.push_back("+cabac");
530
531 return join(Result.begin(), Result.end(), ",");
532}
533}
534
535static bool isCPUValid(StringRef CPU) {
536 return Hexagon::getCpu(CPU).has_value();
537}
538
539namespace {
540std::pair<std::string, std::string> selectCPUAndFS(StringRef CPU,
541 StringRef FS) {
542 std::pair<std::string, std::string> Result;
543 Result.first = std::string(Hexagon_MC::selectHexagonCPU(CPU));
544 Result.second = selectHexagonFS(Result.first, FS);
545 return Result;
546}
547std::mutex ArchSubtargetMutex;
549} // namespace
550
551MCSubtargetInfo const *
553 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
554 auto Existing = ArchSubtarget.find(STI->getCPU());
555 if (Existing == ArchSubtarget.end())
556 return nullptr;
557 return Existing->second.get();
558}
559
561 using namespace Hexagon;
562 // Make sure that +hvx-length turns hvx on, and that "hvx" alone
563 // turns on hvxvNN, corresponding to the existing ArchVNN.
564 FeatureBitset FB = S;
565 unsigned CpuArch = ArchV5;
566 for (unsigned F : {ArchV85, ArchV83, ArchV81, ArchV79, ArchV75, ArchV73,
567 ArchV71, ArchV69, ArchV68, ArchV67, ArchV66, ArchV65,
568 ArchV62, ArchV60, ArchV55, ArchV5}) {
569 if (!FB.test(F))
570 continue;
571 CpuArch = F;
572 break;
573 }
574 bool UseHvx = false;
575 for (unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
576 if (!FB.test(F))
577 continue;
578 UseHvx = true;
579 break;
580 }
581 bool HasHvxVer = false;
582 for (unsigned F :
583 {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, ExtensionHVXV66,
584 ExtensionHVXV67, ExtensionHVXV68, ExtensionHVXV69, ExtensionHVXV71,
585 ExtensionHVXV73, ExtensionHVXV75, ExtensionHVXV79, ExtensionHVXV81,
586 ExtensionHVXV83, ExtensionHVXV85}) {
587 if (!FB.test(F))
588 continue;
589 HasHvxVer = true;
590 UseHvx = true;
591 break;
592 }
593
594 if (!UseHvx || HasHvxVer)
595 return FB;
596
597 // HasHvxVer is false, and UseHvx is true.
598 switch (CpuArch) {
599 case ArchV85:
600 FB.set(ExtensionHVXV85);
601 [[fallthrough]];
602 case ArchV83:
603 FB.set(ExtensionHVXV83);
604 [[fallthrough]];
605 case ArchV81:
606 FB.set(ExtensionHVXV81);
607 [[fallthrough]];
608 case ArchV79:
609 FB.set(ExtensionHVXV79);
610 [[fallthrough]];
611 case ArchV75:
612 FB.set(ExtensionHVXV75);
613 [[fallthrough]];
614 case ArchV73:
615 FB.set(ExtensionHVXV73);
616 [[fallthrough]];
617 case ArchV71:
618 FB.set(ExtensionHVXV71);
619 [[fallthrough]];
620 case ArchV69:
621 FB.set(ExtensionHVXV69);
622 [[fallthrough]];
623 case ArchV68:
624 FB.set(ExtensionHVXV68);
625 [[fallthrough]];
626 case ArchV67:
627 FB.set(ExtensionHVXV67);
628 [[fallthrough]];
629 case ArchV66:
630 FB.set(ExtensionHVXV66);
631 [[fallthrough]];
632 case ArchV65:
633 FB.set(ExtensionHVXV65);
634 [[fallthrough]];
635 case ArchV62:
636 FB.set(ExtensionHVXV62);
637 [[fallthrough]];
638 case ArchV60:
639 FB.set(ExtensionHVXV60);
640 break;
641 }
642 return FB;
643}
644
646 StringRef CPU,
647 StringRef FS) {
648 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
649 StringRef CPUName = Features.first;
650 StringRef ArchFS = Features.second;
651
652 MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(
653 TT, CPUName, /*TuneCPU*/ CPUName, ArchFS);
654 if (X != nullptr && (CPUName == "hexagonv67t" || CPUName == "hexagon71t"))
655 addArchSubtarget(X, ArchFS);
656
657 if (CPU == "help")
658 exit(0);
659
660 if (!isCPUValid(CPUName.str())) {
661 errs() << "error: invalid CPU \"" << CPUName.str().c_str()
662 << "\" specified\n";
663 return nullptr;
664 }
665
666 // Add qfloat subtarget feature by default to v68 and above
667 // unless explicitly disabled
668 if (checkFeature(X, Hexagon::ExtensionHVXV68) &&
669 !ArchFS.contains("-hvx-qfloat")) {
670 llvm::FeatureBitset Features = X->getFeatureBits();
671 X->setFeatureBits(Features.set(Hexagon::ExtensionHVXQFloat));
672 }
673
675 llvm::FeatureBitset Features = X->getFeatureBits();
676 X->setFeatureBits(Features.reset(Hexagon::FeatureDuplex));
677 }
678
679 X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
680
681 // The Z-buffer instructions are grandfathered in for current
682 // architectures but omitted for new ones. Future instruction
683 // sets may introduce new/conflicting z-buffer instructions.
684 const bool ZRegOnDefault =
685 (CPUName == "hexagonv67") || (CPUName == "hexagonv66");
686 if (ZRegOnDefault) {
687 llvm::FeatureBitset Features = X->getFeatureBits();
688 X->setFeatureBits(Features.set(Hexagon::ExtensionZReg));
689 }
690
691 return X;
692}
693
695 assert(STI != nullptr);
696 if (STI->getCPU().contains("t")) {
697 auto ArchSTI = createHexagonMCSubtargetInfo(STI->getTargetTriple(),
698 STI->getCPU().drop_back(), FS);
699 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
700 ArchSubtarget[STI->getCPU()] =
701 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
702 }
703}
704
705std::optional<unsigned>
707 for (auto Arch : {Hexagon::ExtensionHVXV85, Hexagon::ExtensionHVXV83,
708 Hexagon::ExtensionHVXV81, Hexagon::ExtensionHVXV79,
709 Hexagon::ExtensionHVXV75, Hexagon::ExtensionHVXV73,
710 Hexagon::ExtensionHVXV71, Hexagon::ExtensionHVXV69,
711 Hexagon::ExtensionHVXV68, Hexagon::ExtensionHVXV67,
712 Hexagon::ExtensionHVXV66, Hexagon::ExtensionHVXV65,
713 Hexagon::ExtensionHVXV62, Hexagon::ExtensionHVXV60})
714 if (Features.test(Arch))
715 return Arch;
716 return {};
717}
718
719unsigned Hexagon_MC::getArchVersion(const FeatureBitset &Features) {
720 for (auto Arch :
721 {Hexagon::ArchV85, Hexagon::ArchV83, Hexagon::ArchV81, Hexagon::ArchV79,
722 Hexagon::ArchV75, Hexagon::ArchV73, Hexagon::ArchV71, Hexagon::ArchV69,
723 Hexagon::ArchV68, Hexagon::ArchV67, Hexagon::ArchV66, Hexagon::ArchV65,
724 Hexagon::ArchV62, Hexagon::ArchV60, Hexagon::ArchV55, Hexagon::ArchV5})
725 if (Features.test(Arch))
726 return Arch;
727 llvm_unreachable("Expected arch v5-v85");
728 return 0;
729}
730
753
755 const auto &RC = getHexagonMCRegisterClass(Hexagon::VectRegRevRegClassID);
756 return ArrayRef(RC.begin(), RC.end());
757}
758
759namespace {
760class HexagonMCInstrAnalysis : public MCInstrAnalysis {
761public:
762 HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {}
763
764 bool isUnconditionalBranch(MCInst const &Inst) const override {
765 //assert(!HexagonMCInstrInfo::isBundle(Inst));
767 }
768
769 bool isConditionalBranch(MCInst const &Inst) const override {
770 //assert(!HexagonMCInstrInfo::isBundle(Inst));
772 }
773
774 bool evaluateBranch(MCInst const &Inst, uint64_t Addr,
775 uint64_t Size, uint64_t &Target) const override {
776 if (!(isCall(Inst) || isUnconditionalBranch(Inst) ||
777 isConditionalBranch(Inst)))
778 return false;
779
780 //assert(!HexagonMCInstrInfo::isBundle(Inst));
781 if (!HexagonMCInstrInfo::isExtendable(*Info, Inst))
782 return false;
783 auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst));
784 assert(Extended.isExpr());
785 int64_t Value;
786 if (!Extended.getExpr()->evaluateAsAbsolute(Value))
787 return false;
788 Target = Value;
789 return true;
790 }
791
792 uint32_t getValueFromMask(uint32_t Instruction, uint32_t Mask) const {
793 uint32_t Result = 0;
794 uint32_t Offset = 0;
795 while (Mask) {
796 if (Instruction & (Mask & -Mask))
797 Result |= (1 << Offset);
798 Mask &= (Mask - 1);
799 ++Offset;
800 }
801 return Result;
802 }
803
804 std::vector<std::pair<uint64_t, uint64_t>>
805 findPltEntries(uint64_t PltSectionVA, ArrayRef<uint8_t> PltContents,
806 const MCSubtargetInfo &STI) const override {
807 // Do a lightweight parsing of PLT entries.
808 std::vector<std::pair<uint64_t, uint64_t>> Result;
809 for (uint64_t Byte = 0x0, End = PltContents.size(); Byte < End; Byte += 4) {
810 // Recognize immext(##gotpltn)
811 uint32_t ImmExt = support::endian::read32le(PltContents.data() + Byte);
812 if ((ImmExt & 0x00004000) != 0x00004000)
813 continue;
814 uint32_t LoadGotPlt =
815 support::endian::read32le(PltContents.data() + Byte + 4);
816 if ((LoadGotPlt & 0x6a49c00c) != 0x6a49c00c)
817 continue;
818 uint32_t Address = (getValueFromMask(ImmExt, 0xfff3fff) << 6) +
819 getValueFromMask(LoadGotPlt, 0x1f80) + PltSectionVA +
820 Byte;
821 Result.emplace_back(PltSectionVA + Byte, Address);
822 }
823 return Result;
824 }
825};
826} // namespace
827
829 return new HexagonMCInstrAnalysis(Info);
830}
831
832// Force static initialization.
835 // Register the MC asm info.
837
838 // Register the MC instruction info.
841
842 // Register the MC register info.
845
846 // Register the MC subtarget info.
849
850 // Register the MC Code Emitter
853
854 // Register the asm backend
857
858 // Register the MC instruction analyzer.
861
862 // Register the obj streamer
864
865 // Register the obj target streamer
868
869 // Register the asm streamer
872
873 // Register the null streamer
876
877 // Register the MC Inst Printer
880}
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 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 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)