2009-08-06 07:12:45 +08:00
|
|
|
//===-- 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"
|
2010-05-05 04:38:12 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2009-08-06 07:12:45 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2009-10-25 14:33:48 +08:00
|
|
|
class NEONPreAllocPass : public MachineFunctionPass {
|
2009-08-06 07:12:45 +08:00
|
|
|
const TargetInstrInfo *TII;
|
2010-05-05 04:38:12 +08:00
|
|
|
MachineRegisterInfo *MRI;
|
2009-08-06 07:12:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
NEONPreAllocPass() : MachineFunctionPass(&ID) {}
|
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "NEON register pre-allocation pass";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2010-05-05 04:38:12 +08:00
|
|
|
bool FormsRegSequence(MachineInstr *MI,
|
2010-05-15 02:54:59 +08:00
|
|
|
unsigned FirstOpnd, unsigned NumRegs,
|
|
|
|
unsigned Offset, unsigned Stride) const;
|
2009-08-06 07:12:45 +08:00
|
|
|
bool PreAllocNEONRegisters(MachineBasicBlock &MBB);
|
|
|
|
};
|
|
|
|
|
|
|
|
char NEONPreAllocPass::ID = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-08 01:24:55 +08:00
|
|
|
static bool isNEONMultiRegOp(int Opcode, unsigned &FirstOpnd, unsigned &NumRegs,
|
|
|
|
unsigned &Offset, unsigned &Stride) {
|
|
|
|
// Default to unit stride with no offset.
|
|
|
|
Stride = 1;
|
|
|
|
Offset = 0;
|
|
|
|
|
2009-08-06 07:12:45 +08:00
|
|
|
switch (Opcode) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2010-03-23 13:25:43 +08:00
|
|
|
case ARM::VLD1q8:
|
|
|
|
case ARM::VLD1q16:
|
|
|
|
case ARM::VLD1q32:
|
|
|
|
case ARM::VLD1q64:
|
2009-08-06 07:12:45 +08:00
|
|
|
case ARM::VLD2d8:
|
|
|
|
case ARM::VLD2d16:
|
|
|
|
case ARM::VLD2d32:
|
2009-09-01 12:26:28 +08:00
|
|
|
case ARM::VLD2LNd8:
|
|
|
|
case ARM::VLD2LNd16:
|
|
|
|
case ARM::VLD2LNd32:
|
2009-08-06 07:12:45 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 2;
|
|
|
|
return true;
|
2009-10-09 02:56:10 +08:00
|
|
|
|
2009-10-09 06:27:33 +08:00
|
|
|
case ARM::VLD2q8:
|
|
|
|
case ARM::VLD2q16:
|
|
|
|
case ARM::VLD2q32:
|
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 4;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD2LNq16:
|
|
|
|
case ARM::VLD2LNq32:
|
2009-10-09 02:56:10 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 2;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD2LNq16odd:
|
|
|
|
case ARM::VLD2LNq32odd:
|
2009-10-09 02:56:10 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 2;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
2009-08-06 07:12:45 +08:00
|
|
|
|
|
|
|
case ARM::VLD3d8:
|
|
|
|
case ARM::VLD3d16:
|
|
|
|
case ARM::VLD3d32:
|
2010-03-23 02:13:18 +08:00
|
|
|
case ARM::VLD1d64T:
|
2009-09-01 12:26:28 +08:00
|
|
|
case ARM::VLD3LNd8:
|
|
|
|
case ARM::VLD3LNd16:
|
|
|
|
case ARM::VLD3LNd32:
|
2009-08-06 07:12:45 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 3;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD3q8_UPD:
|
|
|
|
case ARM::VLD3q16_UPD:
|
|
|
|
case ARM::VLD3q32_UPD:
|
2009-10-08 01:24:55 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD3q8odd_UPD:
|
|
|
|
case ARM::VLD3q16odd_UPD:
|
|
|
|
case ARM::VLD3q32odd_UPD:
|
2009-10-08 01:24:55 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD3LNq16:
|
|
|
|
case ARM::VLD3LNq32:
|
2009-10-09 06:27:33 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD3LNq16odd:
|
|
|
|
case ARM::VLD3LNq32odd:
|
2009-10-09 06:27:33 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2009-08-06 07:12:45 +08:00
|
|
|
case ARM::VLD4d8:
|
|
|
|
case ARM::VLD4d16:
|
|
|
|
case ARM::VLD4d32:
|
2010-03-23 02:13:18 +08:00
|
|
|
case ARM::VLD1d64Q:
|
2009-09-01 12:26:28 +08:00
|
|
|
case ARM::VLD4LNd8:
|
|
|
|
case ARM::VLD4LNd16:
|
|
|
|
case ARM::VLD4LNd32:
|
2009-08-06 07:12:45 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 4;
|
|
|
|
return true;
|
2009-08-07 02:47:44 +08:00
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD4q8_UPD:
|
|
|
|
case ARM::VLD4q16_UPD:
|
|
|
|
case ARM::VLD4q32_UPD:
|
2009-10-08 02:09:32 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD4q8odd_UPD:
|
|
|
|
case ARM::VLD4q16odd_UPD:
|
|
|
|
case ARM::VLD4q32odd_UPD:
|
2009-10-08 02:09:32 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD4LNq16:
|
|
|
|
case ARM::VLD4LNq32:
|
2009-10-09 06:53:57 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VLD4LNq16odd:
|
|
|
|
case ARM::VLD4LNq32odd:
|
2009-10-09 06:53:57 +08:00
|
|
|
FirstOpnd = 0;
|
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-23 14:20:33 +08:00
|
|
|
case ARM::VST1q8:
|
|
|
|
case ARM::VST1q16:
|
|
|
|
case ARM::VST1q32:
|
|
|
|
case ARM::VST1q64:
|
2009-08-07 02:47:44 +08:00
|
|
|
case ARM::VST2d8:
|
|
|
|
case ARM::VST2d16:
|
|
|
|
case ARM::VST2d32:
|
2009-09-02 02:51:56 +08:00
|
|
|
case ARM::VST2LNd8:
|
|
|
|
case ARM::VST2LNd16:
|
|
|
|
case ARM::VST2LNd32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-08-07 02:47:44 +08:00
|
|
|
NumRegs = 2;
|
|
|
|
return true;
|
|
|
|
|
2009-10-08 02:47:39 +08:00
|
|
|
case ARM::VST2q8:
|
|
|
|
case ARM::VST2q16:
|
|
|
|
case ARM::VST2q32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-08 02:47:39 +08:00
|
|
|
NumRegs = 4;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST2LNq16:
|
|
|
|
case ARM::VST2LNq32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-09 07:38:24 +08:00
|
|
|
NumRegs = 2;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST2LNq16odd:
|
|
|
|
case ARM::VST2LNq32odd:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-09 07:38:24 +08:00
|
|
|
NumRegs = 2;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2009-08-07 02:47:44 +08:00
|
|
|
case ARM::VST3d8:
|
|
|
|
case ARM::VST3d16:
|
|
|
|
case ARM::VST3d32:
|
2010-03-23 02:13:18 +08:00
|
|
|
case ARM::VST1d64T:
|
2009-09-02 02:51:56 +08:00
|
|
|
case ARM::VST3LNd8:
|
|
|
|
case ARM::VST3LNd16:
|
|
|
|
case ARM::VST3LNd32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-08-07 02:47:44 +08:00
|
|
|
NumRegs = 3;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST3q8_UPD:
|
|
|
|
case ARM::VST3q16_UPD:
|
|
|
|
case ARM::VST3q32_UPD:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 4;
|
2009-10-08 04:30:08 +08:00
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST3q8odd_UPD:
|
|
|
|
case ARM::VST3q16odd_UPD:
|
|
|
|
case ARM::VST3q32odd_UPD:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 4;
|
2009-10-08 04:30:08 +08:00
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST3LNq16:
|
|
|
|
case ARM::VST3LNq32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-09 07:51:31 +08:00
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST3LNq16odd:
|
|
|
|
case ARM::VST3LNq32odd:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-09 07:51:31 +08:00
|
|
|
NumRegs = 3;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2009-08-07 02:47:44 +08:00
|
|
|
case ARM::VST4d8:
|
|
|
|
case ARM::VST4d16:
|
|
|
|
case ARM::VST4d32:
|
2010-03-23 02:13:18 +08:00
|
|
|
case ARM::VST1d64Q:
|
2009-09-02 02:51:56 +08:00
|
|
|
case ARM::VST4LNd8:
|
|
|
|
case ARM::VST4LNd16:
|
|
|
|
case ARM::VST4LNd32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-08-07 02:47:44 +08:00
|
|
|
NumRegs = 4;
|
|
|
|
return true;
|
2009-08-13 04:51:55 +08:00
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST4q8_UPD:
|
|
|
|
case ARM::VST4q16_UPD:
|
|
|
|
case ARM::VST4q32_UPD:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 4;
|
2009-10-08 04:49:18 +08:00
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST4q8odd_UPD:
|
|
|
|
case ARM::VST4q16odd_UPD:
|
|
|
|
case ARM::VST4q32odd_UPD:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 4;
|
2009-10-08 04:49:18 +08:00
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST4LNq16:
|
|
|
|
case ARM::VST4LNq32:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-09 08:01:36 +08:00
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 0;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2010-03-21 02:35:24 +08:00
|
|
|
case ARM::VST4LNq16odd:
|
|
|
|
case ARM::VST4LNq32odd:
|
2010-03-21 06:13:40 +08:00
|
|
|
FirstOpnd = 2;
|
2009-10-09 08:01:36 +08:00
|
|
|
NumRegs = 4;
|
|
|
|
Offset = 1;
|
|
|
|
Stride = 2;
|
|
|
|
return true;
|
|
|
|
|
2009-08-13 04:51:55 +08:00
|
|
|
case ARM::VTBL2:
|
|
|
|
FirstOpnd = 1;
|
|
|
|
NumRegs = 2;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case ARM::VTBL3:
|
|
|
|
FirstOpnd = 1;
|
|
|
|
NumRegs = 3;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case ARM::VTBL4:
|
|
|
|
FirstOpnd = 1;
|
|
|
|
NumRegs = 4;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case ARM::VTBX2:
|
|
|
|
FirstOpnd = 2;
|
|
|
|
NumRegs = 2;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case ARM::VTBX3:
|
|
|
|
FirstOpnd = 2;
|
|
|
|
NumRegs = 3;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case ARM::VTBX4:
|
|
|
|
FirstOpnd = 2;
|
|
|
|
NumRegs = 4;
|
|
|
|
return true;
|
2009-08-06 07:12:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-11 05:26:24 +08:00
|
|
|
bool
|
|
|
|
NEONPreAllocPass::FormsRegSequence(MachineInstr *MI,
|
2010-05-15 02:54:59 +08:00
|
|
|
unsigned FirstOpnd, unsigned NumRegs,
|
|
|
|
unsigned Offset, unsigned Stride) const {
|
2010-05-11 05:26:24 +08:00
|
|
|
MachineOperand &FMO = MI->getOperand(FirstOpnd);
|
|
|
|
assert(FMO.isReg() && FMO.getSubReg() == 0 && "unexpected operand");
|
|
|
|
unsigned VirtReg = FMO.getReg();
|
2010-05-13 11:19:36 +08:00
|
|
|
(void)VirtReg;
|
2010-05-11 05:26:24 +08:00
|
|
|
assert(TargetRegisterInfo::isVirtualRegister(VirtReg) &&
|
|
|
|
"expected a virtual register");
|
2010-05-15 02:54:59 +08:00
|
|
|
|
|
|
|
unsigned LastSubIdx = 0;
|
2010-05-11 05:26:24 +08:00
|
|
|
if (FMO.isDef()) {
|
|
|
|
MachineInstr *RegSeq = 0;
|
|
|
|
for (unsigned R = 0; R < NumRegs; ++R) {
|
|
|
|
const 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");
|
2010-05-06 06:15:40 +08:00
|
|
|
// Feeding into a REG_SEQUENCE.
|
|
|
|
if (!MRI->hasOneNonDBGUse(VirtReg))
|
|
|
|
return false;
|
|
|
|
MachineInstr *UseMI = &*MRI->use_nodbg_begin(VirtReg);
|
|
|
|
if (!UseMI->isRegSequence())
|
|
|
|
return false;
|
|
|
|
if (RegSeq && RegSeq != UseMI)
|
|
|
|
return false;
|
2010-05-15 02:54:59 +08:00
|
|
|
unsigned OpIdx = 1 + (Offset + R * Stride) * 2;
|
|
|
|
if (UseMI->getOperand(OpIdx).getReg() != VirtReg)
|
|
|
|
llvm_unreachable("Malformed REG_SEQUENCE instruction!");
|
|
|
|
unsigned SubIdx = UseMI->getOperand(OpIdx + 1).getImm();
|
|
|
|
if (LastSubIdx) {
|
|
|
|
if (LastSubIdx != SubIdx-Stride)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Must start from arm_dsubreg_0 or arm_qsubreg_0.
|
|
|
|
if (SubIdx != (ARM::DSUBREG_0+Offset) &&
|
|
|
|
SubIdx != (ARM::QSUBREG_0+Offset))
|
|
|
|
return false;
|
|
|
|
}
|
2010-05-06 06:15:40 +08:00
|
|
|
RegSeq = UseMI;
|
2010-05-15 02:54:59 +08:00
|
|
|
LastSubIdx = SubIdx;
|
2010-05-11 05:26:24 +08:00
|
|
|
}
|
|
|
|
|
2010-05-15 02:54:59 +08:00
|
|
|
// In the case of vld3, etc., make sure the trailing operand of
|
|
|
|
// REG_SEQUENCE is an undef.
|
|
|
|
if (NumRegs == 3) {
|
|
|
|
unsigned OpIdx = 1 + (Offset + 3 * Stride) * 2;
|
|
|
|
const MachineOperand &MO = RegSeq->getOperand(OpIdx);
|
2010-05-11 05:26:24 +08:00
|
|
|
unsigned VirtReg = MO.getReg();
|
2010-05-06 06:15:40 +08:00
|
|
|
MachineInstr *DefMI = MRI->getVRegDef(VirtReg);
|
2010-05-11 05:26:24 +08:00
|
|
|
if (!DefMI || !DefMI->isImplicitDef())
|
2010-05-06 06:15:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-05-11 05:26:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LastSrcReg = 0;
|
2010-05-12 09:42:50 +08:00
|
|
|
SmallVector<unsigned, 4> SubIds;
|
2010-05-11 05:26:24 +08:00
|
|
|
for (unsigned R = 0; R < NumRegs; ++R) {
|
|
|
|
const 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");
|
|
|
|
// Extracting from a Q or QQ register.
|
|
|
|
MachineInstr *DefMI = MRI->getVRegDef(VirtReg);
|
|
|
|
if (!DefMI || !DefMI->isExtractSubreg())
|
|
|
|
return false;
|
|
|
|
VirtReg = DefMI->getOperand(1).getReg();
|
|
|
|
if (LastSrcReg && LastSrcReg != VirtReg)
|
|
|
|
return false;
|
2010-05-11 09:19:40 +08:00
|
|
|
LastSrcReg = VirtReg;
|
2010-05-11 05:26:24 +08:00
|
|
|
const TargetRegisterClass *RC = MRI->getRegClass(VirtReg);
|
2010-05-11 09:19:40 +08:00
|
|
|
if (RC != ARM::QPRRegisterClass && RC != ARM::QQPRRegisterClass)
|
2010-05-11 05:26:24 +08:00
|
|
|
return false;
|
|
|
|
unsigned SubIdx = DefMI->getOperand(2).getImm();
|
2010-05-11 09:19:40 +08:00
|
|
|
if (LastSubIdx) {
|
2010-05-15 02:54:59 +08:00
|
|
|
if (LastSubIdx != SubIdx-Stride)
|
2010-05-11 09:19:40 +08:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Must start from arm_dsubreg_0 or arm_qsubreg_0.
|
2010-05-15 02:54:59 +08:00
|
|
|
if (SubIdx != (ARM::DSUBREG_0+Offset) &&
|
|
|
|
SubIdx != (ARM::QSUBREG_0+Offset))
|
2010-05-11 09:19:40 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-05-12 09:42:50 +08:00
|
|
|
SubIds.push_back(SubIdx);
|
2010-05-11 05:26:24 +08:00
|
|
|
LastSubIdx = SubIdx;
|
2010-05-05 04:38:12 +08:00
|
|
|
}
|
2010-05-12 09:42:50 +08:00
|
|
|
|
|
|
|
// FIXME: Update the uses of EXTRACT_SUBREG from REG_SEQUENCE is
|
|
|
|
// currently required for correctness. e.g.
|
|
|
|
// %reg1041;<def> = REG_SEQUENCE %reg1040<kill>, 5, %reg1035<kill>, 6
|
|
|
|
// %reg1042<def> = EXTRACT_SUBREG %reg1041, 6
|
|
|
|
// %reg1043<def> = EXTRACT_SUBREG %reg1041, 5
|
|
|
|
// VST1q16 %reg1025<kill>, 0, %reg1043<kill>, %reg1042<kill>,
|
|
|
|
// reg1025 and reg1043 should be replaced with reg1041:6 and reg1041:5
|
|
|
|
// respectively.
|
|
|
|
// We need to change how we model uses of REG_SEQUENCE.
|
|
|
|
for (unsigned R = 0; R < NumRegs; ++R) {
|
|
|
|
MachineOperand &MO = MI->getOperand(FirstOpnd + R);
|
|
|
|
unsigned OldReg = MO.getReg();
|
|
|
|
MachineInstr *DefMI = MRI->getVRegDef(OldReg);
|
|
|
|
assert(DefMI->isExtractSubreg());
|
|
|
|
MO.setReg(LastSrcReg);
|
|
|
|
MO.setSubReg(SubIds[R]);
|
|
|
|
if (R != 0)
|
|
|
|
MO.setIsKill(false);
|
|
|
|
// Delete the EXTRACT_SUBREG if its result is now dead.
|
|
|
|
if (MRI->use_empty(OldReg))
|
|
|
|
DefMI->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
2010-05-05 04:38:12 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-06 07:12:45 +08:00
|
|
|
bool NEONPreAllocPass::PreAllocNEONRegisters(MachineBasicBlock &MBB) {
|
|
|
|
bool Modified = false;
|
|
|
|
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
|
|
|
|
for (; MBBI != E; ++MBBI) {
|
|
|
|
MachineInstr *MI = &*MBBI;
|
2009-10-08 01:24:55 +08:00
|
|
|
unsigned FirstOpnd, NumRegs, Offset, Stride;
|
|
|
|
if (!isNEONMultiRegOp(MI->getOpcode(), FirstOpnd, NumRegs, Offset, Stride))
|
2009-08-06 07:12:45 +08:00
|
|
|
continue;
|
2010-05-12 05:07:36 +08:00
|
|
|
if (llvm::ModelWithRegSequence() &&
|
2010-05-15 02:54:59 +08:00
|
|
|
FormsRegSequence(MI, FirstOpnd, NumRegs, Offset, Stride))
|
2010-05-05 04:38:12 +08:00
|
|
|
continue;
|
2009-08-06 07:12:45 +08:00
|
|
|
|
2009-12-03 08:50:42 +08:00
|
|
|
MachineBasicBlock::iterator NextI = llvm::next(MBBI);
|
2009-08-06 07:12:45 +08:00
|
|
|
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[] = {
|
2009-10-08 01:24:55 +08:00
|
|
|
ARM::D0, ARM::D1, ARM::D2, ARM::D3,
|
|
|
|
ARM::D4, ARM::D5, ARM::D6, ARM::D7
|
2009-08-06 07:12:45 +08:00
|
|
|
};
|
2009-10-08 01:24:55 +08:00
|
|
|
MO.setReg(NEONDRegs[Offset + R * Stride]);
|
2009-08-06 07:12:45 +08:00
|
|
|
|
|
|
|
if (MO.isUse()) {
|
|
|
|
// Insert a copy from VirtReg.
|
2009-10-07 06:01:15 +08:00
|
|
|
TII->copyRegToReg(MBB, MBBI, MO.getReg(), VirtReg,
|
2010-05-07 04:33:48 +08:00
|
|
|
ARM::DPRRegisterClass, ARM::DPRRegisterClass,
|
|
|
|
DebugLoc());
|
2009-08-06 07:12:45 +08:00
|
|
|
if (MO.isKill()) {
|
|
|
|
MachineInstr *CopyMI = prior(MBBI);
|
|
|
|
CopyMI->findRegisterUseOperand(VirtReg)->setIsKill();
|
|
|
|
}
|
|
|
|
MO.setIsKill();
|
|
|
|
} else if (MO.isDef() && !MO.isDead()) {
|
|
|
|
// Add a copy to VirtReg.
|
2009-10-07 06:01:15 +08:00
|
|
|
TII->copyRegToReg(MBB, NextI, VirtReg, MO.getReg(),
|
2010-05-07 04:33:48 +08:00
|
|
|
ARM::DPRRegisterClass, ARM::DPRRegisterClass,
|
|
|
|
DebugLoc());
|
2009-08-06 07:12:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NEONPreAllocPass::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
TII = MF.getTarget().getInstrInfo();
|
2010-05-05 04:38:12 +08:00
|
|
|
MRI = &MF.getRegInfo();
|
2009-08-06 07:12:45 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|