summaryrefslogtreecommitdiff
path: root/lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp')
-rw-r--r--lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp83
1 files changed, 54 insertions, 29 deletions
diff --git a/lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp b/lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp
index 7f8e7a4edb0c..529a5fd5ed82 100644
--- a/lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp
+++ b/lib/Target/Hexagon/MCTargetDesc/HexagonMCShuffler.cpp
@@ -33,42 +33,39 @@ void HexagonMCShuffler::init(MCInst &MCB) {
MCInst const *Extender = nullptr;
// Copy the bundle for the shuffling.
for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
- assert(!HexagonMCInstrInfo::getDesc(MCII, *I.getInst()).isPseudo());
- MCInst *MI = const_cast<MCInst *>(I.getInst());
+ MCInst &MI = *const_cast<MCInst *>(I.getInst());
+ DEBUG(dbgs() << "Shuffling: " << MCII.getName(MI.getOpcode()) << '\n');
+ assert(!HexagonMCInstrInfo::getDesc(MCII, MI).isPseudo());
- if (!HexagonMCInstrInfo::isImmext(*MI)) {
- append(MI, Extender, HexagonMCInstrInfo::getUnits(MCII, STI, *MI),
- false);
+ if (!HexagonMCInstrInfo::isImmext(MI)) {
+ append(MI, Extender, HexagonMCInstrInfo::getUnits(MCII, STI, MI));
Extender = nullptr;
} else
- Extender = MI;
+ Extender = &MI;
}
}
BundleFlags = MCB.getOperand(0).getImm();
}
-void HexagonMCShuffler::init(MCInst &MCB, MCInst const *AddMI,
+void HexagonMCShuffler::init(MCInst &MCB, MCInst const &AddMI,
bool bInsertAtFront) {
if (HexagonMCInstrInfo::isBundle(MCB)) {
- if (bInsertAtFront && AddMI)
- append(AddMI, nullptr, HexagonMCInstrInfo::getUnits(MCII, STI, *AddMI),
- false);
+ if (bInsertAtFront)
+ append(AddMI, nullptr, HexagonMCInstrInfo::getUnits(MCII, STI, AddMI));
MCInst const *Extender = nullptr;
// Copy the bundle for the shuffling.
for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
assert(!HexagonMCInstrInfo::getDesc(MCII, *I.getInst()).isPseudo());
- MCInst *MI = const_cast<MCInst *>(I.getInst());
- if (!HexagonMCInstrInfo::isImmext(*MI)) {
- append(MI, Extender, HexagonMCInstrInfo::getUnits(MCII, STI, *MI),
- false);
+ MCInst &MI = *const_cast<MCInst *>(I.getInst());
+ if (!HexagonMCInstrInfo::isImmext(MI)) {
+ append(MI, Extender, HexagonMCInstrInfo::getUnits(MCII, STI, MI));
Extender = nullptr;
} else
- Extender = MI;
+ Extender = &MI;
}
- if (!bInsertAtFront && AddMI)
- append(AddMI, nullptr, HexagonMCInstrInfo::getUnits(MCII, STI, *AddMI),
- false);
+ if (!bInsertAtFront)
+ append(AddMI, nullptr, HexagonMCInstrInfo::getUnits(MCII, STI, AddMI));
}
BundleFlags = MCB.getOperand(0).getImm();
@@ -80,11 +77,11 @@ void HexagonMCShuffler::copyTo(MCInst &MCB) {
// Copy the results into the bundle.
for (HexagonShuffler::iterator I = begin(); I != end(); ++I) {
- MCInst const *MI = I->getDesc();
+ MCInst const &MI = I->getDesc();
MCInst const *Extender = I->getExtender();
if (Extender)
MCB.addOperand(MCOperand::createInst(Extender));
- MCB.addOperand(MCOperand::createInst(MI));
+ MCB.addOperand(MCOperand::createInst(&MI));
}
}
@@ -98,9 +95,9 @@ bool HexagonMCShuffler::reshuffleTo(MCInst &MCB) {
return (!getError());
}
-bool llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
- MCInst &MCB) {
- HexagonMCShuffler MCS(MCII, STI, MCB);
+bool llvm::HexagonMCShuffle(bool Fatal, MCInstrInfo const &MCII,
+ MCSubtargetInfo const &STI, MCInst &MCB) {
+ HexagonMCShuffler MCS(true, MCII, STI, MCB);
if (DisableShuffle)
// Ignore if user chose so.
@@ -124,6 +121,18 @@ bool llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
if (!MCS.reshuffleTo(MCB)) {
// Unless there is any error, which should not happen at this point.
unsigned shuffleError = MCS.getError();
+
+ if (!Fatal && (shuffleError != HexagonShuffler::SHUFFLE_SUCCESS))
+ return false;
+ if (shuffleError != HexagonShuffler::SHUFFLE_SUCCESS) {
+ errs() << "\nFailing packet:\n";
+ for (const auto& I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
+ MCInst *MI = const_cast<MCInst *>(I.getInst());
+ errs() << HexagonMCInstrInfo::getName(MCII, *MI) << ' ' << HexagonMCInstrInfo::getDesc(MCII, *MI).getOpcode() << '\n';
+ }
+ errs() << '\n';
+ }
+
switch (shuffleError) {
default:
llvm_unreachable("unknown error");
@@ -176,7 +185,7 @@ llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
DuplexCandidate duplexToTry = possibleDuplexes.pop_back_val();
MCInst Attempt(MCB);
HexagonMCInstrInfo::replaceDuplex(Context, Attempt, duplexToTry);
- HexagonMCShuffler MCS(MCII, STI, Attempt); // copy packet to the shuffler
+ HexagonMCShuffler MCS(true, MCII, STI, Attempt); // copy packet to the shuffler
if (MCS.size() == 1) { // case of one duplex
// copy the created duplex in the shuffler to the bundle
MCS.copyTo(MCB);
@@ -191,7 +200,7 @@ llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
}
if (doneShuffling == false) {
- HexagonMCShuffler MCS(MCII, STI, MCB);
+ HexagonMCShuffler MCS(true, MCII, STI, MCB);
doneShuffling = MCS.reshuffleTo(MCB); // shuffle
shuffleError = MCS.getError();
}
@@ -202,8 +211,8 @@ llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
}
bool llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
- MCInst &MCB, MCInst const *AddMI, int fixupCount) {
- if (!HexagonMCInstrInfo::isBundle(MCB) || !AddMI)
+ MCInst &MCB, MCInst const &AddMI, int fixupCount) {
+ if (!HexagonMCInstrInfo::isBundle(MCB))
return false;
// if fixups present, make sure we don't insert too many nops that would
@@ -211,8 +220,15 @@ bool llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
unsigned int bundleSize = HexagonMCInstrInfo::bundleSize(MCB);
if (bundleSize >= HEXAGON_PACKET_SIZE)
return false;
+ bool bhasDuplex = HexagonMCInstrInfo::hasDuplex(MCII, MCB);
if (fixupCount >= 2) {
- return false;
+ if (bhasDuplex) {
+ if (bundleSize >= HEXAGON_PACKET_SIZE - 1) {
+ return false;
+ }
+ } else {
+ return false;
+ }
} else {
if (bundleSize == HEXAGON_PACKET_SIZE - 1 && fixupCount)
return false;
@@ -221,7 +237,16 @@ bool llvm::HexagonMCShuffle(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
if (DisableShuffle)
return false;
- HexagonMCShuffler MCS(MCII, STI, MCB, AddMI);
+ // mgl: temporary code (shuffler doesn't take into account the fact that
+ // a duplex takes up two slots. for example, 3 nops can be put into a packet
+ // containing a duplex oversubscribing slots by 1).
+ unsigned maxBundleSize = (HexagonMCInstrInfo::hasImmExt(MCB))
+ ? HEXAGON_PACKET_SIZE
+ : HEXAGON_PACKET_SIZE - 1;
+ if (bhasDuplex && bundleSize >= maxBundleSize)
+ return false;
+
+ HexagonMCShuffler MCS(MCII, STI, MCB, AddMI, false);
if (!MCS.reshuffleTo(MCB)) {
unsigned shuffleError = MCS.getError();
switch (shuffleError) {