2013-05-08 03:53:00 +08:00
|
|
|
//=== HexagonSplitConst32AndConst64.cpp - split CONST32/Const64 into HI/LO ===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// When the compiler is invoked with no small data, for instance, with the -G0
|
2016-08-11 00:46:36 +08:00
|
|
|
// command line option, then all CONST* opcodes should be broken down into
|
2013-05-08 03:53:00 +08:00
|
|
|
// appropriate LO and HI instructions. This splitting is done by this pass.
|
|
|
|
// The only reason this is not done in the DAG lowering itself is that there
|
|
|
|
// is no simple way of getting the register allocator to allot the same hard
|
|
|
|
// register to the result of LO and HI instructions. This pass is always
|
|
|
|
// scheduled after register allocation.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-08-22 04:36:42 +08:00
|
|
|
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "HexagonSubtarget.h"
|
2014-05-22 06:42:07 +08:00
|
|
|
#include "HexagonTargetMachine.h"
|
|
|
|
#include "HexagonTargetObjectFile.h"
|
2013-05-08 03:53:00 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2013-08-22 04:36:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "xfer"
|
|
|
|
|
2015-06-16 03:05:35 +08:00
|
|
|
namespace llvm {
|
|
|
|
FunctionPass *createHexagonSplitConst32AndConst64();
|
|
|
|
void initializeHexagonSplitConst32AndConst64Pass(PassRegistry&);
|
|
|
|
}
|
|
|
|
|
2013-05-08 03:53:00 +08:00
|
|
|
namespace {
|
2016-08-11 02:05:47 +08:00
|
|
|
class HexagonSplitConst32AndConst64 : public MachineFunctionPass {
|
|
|
|
public:
|
2013-05-08 03:53:00 +08:00
|
|
|
static char ID;
|
2016-08-11 02:05:47 +08:00
|
|
|
HexagonSplitConst32AndConst64() : MachineFunctionPass(ID) {
|
|
|
|
PassRegistry &R = *PassRegistry::getPassRegistry();
|
|
|
|
initializeHexagonSplitConst32AndConst64Pass(R);
|
|
|
|
}
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override {
|
2013-05-08 03:53:00 +08:00
|
|
|
return "Hexagon Split Const32s and Const64s";
|
|
|
|
}
|
2014-04-29 15:58:16 +08:00
|
|
|
bool runOnMachineFunction(MachineFunction &Fn) override;
|
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
|
|
|
}
|
2016-08-11 02:05:47 +08:00
|
|
|
};
|
|
|
|
}
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
char HexagonSplitConst32AndConst64::ID = 0;
|
|
|
|
|
2016-08-11 02:05:47 +08:00
|
|
|
INITIALIZE_PASS(HexagonSplitConst32AndConst64, "split-const-for-sdata",
|
|
|
|
"Hexagon Split Const32s and Const64s", false, false)
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
bool HexagonSplitConst32AndConst64::runOnMachineFunction(MachineFunction &Fn) {
|
2014-05-22 06:42:07 +08:00
|
|
|
const HexagonTargetObjectFile &TLOF =
|
2015-02-03 06:11:43 +08:00
|
|
|
*static_cast<const HexagonTargetObjectFile *>(
|
|
|
|
Fn.getTarget().getObjFileLowering());
|
2016-04-22 02:56:45 +08:00
|
|
|
if (TLOF.isSmallDataEnabled())
|
2014-05-22 06:42:07 +08:00
|
|
|
return true;
|
|
|
|
|
2015-02-03 06:11:43 +08:00
|
|
|
const TargetInstrInfo *TII = Fn.getSubtarget().getInstrInfo();
|
2015-03-10 04:11:02 +08:00
|
|
|
const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
// Loop over all of the basic blocks
|
2016-08-11 02:05:47 +08:00
|
|
|
for (MachineBasicBlock &B : Fn) {
|
|
|
|
for (auto I = B.begin(), E = B.end(); I != E; ) {
|
|
|
|
MachineInstr &MI = *I;
|
|
|
|
++I;
|
|
|
|
unsigned Opc = MI.getOpcode();
|
|
|
|
|
|
|
|
if (Opc == Hexagon::CONST32) {
|
|
|
|
unsigned DestReg = MI.getOperand(0).getReg();
|
|
|
|
uint64_t ImmValue = MI.getOperand(1).getImm();
|
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
|
|
|
BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestReg)
|
2016-07-12 09:55:32 +08:00
|
|
|
.addImm(ImmValue);
|
2016-08-11 02:05:47 +08:00
|
|
|
B.erase(&MI);
|
|
|
|
} else if (Opc == Hexagon::CONST64) {
|
|
|
|
unsigned DestReg = MI.getOperand(0).getReg();
|
2016-08-11 00:46:36 +08:00
|
|
|
int64_t ImmValue = MI.getOperand(1).getImm();
|
2016-08-11 02:05:47 +08:00
|
|
|
const DebugLoc &DL = MI.getDebugLoc();
|
2016-11-10 00:19:08 +08:00
|
|
|
unsigned DestLo = TRI->getSubReg(DestReg, Hexagon::isub_lo);
|
|
|
|
unsigned DestHi = TRI->getSubReg(DestReg, Hexagon::isub_hi);
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
int32_t LowWord = (ImmValue & 0xFFFFFFFF);
|
|
|
|
int32_t HighWord = (ImmValue >> 32) & 0xFFFFFFFF;
|
|
|
|
|
2016-08-11 02:05:47 +08:00
|
|
|
BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestLo)
|
2016-07-12 09:55:32 +08:00
|
|
|
.addImm(LowWord);
|
2016-08-11 02:05:47 +08:00
|
|
|
BuildMI(B, MI, DL, TII->get(Hexagon::A2_tfrsi), DestHi)
|
2016-07-12 09:55:32 +08:00
|
|
|
.addImm(HighWord);
|
2016-08-11 02:05:47 +08:00
|
|
|
B.erase(&MI);
|
2015-03-10 04:11:02 +08:00
|
|
|
}
|
2013-05-08 03:53:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public Constructor Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-08-11 02:05:47 +08:00
|
|
|
FunctionPass *llvm::createHexagonSplitConst32AndConst64() {
|
2015-02-03 06:11:43 +08:00
|
|
|
return new HexagonSplitConst32AndConst64();
|
2013-05-08 03:53:00 +08:00
|
|
|
}
|