2012-02-18 12:03:15 +00:00
|
|
|
//===-- HexagonExpandPredSpillCode.cpp - Expand Predicate Spill Code ------===//
|
2011-12-12 21:14:40 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
2012-02-18 12:03:15 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2011-12-12 21:14:40 +00:00
|
|
|
// The Hexagon processor has no instructions that load or store predicate
|
2012-05-03 21:52:53 +00:00
|
|
|
// registers directly. So, when these registers must be spilled a general
|
|
|
|
// purpose register must be found and the value copied to/from it from/to
|
|
|
|
// the predicate register. This code currently does not use the register
|
2011-12-12 21:14:40 +00:00
|
|
|
// scavenger mechanism available in the allocator. There are two registers
|
|
|
|
// reserved to allow spilling/restoring predicate registers. One is used to
|
|
|
|
// hold the predicate value. The other is used when stack frame offsets are
|
|
|
|
// too large.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "Hexagon.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "HexagonMachineFunctionInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "HexagonSubtarget.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/CodeGen/LatencyPriorityQueue.h"
|
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "llvm/CodeGen/SchedulerRegistry.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
2013-05-06 21:58:00 +00:00
|
|
|
namespace llvm {
|
|
|
|
void initializeHexagonExpandPredSpillCodePass(PassRegistry&);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-12 21:14:40 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class HexagonExpandPredSpillCode : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2015-02-02 18:46:31 +00:00
|
|
|
HexagonExpandPredSpillCode() : MachineFunctionPass(ID) {
|
2013-05-06 21:58:00 +00:00
|
|
|
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
|
|
|
initializeHexagonExpandPredSpillCodePass(Registry);
|
|
|
|
}
|
2011-12-12 21:14:40 +00:00
|
|
|
|
2014-04-29 07:58:16 +00:00
|
|
|
const char *getPassName() const override {
|
2011-12-12 21:14:40 +00:00
|
|
|
return "Hexagon Expand Predicate Spill Code";
|
|
|
|
}
|
2014-04-29 07:58:16 +00:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
2011-12-12 21:14:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
char HexagonExpandPredSpillCode::ID = 0;
|
|
|
|
|
|
|
|
|
|
|
|
bool HexagonExpandPredSpillCode::runOnMachineFunction(MachineFunction &Fn) {
|
|
|
|
|
2015-02-02 18:46:31 +00:00
|
|
|
const HexagonSubtarget &QST = Fn.getSubtarget<HexagonSubtarget>();
|
|
|
|
const HexagonInstrInfo *TII = QST.getInstrInfo();
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
// Loop over all of the basic blocks.
|
|
|
|
for (MachineFunction::iterator MBBb = Fn.begin(), MBBe = Fn.end();
|
|
|
|
MBBb != MBBe; ++MBBb) {
|
|
|
|
MachineBasicBlock* MBB = MBBb;
|
|
|
|
// Traverse the basic block.
|
|
|
|
for (MachineBasicBlock::iterator MII = MBB->begin(); MII != MBB->end();
|
|
|
|
++MII) {
|
|
|
|
MachineInstr *MI = MII;
|
|
|
|
int Opc = MI->getOpcode();
|
|
|
|
if (Opc == Hexagon::STriw_pred) {
|
|
|
|
// STriw_pred [R30], ofst, SrcReg;
|
|
|
|
unsigned FP = MI->getOperand(0).getReg();
|
2015-02-02 18:58:24 +00:00
|
|
|
assert(FP == QST.getRegisterInfo()->getFrameRegister() &&
|
2015-02-02 18:46:31 +00:00
|
|
|
"Not a Frame Pointer, Nor a Spill Slot");
|
2011-12-12 21:14:40 +00:00
|
|
|
assert(MI->getOperand(1).isImm() && "Not an offset");
|
|
|
|
int Offset = MI->getOperand(1).getImm();
|
|
|
|
int SrcReg = MI->getOperand(2).getReg();
|
|
|
|
assert(Hexagon::PredRegsRegClass.contains(SrcReg) &&
|
|
|
|
"Not a predicate register");
|
2014-12-29 20:44:51 +00:00
|
|
|
if (!TII->isValidOffset(Hexagon::S2_storeri_io, Offset)) {
|
2015-02-05 17:49:13 +00:00
|
|
|
if (!TII->isValidOffset(Hexagon::A2_addi, Offset)) {
|
2011-12-12 21:14:40 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
|
|
|
TII->get(Hexagon::CONST32_Int_Real),
|
|
|
|
HEXAGON_RESERVED_REG_1).addImm(Offset);
|
2014-11-18 20:28:11 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::A2_add),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_1)
|
|
|
|
.addReg(FP).addReg(HEXAGON_RESERVED_REG_1);
|
2014-12-09 18:16:49 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::C2_tfrpr),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_2).addReg(SrcReg);
|
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
2014-12-29 20:44:51 +00:00
|
|
|
TII->get(Hexagon::S2_storeri_io))
|
2011-12-12 21:14:40 +00:00
|
|
|
.addReg(HEXAGON_RESERVED_REG_1)
|
|
|
|
.addImm(0).addReg(HEXAGON_RESERVED_REG_2);
|
|
|
|
} else {
|
2015-02-05 17:49:13 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::A2_addi),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_1).addReg(FP).addImm(Offset);
|
2014-12-09 18:16:49 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::C2_tfrpr),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_2).addReg(SrcReg);
|
2012-05-03 21:52:53 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
2014-12-29 20:44:51 +00:00
|
|
|
TII->get(Hexagon::S2_storeri_io))
|
2011-12-12 21:14:40 +00:00
|
|
|
.addReg(HEXAGON_RESERVED_REG_1)
|
|
|
|
.addImm(0)
|
|
|
|
.addReg(HEXAGON_RESERVED_REG_2);
|
|
|
|
}
|
|
|
|
} else {
|
2014-12-09 18:16:49 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::C2_tfrpr),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_2).addReg(SrcReg);
|
2012-05-03 21:52:53 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
2014-12-29 20:44:51 +00:00
|
|
|
TII->get(Hexagon::S2_storeri_io)).
|
2011-12-12 21:14:40 +00:00
|
|
|
addReg(FP).addImm(Offset).addReg(HEXAGON_RESERVED_REG_2);
|
|
|
|
}
|
|
|
|
MII = MBB->erase(MI);
|
|
|
|
--MII;
|
|
|
|
} else if (Opc == Hexagon::LDriw_pred) {
|
|
|
|
// DstReg = LDriw_pred [R30], ofst.
|
|
|
|
int DstReg = MI->getOperand(0).getReg();
|
|
|
|
assert(Hexagon::PredRegsRegClass.contains(DstReg) &&
|
|
|
|
"Not a predicate register");
|
|
|
|
unsigned FP = MI->getOperand(1).getReg();
|
2015-02-02 18:58:24 +00:00
|
|
|
assert(FP == QST.getRegisterInfo()->getFrameRegister() &&
|
2015-02-02 18:46:31 +00:00
|
|
|
"Not a Frame Pointer, Nor a Spill Slot");
|
2011-12-12 21:14:40 +00:00
|
|
|
assert(MI->getOperand(2).isImm() && "Not an offset");
|
|
|
|
int Offset = MI->getOperand(2).getImm();
|
2014-12-23 20:02:16 +00:00
|
|
|
if (!TII->isValidOffset(Hexagon::L2_loadri_io, Offset)) {
|
2015-02-05 17:49:13 +00:00
|
|
|
if (!TII->isValidOffset(Hexagon::A2_addi, Offset)) {
|
2011-12-12 21:14:40 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
|
|
|
TII->get(Hexagon::CONST32_Int_Real),
|
|
|
|
HEXAGON_RESERVED_REG_1).addImm(Offset);
|
2014-11-18 20:28:11 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::A2_add),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_1)
|
|
|
|
.addReg(FP)
|
|
|
|
.addReg(HEXAGON_RESERVED_REG_1);
|
2014-12-23 20:02:16 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::L2_loadri_io),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_2)
|
|
|
|
.addReg(HEXAGON_RESERVED_REG_1)
|
|
|
|
.addImm(0);
|
2014-12-09 18:16:49 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::C2_tfrrp),
|
2011-12-12 21:14:40 +00:00
|
|
|
DstReg).addReg(HEXAGON_RESERVED_REG_2);
|
|
|
|
} else {
|
2015-02-05 17:49:13 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::A2_addi),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_1).addReg(FP).addImm(Offset);
|
2014-12-23 20:02:16 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::L2_loadri_io),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_2)
|
|
|
|
.addReg(HEXAGON_RESERVED_REG_1)
|
|
|
|
.addImm(0);
|
2014-12-09 18:16:49 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::C2_tfrrp),
|
2011-12-12 21:14:40 +00:00
|
|
|
DstReg).addReg(HEXAGON_RESERVED_REG_2);
|
|
|
|
}
|
|
|
|
} else {
|
2014-12-23 20:02:16 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::L2_loadri_io),
|
2011-12-12 21:14:40 +00:00
|
|
|
HEXAGON_RESERVED_REG_2).addReg(FP).addImm(Offset);
|
2014-12-09 18:16:49 +00:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(), TII->get(Hexagon::C2_tfrrp),
|
2011-12-12 21:14:40 +00:00
|
|
|
DstReg).addReg(HEXAGON_RESERVED_REG_2);
|
|
|
|
}
|
|
|
|
MII = MBB->erase(MI);
|
|
|
|
--MII;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public Constructor Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-05-06 21:58:00 +00:00
|
|
|
static void initializePassOnce(PassRegistry &Registry) {
|
|
|
|
const char *Name = "Hexagon Expand Predicate Spill Code";
|
|
|
|
PassInfo *PI = new PassInfo(Name, "hexagon-spill-pred",
|
|
|
|
&HexagonExpandPredSpillCode::ID,
|
2014-04-25 05:30:21 +00:00
|
|
|
nullptr, false, false);
|
2013-05-06 21:58:00 +00:00
|
|
|
Registry.registerPass(*PI, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void llvm::initializeHexagonExpandPredSpillCodePass(PassRegistry &Registry) {
|
|
|
|
CALL_ONCE_INITIALIZATION(initializePassOnce)
|
|
|
|
}
|
|
|
|
|
2013-05-06 18:38:37 +00:00
|
|
|
FunctionPass*
|
2015-02-02 18:46:31 +00:00
|
|
|
llvm::createHexagonExpandPredSpillCode() {
|
|
|
|
return new HexagonExpandPredSpillCode();
|
2011-12-12 21:14:40 +00:00
|
|
|
}
|