15 #define DEBUG_TYPE "hexagon-shuffle"
38 enum { MAX = 360360 };
42 HexagonBid() : Bid(0) {}
46 bool isSold()
const {
return (Bid >= MAX); }
55 class HexagonUnitAuction {
61 HexagonUnitAuction(
unsigned cs = 0) : isSold(cs){};
64 bool bid(
unsigned B) {
66 unsigned b = B & ~isSold;
71 Scores[i] += HexagonBid(b);
72 isSold |= Scores[i].isSold() << i;
83 const unsigned SlotWeight = 8;
84 const unsigned MaskWeight = SlotWeight - 1;
86 unsigned Key = ((1u << s) & Units) != 0;
91 if (Key == 0 || Units == 0 || (SlotWeight * s >= 32))
96 Weight = (1u << (SlotWeight * s)) * ((MaskWeight - Ctpop) << Cttz);
102 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
111 (CPU ==
"hexagonv60")
113 :
UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
115 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
119 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
135 setLanes((*TUL)[T].
second);
157 for (
unsigned i = 1; i < Lanes; ++i)
158 startBit = (startBit << 1) | startBit;
166 if (startIdx < hvxInsts.
size()) {
167 if (!hvxInsts[startIdx].Units)
169 for (
unsigned b = 0x1; b <= 0x8; b <<= 1) {
170 if ((hvxInsts[startIdx].Units & b) == 0)
172 unsigned allBits =
makeAllBits(b, hvxInsts[startIdx].Lanes);
173 if ((allBits & usedUnits) == 0) {
174 if (
checkHVXPipes(hvxInsts, startIdx + 1, usedUnits | allBits))
186 : Context(Context), MCII(MCII), STI(STI), ReportErrors(ReportErrors) {
206 }
jumpSlots[] = {{8, 4}, {8, 2}, {8, 1}, {4, 2}, {4, 1}, {2, 1}};
207 #define MAX_JUMP_SLOTS (sizeof(jumpSlots) / sizeof(jumpSlots[0]))
212 const unsigned slotSingleLoad = 0x1, slotSingleStore = 0x1, slotOne = 0x2,
214 slotFirstLoadStore = 0x2, slotLastLoadStore = 0x1;
217 unsigned slotLoadStore = slotFirstLoadStore;
219 unsigned jumps = 0, jump1 = 0;
222 unsigned memory = 0, loads = 0, load0 = 0,
stores = 0, store0 = 0, store1 = 0;
226 unsigned onlyAin1 = 0;
228 unsigned onlyNo1 = 0;
229 unsigned pSlot3Cnt = 0;
230 unsigned nvstores = 0;
232 unsigned deallocs = 0;
234 std::vector<iterator> foundBranches;
235 unsigned reservedSlots = 0;
258 foundBranches.push_back(ISJ);
268 if (ISJ->Core.getUnits() == slotSingleLoad ||
272 ++deallocs, ++jumps, ++jump1;
273 foundBranches.push_back(ISJ);
284 if (ISJ->Core.getUnits() == slotSingleStore ||
298 foundBranches.push_back(ISJ);
304 if (ISJ->Core.getUnits() == slotSingleLoad ||
321 foundBranches.push_back(ISJ);
334 foundBranches.push_back(ISJ);
338 foundBranches.push_back(ISJ);
341 ++deallocs, ++jumps, ++jump1;
342 foundBranches.push_back(ISJ);
345 ++deallocs, ++jumps, ++jump1;
346 foundBranches.push_back(ISJ);
354 if ((load0 > 1 || store0 > 1) ||
355 (duplex > 1 || (duplex && memory))) {
360 if (jump1 && jumps > 1) {
365 if ((nvstores || memops) &&
stores > 1) {
376 bool bOnlySlot3 =
false;
380 if (!ISJ->Core.getUnits()) {
388 ISJ->Core.setUnits(ISJ->Core.getUnits() & ~slotOne);
395 ISJ->Core.setUnits(ISJ->Core.getUnits() & ~slotOne);
399 if (loads == 1 && loads == memory && memops == 0)
401 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotSingleLoad);
408 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotSingleStore);
410 if (slotLoadStore < slotLastLoadStore) {
413 llvm::Twine(
"invalid instruction packet: too many stores"));
417 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotLoadStore);
422 if (store1 &&
stores > 1) {
430 if (ISJ->Core.getUnits() == slotThree)
433 if (!ISJ->Core.getUnits()) {
441 bool validateSlots =
true;
443 if (foundBranches.size() > 2) {
463 HexagonUnitAuction AuctionCore(reservedSlots);
469 if (!AuctionCore.bid(
I->Core.getUnits()))
474 validateSlots =
false;
480 if (validateSlots ==
true) {
486 if (jumps <= 1 && bOnlySlot3 ==
false && pSlot3Cnt == 1 &&
488 validateSlots =
true;
491 unsigned saveUnits = slot3ISJ->Core.getUnits();
492 slot3ISJ->Core.setUnits(saveUnits & slotThree);
494 HexagonUnitAuction AuctionCore(reservedSlots);
500 if (!AuctionCore.bid(
I->Core.getUnits()))
505 validateSlots =
false;
510 ISJ->Core.setUnits(saveUnits);
517 HexagonUnitAuction AuctionCore(reservedSlots);
522 if (!AuctionCore.bid(
I->Core.getUnits())) {
534 inst.
Units =
I->CVI.getUnits();
535 inst.
Lanes =
I->CVI.getLanes();
541 if (hvxInsts.
size() > 0) {
542 unsigned startIdx, usedUnits;
543 startIdx = usedUnits = 0x0;
569 unsigned slotSkip, slotWeight;
572 for (ISJ = ISK = Packet.
begin(), slotSkip = slotWeight = 0;
573 ISK != Packet.
end(); ++ISK, ++slotSkip)
574 if (slotSkip < nSlot - emptySlots)
579 slotWeight += ISK->Core.setWeight(HEXAGON_PACKET_SIZE - nSlot - 1);
594 dbgs() << ISJ->CVI.getLanes();
bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with an A-type insn in slot #1.
std::string & operator+=(std::string &buffer, StringRef string)
void push_back(const T &Elt)
static bool lessCore(const HexagonInstr &A, const HexagonInstr &B)
void setUnits(unsigned s)
unsigned getOtherReservedSlots(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
Return the slots this instruction consumes in addition to the slot(s) it can execute out of...
bool isReturn() const
Return true if the instruction is a return.
bool mayStore() const
Return true if this instruction could possibly modify memory.
void append(MCInst const &ID, MCInst const *Extender, unsigned S)
unsigned setWeight(unsigned s)
static struct @366 jumpSlots[]
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define HEXAGON_PACKET_SIZE
bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI)
StringRef getCPU() const
getCPU - Return the CPU string.
Context object for machine code objects.
unsigned getUnits() const
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
void reportError(llvm::Twine const &Msg)
Instances of this class represent a single low-level machine instruction.
HexagonCVIResource(TypeUnitsAndLanes *TUL, MCInstrInfo const &MCII, unsigned s, MCInst const *id)
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
MCSubtargetInfo const & STI
Interface to description of machine instruction set.
void reportError(SMLoc L, const Twine &Msg)
SmallVector< struct CVIUnits, 8 > HVXInstsT
bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI)
static unsigned makeAllBits(unsigned startBit, unsigned Lanes)
unsigned getOpcode() const
Return the opcode number for this descriptor.
HexagonPacket::iterator iterator
unsigned countPopulation(T Value)
Count the number of set bits in a value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool mayLoad() const
Return true if this instruction could possibly read memory.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
HexagonShuffler(MCContext &Context, bool ReportErrors, MCInstrInfo const &MCII, MCSubtargetInfo const &STI)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
MCSubtargetInfo - Generic base class for all target subtargets.
const MCInst * getInst() const
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
static bool checkHVXPipes(const HVXInstsT &hvxInsts, unsigned startIdx, unsigned usedUnits)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isBranch(unsigned Opcode)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::pair< unsigned, unsigned > UnitsAndLanes
static bool lessCVI(const HexagonInstr &A, const HexagonInstr &B)
StringRef - Represent a constant reference to a string, i.e.
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
Return the Hexagon ISA class for the insn.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
static void SetupTUL(TypeUnitsAndLanes *TUL, StringRef CPU)
const MCOperand & getOperand(unsigned i) const
bool check()
Check that the packet is legal and enforce relative insn order.