14 #define DEBUG_TYPE "hexagon-shuffle" 45 enum { MAX = 360360 };
49 HexagonBid() =
default;
53 bool isSold()
const {
return (Bid >= MAX); }
62 class HexagonUnitAuction {
68 HexagonUnitAuction(
unsigned cs = 0) : isSold(cs) {}
71 bool bid(
unsigned B) {
73 unsigned b = B & ~isSold;
78 Scores[i] += HexagonBid(b);
79 isSold |= Scores[i].isSold() << i;
91 const unsigned SlotWeight = 8;
92 const unsigned MaskWeight = SlotWeight - 1;
94 unsigned Key = ((1u << s) & Units) != 0;
99 if (Key == 0 || Units == 0 || (SlotWeight * s >= 32))
104 Weight = (1u << (SlotWeight * s)) * ((MaskWeight - Ctpop) << Cttz);
110 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
120 (CPU ==
"hexagonv60")
122 :
UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
124 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
128 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
133 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
135 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
139 UnitsAndLanes(CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1, 1);
154 setLanes((*TUL)[T].
second);
175 for (
unsigned i = 1; i < Lanes; ++i)
176 startBit = (startBit << 1) | startBit;
181 unsigned usedUnits) {
182 if (startIdx < hvxInsts.
size()) {
183 if (!hvxInsts[startIdx].Units)
185 for (
unsigned b = 0x1; b <= 0x8; b <<= 1) {
186 if ((hvxInsts[startIdx].Units & b) == 0)
188 unsigned allBits =
makeAllBits(b, hvxInsts[startIdx].Lanes);
189 if ((allBits & usedUnits) == 0) {
190 if (
checkHVXPipes(hvxInsts, startIdx + 1, usedUnits | allBits))
202 : Context(Context), MCII(MCII), STI(STI), ReportErrors(ReportErrors) {
222 }
jumpSlots[] = {{8, 4}, {8, 2}, {8, 1}, {4, 2}, {4, 1}, {2, 1}};
223 #define MAX_JUMP_SLOTS (sizeof(jumpSlots) / sizeof(jumpSlots[0])) 226 bool HasRestrictSlot1AOK =
false;
229 MCInst const &Inst = ISJ->getDesc();
231 HasRestrictSlot1AOK =
true;
232 RestrictLoc = Inst.
getLoc();
235 if (HasRestrictSlot1AOK)
237 MCInst const &Inst = ISJ->getDesc();
242 unsigned Units = ISJ->Core.getUnits();
246 "Instruction was restricted from being in slot 1"));
248 std::make_pair(RestrictLoc,
"Instruction can only be combine " 249 "with an ALU instruction in slot 1"));
250 ISJ->Core.setUnits(Units & ~2U);
257 bool HasRestrictNoSlot1Store =
false;
260 MCInst const &Inst = ISJ->getDesc();
262 HasRestrictNoSlot1Store =
true;
263 RestrictLoc = Inst.
getLoc();
266 if (HasRestrictNoSlot1Store) {
267 bool AppliedRestriction =
false;
269 MCInst const &Inst = ISJ->getDesc();
271 unsigned Units = ISJ->Core.getUnits();
273 AppliedRestriction =
true;
276 "Instruction was restricted from being in slot 1"));
277 ISJ->Core.setUnits(Units & ~2U);
281 if (AppliedRestriction)
283 RestrictLoc,
"Instruction does not allow a store in slot 1"));
295 const unsigned slotSingleLoad = 0x1, slotSingleStore = 0x1,
297 slotFirstLoadStore = 0x2, slotLastLoadStore = 0x1;
300 unsigned slotLoadStore = slotFirstLoadStore;
303 unsigned memory = 0, loads = 0, load0 = 0,
stores = 0, store0 = 0, store1 = 0;
304 unsigned NonZCVIloads = 0, AllCVIloads = 0, CVIstores = 0;
307 unsigned pSlot3Cnt = 0;
310 std::vector<iterator> foundBranches;
311 unsigned reservedSlots = 0;
329 foundBranches.push_back(ISJ);
344 if (ISJ->Core.getUnits() == slotSingleLoad ||
348 foundBranches.push_back(ISJ);
363 if (ISJ->Core.getUnits() == slotSingleStore ||
376 foundBranches.push_back(ISJ);
382 if (ISJ->Core.getUnits() == slotSingleLoad ||
396 foundBranches.push_back(ISJ);
403 foundBranches.push_back(ISJ);
405 foundBranches.push_back(ISJ);
407 foundBranches.push_back(ISJ);
409 foundBranches.push_back(ISJ);
417 const unsigned ZCVIloads = AllCVIloads - NonZCVIloads;
418 const bool ValidHVXMem =
419 NonZCVIloads <= 1 && ZCVIloads <= 1 && CVIstores <= 1;
420 if ((load0 > 1 || store0 > 1 || !ValidHVXMem) ||
421 (duplex > 1 || (duplex && memory))) {
428 bool bOnlySlot3 =
false;
432 if (!ISJ->Core.getUnits()) {
439 if (loads == 1 && loads == memory && memops == 0)
442 case Hexagon::V6_vgathermw:
443 case Hexagon::V6_vgathermh:
444 case Hexagon::V6_vgathermhw:
445 case Hexagon::V6_vgathermwq:
446 case Hexagon::V6_vgathermhq:
447 case Hexagon::V6_vgathermhwq:
451 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotSingleLoad);
457 if (slotLoadStore < slotLastLoadStore) {
460 llvm::Twine(
"invalid instruction packet: too many loads"));
464 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotLoadStore);
475 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotSingleStore);
477 if (slotLoadStore < slotLastLoadStore) {
483 ISJ->Core.setUnits(ISJ->Core.getUnits() & slotLoadStore);
488 if (store1 &&
stores > 1) {
496 if (ISJ->Core.getUnits() == slotThree)
499 if (!ISJ->Core.getUnits()) {
507 bool validateSlots =
true;
508 if (foundBranches.size() > 1) {
509 if (foundBranches.size() > 2) {
529 HexagonUnitAuction AuctionCore(reservedSlots);
535 if (!AuctionCore.bid(
I->Core.getUnits()))
540 validateSlots =
false;
552 if (foundBranches.size() <= 1 && bOnlySlot3 ==
false && pSlot3Cnt == 1 &&
554 validateSlots =
true;
557 unsigned saveUnits = slot3ISJ->Core.getUnits();
558 slot3ISJ->Core.setUnits(saveUnits & slotThree);
560 HexagonUnitAuction AuctionCore(reservedSlots);
566 if (!AuctionCore.bid(
I->Core.getUnits()))
571 validateSlots =
false;
576 ISJ->Core.setUnits(saveUnits);
583 HexagonUnitAuction AuctionCore(reservedSlots);
588 if (!AuctionCore.bid(
I->Core.getUnits())) {
600 inst.
Units =
I->CVI.getUnits();
601 inst.
Lanes =
I->CVI.getLanes();
607 if (hvxInsts.
size() > 0) {
608 unsigned startIdx, usedUnits;
609 startIdx = usedUnits = 0x0;
635 unsigned slotSkip, slotWeight;
638 for (ISJ = ISK = Packet.
begin(), slotSkip = slotWeight = 0;
639 ISK != Packet.
end(); ++ISK, ++slotSkip)
640 if (slotSkip < nSlot - emptySlots)
645 slotWeight += ISK->Core.setWeight(HEXAGON_PACKET_SIZE - nSlot - 1);
660 dbgs() << ISJ->CVI.getLanes();
std::string & operator+=(std::string &buffer, StringRef string)
static bool lessCore(const HexagonInstr &A, const HexagonInstr &B)
void setUnits(unsigned s)
This class represents lattice values for constants.
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...
void push_back(const T &Elt)
void append(MCInst const &ID, MCInst const *Extender, unsigned S)
unsigned setWeight(unsigned s)
bool mayLoad() const
Return true if this instruction could possibly read memory.
void applySlotRestrictions()
bool isReturn() const
Return true if the instruction is a return.
unsigned 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...
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
bool isRestrictNoSlot1Store(MCInstrInfo const &MCII, MCInst const &MCI)
Context object for machine code objects.
HexagonPacket::iterator iterator
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
const MCInst * getInst() const
Instances of this class represent a single low-level machine instruction.
HexagonCVIResource(TypeUnitsAndLanes *TUL, MCInstrInfo const &MCII, unsigned s, MCInst const *id)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
The instances of the Type class are immutable: once they are created, they are never changed...
MCSubtargetInfo const & STI
Interface to description of machine instruction set.
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
void reportError(SMLoc L, const Twine &Msg)
bool isMemReorderDisabled() const
void restrictNoSlot1Store()
const SourceMgr * getSourceManager() const
bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI)
static unsigned makeAllBits(unsigned startBit, unsigned Lanes)
static struct @460 jumpSlots[]
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...
const MCOperand & getOperand(unsigned i) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool mayStore() const
Return true if this instruction could possibly modify memory.
std::pair< unsigned, unsigned > UnitsAndLanes
void reportError(Twine const &Msg)
HexagonShuffler(MCContext &Context, bool ReportErrors, MCInstrInfo const &MCII, MCSubtargetInfo const &STI)
Generic base class for all target subtargets.
static bool checkHVXPipes(const HVXInstsT &hvxInsts, unsigned startIdx, unsigned usedUnits)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isBranch(unsigned Opcode)
void stable_sort(R &&Range)
#define HEXAGON_PACKET_SIZE
std::vector< std::pair< SMLoc, std::string > > AppliedRestrictions
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
Return the slots used by the insn.
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.
Represents a location in source code.
unsigned getOpcode() const
static void SetupTUL(TypeUnitsAndLanes *TUL, StringRef CPU)
bool isRestrictSlot1AOK(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with an A-type insn in slot #1.
bool check()
Check that the packet is legal and enforce relative insn order.