mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Add pass that expands pseudo instructions into target instructions after register allocation. Define pseudos that get expanded into mtc1 or mfc1 instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129594 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b6a638898a
commit
99a2e98edd
@ -25,6 +25,7 @@ namespace llvm {
|
||||
|
||||
FunctionPass *createMipsISelDag(MipsTargetMachine &TM);
|
||||
FunctionPass *createMipsDelaySlotFillerPass(MipsTargetMachine &TM);
|
||||
FunctionPass *createMipsExpandPseudoPass(MipsTargetMachine &TM);
|
||||
|
||||
extern Target TheMipsTarget;
|
||||
extern Target TheMipselTarget;
|
||||
|
116
lib/Target/Mips/MipsExpandPseudo.cpp
Normal file
116
lib/Target/Mips/MipsExpandPseudo.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
//===-- MipsExpandPseudo.cpp - Expand pseudo instructions ---------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This pass expands pseudo instructions into target instructions after register
|
||||
// allocation but before post-RA scheduling.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#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);
|
||||
void ExpandExtractElementF64(MachineBasicBlock&, MachineBasicBlock::iterator);
|
||||
};
|
||||
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();) {
|
||||
const TargetInstrDesc& Tid = I->getDesc();
|
||||
|
||||
switch(Tid.getOpcode()) {
|
||||
default:
|
||||
++I;
|
||||
continue;
|
||||
case Mips::BuildPairF64:
|
||||
ExpandBuildPairF64(MBB, I);
|
||||
break;
|
||||
case Mips::ExtractElementF64:
|
||||
ExpandExtractElementF64(MBB, I);
|
||||
break;
|
||||
}
|
||||
|
||||
// delete original instr
|
||||
MBB.erase(I++);
|
||||
Changed = true;
|
||||
}
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
void MipsExpandPseudo::ExpandBuildPairF64(MachineBasicBlock& MBB,
|
||||
MachineBasicBlock::iterator I) {
|
||||
unsigned DstReg = I->getOperand(0).getReg();
|
||||
unsigned LoReg = I->getOperand(1).getReg(), HiReg = I->getOperand(2).getReg();
|
||||
const TargetInstrDesc& Mtc1Tdd = TII->get(Mips::MTC1);
|
||||
DebugLoc dl = I->getDebugLoc();
|
||||
const unsigned* SubReg =
|
||||
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,
|
||||
MachineBasicBlock::iterator I) {
|
||||
unsigned DstReg = I->getOperand(0).getReg();
|
||||
unsigned SrcReg = I->getOperand(1).getReg();
|
||||
unsigned N = I->getOperand(2).getImm();
|
||||
const TargetInstrDesc& Mfc1Tdd = TII->get(Mips::MFC1);
|
||||
DebugLoc dl = I->getDebugLoc();
|
||||
const unsigned* SubReg = TM.getRegisterInfo()->getSubRegisters(SrcReg);
|
||||
|
||||
BuildMI(MBB, I, dl, Mfc1Tdd, DstReg).addReg(*(SubReg + N));
|
||||
}
|
||||
|
||||
/// createMipsMipsExpandPseudoPass - Returns a pass that expands pseudo
|
||||
/// instrs into real instrs
|
||||
FunctionPass *llvm::createMipsExpandPseudoPass(MipsTargetMachine &tm) {
|
||||
return new MipsExpandPseudo(tm);
|
||||
}
|
@ -52,6 +52,8 @@ const char *MipsTargetLowering::getTargetNodeName(unsigned Opcode) const {
|
||||
case MipsISD::MSubu : return "MipsISD::MSubu";
|
||||
case MipsISD::DivRem : return "MipsISD::DivRem";
|
||||
case MipsISD::DivRemU : return "MipsISD::DivRemU";
|
||||
case MipsISD::BuildPairF64: return "MipsISD::BuildPairF64";
|
||||
case MipsISD::ExtractElementF64: return "MipsISD::ExtractElementF64";
|
||||
default : return NULL;
|
||||
}
|
||||
}
|
||||
@ -1132,11 +1134,12 @@ MipsTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
|
||||
if (VA.getValVT() == MVT::f32 && VA.getLocVT() == MVT::i32)
|
||||
Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Arg);
|
||||
if (VA.getValVT() == MVT::f64 && VA.getLocVT() == MVT::i32) {
|
||||
Arg = DAG.getNode(ISD::BITCAST, dl, MVT::i64, Arg);
|
||||
SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg,
|
||||
DAG.getConstant(0, getPointerTy()));
|
||||
SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Arg,
|
||||
DAG.getConstant(1, getPointerTy()));
|
||||
SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, dl, MVT::i32, Arg,
|
||||
DAG.getConstant(0, MVT::i32));
|
||||
SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, dl, MVT::i32, Arg,
|
||||
DAG.getConstant(1, MVT::i32));
|
||||
if (!Subtarget->isLittle())
|
||||
std::swap(Lo, Hi);
|
||||
RegsToPass.push_back(std::make_pair(VA.getLocReg(), Lo));
|
||||
RegsToPass.push_back(std::make_pair(VA.getLocReg()+1, Hi));
|
||||
continue;
|
||||
@ -1429,9 +1432,10 @@ MipsTargetLowering::LowerFormalArguments(SDValue Chain,
|
||||
unsigned Reg2 = AddLiveIn(DAG.getMachineFunction(),
|
||||
VA.getLocReg()+1, RC);
|
||||
SDValue ArgValue2 = DAG.getCopyFromReg(Chain, dl, Reg2, RegVT);
|
||||
SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, ArgValue,
|
||||
ArgValue2);
|
||||
ArgValue = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Pair);
|
||||
if (!Subtarget->isLittle())
|
||||
std::swap(ArgValue, ArgValue2);
|
||||
ArgValue = DAG.getNode(MipsISD::BuildPairF64, dl, MVT::f64,
|
||||
ArgValue, ArgValue2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,10 @@ namespace llvm {
|
||||
|
||||
// DivRem(u)
|
||||
DivRem,
|
||||
DivRemU
|
||||
DivRemU,
|
||||
|
||||
BuildPairF64,
|
||||
ExtractElementF64
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,12 @@ def SDT_MipsFPCmp : SDTypeProfile<0, 3, [SDTCisSameAs<0, 1>, SDTCisFP<1>,
|
||||
SDTCisInt<2>]>;
|
||||
def SDT_MipsCMovFP : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
|
||||
SDTCisSameAs<1, 2>]>;
|
||||
def SDT_MipsBuildPairF64 : SDTypeProfile<1, 2, [SDTCisVT<0, f64>,
|
||||
SDTCisVT<1, i32>,
|
||||
SDTCisSameAs<1, 2>]>;
|
||||
def SDT_MipsExtractElementF64 : SDTypeProfile<1, 2, [SDTCisVT<0, i32>,
|
||||
SDTCisVT<1, f64>,
|
||||
SDTCisVT<0, i32>]>;
|
||||
|
||||
def MipsFPCmp : SDNode<"MipsISD::FPCmp", SDT_MipsFPCmp, [SDNPOutGlue]>;
|
||||
def MipsCMovFP_T : SDNode<"MipsISD::CMovFP_T", SDT_MipsCMovFP, [SDNPInGlue]>;
|
||||
@ -37,6 +43,9 @@ def MipsCMovFP_F : SDNode<"MipsISD::CMovFP_F", SDT_MipsCMovFP, [SDNPInGlue]>;
|
||||
def MipsFPRound : SDNode<"MipsISD::FPRound", SDTFPRoundOp, [SDNPOptInGlue]>;
|
||||
def MipsFPBrcond : SDNode<"MipsISD::FPBrcond", SDT_MipsFPBrcond,
|
||||
[SDNPHasChain, SDNPOptInGlue]>;
|
||||
def MipsBuildPairF64 : SDNode<"MipsISD::BuildPairF64", SDT_MipsBuildPairF64>;
|
||||
def MipsExtractElementF64 : SDNode<"MipsISD::ExtractElementF64",
|
||||
SDT_MipsExtractElementF64>;
|
||||
|
||||
// Operand for printing out a condition code.
|
||||
let PrintMethod = "printFCCOperand" in
|
||||
@ -312,6 +321,23 @@ let Predicates = [In32BitMode] in {
|
||||
def MOVCCRToCCR : MipsPseudo<(outs CCR:$dst), (ins CCR:$src),
|
||||
"# MOVCCRToCCR", []>;
|
||||
|
||||
// This pseudo instr gets expanded into 2 mtc1 instrs after register
|
||||
// allocation.
|
||||
def BuildPairF64 :
|
||||
MipsPseudo<(outs AFGR64:$dst),
|
||||
(ins CPURegs:$lo, CPURegs:$hi), "",
|
||||
[(set AFGR64:$dst, (MipsBuildPairF64 CPURegs:$lo, CPURegs:$hi))]>;
|
||||
|
||||
// This pseudo instr gets expanded into 2 mfc1 instrs after register
|
||||
// allocation.
|
||||
// if n is 0, lower part of src is extracted.
|
||||
// if n is 1, higher part of src is extracted.
|
||||
def ExtractElementF64 :
|
||||
MipsPseudo<(outs CPURegs:$dst),
|
||||
(ins AFGR64:$src, i32imm:$n), "",
|
||||
[(set CPURegs:$dst,
|
||||
(MipsExtractElementF64 AFGR64:$src, imm:$n))]>;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Floating Point Patterns
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -75,3 +75,9 @@ addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel)
|
||||
PM.add(createMipsDelaySlotFillerPass(*this));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MipsTargetMachine::
|
||||
addPostRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel) {
|
||||
PM.add(createMipsExpandPseudoPass(*this));
|
||||
return true;
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ namespace llvm {
|
||||
CodeGenOpt::Level OptLevel);
|
||||
virtual bool addPreEmitPass(PassManagerBase &PM,
|
||||
CodeGenOpt::Level OptLevel);
|
||||
virtual bool addPostRegAlloc(PassManagerBase &, CodeGenOpt::Level);
|
||||
};
|
||||
|
||||
/// MipselTargetMachine - Mipsel target machine.
|
||||
|
27
test/CodeGen/Mips/buildpairextractelementf64.ll
Normal file
27
test/CodeGen/Mips/buildpairextractelementf64.ll
Normal file
@ -0,0 +1,27 @@
|
||||
; RUN: llc < %s -march=mipsel | FileCheck %s -check-prefix=CHECK-EL
|
||||
; RUN: llc < %s -march=mips | FileCheck %s -check-prefix=CHECK-EB
|
||||
@a = external global i32
|
||||
|
||||
define double @f(i32 %a1, double %d) nounwind {
|
||||
entry:
|
||||
; CHECK-EL: mtc1 $6, $f12
|
||||
; CHECK-EL: mtc1 $7, $f13
|
||||
; CHECK-EB: mtc1 $7, $f12
|
||||
; CHECK-EB: mtc1 $6, $f13
|
||||
store i32 %a1, i32* @a, align 4
|
||||
%add = fadd double %d, 2.000000e+00
|
||||
ret double %add
|
||||
}
|
||||
|
||||
define void @f3(double %d, i32 %a1) nounwind {
|
||||
entry:
|
||||
; CHECK-EL: mfc1 ${{[0-9]+}}, $f12
|
||||
; CHECK-EL: mfc1 $7, $f13
|
||||
; CHECK-EB: mfc1 ${{[0-9]+}}, $f13
|
||||
; CHECK-EB: mfc1 $7, $f12
|
||||
tail call void @f2(i32 %a1, double %d) nounwind
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @f2(i32, double)
|
||||
|
@ -2,6 +2,9 @@
|
||||
; RUN: llc -march=mipsel -mcpu=mips2 -pre-RA-sched=source < %s -regalloc=basic | FileCheck %s
|
||||
|
||||
|
||||
; FIXME: Temporarily disabled until buildpair patch is committed.
|
||||
; REQUIRES: disabled
|
||||
|
||||
; All test functions do the same thing - they return the first variable
|
||||
; argument.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user