2010-02-23 19:15:24 +00:00
|
|
|
//===- MBlazeInstrInfo.cpp - MBlaze Instruction Information -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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 MBlaze implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MBlazeInstrInfo.h"
|
|
|
|
#include "MBlazeTargetMachine.h"
|
|
|
|
#include "MBlazeMachineFunction.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "MBlazeGenInstrInfo.inc"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
MBlazeInstrInfo::MBlazeInstrInfo(MBlazeTargetMachine &tm)
|
|
|
|
: TargetInstrInfoImpl(MBlazeInsts, array_lengthof(MBlazeInsts)),
|
|
|
|
TM(tm), RI(*TM.getSubtargetImpl(), *this) {}
|
|
|
|
|
|
|
|
static bool isZeroImm(const MachineOperand &op) {
|
|
|
|
return op.isImm() && op.getImm() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isLoadFromStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// load from a stack slot, return the virtual or physical register number of
|
|
|
|
/// the destination 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 loading from the stack slot.
|
|
|
|
unsigned MBlazeInstrInfo::
|
|
|
|
isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == MBlaze::LWI) {
|
|
|
|
if ((MI->getOperand(2).isFI()) && // is a stack slot
|
|
|
|
(MI->getOperand(1).isImm()) && // the imm is zero
|
|
|
|
(isZeroImm(MI->getOperand(1)))) {
|
|
|
|
FrameIndex = MI->getOperand(2).getIndex();
|
|
|
|
return MI->getOperand(0).getReg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
unsigned MBlazeInstrInfo::
|
|
|
|
isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == MBlaze::SWI) {
|
|
|
|
if ((MI->getOperand(2).isFI()) && // is a stack slot
|
|
|
|
(MI->getOperand(1).isImm()) && // the imm is zero
|
|
|
|
(isZeroImm(MI->getOperand(1)))) {
|
|
|
|
FrameIndex = MI->getOperand(2).getIndex();
|
|
|
|
return MI->getOperand(0).getReg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// insertNoop - If data hazard condition is found insert the target nop
|
|
|
|
/// instruction.
|
|
|
|
void MBlazeInstrInfo::
|
|
|
|
insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const {
|
2010-04-02 20:16:16 +00:00
|
|
|
DebugLoc DL;
|
2010-02-23 19:15:24 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(MBlaze::NOP));
|
|
|
|
}
|
|
|
|
|
2010-07-11 06:53:27 +00:00
|
|
|
void MBlazeInstrInfo::
|
|
|
|
copyPhysReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I, DebugLoc DL,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
bool KillSrc) const {
|
2010-04-02 20:16:16 +00:00
|
|
|
llvm::BuildMI(MBB, I, DL, get(MBlaze::ADD), DestReg)
|
2010-07-11 06:53:27 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc)).addReg(MBlaze::R0);
|
2010-02-23 19:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MBlazeInstrInfo::
|
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, bool isKill, int FI,
|
2010-05-06 19:06:44 +00:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2010-04-02 20:16:16 +00:00
|
|
|
DebugLoc DL;
|
|
|
|
BuildMI(MBB, I, DL, get(MBlaze::SWI)).addReg(SrcReg,getKillRegState(isKill))
|
2010-02-23 19:15:24 +00:00
|
|
|
.addImm(0).addFrameIndex(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MBlazeInstrInfo::
|
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
2010-05-06 19:06:44 +00:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2010-04-02 20:16:16 +00:00
|
|
|
DebugLoc DL;
|
|
|
|
BuildMI(MBB, I, DL, get(MBlaze::LWI), DestReg)
|
2010-02-23 19:15:24 +00:00
|
|
|
.addImm(0).addFrameIndex(FI);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Branch Analysis
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
unsigned MBlazeInstrInfo::
|
|
|
|
InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
2010-06-17 22:43:56 +00:00
|
|
|
const SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
DebugLoc DL) const {
|
2010-02-23 19:15:24 +00:00
|
|
|
// Can only insert uncond branches so far.
|
|
|
|
assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, get(MBlaze::BRI)).addMBB(TBB);
|
2010-02-23 19:15:24 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getGlobalBaseReg - Return a virtual register initialized with the
|
|
|
|
/// the global base register value. Output instructions required to
|
|
|
|
/// initialize the register in the function entry block, if necessary.
|
|
|
|
///
|
|
|
|
unsigned MBlazeInstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
|
|
|
|
MBlazeFunctionInfo *MBlazeFI = MF->getInfo<MBlazeFunctionInfo>();
|
|
|
|
unsigned GlobalBaseReg = MBlazeFI->getGlobalBaseReg();
|
|
|
|
if (GlobalBaseReg != 0)
|
|
|
|
return GlobalBaseReg;
|
|
|
|
|
|
|
|
// Insert the set of GlobalBaseReg into the first MBB of the function
|
|
|
|
MachineBasicBlock &FirstMBB = MF->front();
|
|
|
|
MachineBasicBlock::iterator MBBI = FirstMBB.begin();
|
|
|
|
MachineRegisterInfo &RegInfo = MF->getRegInfo();
|
|
|
|
const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
|
|
|
|
|
2010-10-21 19:48:38 +00:00
|
|
|
GlobalBaseReg = RegInfo.createVirtualRegister(MBlaze::GPRRegisterClass);
|
2010-07-10 22:43:03 +00:00
|
|
|
BuildMI(FirstMBB, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY),
|
|
|
|
GlobalBaseReg).addReg(MBlaze::R20);
|
2010-02-23 19:15:24 +00:00
|
|
|
RegInfo.addLiveIn(MBlaze::R20);
|
|
|
|
|
|
|
|
MBlazeFI->setGlobalBaseReg(GlobalBaseReg);
|
|
|
|
return GlobalBaseReg;
|
|
|
|
}
|