45#include <unordered_map>
49#define GET_INSTRINFO_MC_DESC
50#define ENABLE_INSTR_PREDICATE_VERIFIER
51#include "HexagonGenInstrInfo.inc"
53#define GET_SUBTARGETINFO_MC_DESC
54#include "HexagonGenSubtargetInfo.inc"
56#define GET_REGINFO_MC_DESC
57#include "HexagonGenRegisterInfo.inc"
61 cl::desc(
"Disable looking for compound instructions for Hexagon"));
65 cl::desc(
"Disable looking for duplex instructions for Hexagon"));
99 "mhvx",
cl::desc(
"Enable Hexagon Vector eXtensions"),
101 clEnumValN(Hexagon::ArchEnum::V62,
"v62",
"Build for HVX v62"),
102 clEnumValN(Hexagon::ArchEnum::V65,
"v65",
"Build for HVX v65"),
103 clEnumValN(Hexagon::ArchEnum::V66,
"v66",
"Build for HVX v66"),
104 clEnumValN(Hexagon::ArchEnum::V67,
"v67",
"Build for HVX v67"),
105 clEnumValN(Hexagon::ArchEnum::V68,
"v68",
"Build for HVX v68"),
106 clEnumValN(Hexagon::ArchEnum::V69,
"v69",
"Build for HVX v69"),
107 clEnumValN(Hexagon::ArchEnum::V71,
"v71",
"Build for HVX v71"),
108 clEnumValN(Hexagon::ArchEnum::V73,
"v73",
"Build for HVX v73"),
109 clEnumValN(Hexagon::ArchEnum::V75,
"v75",
"Build for HVX v75"),
111 clEnumValN(Hexagon::ArchEnum::Generic,
"",
"")),
117 cl::desc(
"Disable Hexagon Vector eXtensions"));
121 cl::desc(
"Enable HVX IEEE floating point extensions"));
143 return "hexagonv67t";
151 return "hexagonv71t";
164 std::pair<StringRef, StringRef> ArchP = ArchV.
split(
't');
165 std::pair<StringRef, StringRef> CPUP = CPU.
split(
't');
166 if (ArchP.first != CPUP.first)
190 if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
191 ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
192 return (*Lanes = 4, CVI_XLANE);
193 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
194 ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
195 return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
196 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
197 return (*Lanes = 2, CVI_MPY0);
198 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
199 return (*Lanes = 2, CVI_XLANE);
200 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
201 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
202 ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
203 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
204 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
205 else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
206 ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
207 return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
208 else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
209 ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
210 return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
211 else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
212 return (*Lanes = 1, CVI_ZW);
213 else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
214 return (*Lanes = 1, CVI_XLANE);
215 else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
216 return (*Lanes = 1, CVI_SHIFT);
218 return (*Lanes = 0, CVI_NONE);
223namespace HexagonFUnits {
225 return HexagonItinerariesV62FU::SLOT0 == units;
248 InstPrinter.
printInst(&Inst, Address,
"", STI, TempStream);
251 auto PacketBundle = Contents.rsplit(
'\n');
252 auto HeadTail = PacketBundle.first.split(
'\n');
256 while (!HeadTail.first.empty()) {
258 auto Duplex = HeadTail.first.
split(
'\v');
259 if (!Duplex.second.empty()) {
260 OS << Indent << Duplex.first << Separator;
261 InstTxt = Duplex.second;
262 }
else if (!HeadTail.first.trim().starts_with(
"immext")) {
263 InstTxt = Duplex.first;
265 if (!InstTxt.
empty())
266 OS << Indent << InstTxt << Separator;
267 HeadTail = HeadTail.second.
split(
'\n');
271 OS <<
"\n\t} :mem_noshuf" << PacketBundle.second;
273 OS <<
"\t}" << PacketBundle.second;
303 unsigned ByteAlignment,
304 unsigned AccessSize)
override {
308 Symbol,
Size,
Align(ByteAlignment), AccessSize);
312 unsigned ByteAlignment,
313 unsigned AccessSize)
override {
317 Symbol,
Size,
Align(ByteAlignment), AccessSize);
322 void reset()
override { AttributeSection =
nullptr; }
346 InitHexagonMCInstrInfo(
X);
352 InitHexagonMCRegisterInfo(
X, Hexagon::R31, 0,
364 nullptr,
MRI.getDwarfRegNum(Hexagon::R30,
true), 0);
371 unsigned SyntaxVariant,
376 if (SyntaxVariant == 0)
385 return new HexagonTargetAsmStreamer(S,
OS, *IP);
389 std::unique_ptr<MCAsmBackend> &&MAB,
390 std::unique_ptr<MCObjectWriter> &&OW,
391 std::unique_ptr<MCCodeEmitter> &&
Emitter) {
398 return new HexagonTargetELFStreamer(S, STI);
421 case Hexagon::ArchEnum::V5:
422 case Hexagon::ArchEnum::V55:
424 case Hexagon::ArchEnum::V60:
425 Result.push_back(
"+hvxv60");
427 case Hexagon::ArchEnum::V62:
428 Result.push_back(
"+hvxv62");
430 case Hexagon::ArchEnum::V65:
431 Result.push_back(
"+hvxv65");
433 case Hexagon::ArchEnum::V66:
434 Result.push_back(
"+hvxv66");
436 case Hexagon::ArchEnum::V67:
437 Result.push_back(
"+hvxv67");
439 case Hexagon::ArchEnum::V68:
440 Result.push_back(
"+hvxv68");
442 case Hexagon::ArchEnum::V69:
443 Result.push_back(
"+hvxv69");
445 case Hexagon::ArchEnum::V71:
446 Result.push_back(
"+hvxv71");
448 case Hexagon::ArchEnum::V73:
449 Result.push_back(
"+hvxv73");
451 case Hexagon::ArchEnum::V75:
452 Result.push_back(
"+hvxv75");
454 case Hexagon::ArchEnum::Generic: {
456 .Case(
"hexagonv60",
"+hvxv60")
457 .Case(
"hexagonv62",
"+hvxv62")
458 .Case(
"hexagonv65",
"+hvxv65")
459 .Case(
"hexagonv66",
"+hvxv66")
460 .Case(
"hexagonv67",
"+hvxv67")
461 .Case(
"hexagonv67t",
"+hvxv67")
462 .Case(
"hexagonv68",
"+hvxv68")
463 .Case(
"hexagonv69",
"+hvxv69")
464 .Case(
"hexagonv71",
"+hvxv71")
465 .Case(
"hexagonv71t",
"+hvxv71")
466 .Case(
"hexagonv73",
"+hvxv73")
467 .Case(
"hexagonv75",
"+hvxv75"));
470 case Hexagon::ArchEnum::NoArch:
475 Result.push_back(
"+hvx-ieee-fp");
477 Result.push_back(
"+cabac");
488std::pair<std::string, std::string> selectCPUAndFS(
StringRef CPU,
490 std::pair<std::string, std::string>
Result;
495std::mutex ArchSubtargetMutex;
496std::unordered_map<std::string, std::unique_ptr<MCSubtargetInfo const>>
502 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
503 auto Existing = ArchSubtarget.find(std::string(STI->
getCPU()));
504 if (Existing == ArchSubtarget.end())
506 return Existing->second.get();
510 using namespace Hexagon;
514 unsigned CpuArch = ArchV5;
515 for (
unsigned F : {ArchV75, ArchV73, ArchV71, ArchV69, ArchV68, ArchV67,
516 ArchV66, ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) {
523 for (
unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
529 bool HasHvxVer =
false;
531 {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65, ExtensionHVXV66,
532 ExtensionHVXV67, ExtensionHVXV68, ExtensionHVXV69, ExtensionHVXV71,
533 ExtensionHVXV73, ExtensionHVXV75}) {
541 if (!UseHvx || HasHvxVer)
547 FB.
set(ExtensionHVXV75);
550 FB.
set(ExtensionHVXV73);
553 FB.
set(ExtensionHVXV71);
556 FB.
set(ExtensionHVXV69);
559 FB.
set(ExtensionHVXV68);
562 FB.
set(ExtensionHVXV67);
565 FB.
set(ExtensionHVXV66);
568 FB.
set(ExtensionHVXV65);
571 FB.
set(ExtensionHVXV62);
574 FB.
set(ExtensionHVXV60);
583 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
588 TT, CPUName, CPUName, ArchFS);
589 if (
X !=
nullptr && (CPUName ==
"hexagonv67t" || CPUName ==
"hexagon71t"))
596 errs() <<
"error: invalid CPU \"" << CPUName.
str().c_str()
606 X->setFeatureBits(Features.
set(Hexagon::ExtensionHVXQFloat));
611 X->setFeatureBits(Features.
reset(Hexagon::FeatureDuplex));
619 const bool ZRegOnDefault =
620 (CPUName ==
"hexagonv67") || (CPUName ==
"hexagonv66");
623 X->setFeatureBits(Features.
set(Hexagon::ExtensionZReg));
635 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
636 ArchSubtarget[std::string(STI->
getCPU())] =
637 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
641std::optional<unsigned>
643 for (
auto Arch : {Hexagon::ExtensionHVXV75, Hexagon::ExtensionHVXV73,
644 Hexagon::ExtensionHVXV71, Hexagon::ExtensionHVXV69,
645 Hexagon::ExtensionHVXV68, Hexagon::ExtensionHVXV67,
646 Hexagon::ExtensionHVXV66, Hexagon::ExtensionHVXV65,
647 Hexagon::ExtensionHVXV62, Hexagon::ExtensionHVXV60})
648 if (Features.
test(Arch))
655 {Hexagon::ArchV75, Hexagon::ArchV73, Hexagon::ArchV71, Hexagon::ArchV69,
656 Hexagon::ArchV68, Hexagon::ArchV67, Hexagon::ArchV66, Hexagon::ArchV65,
657 Hexagon::ArchV62, Hexagon::ArchV60, Hexagon::ArchV55, Hexagon::ArchV5})
658 if (Features.
test(Arch))
723 return new HexagonMCInstrAnalysis(
Info);
unsigned const MachineRegisterInfo * MRI
Analysis containing CSE Info
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define LLVM_ATTRIBUTE_UNUSED
#define LLVM_EXTERNAL_VISIBILITY
dxil DXContainer Global Emitter
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
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::Generic, "", "")), cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional)
static cl::opt< bool > EnableHexagonCabac("mcabac", cl::desc("tbd"), cl::init(false))
static MCTargetStreamer * createHexagonNullTargetStreamer(MCStreamer &S)
static MCTargetStreamer * createHexagonObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
static MCTargetStreamer * createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *IP)
static MCInstrAnalysis * createHexagonMCInstrAnalysis(const MCInstrInfo *Info)
static MCInstPrinter * createHexagonMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static void LLVM_ATTRIBUTE_UNUSED clearFeature(MCSubtargetInfo *STI, uint64_t F)
static cl::opt< bool > DisableHVX("mno-hvx", cl::Hidden, cl::desc("Disable Hexagon Vector eXtensions"))
static MCStreamer * createMCStreamer(Triple const &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static bool isCPUValid(StringRef CPU)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonTargetMC()
static MCRegisterInfo * createHexagonMCRegisterInfo(const Triple &TT)
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Container class for subtarget features.
constexpr FeatureBitset & reset(unsigned I)
constexpr bool test(unsigned I) const
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)
virtual void finishAttributeSection()
This class is intended to be used as a base class for asm properties and features specific to the tar...
void addInitialFrameState(const MCCFIInstruction &Inst)
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.
Context object for machine code objects.
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.
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.
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.
Streaming machine code generation interface.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() 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 ...
Target specific streamer interface.
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address, const MCInst &Inst, const MCSubtargetInfo &STI, raw_ostream &OS)
MCStreamer & getStreamer()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef attrTypeAsString(unsigned attr, TagNameMap tagNameMap, bool hasTagPrefix=true)
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)
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)
This is an optimization pass for GlobalISel generic memory operations.
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.
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.
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)