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
|
|
|
|
// command line option, then all CONST32_* opcodes should be broken down into
|
|
|
|
// 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
|
|
|
|
|
|
|
#include "HexagonMachineFunctionInfo.h"
|
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/LatencyPriorityQueue.h"
|
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2013-08-22 04:36:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2013-05-08 03:53:00 +08:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2013-08-22 04:36:42 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/CodeGen/ScheduleDAGInstrs.h"
|
2013-05-08 03:53:00 +08:00
|
|
|
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
|
2013-08-22 04:36:42 +08:00
|
|
|
#include "llvm/CodeGen/SchedulerRegistry.h"
|
2013-05-08 03:53:00 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.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 {
|
|
|
|
|
|
|
|
class HexagonSplitConst32AndConst64 : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2015-02-03 06:11:43 +08:00
|
|
|
HexagonSplitConst32AndConst64() : MachineFunctionPass(ID) {}
|
2013-05-08 03:53:00 +08:00
|
|
|
|
2014-04-29 15:58:16 +08:00
|
|
|
const char *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(
|
|
|
|
MachineFunctionProperties::Property::AllVRegsAllocated);
|
|
|
|
}
|
2013-05-08 03:53:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
char HexagonSplitConst32AndConst64::ID = 0;
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
2014-05-22 06:42:07 +08:00
|
|
|
if (TLOF.IsSmallDataEnabled())
|
|
|
|
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
|
|
|
|
for (MachineFunction::iterator MBBb = Fn.begin(), MBBe = Fn.end();
|
|
|
|
MBBb != MBBe; ++MBBb) {
|
Hexagon: Remove implicit ilist iterator conversions, NFC
There are two things out of the ordinary in this commit. First, I made
a loop obviously "infinite" in HexagonInstrInfo.cpp. After checking if
an instruction was at the beginning of a basic block (in which case,
`break`), the loop decremented and checked the iterator for `nullptr` as
the loop condition. This has never been possible (the prev pointers are
always been circular, so even with the weird ilist/iplist
implementation, this isn't been possible), so I removed the condition.
Second, in HexagonAsmPrinter.cpp there was another case of comparing a
`MachineBasicBlock::instr_iterator` against `MachineBasicBlock::end()`
(which returns `MachineBasicBlock::iterator`). While not incorrect,
it's fragile. I switched this to `::instr_end()`.
All that said, no functionality change intended here.
llvm-svn: 250778
2015-10-20 08:46:39 +08:00
|
|
|
MachineBasicBlock *MBB = &*MBBb;
|
2013-05-08 03:53:00 +08:00
|
|
|
// Traverse the basic block
|
|
|
|
MachineBasicBlock::iterator MII = MBB->begin();
|
|
|
|
MachineBasicBlock::iterator MIE = MBB->end ();
|
|
|
|
while (MII != MIE) {
|
|
|
|
MachineInstr *MI = MII;
|
|
|
|
int Opc = MI->getOpcode();
|
2015-04-23 02:25:53 +08:00
|
|
|
if (Opc == Hexagon::CONST32_Int_Real &&
|
|
|
|
MI->getOperand(1).isBlockAddress()) {
|
2013-05-08 03:53:00 +08:00
|
|
|
int DestReg = MI->getOperand(0).getReg();
|
|
|
|
MachineOperand &Symbol = MI->getOperand (1);
|
|
|
|
|
|
|
|
BuildMI (*MBB, MII, MI->getDebugLoc(),
|
2015-03-10 04:11:02 +08:00
|
|
|
TII->get(Hexagon::LO), DestReg).addOperand(Symbol);
|
2013-05-08 03:53:00 +08:00
|
|
|
BuildMI (*MBB, MII, MI->getDebugLoc(),
|
2015-03-10 04:11:02 +08:00
|
|
|
TII->get(Hexagon::HI), DestReg).addOperand(Symbol);
|
2013-05-08 03:53:00 +08:00
|
|
|
// MBB->erase returns the iterator to the next instruction, which is the
|
|
|
|
// one we want to process next
|
|
|
|
MII = MBB->erase (MI);
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-10 04:11:02 +08:00
|
|
|
|
|
|
|
else if (Opc == Hexagon::CONST32_Int_Real ||
|
|
|
|
Opc == Hexagon::CONST32_Float_Real) {
|
2013-05-08 03:53:00 +08:00
|
|
|
int DestReg = MI->getOperand(0).getReg();
|
|
|
|
|
2015-03-10 04:11:02 +08:00
|
|
|
// We have to convert an FP immediate into its corresponding integer
|
|
|
|
// representation
|
|
|
|
int64_t ImmValue;
|
|
|
|
if (Opc == Hexagon::CONST32_Float_Real) {
|
|
|
|
APFloat Val = MI->getOperand(1).getFPImm()->getValueAPF();
|
|
|
|
ImmValue = *Val.bitcastToAPInt().getRawData();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ImmValue = MI->getOperand(1).getImm();
|
|
|
|
|
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
|
|
|
TII->get(Hexagon::A2_tfrsi), DestReg).addImm(ImmValue);
|
2013-05-08 03:53:00 +08:00
|
|
|
MII = MBB->erase (MI);
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-10 04:11:02 +08:00
|
|
|
else if (Opc == Hexagon::CONST64_Int_Real ||
|
|
|
|
Opc == Hexagon::CONST64_Float_Real) {
|
2013-05-08 03:53:00 +08:00
|
|
|
int DestReg = MI->getOperand(0).getReg();
|
2015-03-10 04:11:02 +08:00
|
|
|
|
|
|
|
// We have to convert an FP immediate into its corresponding integer
|
|
|
|
// representation
|
|
|
|
int64_t ImmValue;
|
|
|
|
if (Opc == Hexagon::CONST64_Float_Real) {
|
|
|
|
APFloat Val = MI->getOperand(1).getFPImm()->getValueAPF();
|
|
|
|
ImmValue = *Val.bitcastToAPInt().getRawData();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ImmValue = MI->getOperand(1).getImm();
|
|
|
|
|
|
|
|
unsigned DestLo = TRI->getSubReg(DestReg, Hexagon::subreg_loreg);
|
|
|
|
unsigned DestHi = TRI->getSubReg(DestReg, Hexagon::subreg_hireg);
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
int32_t LowWord = (ImmValue & 0xFFFFFFFF);
|
|
|
|
int32_t HighWord = (ImmValue >> 32) & 0xFFFFFFFF;
|
|
|
|
|
2015-03-10 04:11:02 +08:00
|
|
|
BuildMI(*MBB, MII, MI->getDebugLoc(),
|
|
|
|
TII->get(Hexagon::A2_tfrsi), DestLo).addImm(LowWord);
|
2013-05-08 03:53:00 +08:00
|
|
|
BuildMI (*MBB, MII, MI->getDebugLoc(),
|
2015-03-10 04:11:02 +08:00
|
|
|
TII->get(Hexagon::A2_tfrsi), DestHi).addImm(HighWord);
|
2013-05-08 03:53:00 +08:00
|
|
|
MII = MBB->erase (MI);
|
|
|
|
continue;
|
2015-03-10 04:11:02 +08:00
|
|
|
}
|
2013-05-08 03:53:00 +08:00
|
|
|
++MII;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2013-05-08 03:53:00 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public Constructor Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
FunctionPass *
|
2015-02-03 06:11:43 +08:00
|
|
|
llvm::createHexagonSplitConst32AndConst64() {
|
|
|
|
return new HexagonSplitConst32AndConst64();
|
2013-05-08 03:53:00 +08:00
|
|
|
}
|