2016-11-11 16:27:37 +08:00
|
|
|
//===- ARMInstructionSelector.cpp ----------------------------*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file implements the targeting of the InstructionSelector class for ARM.
|
|
|
|
/// \todo This should be generated by TableGen.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMInstructionSelector.h"
|
|
|
|
#include "ARMRegisterBankInfo.h"
|
|
|
|
#include "ARMSubtarget.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
2016-12-16 20:54:46 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2016-11-11 16:27:37 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "arm-isel"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#ifndef LLVM_BUILD_GLOBAL_ISEL
|
|
|
|
#error "You shouldn't build this"
|
|
|
|
#endif
|
|
|
|
|
2016-11-16 00:42:10 +08:00
|
|
|
ARMInstructionSelector::ARMInstructionSelector(const ARMSubtarget &STI,
|
2016-11-11 16:27:37 +08:00
|
|
|
const ARMRegisterBankInfo &RBI)
|
2016-11-16 00:42:10 +08:00
|
|
|
: InstructionSelector(), TII(*STI.getInstrInfo()),
|
2016-12-16 20:54:46 +08:00
|
|
|
TRI(*STI.getRegisterInfo()), RBI(RBI) {}
|
2016-11-11 16:27:37 +08:00
|
|
|
|
2016-12-16 20:54:46 +08:00
|
|
|
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII,
|
|
|
|
MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
|
|
|
unsigned DstReg = I.getOperand(0).getReg();
|
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(DstReg))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const RegisterBank *RegBank = RBI.getRegBank(DstReg, MRI, TRI);
|
|
|
|
assert(RegBank && "Can't get reg bank for virtual register");
|
|
|
|
|
|
|
|
const unsigned DstSize = MRI.getType(DstReg).getSizeInBits();
|
|
|
|
unsigned SrcReg = I.getOperand(1).getReg();
|
|
|
|
const unsigned SrcSize = RBI.getSizeInBits(SrcReg, MRI, TRI);
|
|
|
|
(void)SrcSize;
|
|
|
|
assert(DstSize == SrcSize && "Copy with different width?!");
|
|
|
|
|
|
|
|
assert(RegBank->getID() == ARM::GPRRegBankID && "Unsupported reg bank");
|
|
|
|
const TargetRegisterClass *RC = &ARM::GPRRegClass;
|
|
|
|
|
|
|
|
// No need to constrain SrcReg. It will get constrained when
|
|
|
|
// we hit another of its uses or its defs.
|
|
|
|
// Copies do not have constraints.
|
|
|
|
if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) {
|
|
|
|
DEBUG(dbgs() << "Failed to constrain " << TII.getName(I.getOpcode())
|
|
|
|
<< " operand\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ARMInstructionSelector::select(MachineInstr &I) const {
|
|
|
|
assert(I.getParent() && "Instruction should be in a basic block!");
|
|
|
|
assert(I.getParent()->getParent() && "Instruction should be in a function!");
|
|
|
|
|
|
|
|
auto &MBB = *I.getParent();
|
|
|
|
auto &MF = *MBB.getParent();
|
|
|
|
auto &MRI = MF.getRegInfo();
|
|
|
|
|
|
|
|
if (!isPreISelGenericOpcode(I.getOpcode())) {
|
|
|
|
if (I.isCopy())
|
|
|
|
return selectCopy(I, TII, MRI, TRI, RBI);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (I.getOpcode() == TargetOpcode::G_ADD) {
|
|
|
|
I.setDesc(TII.get(ARM::ADDrr));
|
|
|
|
AddDefaultCC(AddDefaultPred(MachineInstrBuilder(MF, I)));
|
|
|
|
return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-11-11 16:27:37 +08:00
|
|
|
}
|