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"));
97 "mhvx",
cl::desc(
"Enable Hexagon Vector eXtensions"),
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"),
108 clEnumValN(Hexagon::ArchEnum::Generic,
"",
"")),
114 cl::desc(
"Disable Hexagon Vector eXtensions"));
118 cl::desc(
"Enable HVX IEEE floating point extensions"));
140 return "hexagonv67t";
148 return "hexagonv71t";
159 std::pair<StringRef, StringRef> ArchP = ArchV.
split(
't');
160 std::pair<StringRef, StringRef> CPUP = CPU.
split(
't');
161 if (ArchP.first != CPUP.first)
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);
213 return (*Lanes = 0, CVI_NONE);
218namespace HexagonFUnits {
220 return HexagonItinerariesV62FU::SLOT0 == units;
243 InstPrinter.
printInst(&Inst, Address,
"", STI, TempStream);
246 auto PacketBundle = Contents.rsplit(
'\n');
247 auto HeadTail = PacketBundle.first.split(
'\n');
251 while (!HeadTail.first.empty()) {
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;
260 if (!InstTxt.
empty())
261 OS << Indent << InstTxt << Separator;
262 HeadTail = HeadTail.second.
split(
'\n');
266 OS <<
"\n\t} :mem_noshuf" << PacketBundle.second;
268 OS <<
"\t}" << PacketBundle.second;
298 unsigned ByteAlignment,
299 unsigned AccessSize)
override {
303 Symbol,
Size,
Align(ByteAlignment), AccessSize);
307 unsigned ByteAlignment,
308 unsigned AccessSize)
override {
312 Symbol,
Size,
Align(ByteAlignment), AccessSize);
317 void reset()
override { AttributeSection =
nullptr; }
341 InitHexagonMCInstrInfo(
X);
347 InitHexagonMCRegisterInfo(
X, Hexagon::R31, 0,
359 nullptr,
MRI.getDwarfRegNum(Hexagon::R30,
true), 0);
366 unsigned SyntaxVariant,
371 if (SyntaxVariant == 0)
380 return new HexagonTargetAsmStreamer(S,
OS, *IP);
384 std::unique_ptr<MCAsmBackend> &&MAB,
385 std::unique_ptr<MCObjectWriter> &&OW,
386 std::unique_ptr<MCCodeEmitter> &&
Emitter) {
393 return new HexagonTargetELFStreamer(S, STI);
416 case Hexagon::ArchEnum::V5:
417 case Hexagon::ArchEnum::V55:
419 case Hexagon::ArchEnum::V60:
420 Result.push_back(
"+hvxv60");
422 case Hexagon::ArchEnum::V62:
423 Result.push_back(
"+hvxv62");
425 case Hexagon::ArchEnum::V65:
426 Result.push_back(
"+hvxv65");
428 case Hexagon::ArchEnum::V66:
429 Result.push_back(
"+hvxv66");
431 case Hexagon::ArchEnum::V67:
432 Result.push_back(
"+hvxv67");
434 case Hexagon::ArchEnum::V68:
435 Result.push_back(
"+hvxv68");
437 case Hexagon::ArchEnum::V69:
438 Result.push_back(
"+hvxv69");
440 case Hexagon::ArchEnum::V71:
441 Result.push_back(
"+hvxv71");
443 case Hexagon::ArchEnum::V73:
444 Result.push_back(
"+hvxv73");
446 case Hexagon::ArchEnum::Generic:{
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"));
461 case Hexagon::ArchEnum::NoArch:
466 Result.push_back(
"+hvx-ieee-fp");
468 Result.push_back(
"+cabac");
479std::pair<std::string, std::string> selectCPUAndFS(
StringRef CPU,
481 std::pair<std::string, std::string>
Result;
486std::mutex ArchSubtargetMutex;
487std::unordered_map<std::string, std::unique_ptr<MCSubtargetInfo const>>
493 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
494 auto Existing = ArchSubtarget.find(std::string(STI->
getCPU()));
495 if (Existing == ArchSubtarget.end())
497 return Existing->second.get();
501 using namespace Hexagon;
505 unsigned CpuArch = ArchV5;
506 for (
unsigned F : {ArchV73, ArchV71, ArchV69, ArchV68, ArchV67, ArchV66,
507 ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) {
514 for (
unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
520 bool HasHvxVer =
false;
521 for (
unsigned F : {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65,
522 ExtensionHVXV66, ExtensionHVXV67, ExtensionHVXV68,
523 ExtensionHVXV69, ExtensionHVXV71, ExtensionHVXV73}) {
531 if (!UseHvx || HasHvxVer)
537 FB.
set(ExtensionHVXV73);
540 FB.
set(ExtensionHVXV71);
543 FB.
set(ExtensionHVXV69);
546 FB.
set(ExtensionHVXV68);
549 FB.
set(ExtensionHVXV67);
552 FB.
set(ExtensionHVXV66);
555 FB.
set(ExtensionHVXV65);
558 FB.
set(ExtensionHVXV62);
561 FB.
set(ExtensionHVXV60);
570 std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
575 TT, CPUName, CPUName, ArchFS);
576 if (
X !=
nullptr && (CPUName ==
"hexagonv67t" || CPUName ==
"hexagon71t"))
583 errs() <<
"error: invalid CPU \"" << CPUName.
str().c_str()
593 X->setFeatureBits(Features.
set(Hexagon::ExtensionHVXQFloat));
598 X->setFeatureBits(Features.
reset(Hexagon::FeatureDuplex));
606 const bool ZRegOnDefault =
607 (CPUName ==
"hexagonv67") || (CPUName ==
"hexagonv66");
610 X->setFeatureBits(Features.
set(Hexagon::ExtensionZReg));
622 std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
623 ArchSubtarget[std::string(STI->
getCPU())] =
624 std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
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))
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))
709 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")
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
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)