mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 20:59:51 +00:00
Add a new pre-allocation pass to assign adjacent registers for Neon instructions
that have that constraint. This is currently just assigning a fixed set of registers, and it only handles VLDn for n=2,3,4 with DPR registers. I'm going to expand it to handle more operations next; we can make it smarter once everything is working correctly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78256 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b5e0172405
commit
70cd88fb7b
@ -103,7 +103,7 @@ FunctionPass *createARMObjectCodeEmitterPass(ARMBaseTargetMachine &TM,
|
||||
|
||||
FunctionPass *createARMLoadStoreOptimizationPass(bool PreAlloc = false);
|
||||
FunctionPass *createARMConstantIslandPass();
|
||||
|
||||
FunctionPass *createNEONPreAllocPass();
|
||||
FunctionPass *createThumb2ITBlockPass();
|
||||
|
||||
extern Target TheARMTarget, TheThumbTarget;
|
||||
|
@ -93,6 +93,9 @@ bool ARMBaseTargetMachine::addInstSelector(PassManagerBase &PM,
|
||||
|
||||
bool ARMBaseTargetMachine::addPreRegAlloc(PassManagerBase &PM,
|
||||
CodeGenOpt::Level OptLevel) {
|
||||
if (Subtarget.hasNEON())
|
||||
PM.add(createNEONPreAllocPass());
|
||||
|
||||
// FIXME: temporarily disabling load / store optimization pass for Thumb mode.
|
||||
if (OptLevel != CodeGenOpt::None && !DisableLdStOpti && !Subtarget.isThumb())
|
||||
PM.add(createARMLoadStoreOptimizationPass(true));
|
||||
|
@ -26,6 +26,7 @@ add_llvm_target(ARMCodeGen
|
||||
ARMSubtarget.cpp
|
||||
ARMTargetAsmInfo.cpp
|
||||
ARMTargetMachine.cpp
|
||||
NEONPreAllocPass.cpp
|
||||
Thumb1InstrInfo.cpp
|
||||
Thumb1RegisterInfo.cpp
|
||||
Thumb2ITBlockPass.cpp
|
||||
|
137
lib/Target/ARM/NEONPreAllocPass.cpp
Normal file
137
lib/Target/ARM/NEONPreAllocPass.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
//===-- NEONPreAllocPass.cpp - Allocate adjacent NEON registers--*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DEBUG_TYPE "neon-prealloc"
|
||||
#include "ARM.h"
|
||||
#include "ARMInstrInfo.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
class VISIBILITY_HIDDEN NEONPreAllocPass : public MachineFunctionPass {
|
||||
const TargetInstrInfo *TII;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
NEONPreAllocPass() : MachineFunctionPass(&ID) {}
|
||||
|
||||
virtual bool runOnMachineFunction(MachineFunction &MF);
|
||||
|
||||
virtual const char *getPassName() const {
|
||||
return "NEON register pre-allocation pass";
|
||||
}
|
||||
|
||||
private:
|
||||
bool PreAllocNEONRegisters(MachineBasicBlock &MBB);
|
||||
};
|
||||
|
||||
char NEONPreAllocPass::ID = 0;
|
||||
}
|
||||
|
||||
static bool isNEONMultiRegOp(int Opcode, unsigned &FirstOpnd,
|
||||
unsigned &NumRegs) {
|
||||
switch (Opcode) {
|
||||
default:
|
||||
break;
|
||||
|
||||
case ARM::VLD2d8:
|
||||
case ARM::VLD2d16:
|
||||
case ARM::VLD2d32:
|
||||
case ARM::VLD2d64:
|
||||
FirstOpnd = 0;
|
||||
NumRegs = 2;
|
||||
return true;
|
||||
|
||||
case ARM::VLD3d8:
|
||||
case ARM::VLD3d16:
|
||||
case ARM::VLD3d32:
|
||||
case ARM::VLD3d64:
|
||||
FirstOpnd = 0;
|
||||
NumRegs = 3;
|
||||
return true;
|
||||
|
||||
case ARM::VLD4d8:
|
||||
case ARM::VLD4d16:
|
||||
case ARM::VLD4d32:
|
||||
case ARM::VLD4d64:
|
||||
FirstOpnd = 0;
|
||||
NumRegs = 4;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NEONPreAllocPass::PreAllocNEONRegisters(MachineBasicBlock &MBB) {
|
||||
bool Modified = false;
|
||||
|
||||
MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
||||
for (; MBBI != E; ++MBBI) {
|
||||
MachineInstr *MI = &*MBBI;
|
||||
unsigned FirstOpnd, NumRegs;
|
||||
if (!isNEONMultiRegOp(MI->getOpcode(), FirstOpnd, NumRegs))
|
||||
continue;
|
||||
|
||||
MachineBasicBlock::iterator NextI = next(MBBI);
|
||||
for (unsigned R = 0; R < NumRegs; ++R) {
|
||||
MachineOperand &MO = MI->getOperand(FirstOpnd + R);
|
||||
assert(MO.isReg() && MO.getSubReg() == 0 && "unexpected operand");
|
||||
unsigned VirtReg = MO.getReg();
|
||||
assert(TargetRegisterInfo::isVirtualRegister(VirtReg) &&
|
||||
"expected a virtual register");
|
||||
|
||||
// For now, just assign a fixed set of adjacent registers.
|
||||
// This leaves plenty of room for future improvements.
|
||||
static const unsigned NEONDRegs[] = {
|
||||
ARM::D0, ARM::D1, ARM::D2, ARM::D3
|
||||
};
|
||||
MO.setReg(NEONDRegs[R]);
|
||||
|
||||
if (MO.isUse()) {
|
||||
// Insert a copy from VirtReg.
|
||||
AddDefaultPred(BuildMI(MBB, MBBI, MI->getDebugLoc(),
|
||||
TII->get(ARM::FCPYD), MO.getReg())
|
||||
.addReg(VirtReg));
|
||||
if (MO.isKill()) {
|
||||
MachineInstr *CopyMI = prior(MBBI);
|
||||
CopyMI->findRegisterUseOperand(VirtReg)->setIsKill();
|
||||
}
|
||||
MO.setIsKill();
|
||||
} else if (MO.isDef() && !MO.isDead()) {
|
||||
// Add a copy to VirtReg.
|
||||
AddDefaultPred(BuildMI(MBB, NextI, MI->getDebugLoc(),
|
||||
TII->get(ARM::FCPYD), VirtReg)
|
||||
.addReg(MO.getReg()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Modified;
|
||||
}
|
||||
|
||||
bool NEONPreAllocPass::runOnMachineFunction(MachineFunction &MF) {
|
||||
TII = MF.getTarget().getInstrInfo();
|
||||
|
||||
bool Modified = false;
|
||||
for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
|
||||
++MFI) {
|
||||
MachineBasicBlock &MBB = *MFI;
|
||||
Modified |= PreAllocNEONRegisters(MBB);
|
||||
}
|
||||
|
||||
return Modified;
|
||||
}
|
||||
|
||||
/// createNEONPreAllocPass - returns an instance of the NEON register
|
||||
/// pre-allocation pass.
|
||||
FunctionPass *llvm::createNEONPreAllocPass() {
|
||||
return new NEONPreAllocPass();
|
||||
}
|
Loading…
Reference in New Issue
Block a user