#include "HexagonInstrInfo.h"
#include "HexagonSubtarget.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/Pass.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
using namespace llvm;
#define DEBUG_TYPE "hexagon-copy-combine"
static cl::opt<bool>
IsCombinesDisabled("disable-merge-into-combines", cl::Hidden,
cl::desc("Disable merging into combines"));
static cl::opt<bool>
IsConst64Disabled("disable-const64", cl::Hidden,
cl::desc("Disable generation of const64"));
static
cl::opt<unsigned>
MaxNumOfInstsBetweenNewValueStoreAndTFR("max-num-inst-between-tfr-and-nv-store",
cl::Hidden, cl::init(4),
cl::desc("Maximum distance between a tfr feeding a store we "
"consider the store still to be newifiable"));
namespace llvm {
FunctionPass *createHexagonCopyToCombine();
void initializeHexagonCopyToCombinePass(PassRegistry&);
}
namespace {
class HexagonCopyToCombine : public MachineFunctionPass {
const HexagonInstrInfo *TII;
const TargetRegisterInfo *TRI;
const HexagonSubtarget *ST;
bool ShouldCombineAggressively;
DenseSet<MachineInstr *> PotentiallyNewifiableTFR;
SmallVector<MachineInstr *, 8> DbgMItoMove;
public:
static char ID;
HexagonCopyToCombine() : MachineFunctionPass(ID) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
MachineFunctionPass::getAnalysisUsage(AU);
}
StringRef getPassName() const override {
return "Hexagon Copy-To-Combine Pass";
}
bool runOnMachineFunction(MachineFunction &Fn) override;
MachineFunctionProperties getRequiredProperties() const override {
return MachineFunctionProperties().set(
MachineFunctionProperties::Property::NoVRegs);
}
private:
MachineInstr *findPairable(MachineInstr &I1, bool &DoInsertAtI1,
bool AllowC64);
void findPotentialNewifiableTFRs(MachineBasicBlock &);
void combine(MachineInstr &I1, MachineInstr &I2,
MachineBasicBlock::iterator &MI, bool DoInsertAtI1,
bool OptForSize);
bool isSafeToMoveTogether(MachineInstr &I1, MachineInstr &I2,
unsigned I1DestReg, unsigned I2DestReg,
bool &DoInsertAtI1);
void emitCombineRR(MachineBasicBlock::iterator &Before, unsigned DestReg,
MachineOperand &HiOperand, MachineOperand &LoOperand);
void emitCombineRI(MachineBasicBlock::iterator &Before, unsigned DestReg,
MachineOperand &HiOperand, MachineOperand &LoOperand);
void emitCombineIR(MachineBasicBlock::iterator &Before, unsigned DestReg,
MachineOperand &HiOperand, MachineOperand &LoOperand);
void emitCombineII(MachineBasicBlock::iterator &Before, unsigned DestReg,
MachineOperand &HiOperand, MachineOperand &LoOperand);
void emitConst64(MachineBasicBlock::iterator &Before, unsigned DestReg,
MachineOperand &HiOperand, MachineOperand &LoOperand);
};
}
char HexagonCopyToCombine::ID = 0;
INITIALIZE_PASS(HexagonCopyToCombine, "hexagon-copy-combine",
"Hexagon Copy-To-Combine Pass", false, false)
static bool isCombinableInstType(MachineInstr &MI, const HexagonInstrInfo *TII,
bool ShouldCombineAggressively) {
switch (MI.getOpcode()) {
case Hexagon::A2_tfr: {
const MachineOperand &Op0 = MI.getOperand(0);
const MachineOperand &Op1 = MI.getOperand(1);
assert(Op0.isReg() && Op1.isReg());
Register DestReg = Op0.getReg();
Register SrcReg = Op1.getReg();
return Hexagon::IntRegsRegClass.contains(DestReg) &&
Hexagon::IntRegsRegClass.contains(SrcReg);
}
case Hexagon::A2_tfrsi: {
const MachineOperand &Op0 = MI.getOperand(0);
const MachineOperand &Op1 = MI.getOperand(1);
assert(Op0.isReg());
Register DestReg = Op0.getReg();
if (!Op1.isImm() && Op1.getTargetFlags() != HexagonII::MO_NO_FLAG)
return false;
bool NotExt = Op1.isImm() && isInt<8>(Op1.getImm());
return Hexagon::IntRegsRegClass.contains(DestReg) &&
(ShouldCombineAggressively || NotExt);
}
case Hexagon::V6_vassign:
return true;
default:
break;
}
return false;
}
template <unsigned N> static bool isGreaterThanNBitTFRI(const MachineInstr &I) {
if (I.getOpcode() == Hexagon::TFRI64_V4 ||
I.getOpcode() == Hexagon::A2_tfrsi) {
const MachineOperand &Op = I.getOperand(1);
return !Op.isImm() || !isInt<N>(Op.getImm());
}
return false;
}
static bool areCombinableOperations(const TargetRegisterInfo *TRI,
MachineInstr &HighRegInst,
MachineInstr &LowRegInst, bool AllowC64) {
unsigned HiOpc = HighRegInst.getOpcode();
unsigned LoOpc = LowRegInst.getOpcode();
auto verifyOpc = [](unsigned Opc) -> void {
switch (Opc) {
case Hexagon::A2_tfr:
case Hexagon::A2_tfrsi:
case Hexagon::V6_vassign:
break;
default:
llvm_unreachable("Unexpected opcode");
}
};
verifyOpc(HiOpc);
verifyOpc(LoOpc);
if (HiOpc == Hexagon::V6_vassign || LoOpc == Hexagon::V6_vassign)
return HiOpc == LoOpc;
if (!AllowC64) {
if (isGreaterThanNBitTFRI<8>(HighRegInst) &&
isGreaterThanNBitTFRI<6>(LowRegInst))
return false;
}
if (isGreaterThanNBitTFRI<16>(HighRegInst) &&
isGreaterThanNBitTFRI<16>(LowRegInst) && !IsConst64Disabled)
return (HighRegInst.getOperand(1).isImm() &&
LowRegInst.getOperand(1).isImm());
if (isGreaterThanNBitTFRI<8>(HighRegInst) &&
isGreaterThanNBitTFRI<8>(LowRegInst))
return false;
return true;
}
static bool isEvenReg(unsigned Reg) {
assert(Register::isPhysicalRegister(Reg));
if (Hexagon::IntRegsRegClass.contains(Reg))
return (Reg - Hexagon::R0) % 2 == 0;
if (Hexagon::HvxVRRegClass.contains(Reg))
return (Reg - Hexagon::V0) % 2 == 0;
llvm_unreachable("Invalid register");
}
static void removeKillInfo(MachineInstr &MI, unsigned RegNotKilled) {
for (MachineOperand &Op : MI.operands())
if (Op.isReg() && Op.getReg() == RegNotKilled && Op.isKill())
Op.setIsKill(false);
}
static bool isUnsafeToMoveAcross(MachineInstr &MI, unsigned UseReg,
unsigned DestReg,
const TargetRegisterInfo *TRI) {
return (UseReg && (MI.modifiesRegister(UseReg, TRI))) ||
MI.modifiesRegister(DestReg, TRI) || MI.readsRegister(DestReg, TRI) ||
MI.hasUnmodeledSideEffects() || MI.isInlineAsm() ||
MI.isMetaInstruction();
}
static Register UseReg(const MachineOperand& MO) {
return MO.isReg() ? MO.getReg() : Register();
}
bool HexagonCopyToCombine::isSafeToMoveTogether(MachineInstr &I1,
MachineInstr &I2,
unsigned I1DestReg,
unsigned I2DestReg,
bool &DoInsertAtI1) {
Register I2UseReg = UseReg(I2.getOperand(1));
if (I2UseReg && I1.modifiesRegister(I2UseReg, TRI))
return false;
bool isSafe = true;
{
MachineBasicBlock::reverse_iterator I = ++I2.getIterator().getReverse();
MachineBasicBlock::reverse_iterator End = I1.getIterator().getReverse();
if (!ShouldCombineAggressively)
End = ++I1.getIterator().getReverse();
unsigned KilledOperand = 0;
if (I2.killsRegister(I2UseReg))
KilledOperand = I2UseReg;
MachineInstr *KillingInstr = nullptr;
for (; I != End; ++I) {
if (I->isDebugInstr())
continue;
if (isUnsafeToMoveAcross(*I, I2UseReg, I2DestReg, TRI)) {
isSafe = false;
break;
}
if (!KillingInstr && KilledOperand &&
I->readsRegister(KilledOperand, TRI))
KillingInstr = &*I;
}
if (isSafe) {
if (KillingInstr) {
bool Added = KillingInstr->addRegisterKilled(KilledOperand, TRI, true);
(void)Added; assert(Added && "Must successfully update kill flag");
removeKillInfo(I2, KilledOperand);
}
DoInsertAtI1 = true;
return true;
}
}
{
MachineBasicBlock::iterator I(I1), End(I2);
if (!ShouldCombineAggressively)
End = std::next(MachineBasicBlock::iterator(I2));
Register I1UseReg = UseReg(I1.getOperand(1));
MachineInstr *KillingInstr = nullptr;
unsigned KilledOperand = 0;
while(++I != End) {
MachineInstr &MI = *I;
if (MI.isDebugInstr()) {
if (MI.readsRegister(I1DestReg, TRI)) DbgMItoMove.push_back(&MI);
continue;
}
if (isUnsafeToMoveAcross(MI, I1UseReg, I1DestReg, TRI) ||
(!MI.killsRegister(I1UseReg) && MI.killsRegister(I1UseReg, TRI)))
return false;
if (I1UseReg && MI.killsRegister(I1UseReg)) {
assert(!KillingInstr && "Should only see one killing instruction");
KilledOperand = I1UseReg;
KillingInstr = &MI;
}
}
if (KillingInstr) {
removeKillInfo(*KillingInstr, KilledOperand);
bool Added = I1.addRegisterKilled(KilledOperand, TRI);
(void)Added; assert(Added && "Must successfully update kill flag");
}
DoInsertAtI1 = false;
}
return true;
}
void
HexagonCopyToCombine::findPotentialNewifiableTFRs(MachineBasicBlock &BB) {
DenseMap<unsigned, MachineInstr *> LastDef;
for (MachineInstr &MI : BB) {
if (MI.isDebugInstr())
continue;
if (TII->mayBeNewStore(MI)) {
for (const MachineOperand &Op : MI.operands()) {
if (!Op.isReg() || !Op.isUse() || !Op.getReg())
continue;
Register Reg = Op.getReg();
MachineInstr *DefInst = LastDef[Reg];
if (!DefInst)
continue;
if (!isCombinableInstType(*DefInst, TII, ShouldCombineAggressively))
continue;
MachineBasicBlock::iterator It(DefInst);
unsigned NumInstsToDef = 0;
while (&*It != &MI) {
if (!It->isDebugInstr())
++NumInstsToDef;
++It;
}
if (NumInstsToDef > MaxNumOfInstsBetweenNewValueStoreAndTFR)
continue;
PotentiallyNewifiableTFR.insert(DefInst);
}
continue;
}
for (MachineOperand &Op : MI.operands()) {
if (Op.isReg()) {
if (!Op.isDef() || !Op.getReg())
continue;
Register Reg = Op.getReg();
if (Hexagon::DoubleRegsRegClass.contains(Reg)) {
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs)
LastDef[*SubRegs] = &MI;
} else if (Hexagon::IntRegsRegClass.contains(Reg))
LastDef[Reg] = &MI;
} else if (Op.isRegMask()) {
for (unsigned Reg : Hexagon::IntRegsRegClass)
if (Op.clobbersPhysReg(Reg))
LastDef[Reg] = &MI;
}
}
}
}
bool HexagonCopyToCombine::runOnMachineFunction(MachineFunction &MF) {
if (skipFunction(MF.getFunction()))
return false;
if (IsCombinesDisabled) return false;
bool HasChanged = false;
ST = &MF.getSubtarget<HexagonSubtarget>();
TRI = ST->getRegisterInfo();
TII = ST->getInstrInfo();
const Function &F = MF.getFunction();
bool OptForSize = F.hasFnAttribute(Attribute::OptimizeForSize);
ShouldCombineAggressively =
MF.getTarget().getOptLevel() <= CodeGenOpt::Default;
if (!OptForSize && ST->isTinyCore())
IsConst64Disabled = true;
for (MachineBasicBlock &MBB : MF) {
PotentiallyNewifiableTFR.clear();
findPotentialNewifiableTFRs(MBB);
for (MachineBasicBlock::iterator MI = MBB.begin(), End = MBB.end();
MI != End;) {
MachineInstr &I1 = *MI++;
if (I1.isDebugInstr())
continue;
if (ShouldCombineAggressively && PotentiallyNewifiableTFR.count(&I1))
continue;
if (!isCombinableInstType(I1, TII, ShouldCombineAggressively))
continue;
bool DoInsertAtI1 = false;
DbgMItoMove.clear();
MachineInstr *I2 = findPairable(I1, DoInsertAtI1, OptForSize);
if (I2) {
HasChanged = true;
combine(I1, *I2, MI, DoInsertAtI1, OptForSize);
}
}
}
return HasChanged;
}
MachineInstr *HexagonCopyToCombine::findPairable(MachineInstr &I1,
bool &DoInsertAtI1,
bool AllowC64) {
MachineBasicBlock::iterator I2 = std::next(MachineBasicBlock::iterator(I1));
while (I2 != I1.getParent()->end() && I2->isDebugInstr())
++I2;
Register I1DestReg = I1.getOperand(0).getReg();
for (MachineBasicBlock::iterator End = I1.getParent()->end(); I2 != End;
++I2) {
if (I2->modifiesRegister(I1DestReg, TRI))
break;
if (!isCombinableInstType(*I2, TII, ShouldCombineAggressively))
continue;
if (ShouldCombineAggressively && PotentiallyNewifiableTFR.count(&*I2))
continue;
Register I2DestReg = I2->getOperand(0).getReg();
bool IsI1LowReg = (I2DestReg - I1DestReg) == 1;
bool IsI2LowReg = (I1DestReg - I2DestReg) == 1;
unsigned FirstRegIndex = IsI1LowReg ? I1DestReg : I2DestReg;
if ((!IsI1LowReg && !IsI2LowReg) || !isEvenReg(FirstRegIndex))
continue;
if ((IsI2LowReg && !areCombinableOperations(TRI, I1, *I2, AllowC64)) ||
(IsI1LowReg && !areCombinableOperations(TRI, *I2, I1, AllowC64)))
break;
if (isSafeToMoveTogether(I1, *I2, I1DestReg, I2DestReg, DoInsertAtI1))
return &*I2;
break;
}
return nullptr;
}
void HexagonCopyToCombine::combine(MachineInstr &I1, MachineInstr &I2,
MachineBasicBlock::iterator &MI,
bool DoInsertAtI1, bool OptForSize) {
if (MI == I2.getIterator())
++MI;
Register I1DestReg = I1.getOperand(0).getReg();
Register I2DestReg = I2.getOperand(0).getReg();
bool IsI1Loreg = (I2DestReg - I1DestReg) == 1;
unsigned LoRegDef = IsI1Loreg ? I1DestReg : I2DestReg;
unsigned SubLo;
const TargetRegisterClass *SuperRC = nullptr;
if (Hexagon::IntRegsRegClass.contains(LoRegDef)) {
SuperRC = &Hexagon::DoubleRegsRegClass;
SubLo = Hexagon::isub_lo;
} else if (Hexagon::HvxVRRegClass.contains(LoRegDef)) {
assert(ST->useHVXOps());
SuperRC = &Hexagon::HvxWRRegClass;
SubLo = Hexagon::vsub_lo;
} else
llvm_unreachable("Unexpected register class");
unsigned DoubleRegDest = TRI->getMatchingSuperReg(LoRegDef, SubLo, SuperRC);
assert(DoubleRegDest != 0 && "Expect a valid register");
MachineOperand &LoOperand = IsI1Loreg ? I1.getOperand(1) : I2.getOperand(1);
MachineOperand &HiOperand = IsI1Loreg ? I2.getOperand(1) : I1.getOperand(1);
bool IsHiReg = HiOperand.isReg();
bool IsLoReg = LoOperand.isReg();
bool IsC64 = OptForSize && LoOperand.isImm() && HiOperand.isImm() &&
isGreaterThanNBitTFRI<16>(I1) && isGreaterThanNBitTFRI<16>(I2);
MachineBasicBlock::iterator InsertPt(DoInsertAtI1 ? I1 : I2);
if (IsHiReg && IsLoReg)
emitCombineRR(InsertPt, DoubleRegDest, HiOperand, LoOperand);
else if (IsHiReg)
emitCombineRI(InsertPt, DoubleRegDest, HiOperand, LoOperand);
else if (IsLoReg)
emitCombineIR(InsertPt, DoubleRegDest, HiOperand, LoOperand);
else if (IsC64 && !IsConst64Disabled)
emitConst64(InsertPt, DoubleRegDest, HiOperand, LoOperand);
else
emitCombineII(InsertPt, DoubleRegDest, HiOperand, LoOperand);
if (!DoInsertAtI1 && DbgMItoMove.size() != 0) {
MachineBasicBlock *BB = InsertPt->getParent();
for (auto NewMI : DbgMItoMove) {
if (NewMI == MI)
++MI;
BB->splice(InsertPt, BB, NewMI);
}
}
I1.eraseFromParent();
I2.eraseFromParent();
}
void HexagonCopyToCombine::emitConst64(MachineBasicBlock::iterator &InsertPt,
unsigned DoubleDestReg,
MachineOperand &HiOperand,
MachineOperand &LoOperand) {
LLVM_DEBUG(dbgs() << "Found a CONST64\n");
DebugLoc DL = InsertPt->getDebugLoc();
MachineBasicBlock *BB = InsertPt->getParent();
assert(LoOperand.isImm() && HiOperand.isImm() &&
"Both operands must be immediate");
int64_t V = HiOperand.getImm();
V = (V << 32) | (0x0ffffffffLL & LoOperand.getImm());
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::CONST64), DoubleDestReg)
.addImm(V);
}
void HexagonCopyToCombine::emitCombineII(MachineBasicBlock::iterator &InsertPt,
unsigned DoubleDestReg,
MachineOperand &HiOperand,
MachineOperand &LoOperand) {
DebugLoc DL = InsertPt->getDebugLoc();
MachineBasicBlock *BB = InsertPt->getParent();
if (HiOperand.isGlobal()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
.addGlobalAddress(HiOperand.getGlobal(), HiOperand.getOffset(),
HiOperand.getTargetFlags())
.addImm(LoOperand.getImm());
return;
}
if (LoOperand.isGlobal()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addGlobalAddress(LoOperand.getGlobal(), LoOperand.getOffset(),
LoOperand.getTargetFlags());
return;
}
if (HiOperand.isBlockAddress()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
.addBlockAddress(HiOperand.getBlockAddress(), HiOperand.getOffset(),
HiOperand.getTargetFlags())
.addImm(LoOperand.getImm());
return;
}
if (LoOperand.isBlockAddress()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addBlockAddress(LoOperand.getBlockAddress(), LoOperand.getOffset(),
LoOperand.getTargetFlags());
return;
}
if (HiOperand.isJTI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
.addJumpTableIndex(HiOperand.getIndex(), HiOperand.getTargetFlags())
.addImm(LoOperand.getImm());
return;
}
if (LoOperand.isJTI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addJumpTableIndex(LoOperand.getIndex(), LoOperand.getTargetFlags());
return;
}
if (HiOperand.isCPI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
.addConstantPoolIndex(HiOperand.getIndex(), HiOperand.getOffset(),
HiOperand.getTargetFlags())
.addImm(LoOperand.getImm());
return;
}
if (LoOperand.isCPI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addConstantPoolIndex(LoOperand.getIndex(), LoOperand.getOffset(),
LoOperand.getTargetFlags());
return;
}
if (isInt<8>(LoOperand.getImm())) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addImm(LoOperand.getImm());
return;
}
if (isInt<8>(HiOperand.getImm())) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addImm(LoOperand.getImm());
return;
}
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
.addImm(HiOperand.getImm())
.addImm(LoOperand.getImm());
}
void HexagonCopyToCombine::emitCombineIR(MachineBasicBlock::iterator &InsertPt,
unsigned DoubleDestReg,
MachineOperand &HiOperand,
MachineOperand &LoOperand) {
Register LoReg = LoOperand.getReg();
unsigned LoRegKillFlag = getKillRegState(LoOperand.isKill());
DebugLoc DL = InsertPt->getDebugLoc();
MachineBasicBlock *BB = InsertPt->getParent();
if (HiOperand.isGlobal()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
.addGlobalAddress(HiOperand.getGlobal(), HiOperand.getOffset(),
HiOperand.getTargetFlags())
.addReg(LoReg, LoRegKillFlag);
return;
}
if (HiOperand.isBlockAddress()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
.addBlockAddress(HiOperand.getBlockAddress(), HiOperand.getOffset(),
HiOperand.getTargetFlags())
.addReg(LoReg, LoRegKillFlag);
return;
}
if (HiOperand.isJTI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
.addJumpTableIndex(HiOperand.getIndex(), HiOperand.getTargetFlags())
.addReg(LoReg, LoRegKillFlag);
return;
}
if (HiOperand.isCPI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
.addConstantPoolIndex(HiOperand.getIndex(), HiOperand.getOffset(),
HiOperand.getTargetFlags())
.addReg(LoReg, LoRegKillFlag);
return;
}
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
.addImm(HiOperand.getImm())
.addReg(LoReg, LoRegKillFlag);
}
void HexagonCopyToCombine::emitCombineRI(MachineBasicBlock::iterator &InsertPt,
unsigned DoubleDestReg,
MachineOperand &HiOperand,
MachineOperand &LoOperand) {
unsigned HiRegKillFlag = getKillRegState(HiOperand.isKill());
Register HiReg = HiOperand.getReg();
DebugLoc DL = InsertPt->getDebugLoc();
MachineBasicBlock *BB = InsertPt->getParent();
if (LoOperand.isGlobal()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
.addReg(HiReg, HiRegKillFlag)
.addGlobalAddress(LoOperand.getGlobal(), LoOperand.getOffset(),
LoOperand.getTargetFlags());
return;
}
if (LoOperand.isBlockAddress()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
.addReg(HiReg, HiRegKillFlag)
.addBlockAddress(LoOperand.getBlockAddress(), LoOperand.getOffset(),
LoOperand.getTargetFlags());
return;
}
if (LoOperand.isJTI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
.addReg(HiOperand.getReg(), HiRegKillFlag)
.addJumpTableIndex(LoOperand.getIndex(), LoOperand.getTargetFlags());
return;
}
if (LoOperand.isCPI()) {
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
.addReg(HiOperand.getReg(), HiRegKillFlag)
.addConstantPoolIndex(LoOperand.getIndex(), LoOperand.getOffset(),
LoOperand.getTargetFlags());
return;
}
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
.addReg(HiReg, HiRegKillFlag)
.addImm(LoOperand.getImm());
}
void HexagonCopyToCombine::emitCombineRR(MachineBasicBlock::iterator &InsertPt,
unsigned DoubleDestReg,
MachineOperand &HiOperand,
MachineOperand &LoOperand) {
unsigned LoRegKillFlag = getKillRegState(LoOperand.isKill());
unsigned HiRegKillFlag = getKillRegState(HiOperand.isKill());
Register LoReg = LoOperand.getReg();
Register HiReg = HiOperand.getReg();
DebugLoc DL = InsertPt->getDebugLoc();
MachineBasicBlock *BB = InsertPt->getParent();
unsigned NewOpc;
if (Hexagon::DoubleRegsRegClass.contains(DoubleDestReg)) {
NewOpc = Hexagon::A2_combinew;
} else if (Hexagon::HvxWRRegClass.contains(DoubleDestReg)) {
assert(ST->useHVXOps());
NewOpc = Hexagon::V6_vcombine;
} else
llvm_unreachable("Unexpected register");
BuildMI(*BB, InsertPt, DL, TII->get(NewOpc), DoubleDestReg)
.addReg(HiReg, HiRegKillFlag)
.addReg(LoReg, LoRegKillFlag);
}
FunctionPass *llvm::createHexagonCopyToCombine() {
return new HexagonCopyToCombine();
}