#include "HexagonMCExpr.h"
#include "MCTargetDesc/HexagonBaseInfo.h"
#include "MCTargetDesc/HexagonMCInstrInfo.h"
#include "MCTargetDesc/HexagonMCTargetDesc.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <map>
#include <utility>
using namespace llvm;
using namespace Hexagon;
#define DEBUG_TYPE "hexagon-mcduplex-info"
static const std::pair<unsigned, unsigned> opcodeData[] = {
std::make_pair((unsigned)SA1_addi, 0),
std::make_pair((unsigned)SA1_addrx, 6144),
std::make_pair((unsigned)SA1_addsp, 3072),
std::make_pair((unsigned)SA1_and1, 4608),
std::make_pair((unsigned)SA1_clrf, 6768),
std::make_pair((unsigned)SA1_clrfnew, 6736),
std::make_pair((unsigned)SA1_clrt, 6752),
std::make_pair((unsigned)SA1_clrtnew, 6720),
std::make_pair((unsigned)SA1_cmpeqi, 6400),
std::make_pair((unsigned)SA1_combine0i, 7168),
std::make_pair((unsigned)SA1_combine1i, 7176),
std::make_pair((unsigned)SA1_combine2i, 7184),
std::make_pair((unsigned)SA1_combine3i, 7192),
std::make_pair((unsigned)SA1_combinerz, 7432),
std::make_pair((unsigned)SA1_combinezr, 7424),
std::make_pair((unsigned)SA1_dec, 4864),
std::make_pair((unsigned)SA1_inc, 4352),
std::make_pair((unsigned)SA1_seti, 2048),
std::make_pair((unsigned)SA1_setin1, 6656),
std::make_pair((unsigned)SA1_sxtb, 5376),
std::make_pair((unsigned)SA1_sxth, 5120),
std::make_pair((unsigned)SA1_tfr, 4096),
std::make_pair((unsigned)SA1_zxtb, 5888),
std::make_pair((unsigned)SA1_zxth, 5632),
std::make_pair((unsigned)SL1_loadri_io, 0),
std::make_pair((unsigned)SL1_loadrub_io, 4096),
std::make_pair((unsigned)SL2_deallocframe, 7936),
std::make_pair((unsigned)SL2_jumpr31, 8128),
std::make_pair((unsigned)SL2_jumpr31_f, 8133),
std::make_pair((unsigned)SL2_jumpr31_fnew, 8135),
std::make_pair((unsigned)SL2_jumpr31_t, 8132),
std::make_pair((unsigned)SL2_jumpr31_tnew, 8134),
std::make_pair((unsigned)SL2_loadrb_io, 4096),
std::make_pair((unsigned)SL2_loadrd_sp, 7680),
std::make_pair((unsigned)SL2_loadrh_io, 0),
std::make_pair((unsigned)SL2_loadri_sp, 7168),
std::make_pair((unsigned)SL2_loadruh_io, 2048),
std::make_pair((unsigned)SL2_return, 8000),
std::make_pair((unsigned)SL2_return_f, 8005),
std::make_pair((unsigned)SL2_return_fnew, 8007),
std::make_pair((unsigned)SL2_return_t, 8004),
std::make_pair((unsigned)SL2_return_tnew, 8006),
std::make_pair((unsigned)SS1_storeb_io, 4096),
std::make_pair((unsigned)SS1_storew_io, 0),
std::make_pair((unsigned)SS2_allocframe, 7168),
std::make_pair((unsigned)SS2_storebi0, 4608),
std::make_pair((unsigned)SS2_storebi1, 4864),
std::make_pair((unsigned)SS2_stored_sp, 2560),
std::make_pair((unsigned)SS2_storeh_io, 0),
std::make_pair((unsigned)SS2_storew_sp, 2048),
std::make_pair((unsigned)SS2_storewi0, 4096),
std::make_pair((unsigned)SS2_storewi1, 4352)};
bool HexagonMCInstrInfo::isDuplexPairMatch(unsigned Ga, unsigned Gb) {
switch (Ga) {
case HexagonII::HSIG_None:
default:
return false;
case HexagonII::HSIG_L1:
return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_A);
case HexagonII::HSIG_L2:
return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
Gb == HexagonII::HSIG_A);
case HexagonII::HSIG_S1:
return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_A);
case HexagonII::HSIG_S2:
return (Gb == HexagonII::HSIG_L1 || Gb == HexagonII::HSIG_L2 ||
Gb == HexagonII::HSIG_S1 || Gb == HexagonII::HSIG_S2 ||
Gb == HexagonII::HSIG_A);
case HexagonII::HSIG_A:
return (Gb == HexagonII::HSIG_A);
case HexagonII::HSIG_Compound:
return (Gb == HexagonII::HSIG_Compound);
}
return false;
}
unsigned HexagonMCInstrInfo::iClassOfDuplexPair(unsigned Ga, unsigned Gb) {
switch (Ga) {
case HexagonII::HSIG_None:
default:
break;
case HexagonII::HSIG_L1:
switch (Gb) {
default:
break;
case HexagonII::HSIG_L1:
return 0;
case HexagonII::HSIG_A:
return 0x4;
}
break;
case HexagonII::HSIG_L2:
switch (Gb) {
default:
break;
case HexagonII::HSIG_L1:
return 0x1;
case HexagonII::HSIG_L2:
return 0x2;
case HexagonII::HSIG_A:
return 0x5;
}
break;
case HexagonII::HSIG_S1:
switch (Gb) {
default:
break;
case HexagonII::HSIG_L1:
return 0x8;
case HexagonII::HSIG_L2:
return 0x9;
case HexagonII::HSIG_S1:
return 0xA;
case HexagonII::HSIG_A:
return 0x6;
}
break;
case HexagonII::HSIG_S2:
switch (Gb) {
default:
break;
case HexagonII::HSIG_L1:
return 0xC;
case HexagonII::HSIG_L2:
return 0xD;
case HexagonII::HSIG_S1:
return 0xB;
case HexagonII::HSIG_S2:
return 0xE;
case HexagonII::HSIG_A:
return 0x7;
}
break;
case HexagonII::HSIG_A:
switch (Gb) {
default:
break;
case HexagonII::HSIG_A:
return 0x3;
}
break;
case HexagonII::HSIG_Compound:
switch (Gb) {
case HexagonII::HSIG_Compound:
return 0xFFFFFFFF;
}
break;
}
return 0xFFFFFFFF;
}
unsigned HexagonMCInstrInfo::getDuplexCandidateGroup(MCInst const &MCI) {
unsigned DstReg, PredReg, SrcReg, Src1Reg, Src2Reg;
switch (MCI.getOpcode()) {
default:
return HexagonII::HSIG_None;
case Hexagon::L2_loadri_io:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg)) {
if (HexagonMCInstrInfo::isIntReg(SrcReg) &&
Hexagon::R29 == SrcReg && inRange<5, 2>(MCI, 2)) {
return HexagonII::HSIG_L2;
}
if (HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
inRange<4, 2>(MCI, 2)) {
return HexagonII::HSIG_L1;
}
}
break;
case Hexagon::L2_loadrub_io:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
inRange<4>(MCI, 2)) {
return HexagonII::HSIG_L1;
}
break;
case Hexagon::L2_loadrh_io:
case Hexagon::L2_loadruh_io:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
inRange<3, 1>(MCI, 2)) {
return HexagonII::HSIG_L2;
}
break;
case Hexagon::L2_loadrb_io:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
inRange<3>(MCI, 2)) {
return HexagonII::HSIG_L2;
}
break;
case Hexagon::L2_loadrd_io:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isDblRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntReg(SrcReg) && Hexagon::R29 == SrcReg &&
inRange<5, 3>(MCI, 2)) {
return HexagonII::HSIG_L2;
}
break;
case Hexagon::L4_return:
case Hexagon::L2_deallocframe:
return HexagonII::HSIG_L2;
case Hexagon::EH_RETURN_JMPR:
case Hexagon::J2_jumpr:
case Hexagon::PS_jmpret:
DstReg = MCI.getOperand(0).getReg();
if (Hexagon::R31 == DstReg)
return HexagonII::HSIG_L2;
break;
case Hexagon::J2_jumprt:
case Hexagon::J2_jumprf:
case Hexagon::J2_jumprtnew:
case Hexagon::J2_jumprfnew:
case Hexagon::PS_jmprett:
case Hexagon::PS_jmpretf:
case Hexagon::PS_jmprettnew:
case Hexagon::PS_jmpretfnew:
case Hexagon::PS_jmprettnewpt:
case Hexagon::PS_jmpretfnewpt:
DstReg = MCI.getOperand(1).getReg();
SrcReg = MCI.getOperand(0).getReg();
if ((Hexagon::P0 == SrcReg) && (Hexagon::R31 == DstReg)) {
return HexagonII::HSIG_L2;
}
break;
case Hexagon::L4_return_t:
case Hexagon::L4_return_f:
case Hexagon::L4_return_tnew_pnt:
case Hexagon::L4_return_fnew_pnt:
SrcReg = MCI.getOperand(1).getReg();
if (Hexagon::P0 == SrcReg) {
return HexagonII::HSIG_L2;
}
break;
case Hexagon::S2_storeri_io:
Src1Reg = MCI.getOperand(0).getReg();
Src2Reg = MCI.getOperand(2).getReg();
if (HexagonMCInstrInfo::isIntReg(Src1Reg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src2Reg) &&
Hexagon::R29 == Src1Reg && inRange<5, 2>(MCI, 1)) {
return HexagonII::HSIG_S2;
}
if (HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src2Reg) &&
inRange<4, 2>(MCI, 1)) {
return HexagonII::HSIG_S1;
}
break;
case Hexagon::S2_storerb_io:
Src1Reg = MCI.getOperand(0).getReg();
Src2Reg = MCI.getOperand(2).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src2Reg) &&
inRange<4>(MCI, 1)) {
return HexagonII::HSIG_S1;
}
break;
case Hexagon::S2_storerh_io:
Src1Reg = MCI.getOperand(0).getReg();
Src2Reg = MCI.getOperand(2).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src2Reg) &&
inRange<3, 1>(MCI, 1)) {
return HexagonII::HSIG_S2;
}
break;
case Hexagon::S2_storerd_io:
Src1Reg = MCI.getOperand(0).getReg();
Src2Reg = MCI.getOperand(2).getReg();
if (HexagonMCInstrInfo::isDblRegForSubInst(Src2Reg) &&
HexagonMCInstrInfo::isIntReg(Src1Reg) && Hexagon::R29 == Src1Reg &&
inSRange<6, 3>(MCI, 1)) {
return HexagonII::HSIG_S2;
}
break;
case Hexagon::S4_storeiri_io:
Src1Reg = MCI.getOperand(0).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
inRange<4, 2>(MCI, 1) && inRange<1>(MCI, 2)) {
return HexagonII::HSIG_S2;
}
break;
case Hexagon::S4_storeirb_io:
Src1Reg = MCI.getOperand(0).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(Src1Reg) &&
inRange<4>(MCI, 1) && inRange<1>(MCI, 2)) {
return HexagonII::HSIG_S2;
}
break;
case Hexagon::S2_allocframe:
if (inRange<5, 3>(MCI, 2))
return HexagonII::HSIG_S2;
break;
case Hexagon::A2_addi:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg)) {
if (HexagonMCInstrInfo::isIntReg(SrcReg) && Hexagon::R29 == SrcReg &&
inRange<6, 2>(MCI, 2)) {
return HexagonII::HSIG_A;
}
if (DstReg == SrcReg) {
return HexagonII::HSIG_A;
}
if (HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
(minConstant(MCI, 2) == 1 || minConstant(MCI, 2) == -1)) {
return HexagonII::HSIG_A;
}
}
break;
case Hexagon::A2_add:
DstReg = MCI.getOperand(0).getReg();
Src1Reg = MCI.getOperand(1).getReg();
Src2Reg = MCI.getOperand(2).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) && (DstReg == Src1Reg) &&
HexagonMCInstrInfo::isIntRegForSubInst(Src2Reg)) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A2_andir:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
(minConstant(MCI, 2) == 1 || minConstant(MCI, 2) == 255)) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A2_tfr:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg)) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A2_tfrsi:
DstReg = MCI.getOperand(0).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg)) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::C2_cmoveit:
case Hexagon::C2_cmovenewit:
case Hexagon::C2_cmoveif:
case Hexagon::C2_cmovenewif:
DstReg = MCI.getOperand(0).getReg(); PredReg = MCI.getOperand(1).getReg(); if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
Hexagon::P0 == PredReg && minConstant(MCI, 2) == 0) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::C2_cmpeqi:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (Hexagon::P0 == DstReg &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
inRange<2>(MCI, 2)) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A2_combineii:
case Hexagon::A4_combineii:
DstReg = MCI.getOperand(0).getReg();
if (HexagonMCInstrInfo::isDblRegForSubInst(DstReg) &&
inRange<2>(MCI, 1) && inRange<2>(MCI, 2)) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A4_combineri:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isDblRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
minConstant(MCI, 2) == 0) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A4_combineir:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(2).getReg();
if (HexagonMCInstrInfo::isDblRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg) &&
minConstant(MCI, 1) == 0) {
return HexagonII::HSIG_A;
}
break;
case Hexagon::A2_sxtb:
case Hexagon::A2_sxth:
case Hexagon::A2_zxtb:
case Hexagon::A2_zxth:
DstReg = MCI.getOperand(0).getReg();
SrcReg = MCI.getOperand(1).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg) &&
HexagonMCInstrInfo::isIntRegForSubInst(SrcReg)) {
return HexagonII::HSIG_A;
}
break;
}
return HexagonII::HSIG_None;
}
bool HexagonMCInstrInfo::subInstWouldBeExtended(MCInst const &potentialDuplex) {
unsigned DstReg, SrcReg;
switch (potentialDuplex.getOpcode()) {
case Hexagon::A2_addi:
DstReg = potentialDuplex.getOperand(0).getReg();
SrcReg = potentialDuplex.getOperand(1).getReg();
if (DstReg == SrcReg && HexagonMCInstrInfo::isIntRegForSubInst(DstReg)) {
int64_t Value;
if (!potentialDuplex.getOperand(2).getExpr()->evaluateAsAbsolute(Value))
return true;
if (!isShiftedInt<7, 0>(Value))
return true;
}
break;
case Hexagon::A2_tfrsi:
DstReg = potentialDuplex.getOperand(0).getReg();
if (HexagonMCInstrInfo::isIntRegForSubInst(DstReg)) {
int64_t Value;
if (!potentialDuplex.getOperand(1).getExpr()->evaluateAsAbsolute(Value))
return true;
if (Value == -1)
return false;
if (!isShiftedUInt<6, 0>(Value))
return true;
}
break;
default:
break;
}
return false;
}
bool HexagonMCInstrInfo::isOrderedDuplexPair(MCInstrInfo const &MCII,
MCInst const &MIa, bool ExtendedA,
MCInst const &MIb, bool ExtendedB,
bool bisReversable,
MCSubtargetInfo const &STI) {
if (ExtendedA)
return false;
if (ExtendedB) {
unsigned Opcode = MIb.getOpcode();
if ((Opcode != Hexagon::A2_addi) && (Opcode != Hexagon::A2_tfrsi))
return false;
}
unsigned MIaG = HexagonMCInstrInfo::getDuplexCandidateGroup(MIa),
MIbG = HexagonMCInstrInfo::getDuplexCandidateGroup(MIb);
static std::map<unsigned, unsigned> subinstOpcodeMap(std::begin(opcodeData),
std::end(opcodeData));
if ((MIaG != HexagonII::HSIG_None) && (MIaG == MIbG) && bisReversable) {
MCInst SubInst0 = HexagonMCInstrInfo::deriveSubInst(MIa);
MCInst SubInst1 = HexagonMCInstrInfo::deriveSubInst(MIb);
unsigned zeroedSubInstS0 =
subinstOpcodeMap.find(SubInst0.getOpcode())->second;
unsigned zeroedSubInstS1 =
subinstOpcodeMap.find(SubInst1.getOpcode())->second;
if (zeroedSubInstS0 < zeroedSubInstS1)
return false;
}
if (MIb.getOpcode() == Hexagon::S2_allocframe)
return false;
if ((MIaG != HexagonII::HSIG_None) && (MIbG != HexagonII::HSIG_None)) {
if (subInstWouldBeExtended(MIa))
return false;
if (subInstWouldBeExtended(MIb) && !ExtendedB)
return false;
}
if (MIbG == HexagonII::HSIG_L2) {
if ((MIb.getNumOperands() > 1) && MIb.getOperand(1).isReg() &&
(MIb.getOperand(1).getReg() == Hexagon::R31))
return false;
if ((MIb.getNumOperands() > 0) && MIb.getOperand(0).isReg() &&
(MIb.getOperand(0).getReg() == Hexagon::R31))
return false;
}
if (STI.getCPU().equals_insensitive("hexagonv5") ||
STI.getCPU().equals_insensitive("hexagonv55") ||
STI.getCPU().equals_insensitive("hexagonv60")) {
if ((MIbG == HexagonII::HSIG_S1) || (MIbG == HexagonII::HSIG_S2)) {
if ((MIaG != HexagonII::HSIG_S1) && (MIaG != HexagonII::HSIG_S2))
return false;
}
}
return (isDuplexPairMatch(MIaG, MIbG));
}
bool HexagonMCInstrInfo::isDuplexPair(MCInst const &MIa, MCInst const &MIb) {
unsigned MIaG = getDuplexCandidateGroup(MIa),
MIbG = getDuplexCandidateGroup(MIb);
return (isDuplexPairMatch(MIaG, MIbG) || isDuplexPairMatch(MIbG, MIaG));
}
inline static void addOps(MCInst &subInstPtr, MCInst const &Inst,
unsigned opNum) {
if (Inst.getOperand(opNum).isReg()) {
switch (Inst.getOperand(opNum).getReg()) {
default:
llvm_unreachable("Not Duplexable Register");
break;
case Hexagon::R0:
case Hexagon::R1:
case Hexagon::R2:
case Hexagon::R3:
case Hexagon::R4:
case Hexagon::R5:
case Hexagon::R6:
case Hexagon::R7:
case Hexagon::D0:
case Hexagon::D1:
case Hexagon::D2:
case Hexagon::D3:
case Hexagon::R16:
case Hexagon::R17:
case Hexagon::R18:
case Hexagon::R19:
case Hexagon::R20:
case Hexagon::R21:
case Hexagon::R22:
case Hexagon::R23:
case Hexagon::D8:
case Hexagon::D9:
case Hexagon::D10:
case Hexagon::D11:
case Hexagon::P0:
subInstPtr.addOperand(Inst.getOperand(opNum));
break;
}
} else
subInstPtr.addOperand(Inst.getOperand(opNum));
}
MCInst HexagonMCInstrInfo::deriveSubInst(MCInst const &Inst) {
MCInst Result;
Result.setLoc(Inst.getLoc());
bool Absolute;
int64_t Value;
switch (Inst.getOpcode()) {
default:
llvm_unreachable("Unimplemented subinstruction \n");
break;
case Hexagon::A2_addi:
Absolute = Inst.getOperand(2).getExpr()->evaluateAsAbsolute(Value);
if (Absolute) {
if (Value == 1) {
Result.setOpcode(Hexagon::SA1_inc);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break;
} if (Value == -1) {
Result.setOpcode(Hexagon::SA1_dec);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break;
} if (Inst.getOperand(1).getReg() == Hexagon::R29) {
Result.setOpcode(Hexagon::SA1_addsp);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break;
} }
Result.setOpcode(Hexagon::SA1_addi);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::A2_add:
Result.setOpcode(Hexagon::SA1_addrx);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::S2_allocframe:
Result.setOpcode(Hexagon::SS2_allocframe);
addOps(Result, Inst, 2);
break; case Hexagon::A2_andir:
if (minConstant(Inst, 2) == 255) {
Result.setOpcode(Hexagon::SA1_zxtb);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; } else {
Result.setOpcode(Hexagon::SA1_and1);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; }
case Hexagon::C2_cmpeqi:
Result.setOpcode(Hexagon::SA1_cmpeqi);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::A4_combineii:
case Hexagon::A2_combineii:
Absolute = Inst.getOperand(1).getExpr()->evaluateAsAbsolute(Value);
assert(Absolute);(void)Absolute;
if (Value == 1) {
Result.setOpcode(Hexagon::SA1_combine1i);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; }
if (Value == 3) {
Result.setOpcode(Hexagon::SA1_combine3i);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; }
if (Value == 0) {
Result.setOpcode(Hexagon::SA1_combine0i);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; }
if (Value == 2) {
Result.setOpcode(Hexagon::SA1_combine2i);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; }
break;
case Hexagon::A4_combineir:
Result.setOpcode(Hexagon::SA1_combinezr);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; case Hexagon::A4_combineri:
Result.setOpcode(Hexagon::SA1_combinerz);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::L4_return_tnew_pnt:
case Hexagon::L4_return_tnew_pt:
Result.setOpcode(Hexagon::SL2_return_tnew);
break; case Hexagon::L4_return_fnew_pnt:
case Hexagon::L4_return_fnew_pt:
Result.setOpcode(Hexagon::SL2_return_fnew);
break; case Hexagon::L4_return_f:
Result.setOpcode(Hexagon::SL2_return_f);
break; case Hexagon::L4_return_t:
Result.setOpcode(Hexagon::SL2_return_t);
break; case Hexagon::L4_return:
Result.setOpcode(Hexagon::SL2_return);
break; case Hexagon::L2_deallocframe:
Result.setOpcode(Hexagon::SL2_deallocframe);
break; case Hexagon::EH_RETURN_JMPR:
case Hexagon::J2_jumpr:
case Hexagon::PS_jmpret:
Result.setOpcode(Hexagon::SL2_jumpr31);
break; case Hexagon::J2_jumprf:
case Hexagon::PS_jmpretf:
Result.setOpcode(Hexagon::SL2_jumpr31_f);
break; case Hexagon::J2_jumprfnew:
case Hexagon::PS_jmpretfnewpt:
case Hexagon::PS_jmpretfnew:
Result.setOpcode(Hexagon::SL2_jumpr31_fnew);
break; case Hexagon::J2_jumprt:
case Hexagon::PS_jmprett:
Result.setOpcode(Hexagon::SL2_jumpr31_t);
break; case Hexagon::J2_jumprtnew:
case Hexagon::PS_jmprettnewpt:
case Hexagon::PS_jmprettnew:
Result.setOpcode(Hexagon::SL2_jumpr31_tnew);
break; case Hexagon::L2_loadrb_io:
Result.setOpcode(Hexagon::SL2_loadrb_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::L2_loadrd_io:
Result.setOpcode(Hexagon::SL2_loadrd_sp);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; case Hexagon::L2_loadrh_io:
Result.setOpcode(Hexagon::SL2_loadrh_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::L2_loadrub_io:
Result.setOpcode(Hexagon::SL1_loadrub_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::L2_loadruh_io:
Result.setOpcode(Hexagon::SL2_loadruh_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::L2_loadri_io:
if (Inst.getOperand(1).getReg() == Hexagon::R29) {
Result.setOpcode(Hexagon::SL2_loadri_sp);
addOps(Result, Inst, 0);
addOps(Result, Inst, 2);
break; } else {
Result.setOpcode(Hexagon::SL1_loadri_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; }
case Hexagon::S4_storeirb_io:
Absolute = Inst.getOperand(2).getExpr()->evaluateAsAbsolute(Value);
assert(Absolute);(void)Absolute;
if (Value == 0) {
Result.setOpcode(Hexagon::SS2_storebi0);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; } else if (Value == 1) {
Result.setOpcode(Hexagon::SS2_storebi1);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; }
break;
case Hexagon::S2_storerb_io:
Result.setOpcode(Hexagon::SS1_storeb_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::S2_storerd_io:
Result.setOpcode(Hexagon::SS2_stored_sp);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::S2_storerh_io:
Result.setOpcode(Hexagon::SS2_storeh_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; case Hexagon::S4_storeiri_io:
Absolute = Inst.getOperand(2).getExpr()->evaluateAsAbsolute(Value);
assert(Absolute);(void)Absolute;
if (Value == 0) {
Result.setOpcode(Hexagon::SS2_storewi0);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; } else if (Value == 1) {
Result.setOpcode(Hexagon::SS2_storewi1);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; } else if (Inst.getOperand(0).getReg() == Hexagon::R29) {
Result.setOpcode(Hexagon::SS2_storew_sp);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2);
break; }
break;
case Hexagon::S2_storeri_io:
if (Inst.getOperand(0).getReg() == Hexagon::R29) {
Result.setOpcode(Hexagon::SS2_storew_sp);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2); } else {
Result.setOpcode(Hexagon::SS1_storew_io);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
addOps(Result, Inst, 2); }
break;
case Hexagon::A2_sxtb:
Result.setOpcode(Hexagon::SA1_sxtb);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::A2_sxth:
Result.setOpcode(Hexagon::SA1_sxth);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::A2_tfr:
Result.setOpcode(Hexagon::SA1_tfr);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::C2_cmovenewif:
Result.setOpcode(Hexagon::SA1_clrfnew);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::C2_cmovenewit:
Result.setOpcode(Hexagon::SA1_clrtnew);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::C2_cmoveif:
Result.setOpcode(Hexagon::SA1_clrf);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::C2_cmoveit:
Result.setOpcode(Hexagon::SA1_clrt);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; case Hexagon::A2_tfrsi:
Absolute = Inst.getOperand(1).getExpr()->evaluateAsAbsolute(Value);
if (Absolute && Value == -1) {
Result.setOpcode(Hexagon::SA1_setin1);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; } else {
Result.setOpcode(Hexagon::SA1_seti);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; }
case Hexagon::A2_zxtb:
Result.setOpcode(Hexagon::SA1_zxtb);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break;
case Hexagon::A2_zxth:
Result.setOpcode(Hexagon::SA1_zxth);
addOps(Result, Inst, 0);
addOps(Result, Inst, 1);
break; }
return Result;
}
static bool isStoreInst(unsigned opCode) {
switch (opCode) {
case Hexagon::S2_storeri_io:
case Hexagon::S2_storerb_io:
case Hexagon::S2_storerh_io:
case Hexagon::S2_storerd_io:
case Hexagon::S4_storeiri_io:
case Hexagon::S4_storeirb_io:
case Hexagon::S2_allocframe:
return true;
default:
return false;
}
}
SmallVector<DuplexCandidate, 8>
HexagonMCInstrInfo::getDuplexPossibilties(MCInstrInfo const &MCII,
MCSubtargetInfo const &STI,
MCInst const &MCB) {
assert(isBundle(MCB));
SmallVector<DuplexCandidate, 8> duplexToTry;
unsigned numInstrInPacket = MCB.getNumOperands();
for (unsigned distance = 1; distance < numInstrInPacket; ++distance) {
for (unsigned j = HexagonMCInstrInfo::bundleInstructionsOffset,
k = j + distance;
(j < numInstrInPacket) && (k < numInstrInPacket); ++j, ++k) {
bool bisReversable = true;
if (isStoreInst(MCB.getOperand(j).getInst()->getOpcode()) &&
isStoreInst(MCB.getOperand(k).getInst()->getOpcode())) {
LLVM_DEBUG(dbgs() << "skip out of order write pair: " << k << "," << j
<< "\n");
bisReversable = false;
}
if (HexagonMCInstrInfo::isMemReorderDisabled(MCB)) bisReversable = false;
if (isOrderedDuplexPair(
MCII, *MCB.getOperand(k).getInst(),
HexagonMCInstrInfo::hasExtenderForIndex(MCB, k - 1),
*MCB.getOperand(j).getInst(),
HexagonMCInstrInfo::hasExtenderForIndex(MCB, j - 1),
bisReversable, STI)) {
unsigned iClass = iClassOfDuplexPair(
getDuplexCandidateGroup(*MCB.getOperand(k).getInst()),
getDuplexCandidateGroup(*MCB.getOperand(j).getInst()));
duplexToTry.push_back(DuplexCandidate(j, k, iClass));
LLVM_DEBUG(dbgs() << "adding pair: " << j << "," << k << ":"
<< MCB.getOperand(j).getInst()->getOpcode() << ","
<< MCB.getOperand(k).getInst()->getOpcode() << "\n");
continue;
} else {
LLVM_DEBUG(dbgs() << "skipping pair: " << j << "," << k << ":"
<< MCB.getOperand(j).getInst()->getOpcode() << ","
<< MCB.getOperand(k).getInst()->getOpcode() << "\n");
}
if (bisReversable) {
if (isOrderedDuplexPair(
MCII, *MCB.getOperand(j).getInst(),
HexagonMCInstrInfo::hasExtenderForIndex(MCB, j - 1),
*MCB.getOperand(k).getInst(),
HexagonMCInstrInfo::hasExtenderForIndex(MCB, k - 1),
bisReversable, STI)) {
unsigned iClass = iClassOfDuplexPair(
getDuplexCandidateGroup(*MCB.getOperand(j).getInst()),
getDuplexCandidateGroup(*MCB.getOperand(k).getInst()));
duplexToTry.push_back(DuplexCandidate(k, j, iClass));
LLVM_DEBUG(dbgs()
<< "adding pair:" << k << "," << j << ":"
<< MCB.getOperand(j).getInst()->getOpcode() << ","
<< MCB.getOperand(k).getInst()->getOpcode() << "\n");
} else {
LLVM_DEBUG(dbgs()
<< "skipping pair: " << k << "," << j << ":"
<< MCB.getOperand(j).getInst()->getOpcode() << ","
<< MCB.getOperand(k).getInst()->getOpcode() << "\n");
}
}
}
}
return duplexToTry;
}