mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
aa29915b58
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70735 91177308-0d34-0410-b5e6-96231b3b80d8
111 lines
3.9 KiB
C++
111 lines
3.9 KiB
C++
//===- MSP430InstrInfo.cpp - MSP430 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 MSP430 implementation of the TargetInstrInfo class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "MSP430.h"
|
|
#include "MSP430InstrInfo.h"
|
|
#include "MSP430TargetMachine.h"
|
|
#include "MSP430GenInstrInfo.inc"
|
|
#include "llvm/Function.h"
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
|
|
|
using namespace llvm;
|
|
|
|
MSP430InstrInfo::MSP430InstrInfo(MSP430TargetMachine &tm)
|
|
: TargetInstrInfoImpl(MSP430Insts, array_lengthof(MSP430Insts)),
|
|
RI(tm, *this), TM(tm) {}
|
|
|
|
void MSP430InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator MI,
|
|
unsigned SrcReg, bool isKill, int FrameIdx,
|
|
const TargetRegisterClass *RC) const {
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
if (RC == &MSP430::GR16RegClass)
|
|
BuildMI(MBB, MI, DL, get(MSP430::MOV16mr))
|
|
.addFrameIndex(FrameIdx).addImm(0)
|
|
.addReg(SrcReg, false, false, isKill);
|
|
else if (RC == &MSP430::GR8RegClass)
|
|
BuildMI(MBB, MI, DL, get(MSP430::MOV8mr))
|
|
.addFrameIndex(FrameIdx).addImm(0)
|
|
.addReg(SrcReg, false, false, isKill);
|
|
else
|
|
assert(0 && "Cannot store this register to stack slot!");
|
|
}
|
|
|
|
void MSP430InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator MI,
|
|
unsigned DestReg, int FrameIdx,
|
|
const TargetRegisterClass *RC) const{
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
if (RC == &MSP430::GR16RegClass)
|
|
BuildMI(MBB, MI, DL, get(MSP430::MOV16rm))
|
|
.addReg(DestReg).addFrameIndex(FrameIdx).addImm(0);
|
|
else if (RC == &MSP430::GR8RegClass)
|
|
BuildMI(MBB, MI, DL, get(MSP430::MOV8rm))
|
|
.addReg(DestReg).addFrameIndex(FrameIdx).addImm(0);
|
|
else
|
|
assert(0 && "Cannot store this register to stack slot!");
|
|
}
|
|
|
|
bool MSP430InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
MachineBasicBlock::iterator I,
|
|
unsigned DestReg, unsigned SrcReg,
|
|
const TargetRegisterClass *DestRC,
|
|
const TargetRegisterClass *SrcRC) const {
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
if (DestRC == SrcRC) {
|
|
unsigned Opc;
|
|
if (DestRC == &MSP430::GR16RegClass) {
|
|
Opc = MSP430::MOV16rr;
|
|
} else if (DestRC == &MSP430::GR8RegClass) {
|
|
Opc = MSP430::MOV8rr;
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
BuildMI(MBB, I, DL, get(Opc), DestReg).addReg(SrcReg);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
MSP430InstrInfo::isMoveInstr(const MachineInstr& MI,
|
|
unsigned &SrcReg, unsigned &DstReg,
|
|
unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
|
|
SrcSubIdx = DstSubIdx = 0; // No sub-registers yet.
|
|
|
|
switch (MI.getOpcode()) {
|
|
default:
|
|
return false;
|
|
case MSP430::MOV8rr:
|
|
case MSP430::MOV16rr:
|
|
assert(MI.getNumOperands() >= 2 &&
|
|
MI.getOperand(0).isReg() &&
|
|
MI.getOperand(1).isReg() &&
|
|
"invalid register-register move instruction");
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
DstReg = MI.getOperand(0).getReg();
|
|
return true;
|
|
}
|
|
}
|