2013-05-15 02:54:06 +08:00
|
|
|
//===------- HexagonCopyToCombine.cpp - Hexagon Copy-To-Combine Pass ------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-05-15 02:54:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// This pass replaces transfer instructions by combine instructions.
|
|
|
|
// We walk along a basic block and look for two combinable instructions and try
|
|
|
|
// to move them together. If we can move them next to each other we do so and
|
|
|
|
// replace them with a combine instruction.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "HexagonInstrInfo.h"
|
|
|
|
#include "HexagonSubtarget.h"
|
2013-05-15 02:54:06 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2013-05-15 02:54:06 +08:00
|
|
|
#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"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/PassSupport.h"
|
2013-05-15 02:54:06 +08:00
|
|
|
#include "llvm/Support/CodeGen.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "hexagon-copy-combine"
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
static
|
|
|
|
cl::opt<bool> IsCombinesDisabled("disable-merge-into-combines",
|
|
|
|
cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::init(false),
|
|
|
|
cl::desc("Disable merging into combines"));
|
|
|
|
static
|
2016-01-15 22:08:31 +08:00
|
|
|
cl::opt<bool> IsConst64Disabled("disable-const64",
|
|
|
|
cl::Hidden, cl::ZeroOrMore,
|
|
|
|
cl::init(false),
|
|
|
|
cl::desc("Disable generation of const64"));
|
|
|
|
static
|
2013-05-15 02:54:06 +08:00
|
|
|
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 {
|
2015-06-16 03:05:35 +08:00
|
|
|
FunctionPass *createHexagonCopyToCombine();
|
2013-05-15 02:54:06 +08:00
|
|
|
void initializeHexagonCopyToCombinePass(PassRegistry&);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class HexagonCopyToCombine : public MachineFunctionPass {
|
|
|
|
const HexagonInstrInfo *TII;
|
|
|
|
const TargetRegisterInfo *TRI;
|
2016-08-18 22:12:34 +08:00
|
|
|
const HexagonSubtarget *ST;
|
2013-05-15 02:54:06 +08:00
|
|
|
bool ShouldCombineAggressively;
|
|
|
|
|
|
|
|
DenseSet<MachineInstr *> PotentiallyNewifiableTFR;
|
2016-01-15 21:55:57 +08:00
|
|
|
SmallVector<MachineInstr *, 8> DbgMItoMove;
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
HexagonCopyToCombine() : MachineFunctionPass(ID) {
|
|
|
|
initializeHexagonCopyToCombinePass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2013-05-15 02:54:06 +08:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override {
|
2013-05-15 02:54:06 +08:00
|
|
|
return "Hexagon Copy-To-Combine Pass";
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2016-04-05 01:09:25 +08:00
|
|
|
MachineFunctionProperties getRequiredProperties() const override {
|
|
|
|
return MachineFunctionProperties().set(
|
2016-08-25 09:27:13 +08:00
|
|
|
MachineFunctionProperties::Property::NoVRegs);
|
2016-04-05 01:09:25 +08:00
|
|
|
}
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
private:
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr *findPairable(MachineInstr &I1, bool &DoInsertAtI1,
|
2016-01-15 22:08:31 +08:00
|
|
|
bool AllowC64);
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
void findPotentialNewifiableTFRs(MachineBasicBlock &);
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
void combine(MachineInstr &I1, MachineInstr &I2,
|
2016-01-15 22:08:31 +08:00
|
|
|
MachineBasicBlock::iterator &MI, bool DoInsertAtI1,
|
|
|
|
bool OptForSize);
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
bool isSafeToMoveTogether(MachineInstr &I1, MachineInstr &I2,
|
2013-05-15 02:54:06 +08:00
|
|
|
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);
|
2016-01-15 22:08:31 +08:00
|
|
|
|
|
|
|
void emitConst64(MachineBasicBlock::iterator &Before, unsigned DestReg,
|
|
|
|
MachineOperand &HiOperand, MachineOperand &LoOperand);
|
2013-05-15 02:54:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End anonymous namespace.
|
|
|
|
|
|
|
|
char HexagonCopyToCombine::ID = 0;
|
|
|
|
|
|
|
|
INITIALIZE_PASS(HexagonCopyToCombine, "hexagon-copy-combine",
|
|
|
|
"Hexagon Copy-To-Combine Pass", false, false)
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
static bool isCombinableInstType(MachineInstr &MI, const HexagonInstrInfo *TII,
|
2013-05-15 02:54:06 +08:00
|
|
|
bool ShouldCombineAggressively) {
|
2016-07-12 09:55:32 +08:00
|
|
|
switch (MI.getOpcode()) {
|
2014-12-10 04:23:30 +08:00
|
|
|
case Hexagon::A2_tfr: {
|
2013-05-15 02:54:06 +08:00
|
|
|
// A COPY instruction can be combined if its arguments are IntRegs (32bit).
|
2016-07-12 09:55:32 +08:00
|
|
|
const MachineOperand &Op0 = MI.getOperand(0);
|
|
|
|
const MachineOperand &Op1 = MI.getOperand(1);
|
2015-04-23 02:25:53 +08:00
|
|
|
assert(Op0.isReg() && Op1.isReg());
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2015-04-23 02:25:53 +08:00
|
|
|
unsigned DestReg = Op0.getReg();
|
|
|
|
unsigned SrcReg = Op1.getReg();
|
2013-05-15 02:54:06 +08:00
|
|
|
return Hexagon::IntRegsRegClass.contains(DestReg) &&
|
2015-04-23 02:25:53 +08:00
|
|
|
Hexagon::IntRegsRegClass.contains(SrcReg);
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
2014-12-10 04:23:30 +08:00
|
|
|
case Hexagon::A2_tfrsi: {
|
2013-05-15 02:54:06 +08:00
|
|
|
// A transfer-immediate can be combined if its argument is a signed 8bit
|
|
|
|
// value.
|
2016-07-12 09:55:32 +08:00
|
|
|
const MachineOperand &Op0 = MI.getOperand(0);
|
|
|
|
const MachineOperand &Op1 = MI.getOperand(1);
|
2015-03-10 05:48:13 +08:00
|
|
|
assert(Op0.isReg());
|
|
|
|
|
|
|
|
unsigned DestReg = Op0.getReg();
|
|
|
|
// Ensure that TargetFlags are MO_NO_FLAG for a global. This is a
|
|
|
|
// workaround for an ABI bug that prevents GOT relocations on combine
|
|
|
|
// instructions
|
|
|
|
if (!Op1.isImm() && Op1.getTargetFlags() != HexagonII::MO_NO_FLAG)
|
|
|
|
return false;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2015-03-10 05:48:13 +08:00
|
|
|
// Only combine constant extended A2_tfrsi if we are in aggressive mode.
|
|
|
|
bool NotExt = Op1.isImm() && isInt<8>(Op1.getImm());
|
2013-05-15 02:54:06 +08:00
|
|
|
return Hexagon::IntRegsRegClass.contains(DestReg) &&
|
2015-03-10 05:48:13 +08:00
|
|
|
(ShouldCombineAggressively || NotExt);
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
2016-08-18 22:12:34 +08:00
|
|
|
case Hexagon::V6_vassign:
|
|
|
|
return true;
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
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);
|
2015-04-23 02:25:53 +08:00
|
|
|
return !Op.isImm() || !isInt<N>(Op.getImm());
|
|
|
|
}
|
|
|
|
return false;
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// areCombinableOperations - Returns true if the two instruction can be merge
|
|
|
|
/// into a combine (ignoring register constraints).
|
|
|
|
static bool areCombinableOperations(const TargetRegisterInfo *TRI,
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr &HighRegInst,
|
|
|
|
MachineInstr &LowRegInst, bool AllowC64) {
|
|
|
|
unsigned HiOpc = HighRegInst.getOpcode();
|
|
|
|
unsigned LoOpc = LowRegInst.getOpcode();
|
2016-08-18 22:12:34 +08:00
|
|
|
|
|
|
|
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;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2016-01-15 22:08:31 +08:00
|
|
|
if (!AllowC64) {
|
|
|
|
// There is no combine of two constant extended values.
|
|
|
|
if (isGreaterThanNBitTFRI<8>(HighRegInst) &&
|
|
|
|
isGreaterThanNBitTFRI<6>(LowRegInst))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is a combine of two constant extended values into CONST64,
|
|
|
|
// provided both constants are true immediates.
|
|
|
|
if (isGreaterThanNBitTFRI<16>(HighRegInst) &&
|
|
|
|
isGreaterThanNBitTFRI<16>(LowRegInst))
|
2016-07-12 09:55:32 +08:00
|
|
|
return (HighRegInst.getOperand(1).isImm() &&
|
|
|
|
LowRegInst.getOperand(1).isImm());
|
2016-01-15 22:08:31 +08:00
|
|
|
|
|
|
|
// There is no combine of two constant extended values, unless handled above
|
|
|
|
// Make both 8-bit size checks to allow both combine (#,##) and combine(##,#)
|
2015-04-23 02:25:53 +08:00
|
|
|
if (isGreaterThanNBitTFRI<8>(HighRegInst) &&
|
2016-01-15 22:08:31 +08:00
|
|
|
isGreaterThanNBitTFRI<8>(LowRegInst))
|
2013-05-15 02:54:06 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isEvenReg(unsigned Reg) {
|
2019-08-02 07:27:28 +08:00
|
|
|
assert(Register::isPhysicalRegister(Reg));
|
2016-08-18 22:12:34 +08:00
|
|
|
if (Hexagon::IntRegsRegClass.contains(Reg))
|
|
|
|
return (Reg - Hexagon::R0) % 2 == 0;
|
2017-09-15 23:46:05 +08:00
|
|
|
if (Hexagon::HvxVRRegClass.contains(Reg))
|
2016-08-18 22:12:34 +08:00
|
|
|
return (Reg - Hexagon::V0) % 2 == 0;
|
|
|
|
llvm_unreachable("Invalid register");
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
static void removeKillInfo(MachineInstr &MI, unsigned RegNotKilled) {
|
|
|
|
for (unsigned I = 0, E = MI.getNumOperands(); I != E; ++I) {
|
|
|
|
MachineOperand &Op = MI.getOperand(I);
|
2013-05-15 02:54:06 +08:00
|
|
|
if (!Op.isReg() || Op.getReg() != RegNotKilled || !Op.isKill())
|
|
|
|
continue;
|
|
|
|
Op.setIsKill(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
/// Returns true if it is unsafe to move a copy instruction from \p UseReg to
|
|
|
|
/// \p DestReg over the instruction \p MI.
|
|
|
|
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) ||
|
2017-08-10 23:00:30 +08:00
|
|
|
MI.hasUnmodeledSideEffects() || MI.isInlineAsm() ||
|
|
|
|
MI.isMetaInstruction();
|
2015-04-23 02:25:53 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 23:50:29 +08:00
|
|
|
static Register UseReg(const MachineOperand& MO) {
|
|
|
|
return MO.isReg() ? MO.getReg() : Register();
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isSafeToMoveTogether - Returns true if it is safe to move I1 next to I2 such
|
|
|
|
/// that the two instructions can be paired in a combine.
|
2016-07-12 09:55:32 +08:00
|
|
|
bool HexagonCopyToCombine::isSafeToMoveTogether(MachineInstr &I1,
|
|
|
|
MachineInstr &I2,
|
2013-05-15 02:54:06 +08:00
|
|
|
unsigned I1DestReg,
|
|
|
|
unsigned I2DestReg,
|
|
|
|
bool &DoInsertAtI1) {
|
2016-07-12 09:55:32 +08:00
|
|
|
unsigned I2UseReg = UseReg(I2.getOperand(1));
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
// It is not safe to move I1 and I2 into one combine if I2 has a true
|
|
|
|
// dependence on I1.
|
2016-07-12 09:55:32 +08:00
|
|
|
if (I2UseReg && I1.modifiesRegister(I2UseReg, TRI))
|
2013-05-15 02:54:06 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
bool isSafe = true;
|
|
|
|
|
|
|
|
// First try to move I2 towards I1.
|
|
|
|
{
|
|
|
|
// A reverse_iterator instantiated like below starts before I2, and I1
|
|
|
|
// respectively.
|
|
|
|
// Look at instructions I in between I2 and (excluding) I1.
|
|
|
|
MachineBasicBlock::reverse_iterator I(I2),
|
|
|
|
End = --(MachineBasicBlock::reverse_iterator(I1));
|
|
|
|
// At 03 we got better results (dhrystone!) by being more conservative.
|
|
|
|
if (!ShouldCombineAggressively)
|
|
|
|
End = MachineBasicBlock::reverse_iterator(I1);
|
|
|
|
// If I2 kills its operand and we move I2 over an instruction that also
|
|
|
|
// uses I2's use reg we need to modify that (first) instruction to now kill
|
|
|
|
// this reg.
|
|
|
|
unsigned KilledOperand = 0;
|
2016-07-12 09:55:32 +08:00
|
|
|
if (I2.killsRegister(I2UseReg))
|
2013-05-15 02:54:06 +08:00
|
|
|
KilledOperand = I2UseReg;
|
2014-04-25 13:30:21 +08:00
|
|
|
MachineInstr *KillingInstr = nullptr;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
for (; I != End; ++I) {
|
|
|
|
// If the intervening instruction I:
|
|
|
|
// * modifies I2's use reg
|
|
|
|
// * modifies I2's def reg
|
|
|
|
// * reads I2's def reg
|
|
|
|
// * or has unmodelled side effects
|
|
|
|
// we can't move I2 across it.
|
2018-05-09 10:42:00 +08:00
|
|
|
if (I->isDebugInstr())
|
2016-01-15 21:55:57 +08:00
|
|
|
continue;
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
if (isUnsafeToMoveAcross(*I, I2UseReg, I2DestReg, TRI)) {
|
2013-05-15 02:54:06 +08:00
|
|
|
isSafe = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update first use of the killed operand.
|
|
|
|
if (!KillingInstr && KilledOperand &&
|
|
|
|
I->readsRegister(KilledOperand, TRI))
|
|
|
|
KillingInstr = &*I;
|
|
|
|
}
|
|
|
|
if (isSafe) {
|
|
|
|
// Update the intermediate instruction to with the kill flag.
|
|
|
|
if (KillingInstr) {
|
|
|
|
bool Added = KillingInstr->addRegisterKilled(KilledOperand, TRI, true);
|
2014-01-25 01:20:08 +08:00
|
|
|
(void)Added; // suppress compiler warning
|
2013-05-15 02:54:06 +08:00
|
|
|
assert(Added && "Must successfully update kill flag");
|
|
|
|
removeKillInfo(I2, KilledOperand);
|
|
|
|
}
|
|
|
|
DoInsertAtI1 = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to move I1 towards I2.
|
|
|
|
{
|
|
|
|
// Look at instructions I in between I1 and (excluding) I2.
|
|
|
|
MachineBasicBlock::iterator I(I1), End(I2);
|
|
|
|
// At O3 we got better results (dhrystone) by being more conservative here.
|
|
|
|
if (!ShouldCombineAggressively)
|
2014-03-02 20:27:27 +08:00
|
|
|
End = std::next(MachineBasicBlock::iterator(I2));
|
2016-07-12 09:55:32 +08:00
|
|
|
unsigned I1UseReg = UseReg(I1.getOperand(1));
|
2013-05-29 03:01:45 +08:00
|
|
|
// Track killed operands. If we move across an instruction that kills our
|
2013-05-15 02:54:06 +08:00
|
|
|
// operand, we need to update the kill information on the moved I1. It kills
|
|
|
|
// the operand now.
|
2014-04-25 13:30:21 +08:00
|
|
|
MachineInstr *KillingInstr = nullptr;
|
2013-05-15 02:54:06 +08:00
|
|
|
unsigned KilledOperand = 0;
|
|
|
|
|
|
|
|
while(++I != End) {
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr &MI = *I;
|
|
|
|
// If the intervening instruction MI:
|
2013-05-15 02:54:06 +08:00
|
|
|
// * modifies I1's use reg
|
|
|
|
// * modifies I1's def reg
|
|
|
|
// * reads I1's def reg
|
|
|
|
// * or has unmodelled side effects
|
|
|
|
// We introduce this special case because llvm has no api to remove a
|
|
|
|
// kill flag for a register (a removeRegisterKilled() analogous to
|
|
|
|
// addRegisterKilled) that handles aliased register correctly.
|
|
|
|
// * or has a killed aliased register use of I1's use reg
|
2017-12-07 18:40:31 +08:00
|
|
|
// %d4 = A2_tfrpi 16
|
|
|
|
// %r6 = A2_tfr %r9
|
|
|
|
// %r8 = KILL %r8, implicit killed %d4
|
2013-05-15 02:54:06 +08:00
|
|
|
// If we want to move R6 = across the KILL instruction we would have
|
2017-12-07 18:40:31 +08:00
|
|
|
// to remove the implicit killed %d4 operand. For now, we are
|
2013-05-15 02:54:06 +08:00
|
|
|
// conservative and disallow the move.
|
|
|
|
// we can't move I1 across it.
|
2018-05-09 10:42:00 +08:00
|
|
|
if (MI.isDebugInstr()) {
|
2016-07-12 09:55:32 +08:00
|
|
|
if (MI.readsRegister(I1DestReg, TRI)) // Move this instruction after I2.
|
|
|
|
DbgMItoMove.push_back(&MI);
|
2016-01-15 21:55:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
if (isUnsafeToMoveAcross(MI, I1UseReg, I1DestReg, TRI) ||
|
2013-05-15 02:54:06 +08:00
|
|
|
// Check for an aliased register kill. Bail out if we see one.
|
2016-07-12 09:55:32 +08:00
|
|
|
(!MI.killsRegister(I1UseReg) && MI.killsRegister(I1UseReg, TRI)))
|
2013-05-15 02:54:06 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check for an exact kill (registers match).
|
2016-07-12 09:55:32 +08:00
|
|
|
if (I1UseReg && MI.killsRegister(I1UseReg)) {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(!KillingInstr && "Should only see one killing instruction");
|
2013-05-15 02:54:06 +08:00
|
|
|
KilledOperand = I1UseReg;
|
2016-07-12 09:55:32 +08:00
|
|
|
KillingInstr = &MI;
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (KillingInstr) {
|
2016-07-12 09:55:32 +08:00
|
|
|
removeKillInfo(*KillingInstr, KilledOperand);
|
2013-05-15 02:54:06 +08:00
|
|
|
// Update I1 to set the kill flag. This flag will later be picked up by
|
|
|
|
// the new COMBINE instruction.
|
2016-07-12 09:55:32 +08:00
|
|
|
bool Added = I1.addRegisterKilled(KilledOperand, TRI);
|
2014-01-25 01:20:08 +08:00
|
|
|
(void)Added; // suppress compiler warning
|
2013-05-15 02:54:06 +08:00
|
|
|
assert(Added && "Must successfully update kill flag");
|
|
|
|
}
|
|
|
|
DoInsertAtI1 = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findPotentialNewifiableTFRs - Finds tranfers that feed stores that could be
|
|
|
|
/// newified. (A use of a 64 bit register define can not be newified)
|
|
|
|
void
|
|
|
|
HexagonCopyToCombine::findPotentialNewifiableTFRs(MachineBasicBlock &BB) {
|
|
|
|
DenseMap<unsigned, MachineInstr *> LastDef;
|
2016-07-12 09:55:32 +08:00
|
|
|
for (MachineInstr &MI : BB) {
|
2018-05-09 10:42:00 +08:00
|
|
|
if (MI.isDebugInstr())
|
2016-01-15 21:55:57 +08:00
|
|
|
continue;
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
// Mark TFRs that feed a potential new value store as such.
|
2016-07-30 05:49:42 +08:00
|
|
|
if (TII->mayBeNewStore(MI)) {
|
2013-05-15 02:54:06 +08:00
|
|
|
// Look for uses of TFR instructions.
|
2016-07-12 09:55:32 +08:00
|
|
|
for (unsigned OpdIdx = 0, OpdE = MI.getNumOperands(); OpdIdx != OpdE;
|
2013-05-15 02:54:06 +08:00
|
|
|
++OpdIdx) {
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineOperand &Op = MI.getOperand(OpdIdx);
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
// Skip over anything except register uses.
|
|
|
|
if (!Op.isReg() || !Op.isUse() || !Op.getReg())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Look for the defining instruction.
|
|
|
|
unsigned Reg = Op.getReg();
|
|
|
|
MachineInstr *DefInst = LastDef[Reg];
|
|
|
|
if (!DefInst)
|
|
|
|
continue;
|
2016-07-12 09:55:32 +08:00
|
|
|
if (!isCombinableInstType(*DefInst, TII, ShouldCombineAggressively))
|
2013-05-15 02:54:06 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Only close newifiable stores should influence the decision.
|
2016-01-15 21:55:57 +08:00
|
|
|
// Ignore the debug instructions in between.
|
2013-05-15 02:54:06 +08:00
|
|
|
MachineBasicBlock::iterator It(DefInst);
|
|
|
|
unsigned NumInstsToDef = 0;
|
2016-07-12 09:55:32 +08:00
|
|
|
while (&*It != &MI) {
|
2018-05-09 10:42:00 +08:00
|
|
|
if (!It->isDebugInstr())
|
2016-01-15 21:55:57 +08:00
|
|
|
++NumInstsToDef;
|
2016-01-21 20:45:17 +08:00
|
|
|
++It;
|
2016-01-15 21:55:57 +08:00
|
|
|
}
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
if (NumInstsToDef > MaxNumOfInstsBetweenNewValueStoreAndTFR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PotentiallyNewifiableTFR.insert(DefInst);
|
|
|
|
}
|
|
|
|
// Skip to next instruction.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put instructions that last defined integer or double registers into the
|
|
|
|
// map.
|
2017-02-18 06:14:51 +08:00
|
|
|
for (MachineOperand &Op : MI.operands()) {
|
|
|
|
if (Op.isReg()) {
|
|
|
|
if (!Op.isDef() || !Op.getReg())
|
|
|
|
continue;
|
|
|
|
unsigned 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;
|
|
|
|
}
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HexagonCopyToCombine::runOnMachineFunction(MachineFunction &MF) {
|
2017-12-16 06:22:58 +08:00
|
|
|
if (skipFunction(MF.getFunction()))
|
2017-04-14 23:26:34 +08:00
|
|
|
return false;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
if (IsCombinesDisabled) return false;
|
|
|
|
|
|
|
|
bool HasChanged = false;
|
|
|
|
|
|
|
|
// Get target info.
|
2016-08-18 22:12:34 +08:00
|
|
|
ST = &MF.getSubtarget<HexagonSubtarget>();
|
|
|
|
TRI = ST->getRegisterInfo();
|
|
|
|
TII = ST->getInstrInfo();
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2017-12-16 06:22:58 +08:00
|
|
|
const Function &F = MF.getFunction();
|
|
|
|
bool OptForSize = F.hasFnAttribute(Attribute::OptimizeForSize);
|
2016-01-15 22:08:31 +08:00
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
// Combine aggressively (for code size)
|
|
|
|
ShouldCombineAggressively =
|
|
|
|
MF.getTarget().getOptLevel() <= CodeGenOpt::Default;
|
|
|
|
|
|
|
|
// Traverse basic blocks.
|
|
|
|
for (MachineFunction::iterator BI = MF.begin(), BE = MF.end(); BI != BE;
|
|
|
|
++BI) {
|
|
|
|
PotentiallyNewifiableTFR.clear();
|
|
|
|
findPotentialNewifiableTFRs(*BI);
|
|
|
|
|
|
|
|
// Traverse instructions in basic block.
|
|
|
|
for(MachineBasicBlock::iterator MI = BI->begin(), End = BI->end();
|
|
|
|
MI != End;) {
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr &I1 = *MI++;
|
2016-01-15 21:55:57 +08:00
|
|
|
|
2018-05-09 10:42:00 +08:00
|
|
|
if (I1.isDebugInstr())
|
2016-01-15 21:55:57 +08:00
|
|
|
continue;
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
// Don't combine a TFR whose user could be newified (instructions that
|
|
|
|
// define double registers can not be newified - Programmer's Ref Manual
|
|
|
|
// 5.4.2 New-value stores).
|
2016-07-12 09:55:32 +08:00
|
|
|
if (ShouldCombineAggressively && PotentiallyNewifiableTFR.count(&I1))
|
2013-05-15 02:54:06 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Ignore instructions that are not combinable.
|
|
|
|
if (!isCombinableInstType(I1, TII, ShouldCombineAggressively))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Find a second instruction that can be merged into a combine
|
2016-01-15 21:55:57 +08:00
|
|
|
// instruction. In addition, also find all the debug instructions that
|
|
|
|
// need to be moved along with it.
|
2013-05-15 02:54:06 +08:00
|
|
|
bool DoInsertAtI1 = false;
|
2016-01-15 21:55:57 +08:00
|
|
|
DbgMItoMove.clear();
|
2016-01-15 22:08:31 +08:00
|
|
|
MachineInstr *I2 = findPairable(I1, DoInsertAtI1, OptForSize);
|
2013-05-15 02:54:06 +08:00
|
|
|
if (I2) {
|
|
|
|
HasChanged = true;
|
2016-07-12 09:55:32 +08:00
|
|
|
combine(I1, *I2, MI, DoInsertAtI1, OptForSize);
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return HasChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// findPairable - Returns an instruction that can be merged with \p I1 into a
|
|
|
|
/// COMBINE instruction or 0 if no such instruction can be found. Returns true
|
|
|
|
/// in \p DoInsertAtI1 if the combine must be inserted at instruction \p I1
|
|
|
|
/// false if the combine must be inserted at the returned instruction.
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineInstr *HexagonCopyToCombine::findPairable(MachineInstr &I1,
|
2016-01-15 22:08:31 +08:00
|
|
|
bool &DoInsertAtI1,
|
|
|
|
bool AllowC64) {
|
2014-03-02 20:27:27 +08:00
|
|
|
MachineBasicBlock::iterator I2 = std::next(MachineBasicBlock::iterator(I1));
|
2018-05-09 10:42:00 +08:00
|
|
|
while (I2 != I1.getParent()->end() && I2->isDebugInstr())
|
2016-08-25 06:36:35 +08:00
|
|
|
++I2;
|
2016-01-15 21:55:57 +08:00
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
unsigned I1DestReg = I1.getOperand(0).getReg();
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
for (MachineBasicBlock::iterator End = I1.getParent()->end(); I2 != End;
|
2013-05-15 02:54:06 +08:00
|
|
|
++I2) {
|
|
|
|
// Bail out early if we see a second definition of I1DestReg.
|
|
|
|
if (I2->modifiesRegister(I1DestReg, TRI))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Ignore non-combinable instructions.
|
2016-07-12 09:55:32 +08:00
|
|
|
if (!isCombinableInstType(*I2, TII, ShouldCombineAggressively))
|
2013-05-15 02:54:06 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Don't combine a TFR whose user could be newified.
|
2016-07-12 09:55:32 +08:00
|
|
|
if (ShouldCombineAggressively && PotentiallyNewifiableTFR.count(&*I2))
|
2013-05-15 02:54:06 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned I2DestReg = I2->getOperand(0).getReg();
|
|
|
|
|
|
|
|
// Check that registers are adjacent and that the first destination register
|
|
|
|
// is even.
|
|
|
|
bool IsI1LowReg = (I2DestReg - I1DestReg) == 1;
|
|
|
|
bool IsI2LowReg = (I1DestReg - I2DestReg) == 1;
|
|
|
|
unsigned FirstRegIndex = IsI1LowReg ? I1DestReg : I2DestReg;
|
|
|
|
if ((!IsI1LowReg && !IsI2LowReg) || !isEvenReg(FirstRegIndex))
|
|
|
|
continue;
|
|
|
|
|
2018-10-20 01:31:11 +08:00
|
|
|
// Check that the two instructions are combinable.
|
2016-01-15 21:55:57 +08:00
|
|
|
// The order matters because in a A2_tfrsi we might can encode a int8 as
|
|
|
|
// the hi reg operand but only a uint6 as the low reg operand.
|
2016-07-12 09:55:32 +08:00
|
|
|
if ((IsI2LowReg && !areCombinableOperations(TRI, I1, *I2, AllowC64)) ||
|
|
|
|
(IsI1LowReg && !areCombinableOperations(TRI, *I2, I1, AllowC64)))
|
2013-05-15 02:54:06 +08:00
|
|
|
break;
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
if (isSafeToMoveTogether(I1, *I2, I1DestReg, I2DestReg, DoInsertAtI1))
|
|
|
|
return &*I2;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
// Not safe. Stop searching.
|
|
|
|
break;
|
|
|
|
}
|
2014-04-25 13:30:21 +08:00
|
|
|
return nullptr;
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
void HexagonCopyToCombine::combine(MachineInstr &I1, MachineInstr &I2,
|
2013-05-15 02:54:06 +08:00
|
|
|
MachineBasicBlock::iterator &MI,
|
2016-01-15 22:08:31 +08:00
|
|
|
bool DoInsertAtI1, bool OptForSize) {
|
2013-05-15 02:54:06 +08:00
|
|
|
// We are going to delete I2. If MI points to I2 advance it to the next
|
|
|
|
// instruction.
|
2016-07-12 09:55:32 +08:00
|
|
|
if (MI == I2.getIterator())
|
|
|
|
++MI;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
// Figure out whether I1 or I2 goes into the lowreg part.
|
2016-07-12 09:55:32 +08:00
|
|
|
unsigned I1DestReg = I1.getOperand(0).getReg();
|
|
|
|
unsigned I2DestReg = I2.getOperand(0).getReg();
|
2013-05-15 02:54:06 +08:00
|
|
|
bool IsI1Loreg = (I2DestReg - I1DestReg) == 1;
|
|
|
|
unsigned LoRegDef = IsI1Loreg ? I1DestReg : I2DestReg;
|
2016-11-10 00:19:08 +08:00
|
|
|
unsigned SubLo;
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2016-08-18 22:12:34 +08:00
|
|
|
const TargetRegisterClass *SuperRC = nullptr;
|
|
|
|
if (Hexagon::IntRegsRegClass.contains(LoRegDef)) {
|
|
|
|
SuperRC = &Hexagon::DoubleRegsRegClass;
|
2016-11-10 00:19:08 +08:00
|
|
|
SubLo = Hexagon::isub_lo;
|
2017-09-15 23:46:05 +08:00
|
|
|
} else if (Hexagon::HvxVRRegClass.contains(LoRegDef)) {
|
2016-08-18 22:12:34 +08:00
|
|
|
assert(ST->useHVXOps());
|
2017-09-15 23:46:05 +08:00
|
|
|
SuperRC = &Hexagon::HvxWRRegClass;
|
2016-11-10 00:19:08 +08:00
|
|
|
SubLo = Hexagon::vsub_lo;
|
2016-11-10 01:50:46 +08:00
|
|
|
} else
|
|
|
|
llvm_unreachable("Unexpected register class");
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
// Get the double word register.
|
2016-11-10 00:19:08 +08:00
|
|
|
unsigned DoubleRegDest = TRI->getMatchingSuperReg(LoRegDef, SubLo, SuperRC);
|
2013-05-15 02:54:06 +08:00
|
|
|
assert(DoubleRegDest != 0 && "Expect a valid register");
|
|
|
|
|
|
|
|
// Setup source operands.
|
2016-07-12 09:55:32 +08:00
|
|
|
MachineOperand &LoOperand = IsI1Loreg ? I1.getOperand(1) : I2.getOperand(1);
|
|
|
|
MachineOperand &HiOperand = IsI1Loreg ? I2.getOperand(1) : I1.getOperand(1);
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
// Figure out which source is a register and which a constant.
|
|
|
|
bool IsHiReg = HiOperand.isReg();
|
|
|
|
bool IsLoReg = LoOperand.isReg();
|
|
|
|
|
2016-01-15 22:08:31 +08:00
|
|
|
// There is a combine of two constant extended values into CONST64.
|
|
|
|
bool IsC64 = OptForSize && LoOperand.isImm() && HiOperand.isImm() &&
|
|
|
|
isGreaterThanNBitTFRI<16>(I1) && isGreaterThanNBitTFRI<16>(I2);
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
MachineBasicBlock::iterator InsertPt(DoInsertAtI1 ? I1 : I2);
|
|
|
|
// Emit combine.
|
|
|
|
if (IsHiReg && IsLoReg)
|
|
|
|
emitCombineRR(InsertPt, DoubleRegDest, HiOperand, LoOperand);
|
|
|
|
else if (IsHiReg)
|
|
|
|
emitCombineRI(InsertPt, DoubleRegDest, HiOperand, LoOperand);
|
|
|
|
else if (IsLoReg)
|
|
|
|
emitCombineIR(InsertPt, DoubleRegDest, HiOperand, LoOperand);
|
2016-01-15 22:08:31 +08:00
|
|
|
else if (IsC64 && !IsConst64Disabled)
|
|
|
|
emitConst64(InsertPt, DoubleRegDest, HiOperand, LoOperand);
|
2013-05-15 02:54:06 +08:00
|
|
|
else
|
|
|
|
emitCombineII(InsertPt, DoubleRegDest, HiOperand, LoOperand);
|
|
|
|
|
2016-01-15 21:55:57 +08:00
|
|
|
// Move debug instructions along with I1 if it's being
|
|
|
|
// moved towards I2.
|
|
|
|
if (!DoInsertAtI1 && DbgMItoMove.size() != 0) {
|
|
|
|
// Insert debug instructions at the new location before I2.
|
|
|
|
MachineBasicBlock *BB = InsertPt->getParent();
|
|
|
|
for (auto NewMI : DbgMItoMove) {
|
|
|
|
// If iterator MI is pointing to DEBUG_VAL, make sure
|
|
|
|
// MI now points to next relevant instruction.
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 13:05:36 +08:00
|
|
|
if (NewMI == MI)
|
2016-01-15 21:55:57 +08:00
|
|
|
++MI;
|
|
|
|
BB->splice(InsertPt, BB, NewMI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 09:55:32 +08:00
|
|
|
I1.eraseFromParent();
|
|
|
|
I2.eraseFromParent();
|
2013-05-15 02:54:06 +08:00
|
|
|
}
|
|
|
|
|
2016-01-15 22:08:31 +08:00
|
|
|
void HexagonCopyToCombine::emitConst64(MachineBasicBlock::iterator &InsertPt,
|
|
|
|
unsigned DoubleDestReg,
|
|
|
|
MachineOperand &HiOperand,
|
|
|
|
MachineOperand &LoOperand) {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "Found a CONST64\n");
|
2016-01-15 22:08:31 +08:00
|
|
|
|
|
|
|
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());
|
2016-08-11 00:46:36 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::CONST64), DoubleDestReg)
|
2016-01-15 22:08:31 +08:00
|
|
|
.addImm(V);
|
|
|
|
}
|
|
|
|
|
2013-05-15 02:54:06 +08:00
|
|
|
void HexagonCopyToCombine::emitCombineII(MachineBasicBlock::iterator &InsertPt,
|
|
|
|
unsigned DoubleDestReg,
|
|
|
|
MachineOperand &HiOperand,
|
|
|
|
MachineOperand &LoOperand) {
|
|
|
|
DebugLoc DL = InsertPt->getDebugLoc();
|
|
|
|
MachineBasicBlock *BB = InsertPt->getParent();
|
|
|
|
|
2015-04-23 02:25:53 +08:00
|
|
|
// Handle globals.
|
2013-05-15 02:54:06 +08:00
|
|
|
if (HiOperand.isGlobal()) {
|
2014-12-10 03:23:45 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addGlobalAddress(HiOperand.getGlobal(), HiOperand.getOffset(),
|
|
|
|
HiOperand.getTargetFlags())
|
|
|
|
.addImm(LoOperand.getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (LoOperand.isGlobal()) {
|
2014-12-31 01:53:54 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addImm(HiOperand.getImm())
|
|
|
|
.addGlobalAddress(LoOperand.getGlobal(), LoOperand.getOffset(),
|
|
|
|
LoOperand.getTargetFlags());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-23 02:25:53 +08:00
|
|
|
// Handle block addresses.
|
|
|
|
if (HiOperand.isBlockAddress()) {
|
2014-12-10 03:23:45 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
|
2015-04-23 02:25:53 +08:00
|
|
|
.addBlockAddress(HiOperand.getBlockAddress(), HiOperand.getOffset(),
|
|
|
|
HiOperand.getTargetFlags())
|
|
|
|
.addImm(LoOperand.getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (LoOperand.isBlockAddress()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addImm(HiOperand.getImm())
|
2015-04-23 02:25:53 +08:00
|
|
|
.addBlockAddress(LoOperand.getBlockAddress(), LoOperand.getOffset(),
|
|
|
|
LoOperand.getTargetFlags());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle jump tables.
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle constant pools.
|
|
|
|
if (HiOperand.isCPI()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
|
|
|
|
.addConstantPoolIndex(HiOperand.getIndex(), HiOperand.getOffset(),
|
|
|
|
HiOperand.getTargetFlags())
|
2013-05-15 02:54:06 +08:00
|
|
|
.addImm(LoOperand.getImm());
|
|
|
|
return;
|
|
|
|
}
|
2015-04-23 02:25:53 +08:00
|
|
|
if (LoOperand.isCPI()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
|
|
|
|
.addImm(HiOperand.getImm())
|
|
|
|
.addConstantPoolIndex(LoOperand.getIndex(), LoOperand.getOffset(),
|
|
|
|
LoOperand.getTargetFlags());
|
|
|
|
return;
|
|
|
|
}
|
2013-05-15 02:54:06 +08:00
|
|
|
|
2015-04-23 02:25:53 +08:00
|
|
|
// First preference should be given to Hexagon::A2_combineii instruction
|
|
|
|
// as it can include U6 (in Hexagon::A4_combineii) as well.
|
|
|
|
// In this instruction, HiOperand is const extended, if required.
|
|
|
|
if (isInt<8>(LoOperand.getImm())) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
|
|
|
|
.addImm(HiOperand.getImm())
|
|
|
|
.addImm(LoOperand.getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In this instruction, LoOperand is const extended, if required.
|
|
|
|
if (isInt<8>(HiOperand.getImm())) {
|
2014-12-31 01:53:54 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineii), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addImm(HiOperand.getImm())
|
|
|
|
.addImm(LoOperand.getImm());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert new combine instruction.
|
|
|
|
// DoubleRegDest = combine #HiImm, #LoImm
|
2014-12-10 03:23:45 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A2_combineii), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addImm(HiOperand.getImm())
|
|
|
|
.addImm(LoOperand.getImm());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexagonCopyToCombine::emitCombineIR(MachineBasicBlock::iterator &InsertPt,
|
|
|
|
unsigned DoubleDestReg,
|
|
|
|
MachineOperand &HiOperand,
|
|
|
|
MachineOperand &LoOperand) {
|
|
|
|
unsigned LoReg = LoOperand.getReg();
|
|
|
|
unsigned LoRegKillFlag = getKillRegState(LoOperand.isKill());
|
|
|
|
|
|
|
|
DebugLoc DL = InsertPt->getDebugLoc();
|
|
|
|
MachineBasicBlock *BB = InsertPt->getParent();
|
|
|
|
|
2015-04-23 02:25:53 +08:00
|
|
|
// Handle globals.
|
2013-05-15 02:54:06 +08:00
|
|
|
if (HiOperand.isGlobal()) {
|
2014-12-31 01:53:54 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addGlobalAddress(HiOperand.getGlobal(), HiOperand.getOffset(),
|
|
|
|
HiOperand.getTargetFlags())
|
|
|
|
.addReg(LoReg, LoRegKillFlag);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-23 02:25:53 +08:00
|
|
|
// Handle block addresses.
|
|
|
|
if (HiOperand.isBlockAddress()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
|
|
|
|
.addBlockAddress(HiOperand.getBlockAddress(), HiOperand.getOffset(),
|
|
|
|
HiOperand.getTargetFlags())
|
|
|
|
.addReg(LoReg, LoRegKillFlag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handle jump tables.
|
|
|
|
if (HiOperand.isJTI()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
|
|
|
|
.addJumpTableIndex(HiOperand.getIndex(), HiOperand.getTargetFlags())
|
|
|
|
.addReg(LoReg, LoRegKillFlag);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handle constant pools.
|
|
|
|
if (HiOperand.isCPI()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
|
|
|
|
.addConstantPoolIndex(HiOperand.getIndex(), HiOperand.getOffset(),
|
|
|
|
HiOperand.getTargetFlags())
|
|
|
|
.addReg(LoReg, LoRegKillFlag);
|
|
|
|
return;
|
|
|
|
}
|
2013-05-15 02:54:06 +08:00
|
|
|
// Insert new combine instruction.
|
|
|
|
// DoubleRegDest = combine #HiImm, LoReg
|
2014-12-31 01:53:54 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineir), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addImm(HiOperand.getImm())
|
|
|
|
.addReg(LoReg, LoRegKillFlag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HexagonCopyToCombine::emitCombineRI(MachineBasicBlock::iterator &InsertPt,
|
|
|
|
unsigned DoubleDestReg,
|
|
|
|
MachineOperand &HiOperand,
|
|
|
|
MachineOperand &LoOperand) {
|
|
|
|
unsigned HiRegKillFlag = getKillRegState(HiOperand.isKill());
|
|
|
|
unsigned HiReg = HiOperand.getReg();
|
|
|
|
|
|
|
|
DebugLoc DL = InsertPt->getDebugLoc();
|
|
|
|
MachineBasicBlock *BB = InsertPt->getParent();
|
|
|
|
|
|
|
|
// Handle global.
|
|
|
|
if (LoOperand.isGlobal()) {
|
2014-12-31 01:53:54 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addReg(HiReg, HiRegKillFlag)
|
|
|
|
.addGlobalAddress(LoOperand.getGlobal(), LoOperand.getOffset(),
|
|
|
|
LoOperand.getTargetFlags());
|
|
|
|
return;
|
|
|
|
}
|
2015-04-23 02:25:53 +08:00
|
|
|
// Handle block addresses.
|
|
|
|
if (LoOperand.isBlockAddress()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
|
|
|
|
.addReg(HiReg, HiRegKillFlag)
|
|
|
|
.addBlockAddress(LoOperand.getBlockAddress(), LoOperand.getOffset(),
|
|
|
|
LoOperand.getTargetFlags());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handle jump tables.
|
|
|
|
if (LoOperand.isJTI()) {
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
|
|
|
|
.addReg(HiOperand.getReg(), HiRegKillFlag)
|
|
|
|
.addJumpTableIndex(LoOperand.getIndex(), LoOperand.getTargetFlags());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Handle constant pools.
|
|
|
|
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;
|
|
|
|
}
|
2013-05-15 02:54:06 +08:00
|
|
|
|
|
|
|
// Insert new combine instruction.
|
|
|
|
// DoubleRegDest = combine HiReg, #LoImm
|
2014-12-31 01:53:54 +08:00
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(Hexagon::A4_combineri), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.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());
|
|
|
|
unsigned LoReg = LoOperand.getReg();
|
|
|
|
unsigned HiReg = HiOperand.getReg();
|
|
|
|
|
|
|
|
DebugLoc DL = InsertPt->getDebugLoc();
|
|
|
|
MachineBasicBlock *BB = InsertPt->getParent();
|
|
|
|
|
|
|
|
// Insert new combine instruction.
|
|
|
|
// DoubleRegDest = combine HiReg, LoReg
|
2016-08-18 22:12:34 +08:00
|
|
|
unsigned NewOpc;
|
|
|
|
if (Hexagon::DoubleRegsRegClass.contains(DoubleDestReg)) {
|
|
|
|
NewOpc = Hexagon::A2_combinew;
|
2017-09-15 23:46:05 +08:00
|
|
|
} else if (Hexagon::HvxWRRegClass.contains(DoubleDestReg)) {
|
2016-08-18 22:12:34 +08:00
|
|
|
assert(ST->useHVXOps());
|
2017-09-15 23:46:05 +08:00
|
|
|
NewOpc = Hexagon::V6_vcombine;
|
2016-08-18 22:12:34 +08:00
|
|
|
} else
|
|
|
|
llvm_unreachable("Unexpected register");
|
|
|
|
|
|
|
|
BuildMI(*BB, InsertPt, DL, TII->get(NewOpc), DoubleDestReg)
|
2013-05-15 02:54:06 +08:00
|
|
|
.addReg(HiReg, HiRegKillFlag)
|
|
|
|
.addReg(LoReg, LoRegKillFlag);
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *llvm::createHexagonCopyToCombine() {
|
|
|
|
return new HexagonCopyToCombine();
|
|
|
|
}
|