2006-09-19 16:41:40 +00:00
|
|
|
//===-- ARMMul.cpp - Define TargetMachine for A5CRM -----------------------===//
|
2006-09-19 15:49:25 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the "Instituto Nokia de Tecnologia" and
|
|
|
|
// is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-10-16 16:33:29 +00:00
|
|
|
// Modify the ARM multiplication instructions so that Rd{Hi,Lo} and Rm are distinct
|
2006-09-19 15:49:25 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2006-11-27 23:37:22 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-09-19 15:49:25 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN FixMul : public MachineFunctionPass {
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *llvm::createARMFixMulPass() { return new FixMul(); }
|
|
|
|
|
|
|
|
bool FixMul::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
for (MachineFunction::iterator BB = MF.begin(), E = MF.end();
|
|
|
|
BB != E; ++BB) {
|
|
|
|
MachineBasicBlock &MBB = *BB;
|
|
|
|
|
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
MachineInstr *MI = I;
|
|
|
|
|
2006-10-16 16:33:29 +00:00
|
|
|
int Op = MI->getOpcode();
|
|
|
|
if (Op == ARM::MUL ||
|
|
|
|
Op == ARM::SMULL ||
|
|
|
|
Op == ARM::UMULL) {
|
2006-09-19 16:41:40 +00:00
|
|
|
MachineOperand &RdOp = MI->getOperand(0);
|
|
|
|
MachineOperand &RmOp = MI->getOperand(1);
|
|
|
|
MachineOperand &RsOp = MI->getOperand(2);
|
2006-09-19 15:49:25 +00:00
|
|
|
|
2006-09-19 16:41:40 +00:00
|
|
|
unsigned Rd = RdOp.getReg();
|
|
|
|
unsigned Rm = RmOp.getReg();
|
|
|
|
unsigned Rs = RsOp.getReg();
|
2006-09-19 15:49:25 +00:00
|
|
|
|
2006-10-16 16:33:29 +00:00
|
|
|
if (Rd == Rm) {
|
2006-09-19 16:41:40 +00:00
|
|
|
Changed = true;
|
|
|
|
if (Rd != Rs) {
|
|
|
|
//Rd and Rm must be distinct, but Rd can be equal to Rs.
|
|
|
|
//Swap Rs and Rm
|
|
|
|
RmOp.setReg(Rs);
|
|
|
|
RsOp.setReg(Rm);
|
|
|
|
} else {
|
2006-10-16 16:33:29 +00:00
|
|
|
unsigned scratch = Op == ARM::MUL ? ARM::R12 : ARM::R0;
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, I, MF.getTarget().getInstrInfo()->get(ARM::MOV),
|
|
|
|
scratch).addReg(Rm).addImm(0).addImm(ARMShift::LSL);
|
2006-10-16 16:33:29 +00:00
|
|
|
RmOp.setReg(scratch);
|
2006-09-19 16:41:40 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-19 15:49:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|