#ifndef LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
#define LLVM_LIB_TARGET_HEXAGON_MCTARGETDESC_HEXAGONMCINSTRINFO_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/MC/MCInst.h"
#include "llvm/Support/MathExtras.h"
#include <cstddef>
#include <cstdint>
namespace llvm {
class HexagonMCChecker;
class MCContext;
class MCExpr;
class MCInstrDesc;
class MCInstrInfo;
class MCRegisterInfo;
class MCSubtargetInfo;
class DuplexCandidate {
public:
unsigned packetIndexI, packetIndexJ, iClass;
DuplexCandidate(unsigned i, unsigned j, unsigned iClass)
: packetIndexI(i), packetIndexJ(j), iClass(iClass) {}
};
namespace Hexagon {
class PacketIterator : public std::iterator<std::forward_iterator_tag,
PacketIterator> {
MCInstrInfo const &MCII;
MCInst::const_iterator BundleCurrent;
MCInst::const_iterator BundleEnd;
MCInst::const_iterator DuplexCurrent;
MCInst::const_iterator DuplexEnd;
public:
PacketIterator(MCInstrInfo const &MCII, MCInst const &Inst);
PacketIterator(MCInstrInfo const &MCII, MCInst const &Inst, std::nullptr_t);
PacketIterator &operator++();
MCInst const &operator*() const;
bool operator==(PacketIterator const &Other) const;
bool operator!=(PacketIterator const &Other) const {
return !(*this == Other);
}
};
}
namespace HexagonMCInstrInfo {
constexpr size_t innerLoopOffset = 0;
constexpr int64_t innerLoopMask = 1 << innerLoopOffset;
constexpr size_t outerLoopOffset = 1;
constexpr int64_t outerLoopMask = 1 << outerLoopOffset;
constexpr size_t memReorderDisabledOffset = 2;
constexpr int64_t memReorderDisabledMask = 1 << memReorderDisabledOffset;
constexpr size_t splitNoMemOrderOffset = 3;
constexpr int64_t splitNoMemorderMask = 1 << splitNoMemOrderOffset;
constexpr size_t noShuffleOffset = 4;
constexpr int64_t noShuffleMask = 1 << noShuffleOffset;
constexpr size_t bundleInstructionsOffset = 1;
void addConstant(MCInst &MI, uint64_t Value, MCContext &Context);
void addConstExtender(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB,
MCInst const &MCI);
iterator_range<Hexagon::PacketIterator>
bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI);
iterator_range<MCInst::const_iterator> bundleInstructions(MCInst const &MCI);
size_t bundleSize(MCInst const &MCI);
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCContext &Context, MCInst &MCB,
HexagonMCChecker *Checker,
bool AttemptCompatibility = false);
bool IsABranchingInst(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCInst const &I);
MCInst *deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0,
MCInst const &inst1);
MCInst deriveExtender(MCInstrInfo const &MCII, MCInst const &Inst,
MCOperand const &MO);
MCInst deriveSubInst(MCInst const &Inst);
MCInst const *extenderForIndex(MCInst const &MCB, size_t Index);
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB,
MCInst const &MCI);
unsigned getMemAccessSize(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned getAddrMode(MCInstrInfo const &MCII, MCInst const &MCI);
MCInstrDesc const &getDesc(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned getDuplexCandidateGroup(MCInst const &MI);
SmallVector<DuplexCandidate, 8>
getDuplexPossibilties(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCInst const &MCB);
unsigned getDuplexRegisterNumbering(unsigned Reg);
MCExpr const &getExpr(MCExpr const &Expr);
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI);
MCOperand const &getExtendableOperand(MCInstrInfo const &MCII,
MCInst const &MCI);
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI);
bool isExtentSigned(MCInstrInfo const &MCII, MCInst const &MCI);
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI);
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI);
StringRef getName(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI);
MCOperand const &getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned short getNewValueOp2(MCInstrInfo const &MCII, MCInst const &MCI);
MCOperand const &getNewValueOperand2(MCInstrInfo const &MCII,
MCInst const &MCI);
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned getCVIResources(MCInstrInfo const &MCII,
MCSubtargetInfo const &STI,
MCInst const &MCI);
unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCInst const &MCI);
unsigned getOtherReservedSlots(MCInstrInfo const &MCII,
MCSubtargetInfo const &STI, MCInst const &MCI);
bool hasDuplex(MCInstrInfo const &MCII, MCInst const &MCI);
bool hasExtenderForIndex(MCInst const &MCB, size_t Index);
bool hasImmExt(MCInst const &MCI);
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI);
bool hasTmpDst(MCInstrInfo const &MCII, MCInst const &MCI);
bool hasHvxTmp(MCInstrInfo const &MCII, MCInst const &MCI);
unsigned iClassOfDuplexPair(unsigned Ga, unsigned Gb);
int64_t minConstant(MCInst const &MCI, size_t Index);
template <unsigned N, unsigned S>
bool inRange(MCInst const &MCI, size_t Index) {
return isShiftedUInt<N, S>(minConstant(MCI, Index));
}
template <unsigned N, unsigned S>
bool inSRange(MCInst const &MCI, size_t Index) {
return isShiftedInt<N, S>(minConstant(MCI, Index));
}
template <unsigned N> bool inRange(MCInst const &MCI, size_t Index) {
return isUInt<N>(minConstant(MCI, Index));
}
MCInst const &instruction(MCInst const &MCB, size_t Index);
bool isAccumulator(MCInstrInfo const &MCII, MCInst const &MCI);
bool isBundle(MCInst const &MCI);
bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI);
bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI);
bool isCofRelax1(MCInstrInfo const &MCII, MCInst const &MCI);
bool isCofRelax2(MCInstrInfo const &MCII, MCInst const &MCI);
bool isCompound(MCInstrInfo const &MCII, MCInst const &MCI);
bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI);
bool isCVINew(MCInstrInfo const &MCII, MCInst const &MCI);
bool isDblRegForSubInst(unsigned Reg);
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI);
bool isDuplexPair(MCInst const &MIa, MCInst const &MIb);
bool isDuplexPairMatch(unsigned Ga, unsigned Gb);
bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI);
bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI);
bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI);
bool isHVX(MCInstrInfo const &MCII, MCInst const &MCI);
bool isImmext(MCInst const &MCI);
bool isInnerLoop(MCInst const &MCI);
bool isIntReg(unsigned Reg);
bool isIntRegForSubInst(unsigned Reg);
bool isMemReorderDisabled(MCInst const &MCI);
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI);
bool isNewValueStore(MCInstrInfo const &MCII, MCInst const &MCI);
bool isOpExtendable(MCInstrInfo const &MCII, MCInst const &MCI, unsigned short);
bool isOrderedDuplexPair(MCInstrInfo const &MCII, MCInst const &MIa,
bool ExtendedA, MCInst const &MIb, bool ExtendedB,
bool bisReversable, MCSubtargetInfo const &STI);
bool isOuterLoop(MCInst const &MCI);
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI);
bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI);
bool isPredicatedNew(MCInstrInfo const &MCII, MCInst const &MCI);
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI);
bool isPredReg(MCRegisterInfo const &MRI, unsigned Reg);
bool isPredRegister(MCInstrInfo const &MCII, MCInst const &Inst, unsigned I);
bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI);
bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI);
bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI);
bool isRestrictSlot1AOK(MCInstrInfo const &MCII, MCInst const &MCI);
bool isRestrictNoSlot1Store(MCInstrInfo const &MCII, MCInst const &MCI);
bool isSubInstruction(MCInst const &MCI);
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI);
bool mustExtend(MCExpr const &Expr);
bool mustNotExtend(MCExpr const &Expr);
bool requiresSlot(MCSubtargetInfo const &STI, MCInst const &MCI);
bool LoopNeedsPadding(MCInst const &MCB);
unsigned packetSize(StringRef CPU);
unsigned packetSizeSlots(MCSubtargetInfo const &STI);
unsigned slotsConsumed(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCInst const &MCI);
void padEndloop(MCInst &MCI, MCContext &Context);
class PredicateInfo {
public:
PredicateInfo() : Register(0), Operand(0), PredicatedTrue(false) {}
PredicateInfo(unsigned Register, unsigned Operand, bool PredicatedTrue)
: Register(Register), Operand(Operand), PredicatedTrue(PredicatedTrue) {}
bool isPredicated() const;
unsigned Register;
unsigned Operand;
bool PredicatedTrue;
};
PredicateInfo predicateInfo(MCInstrInfo const &MCII, MCInst const &MCI);
bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI);
void replaceDuplex(MCContext &Context, MCInst &MCI, DuplexCandidate Candidate);
bool s27_2_reloc(MCExpr const &Expr);
void setInnerLoop(MCInst &MCI);
void setMemReorderDisabled(MCInst &MCI);
void setMustExtend(MCExpr const &Expr, bool Val = true);
void setMustNotExtend(MCExpr const &Expr, bool Val = true);
void setS27_2_reloc(MCExpr const &Expr, bool Val = true);
void setOuterLoop(MCInst &MCI);
bool subInstWouldBeExtended(MCInst const &potentialDuplex);
unsigned SubregisterBit(unsigned Consumer, unsigned Producer,
unsigned Producer2);
bool IsVecRegSingle(unsigned VecReg);
bool IsVecRegPair(unsigned VecReg);
bool IsReverseVecRegPair(unsigned VecReg);
bool IsSingleConsumerRefPairProducer(unsigned Producer, unsigned Consumer);
std::pair<unsigned, unsigned> GetVecRegPairIndices(unsigned VecRegPair);
void tryCompound(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
MCContext &Context, MCInst &MCI);
}
}
#endif