2012-02-17 08:55:11 +00:00
|
|
|
//===-- MipsExpandPseudo.cpp - Expand Pseudo Instructions ----------------===//
|
2011-04-15 19:52:08 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2011-04-15 19:52:08 +00:00
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
// This pass expands pseudo instructions into target instructions after register
|
|
|
|
// allocation but before post-RA scheduling.
|
2011-04-15 19:52:08 +00:00
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2011-04-15 19:52:08 +00:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "mips-expand-pseudo"
|
|
|
|
|
|
|
|
#include "Mips.h"
|
|
|
|
#include "MipsTargetMachine.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct MipsExpandPseudo : public MachineFunctionPass {
|
|
|
|
|
|
|
|
TargetMachine &TM;
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
|
|
|
|
static char ID;
|
|
|
|
MipsExpandPseudo(TargetMachine &tm)
|
|
|
|
: MachineFunctionPass(ID), TM(tm), TII(tm.getInstrInfo()) { }
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Mips PseudoInstrs Expansion";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &F);
|
|
|
|
bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ExpandBuildPairF64(MachineBasicBlock&, MachineBasicBlock::iterator);
|
2011-04-15 21:00:26 +00:00
|
|
|
void ExpandExtractElementF64(MachineBasicBlock&,
|
|
|
|
MachineBasicBlock::iterator);
|
2011-04-15 19:52:08 +00:00
|
|
|
};
|
|
|
|
char MipsExpandPseudo::ID = 0;
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
bool MipsExpandPseudo::runOnMachineFunction(MachineFunction& F) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
for (MachineFunction::iterator I = F.begin(); I != F.end(); ++I)
|
|
|
|
Changed |= runOnMachineBasicBlock(*I);
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsExpandPseudo::runOnMachineBasicBlock(MachineBasicBlock& MBB) {
|
|
|
|
|
|
|
|
bool Changed = false;
|
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end();) {
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc& MCid = I->getDesc();
|
2011-04-15 19:52:08 +00:00
|
|
|
|
2011-06-28 19:10:37 +00:00
|
|
|
switch(MCid.getOpcode()) {
|
2012-02-28 07:46:26 +00:00
|
|
|
default:
|
2011-04-15 19:52:08 +00:00
|
|
|
++I;
|
|
|
|
continue;
|
2012-02-24 22:34:47 +00:00
|
|
|
case Mips::SETGP2:
|
|
|
|
// Convert "setgp2 $globalreg, $t9" to "addu $globalreg, $v0, $t9"
|
|
|
|
BuildMI(MBB, I, I->getDebugLoc(), TII->get(Mips::ADDu),
|
|
|
|
I->getOperand(0).getReg())
|
|
|
|
.addReg(Mips::V0).addReg(I->getOperand(1).getReg());
|
|
|
|
break;
|
2011-04-15 19:52:08 +00:00
|
|
|
case Mips::BuildPairF64:
|
|
|
|
ExpandBuildPairF64(MBB, I);
|
|
|
|
break;
|
|
|
|
case Mips::ExtractElementF64:
|
|
|
|
ExpandExtractElementF64(MBB, I);
|
|
|
|
break;
|
2012-02-28 07:46:26 +00:00
|
|
|
}
|
2011-04-15 19:52:08 +00:00
|
|
|
|
|
|
|
// delete original instr
|
|
|
|
MBB.erase(I++);
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsExpandPseudo::ExpandBuildPairF64(MachineBasicBlock& MBB,
|
2012-02-28 07:46:26 +00:00
|
|
|
MachineBasicBlock::iterator I) {
|
2011-04-15 19:52:08 +00:00
|
|
|
unsigned DstReg = I->getOperand(0).getReg();
|
2011-04-15 21:51:11 +00:00
|
|
|
unsigned LoReg = I->getOperand(1).getReg(), HiReg = I->getOperand(2).getReg();
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc& Mtc1Tdd = TII->get(Mips::MTC1);
|
2011-04-15 19:52:08 +00:00
|
|
|
DebugLoc dl = I->getDebugLoc();
|
2012-03-05 05:37:41 +00:00
|
|
|
const uint16_t* SubReg =
|
2011-04-15 19:52:08 +00:00
|
|
|
TM.getRegisterInfo()->getSubRegisters(DstReg);
|
|
|
|
|
|
|
|
// mtc1 Lo, $fp
|
|
|
|
// mtc1 Hi, $fp + 1
|
|
|
|
BuildMI(MBB, I, dl, Mtc1Tdd, *SubReg).addReg(LoReg);
|
|
|
|
BuildMI(MBB, I, dl, Mtc1Tdd, *(SubReg + 1)).addReg(HiReg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsExpandPseudo::ExpandExtractElementF64(MachineBasicBlock& MBB,
|
2011-04-15 21:00:26 +00:00
|
|
|
MachineBasicBlock::iterator I) {
|
2011-04-15 19:52:08 +00:00
|
|
|
unsigned DstReg = I->getOperand(0).getReg();
|
|
|
|
unsigned SrcReg = I->getOperand(1).getReg();
|
|
|
|
unsigned N = I->getOperand(2).getImm();
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc& Mfc1Tdd = TII->get(Mips::MFC1);
|
2011-04-15 19:52:08 +00:00
|
|
|
DebugLoc dl = I->getDebugLoc();
|
2012-03-05 05:37:41 +00:00
|
|
|
const uint16_t* SubReg = TM.getRegisterInfo()->getSubRegisters(SrcReg);
|
2011-04-15 19:52:08 +00:00
|
|
|
|
|
|
|
BuildMI(MBB, I, dl, Mfc1Tdd, DstReg).addReg(*(SubReg + N));
|
|
|
|
}
|
|
|
|
|
2012-02-28 07:46:26 +00:00
|
|
|
/// createMipsMipsExpandPseudoPass - Returns a pass that expands pseudo
|
2011-04-15 19:52:08 +00:00
|
|
|
/// instrs into real instrs
|
|
|
|
FunctionPass *llvm::createMipsExpandPseudoPass(MipsTargetMachine &tm) {
|
|
|
|
return new MipsExpandPseudo(tm);
|
|
|
|
}
|