2008-05-13 09:02:57 +00:00
|
|
|
//===- PIC16InstrInfo.cpp - PIC16 Instruction Information -----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the PIC16 implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "PIC16.h"
|
|
|
|
#include "PIC16InstrInfo.h"
|
2008-11-19 11:00:54 +00:00
|
|
|
#include "PIC16TargetMachine.h"
|
|
|
|
#include "PIC16GenInstrInfo.inc"
|
2008-05-13 09:02:57 +00:00
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2008-11-19 11:00:54 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2008-11-28 10:20:03 +00:00
|
|
|
#include <cstdio>
|
2008-11-19 11:00:54 +00:00
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2008-05-14 11:31:39 +00:00
|
|
|
// FIXME: Add the subtarget support on this constructor.
|
2008-05-13 09:02:57 +00:00
|
|
|
PIC16InstrInfo::PIC16InstrInfo(PIC16TargetMachine &tm)
|
|
|
|
: TargetInstrInfoImpl(PIC16Insts, array_lengthof(PIC16Insts)),
|
2008-11-19 11:00:54 +00:00
|
|
|
TM(tm),
|
|
|
|
RegInfo(*this, *TM.getSubtargetImpl()) {}
|
2008-05-13 09:02:57 +00:00
|
|
|
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
/// isStoreToStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// store to a stack slot, return the virtual or physical register number of
|
|
|
|
/// the source reg along with the FrameIndex of the loaded stack slot.
|
|
|
|
/// If not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than storing to the stack slot.
|
2008-11-19 11:27:59 +00:00
|
|
|
unsigned PIC16InstrInfo::isStoreToStackSlot(const MachineInstr *MI,
|
2008-11-19 11:00:54 +00:00
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == PIC16::movwf
|
|
|
|
&& MI->getOperand(0).isReg()
|
|
|
|
&& MI->getOperand(1).isSymbol()) {
|
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
|
|
|
return MI->getOperand(0).getReg();
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
/// isLoadFromStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// load from a stack slot, return the virtual or physical register number of
|
|
|
|
/// the dest reg along with the FrameIndex of the stack slot.
|
|
|
|
/// If not, return 0. This predicate must return 0 if the instruction has
|
2008-05-13 09:02:57 +00:00
|
|
|
/// any side effects other than storing to the stack slot.
|
2008-11-19 11:27:59 +00:00
|
|
|
unsigned PIC16InstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
|
2008-11-19 11:00:54 +00:00
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == PIC16::movf
|
|
|
|
&& MI->getOperand(0).isReg()
|
|
|
|
&& MI->getOperand(1).isSymbol()) {
|
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
|
|
|
return MI->getOperand(0).getReg();
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
|
|
|
|
void PIC16InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, bool isKill, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2009-04-06 10:54:50 +00:00
|
|
|
PIC16TargetLowering *PTLI = TM.getTargetLowering();
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
2008-11-19 11:00:54 +00:00
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
const Function *Func = MBB.getParent()->getFunction();
|
|
|
|
const std::string FuncName = Func->getName();
|
|
|
|
|
2009-05-10 05:23:47 +00:00
|
|
|
const char *tmpName = createESName(PAN::getTempdataLabel(FuncName));
|
2008-11-19 11:00:54 +00:00
|
|
|
|
|
|
|
// On the order of operands here: think "movwf SrcReg, tmp_slot, offset".
|
|
|
|
if (RC == PIC16::GPRRegisterClass) {
|
|
|
|
//MachineFunction &MF = *MBB.getParent();
|
|
|
|
//MachineRegisterInfo &RI = MF.getRegInfo();
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(PIC16::movwf))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2009-04-10 15:10:14 +00:00
|
|
|
.addImm(PTLI->GetTmpOffsetForFI(FI, 1))
|
|
|
|
.addExternalSymbol(tmpName)
|
|
|
|
.addImm(1); // Emit banksel for it.
|
|
|
|
}
|
|
|
|
else if (RC == PIC16::FSR16RegisterClass) {
|
|
|
|
// This is a 16-bit register and the frameindex given by llvm is of
|
|
|
|
// size two here. Break this index N into two zero based indexes and
|
|
|
|
// put one into the map. The second one is always obtained by adding 1
|
|
|
|
// to the first zero based index. In fact it is going to use 3 slots
|
|
|
|
// as saving FSRs corrupts W also and hence we need to save/restore W also.
|
|
|
|
|
|
|
|
unsigned opcode = (SrcReg == PIC16::FSR0) ? PIC16::save_fsr0
|
|
|
|
: PIC16::save_fsr1;
|
|
|
|
BuildMI(MBB, I, DL, get(opcode))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2009-04-10 15:10:14 +00:00
|
|
|
.addImm(PTLI->GetTmpOffsetForFI(FI, 3))
|
2008-11-19 11:00:54 +00:00
|
|
|
.addExternalSymbol(tmpName)
|
|
|
|
.addImm(1); // Emit banksel for it.
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
assert(0 && "Can't store this register to stack slot");
|
|
|
|
}
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
void PIC16InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2009-04-06 10:54:50 +00:00
|
|
|
PIC16TargetLowering *PTLI = TM.getTargetLowering();
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
2008-11-19 11:00:54 +00:00
|
|
|
|
2008-05-13 09:02:57 +00:00
|
|
|
const Function *Func = MBB.getParent()->getFunction();
|
|
|
|
const std::string FuncName = Func->getName();
|
|
|
|
|
2009-05-10 05:23:47 +00:00
|
|
|
const char *tmpName = createESName(PAN::getTempdataLabel(FuncName));
|
2008-11-19 11:00:54 +00:00
|
|
|
|
|
|
|
// On the order of operands here: think "movf FrameIndex, W".
|
|
|
|
if (RC == PIC16::GPRRegisterClass) {
|
|
|
|
//MachineFunction &MF = *MBB.getParent();
|
|
|
|
//MachineRegisterInfo &RI = MF.getRegInfo();
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(PIC16::movf), DestReg)
|
2009-04-10 15:10:14 +00:00
|
|
|
.addImm(PTLI->GetTmpOffsetForFI(FI, 1))
|
|
|
|
.addExternalSymbol(tmpName)
|
|
|
|
.addImm(1); // Emit banksel for it.
|
|
|
|
}
|
|
|
|
else if (RC == PIC16::FSR16RegisterClass) {
|
|
|
|
// This is a 16-bit register and the frameindex given by llvm is of
|
|
|
|
// size two here. Break this index N into two zero based indexes and
|
|
|
|
// put one into the map. The second one is always obtained by adding 1
|
|
|
|
// to the first zero based index. In fact it is going to use 3 slots
|
|
|
|
// as saving FSRs corrupts W also and hence we need to save/restore W also.
|
|
|
|
|
|
|
|
unsigned opcode = (DestReg == PIC16::FSR0) ? PIC16::restore_fsr0
|
|
|
|
: PIC16::restore_fsr1;
|
|
|
|
BuildMI(MBB, I, DL, get(opcode), DestReg)
|
|
|
|
.addImm(PTLI->GetTmpOffsetForFI(FI, 3))
|
2008-11-19 11:00:54 +00:00
|
|
|
.addExternalSymbol(tmpName)
|
|
|
|
.addImm(1); // Emit banksel for it.
|
|
|
|
}
|
2008-05-13 09:02:57 +00:00
|
|
|
else
|
|
|
|
assert(0 && "Can't load this register from stack slot");
|
|
|
|
}
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
bool PIC16InstrInfo::copyRegToReg (MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const {
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
if (DestRC == PIC16::FSR16RegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(PIC16::copy_fsr), DestReg).addReg(SrcReg);
|
2009-01-13 19:18:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DestRC == PIC16::GPRRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(PIC16::copy_w), DestReg).addReg(SrcReg);
|
2009-01-13 19:18:47 +00:00
|
|
|
return true;
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 19:18:47 +00:00
|
|
|
// Not yet supported.
|
|
|
|
return false;
|
2008-11-19 11:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PIC16InstrInfo::isMoveInstr(const MachineInstr &MI,
|
2009-01-21 09:02:46 +00:00
|
|
|
unsigned &SrcReg, unsigned &DestReg,
|
|
|
|
unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
|
|
|
|
SrcSubIdx = DstSubIdx = 0; // No sub-registers.
|
2008-11-19 11:00:54 +00:00
|
|
|
|
2009-01-13 19:18:47 +00:00
|
|
|
if (MI.getOpcode() == PIC16::copy_fsr
|
|
|
|
|| MI.getOpcode() == PIC16::copy_w) {
|
2008-11-19 11:00:54 +00:00
|
|
|
DestReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-13 19:18:47 +00:00
|
|
|
|
2008-11-19 11:00:54 +00:00
|
|
|
return false;
|
2008-05-13 09:02:57 +00:00
|
|
|
}
|
|
|
|
|