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));
94} // namespace
95
97 "mhvx", cl::desc("Enable Hexagon Vector eXtensions"),
98 cl::values(clEnumValN(Hexagon::ArchEnum::V60, "v60", "Build for HVX v60"),
99 clEnumValN(Hexagon::ArchEnum::V62, "v62", "Build for HVX v62"),
100 clEnumValN(Hexagon::ArchEnum::V65, "v65", "Build for HVX v65"),
101 clEnumValN(Hexagon::ArchEnum::V66, "v66", "Build for HVX v66"),
102 clEnumValN(Hexagon::ArchEnum::V67, "v67", "Build for HVX v67"),
103 clEnumValN(Hexagon::ArchEnum::V68, "v68", "Build for HVX v68"),
104 clEnumValN(Hexagon::ArchEnum::V69, "v69", "Build for HVX v69"),
105 clEnumValN(Hexagon::ArchEnum::V71, "v71", "Build for HVX v71"),
106 clEnumValN(Hexagon::ArchEnum::V73, "v73", "Build for HVX v73"),
107 // Sentinel for no value specified.
108 clEnumValN(Hexagon::ArchEnum::Generic, "", "")),
109 // Sentinel for flag not present.
110 cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional);
111
112static cl::opt<bool>
114 cl::desc("Disable Hexagon Vector eXtensions"));
115
116static cl::opt<bool>
118 cl::desc("Enable HVX IEEE floating point extensions"));
120 ("mcabac", cl::desc("tbd"), cl::init(false));
121
122static StringRef DefaultArch = "hexagonv60";
123
125 if (MV5)
126 return "hexagonv5";
127 if (MV55)
128 return "hexagonv55";
129 if (MV60)
130 return "hexagonv60";
131 if (MV62)
132 return "hexagonv62";
133 if (MV65)
134 return "hexagonv65";
135 if (MV66)
136 return "hexagonv66";
137 if (MV67)
138 return "hexagonv67";
139 if (MV67T)
140 return "hexagonv67t";
141 if (MV68)
142 return "hexagonv68";
143 if (MV69)
144 return "hexagonv69";
145 if (MV71)
146 return "hexagonv71";
147 if (MV71T)
148 return "hexagonv71t";
149 if (MV73)
150 return "hexagonv73";
151 return "";
152}
153
156 if (!ArchV.empty() && !CPU.empty()) {
157 // Tiny cores have a "t" suffix that is discarded when creating a secondary
158 // non-tiny subtarget. See: addArchSubtarget
159 std::pair<StringRef, StringRef> ArchP = ArchV.split('t');
160 std::pair<StringRef, StringRef> CPUP = CPU.split('t');
161 if (ArchP.first != CPUP.first)
162 report_fatal_error("conflicting architectures specified.");
163 return CPU;
164 }
165 if (ArchV.empty()) {
166 if (CPU.empty())
167 CPU = DefaultArch;
168 return CPU;
169 }
170 return ArchV;
171}
172
173unsigned llvm::HexagonGetLastSlot() { return HexagonItinerariesV5FU::SLOT3; }
174
175unsigned llvm::HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes) {
176 enum {
177 CVI_NONE = 0,
178 CVI_XLANE = 1 << 0,
179 CVI_SHIFT = 1 << 1,
180 CVI_MPY0 = 1 << 2,
181 CVI_MPY1 = 1 << 3,
182 CVI_ZW = 1 << 4
183 };
184
185 if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
186 ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
187 return (*Lanes = 4, CVI_XLANE);
188 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
189 ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
190 return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
191 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
192 return (*Lanes = 2, CVI_MPY0);
193 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
194 return (*Lanes = 2, CVI_XLANE);
195 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
196 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
197 ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
198 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
199 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
200 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
201 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
202 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
203 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
204 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
205 return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
206 else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
207 return (*Lanes = 1, CVI_ZW);
208 else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
209 return (*Lanes = 1, CVI_XLANE);
210 else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
211 return (*Lanes = 1, CVI_SHIFT);
212
213 return (*Lanes = 0, CVI_NONE);
214}
215
216
217namespace llvm {
218namespace HexagonFUnits {
219bool isSlot0Only(unsigned units) {
220 return HexagonItinerariesV62FU::SLOT0 == units;
221}
222} // namespace HexagonFUnits
223} // namespace llvm
224
225namespace {
226
227class HexagonTargetAsmStreamer : public HexagonTargetStreamer {
229
230public:
231 HexagonTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS,
232 MCInstPrinter &IP)
233 : HexagonTargetStreamer(S), OS(OS) {}
234
235 void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
236 const MCInst &Inst, const MCSubtargetInfo &STI,
237 raw_ostream &OS) override {
240 std::string Buffer;
241 {
242 raw_string_ostream TempStream(Buffer);
243 InstPrinter.printInst(&Inst, Address, "", STI, TempStream);
244 }
245 StringRef Contents(Buffer);
246 auto PacketBundle = Contents.rsplit('\n');
247 auto HeadTail = PacketBundle.first.split('\n');
248 StringRef Separator = "\n";
249 StringRef Indent = "\t";
250 OS << "\t{\n";
251 while (!HeadTail.first.empty()) {
252 StringRef InstTxt;
253 auto Duplex = HeadTail.first.split('\v');
254 if (!Duplex.second.empty()) {
255 OS << Indent << Duplex.first << Separator;
256 InstTxt = Duplex.second;
257 } else if (!HeadTail.first.trim().starts_with("immext")) {
258 InstTxt = Duplex.first;
259 }
260 if (!InstTxt.empty())
261 OS << Indent << InstTxt << Separator;
262 HeadTail = HeadTail.second.split('\n');
263 }
264
266 OS << "\n\t} :mem_noshuf" << PacketBundle.second;
267 else
268 OS << "\t}" << PacketBundle.second;
269 }
270
271 void finish() override { finishAttributeSection(); }
272
273 void finishAttributeSection() override {}
274
275 void emitAttribute(unsigned Attribute, unsigned Value) override {
276 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value);
277 if (getStreamer().isVerboseAsm()) {
280 if (!Name.empty())
281 OS << "\t// " << Name;
282 }
283 OS << "\n";
284 }
285};
286
287class HexagonTargetELFStreamer : public HexagonTargetStreamer {
288public:
290 return static_cast<MCELFStreamer &>(Streamer);
291 }
292 HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
294 getStreamer().getWriter().setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI));
295 }
296
298 unsigned ByteAlignment,
299 unsigned AccessSize) override {
300 HexagonMCELFStreamer &HexagonELFStreamer =
301 static_cast<HexagonMCELFStreamer &>(getStreamer());
302 HexagonELFStreamer.HexagonMCEmitCommonSymbol(
303 Symbol, Size, Align(ByteAlignment), AccessSize);
304 }
305
307 unsigned ByteAlignment,
308 unsigned AccessSize) override {
309 HexagonMCELFStreamer &HexagonELFStreamer =
310 static_cast<HexagonMCELFStreamer &>(getStreamer());
311 HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
312 Symbol, Size, Align(ByteAlignment), AccessSize);
313 }
314
315 void finish() override { finishAttributeSection(); }
316
317 void reset() override { AttributeSection = nullptr; }
318
319private:
320 MCSection *AttributeSection = nullptr;
321
322 void finishAttributeSection() override {
324 if (S.Contents.empty())
325 return;
326
327 S.emitAttributesSection("hexagon", ".hexagon.attributes",
328 ELF::SHT_HEXAGON_ATTRIBUTES, AttributeSection);
329 }
330
332 getStreamer().setAttributeItem(Attribute, Value,
333 /*OverwriteExisting=*/true);
334 }
335};
336
337} // end anonymous namespace
338
340 MCInstrInfo *X = new MCInstrInfo();
341 InitHexagonMCInstrInfo(X);
342 return X;
343}
344
347 InitHexagonMCRegisterInfo(X, Hexagon::R31, /*DwarfFlavour=*/0,
348 /*EHFlavour=*/0, /*PC=*/Hexagon::PC);
349 return X;
350}
351
353 const Triple &TT,
354 const MCTargetOptions &Options) {
355 MCAsmInfo *MAI = new HexagonMCAsmInfo(TT);
356
357 // VirtualFP = (R30 + #0).
359 nullptr, MRI.getDwarfRegNum(Hexagon::R30, true), 0);
360 MAI->addInitialFrameState(Inst);
361
362 return MAI;
363}
364
366 unsigned SyntaxVariant,
367 const MCAsmInfo &MAI,
368 const MCInstrInfo &MII,
369 const MCRegisterInfo &MRI)
370{
371 if (SyntaxVariant == 0)
372 return new HexagonInstPrinter(MAI, MII, MRI);
373 else
374 return nullptr;
375}
376
379 MCInstPrinter *IP) {
380 return new HexagonTargetAsmStreamer(S, OS, *IP);
381}
382
384 std::unique_ptr<MCAsmBackend> &&MAB,
385 std::unique_ptr<MCObjectWriter> &&OW,
386 std::unique_ptr<MCCodeEmitter> &&Emitter) {
387 return createHexagonELFStreamer(T, Context, std::move(MAB), std::move(OW),
388 std::move(Emitter));
389}
390
391static MCTargetStreamer *
393 return new HexagonTargetELFStreamer(S, STI);
394}
395
397 return new HexagonTargetStreamer(S);
398}
399
401 if (STI->hasFeature(F))
402 STI->ToggleFeature(F);
403}
404
406 return STI->hasFeature(F);
407}
408
409namespace {
410std::string selectHexagonFS(StringRef CPU, StringRef FS) {
412 if (!FS.empty())
413 Result.push_back(FS);
414
415 switch (EnableHVX) {
416 case Hexagon::ArchEnum::V5:
417 case Hexagon::ArchEnum::V55:
418 break;
419 case Hexagon::ArchEnum::V60:
420 Result.push_back("+hvxv60");
421 break;
422 case Hexagon::ArchEnum::V62:
423 Result.push_back("+hvxv62");
424 break;
425 case Hexagon::ArchEnum::V65:
426 Result.push_back("+hvxv65");
427 break;
428 case Hexagon::ArchEnum::V66:
429 Result.push_back("+hvxv66");
430 break;
431 case Hexagon::ArchEnum::V67:
432 Result.push_back("+hvxv67");
433 break;
434 case Hexagon::ArchEnum::V68:
435 Result.push_back("+hvxv68");
436 break;
437 case Hexagon::ArchEnum::V69:
438 Result.push_back("+hvxv69");
439 break;
440 case Hexagon::ArchEnum::V71:
441 Result.push_back("+hvxv71");
442 break;
443 case Hexagon::ArchEnum::V73:
444 Result.push_back("+hvxv73");
445 break;
446 case Hexagon::ArchEnum::Generic:{
447 Result.push_back(StringSwitch<StringRef>(CPU)
448 .Case("hexagonv60", "+hvxv60")
449 .Case("hexagonv62", "+hvxv62")
450 .Case("hexagonv65", "+hvxv65")
451 .Case("hexagonv66", "+hvxv66")
452 .Case("hexagonv67", "+hvxv67")
453 .Case("hexagonv67t", "+hvxv67")
454 .Case("hexagonv68", "+hvxv68")
455 .Case("hexagonv69", "+hvxv69")
456 .Case("hexagonv71", "+hvxv71")
457 .Case("hexagonv71t", "+hvxv71")
458 .Case("hexagonv73", "+hvxv73"));
459 break;
460 }
461 case Hexagon::ArchEnum::NoArch:
462 // Sentinel if -mhvx isn't specified
463 break;
464 }
465 if (EnableHvxIeeeFp)
466 Result.push_back("+hvx-ieee-fp");
468 Result.push_back("+cabac");
469
470 return join(Result.begin(), Result.end(), ",");
471}
472}
473
474static bool isCPUValid(StringRef CPU) {
475 return Hexagon::getCpu(CPU).has_value();
476}
477
478namespace {
479std::pair<std::string, std::string> selectCPUAndFS(StringRef CPU,
480 StringRef FS) {
481 std::pair<std::string, std::string> Result;
482 Result.first = std::string(Hexagon_MC::selectHexagonCPU(CPU));
483 Result.second = selectHexagonFS(Result.first, FS);
484 return Result;
485}
486std::mutex ArchSubtargetMutex;
487std::unordered_map<std::string, std::unique_ptr<MCSubtargetInfo const>>
488 ArchSubtarget;
489} // namespace
490
491MCSubtargetInfo const *
493 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
494 auto Existing = ArchSubtarget.find(std::string(STI->getCPU()));
495 if (Existing == ArchSubtarget.end())
496 return nullptr;
497 return Existing->second.get();
498}
499
501 using namespace Hexagon;
502 // Make sure that +hvx-length turns hvx on, and that "hvx" alone
503 // turns on hvxvNN, corresponding to the existing ArchVNN.
504 FeatureBitset FB = S;
505 unsigned CpuArch = ArchV5;
506 for (unsigned F : {ArchV73, ArchV71, ArchV69, ArchV68, ArchV67, ArchV66,
507 ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) {
508 if (!FB.test(F))
509 continue;
510 CpuArch = F;
511 break;
512 }
513 bool UseHvx = false;
514 for (unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
515 if (!FB.test(F))
516 continue;
517 UseHvx = true;
518 break;
519 }
520 bool HasHvxVer = false;
521 for (unsigned F : {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65,
522 ExtensionHVXV66, ExtensionHVXV67, ExtensionHVXV68,
523 ExtensionHVXV69, ExtensionHVXV71, ExtensionHVXV73}) {
524 if (!FB.test(F))
525 continue;
526 HasHvxVer = true;
527 UseHvx = true;
528 break;
529 }
530
531 if (!UseHvx || HasHvxVer)
532 return FB;
533
534 // HasHvxVer is false, and UseHvx is true.
535 switch (CpuArch) {
536 case ArchV73:
537 FB.set(ExtensionHVXV73);
538 [[fallthrough]];
539 case ArchV71:
540 FB.set(ExtensionHVXV71);
541 [[fallthrough]];
542 case ArchV69:
543 FB.set(ExtensionHVXV69);
544 [[fallthrough]];
545 case ArchV68:
546 FB.set(ExtensionHVXV68);
547 [[fallthrough]];
548 case ArchV67:
549 FB.set(ExtensionHVXV67);
550 [[fallthrough]];
551 case ArchV66:
552 FB.set(ExtensionHVXV66);
553 [[fallthrough]];
554 case ArchV65:
555 FB.set(ExtensionHVXV65);
556 [[fallthrough]];
557 case ArchV62:
558 FB.set(ExtensionHVXV62);
559 [[fallthrough]];
560 case ArchV60:
561 FB.set(ExtensionHVXV60);
562 break;
563 }
564 return FB;
565}
566
568 StringRef CPU,
569 StringRef FS) {
570 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
571 StringRef CPUName = Features.first;
572 StringRef ArchFS = Features.second;
573
574 MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(
575 TT, CPUName, /*TuneCPU*/ CPUName, ArchFS);
576 if (X != nullptr && (CPUName == "hexagonv67t" || CPUName == "hexagon71t"))
577 addArchSubtarget(X, ArchFS);
578
579 if (CPU == "help")
580 exit(0);
581
582 if (!isCPUValid(CPUName.str())) {
583 errs() << "error: invalid CPU \"" << CPUName.str().c_str()
584 << "\" specified\n";
585 return nullptr;
586 }
587
588 // Add qfloat subtarget feature by default to v68 and above
589 // unless explicitely disabled
590 if (checkFeature(X, Hexagon::ExtensionHVXV68) &&
591 !ArchFS.contains("-hvx-qfloat")) {
592 llvm::FeatureBitset Features = X->getFeatureBits();
593 X->setFeatureBits(Features.set(Hexagon::ExtensionHVXQFloat));
594 }
595
597 llvm::FeatureBitset Features = X->getFeatureBits();
598 X->setFeatureBits(Features.reset(Hexagon::FeatureDuplex));
599 }
600
601 X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
602
603 // The Z-buffer instructions are grandfathered in for current
604 // architectures but omitted for new ones. Future instruction
605 // sets may introduce new/conflicting z-buffer instructions.
606 const bool ZRegOnDefault =
607 (CPUName == "hexagonv67") || (CPUName == "hexagonv66");
608 if (ZRegOnDefault) {
609 llvm::FeatureBitset Features = X->getFeatureBits();
610 X->setFeatureBits(Features.set(Hexagon::ExtensionZReg));
611 }
612
613 return X;
614}
615
617 assert(STI != nullptr);
618 if (STI->getCPU().contains("t")) {
619 auto ArchSTI = createHexagonMCSubtargetInfo(
620 STI->getTargetTriple(),
621 STI->getCPU().substr(0, STI->getCPU().size() - 1), FS);
622 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
623 ArchSubtarget[std::string(STI->getCPU())] =
624 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
625 }
626}
627
628std::optional<unsigned>
630 for (auto Arch : {Hexagon::ExtensionHVXV73, Hexagon::ExtensionHVXV71,
631 Hexagon::ExtensionHVXV69, Hexagon::ExtensionHVXV68,
632 Hexagon::ExtensionHVXV67, Hexagon::ExtensionHVXV66,
633 Hexagon::ExtensionHVXV65, Hexagon::ExtensionHVXV62,
634 Hexagon::ExtensionHVXV60})
635 if (Features.test(Arch))
636 return Arch;
637 return {};
638}
639
640unsigned Hexagon_MC::getArchVersion(const FeatureBitset &Features) {
641 for (auto Arch :
642 {Hexagon::ArchV73, Hexagon::ArchV71, Hexagon::ArchV69, Hexagon::ArchV68,
643 Hexagon::ArchV67, Hexagon::ArchV66, Hexagon::ArchV65, Hexagon::ArchV62,
644 Hexagon::ArchV60, Hexagon::ArchV55, Hexagon::ArchV5})
645 if (Features.test(Arch))
646 return Arch;
647 llvm_unreachable("Expected arch v5-v73");
648 return 0;
649}
650
652 return StringSwitch<unsigned>(STI.getCPU())
666 .Case("hexagonv73", llvm::ELF::EF_HEXAGON_MACH_V73);
667}
668
670 return ArrayRef(VectRegRev);
671}
672
673namespace {
674class HexagonMCInstrAnalysis : public MCInstrAnalysis {
675public:
676 HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {}
677
678 bool isUnconditionalBranch(MCInst const &Inst) const override {
679 //assert(!HexagonMCInstrInfo::isBundle(Inst));
681 }
682
683 bool isConditionalBranch(MCInst const &Inst) const override {
684 //assert(!HexagonMCInstrInfo::isBundle(Inst));
686 }
687
688 bool evaluateBranch(MCInst const &Inst, uint64_t Addr,
689 uint64_t Size, uint64_t &Target) const override {
690 if (!(isCall(Inst) || isUnconditionalBranch(Inst) ||
691 isConditionalBranch(Inst)))
692 return false;
693
694 //assert(!HexagonMCInstrInfo::isBundle(Inst));
695 if (!HexagonMCInstrInfo::isExtendable(*Info, Inst))
696 return false;
697 auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst));
698 assert(Extended.isExpr());
699 int64_t Value;
700 if (!Extended.getExpr()->evaluateAsAbsolute(Value))
701 return false;
702 Target = Value;
703 return true;
704 }
705};
706}
707
709 return new HexagonMCInstrAnalysis(Info);
710}
711
712// Force static initialization.
714 // Register the MC asm info.
716
717 // Register the MC instruction info.
720
721 // Register the MC register info.
724
725 // Register the MC subtarget info.
728
729 // Register the MC Code Emitter
732
733 // Register the asm backend
736
737 // Register the MC instruction analyzer.
740
741 // Register the obj streamer
743
744 // Register the obj target streamer
747
748 // Register the asm streamer
751
752 // Register the null streamer
755
756 // Register the MC Inst Printer
759}
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)
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::Generic, "", "")), cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional)
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)
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:1175
@ EF_HEXAGON_MACH_V5
Definition: ELF.h:617
@ EF_HEXAGON_MACH_V71T
Definition: ELF.h:628
@ EF_HEXAGON_MACH_V67T
Definition: ELF.h:624
@ EF_HEXAGON_MACH_V65
Definition: ELF.h:621
@ EF_HEXAGON_MACH_V67
Definition: ELF.h:623
@ EF_HEXAGON_MACH_V62
Definition: ELF.h:620
@ EF_HEXAGON_MACH_V73
Definition: ELF.h:629
@ EF_HEXAGON_MACH_V71
Definition: ELF.h:627
@ EF_HEXAGON_MACH_V68
Definition: ELF.h:625
@ EF_HEXAGON_MACH_V66
Definition: ELF.h:622
@ EF_HEXAGON_MACH_V55
Definition: ELF.h:618
@ EF_HEXAGON_MACH_V60
Definition: ELF.h:619
@ EF_HEXAGON_MACH_V69
Definition: ELF.h:626
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)