2010-07-22 06:26:11 +08:00
|
|
|
//===-- ARMFastISel.cpp - ARM FastISel implementation ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the ARM-specific support for the FastISel class. Some
|
|
|
|
// of the target-specific code is generated by tablegen in the file
|
|
|
|
// ARMGenFastISel.inc, which is #included here.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARM.h"
|
2010-08-19 08:37:05 +08:00
|
|
|
#include "ARMBaseInstrInfo.h"
|
2010-09-11 07:18:12 +08:00
|
|
|
#include "ARMCallingConv.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "ARMRegisterInfo.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
|
|
|
#include "ARMSubtarget.h"
|
2010-10-02 07:24:42 +08:00
|
|
|
#include "ARMConstantPoolValue.h"
|
2011-07-21 07:34:39 +08:00
|
|
|
#include "MCTargetDesc/ARMAddressingModes.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/CallingConv.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/GlobalVariable.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/IntrinsicInst.h"
|
2010-09-15 07:03:37 +08:00
|
|
|
#include "llvm/Module.h"
|
2011-04-11 17:35:34 +08:00
|
|
|
#include "llvm/Operator.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/CodeGen/Analysis.h"
|
|
|
|
#include "llvm/CodeGen/FastISel.h"
|
|
|
|
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
2010-08-17 09:25:29 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2010-10-17 09:51:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2010-10-17 09:51:42 +08:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2010-08-17 08:46:57 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
2010-08-17 09:25:29 +08:00
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2010-07-22 06:26:11 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2010-08-17 08:46:57 +08:00
|
|
|
static cl::opt<bool>
|
2010-10-19 06:53:53 +08:00
|
|
|
DisableARMFastISel("disable-arm-fast-isel",
|
|
|
|
cl::desc("Turn off experimental ARM fast-isel support"),
|
2010-10-12 04:05:22 +08:00
|
|
|
cl::init(false), cl::Hidden);
|
2010-08-17 08:46:57 +08:00
|
|
|
|
2010-12-16 07:47:29 +08:00
|
|
|
extern cl::opt<bool> EnableARMLongCalls;
|
|
|
|
|
2010-07-22 06:26:11 +08:00
|
|
|
namespace {
|
2010-11-21 06:38:27 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
// All possible address modes, plus some.
|
|
|
|
typedef struct Address {
|
|
|
|
enum {
|
|
|
|
RegBase,
|
|
|
|
FrameIndexBase
|
|
|
|
} BaseType;
|
2010-11-21 06:38:27 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
union {
|
|
|
|
unsigned Reg;
|
|
|
|
int FI;
|
|
|
|
} Base;
|
2010-11-21 06:38:27 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
int Offset;
|
2010-11-21 06:38:27 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
// Innocuous defaults for our address.
|
|
|
|
Address()
|
2011-05-17 06:24:07 +08:00
|
|
|
: BaseType(RegBase), Offset(0) {
|
2010-11-20 06:30:02 +08:00
|
|
|
Base.Reg = 0;
|
|
|
|
}
|
|
|
|
} Address;
|
2010-07-22 06:26:11 +08:00
|
|
|
|
|
|
|
class ARMFastISel : public FastISel {
|
|
|
|
|
|
|
|
/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
|
|
|
|
/// make the right decision when generating code for different targets.
|
|
|
|
const ARMSubtarget *Subtarget;
|
2010-08-17 09:25:29 +08:00
|
|
|
const TargetMachine &TM;
|
|
|
|
const TargetInstrInfo &TII;
|
|
|
|
const TargetLowering &TLI;
|
2010-10-02 07:24:42 +08:00
|
|
|
ARMFunctionInfo *AFI;
|
2010-07-22 06:26:11 +08:00
|
|
|
|
2010-09-30 06:24:45 +08:00
|
|
|
// Convenience variables to avoid some queries.
|
2010-09-02 09:39:14 +08:00
|
|
|
bool isThumb;
|
2010-09-30 06:24:45 +08:00
|
|
|
LLVMContext *Context;
|
2010-09-02 09:39:14 +08:00
|
|
|
|
2010-07-22 06:26:11 +08:00
|
|
|
public:
|
2010-09-09 09:06:51 +08:00
|
|
|
explicit ARMFastISel(FunctionLoweringInfo &funcInfo)
|
2010-08-17 09:25:29 +08:00
|
|
|
: FastISel(funcInfo),
|
|
|
|
TM(funcInfo.MF->getTarget()),
|
|
|
|
TII(*TM.getInstrInfo()),
|
|
|
|
TLI(*TM.getTargetLowering()) {
|
2010-07-22 06:26:11 +08:00
|
|
|
Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
2010-08-24 06:32:45 +08:00
|
|
|
AFI = funcInfo.MF->getInfo<ARMFunctionInfo>();
|
2010-09-02 09:39:14 +08:00
|
|
|
isThumb = AFI->isThumbFunction();
|
2010-09-30 06:24:45 +08:00
|
|
|
Context = &funcInfo.Fn->getContext();
|
2010-07-22 06:26:11 +08:00
|
|
|
}
|
|
|
|
|
2010-08-20 08:20:31 +08:00
|
|
|
// Code from FastISel.cpp.
|
2010-08-17 09:25:29 +08:00
|
|
|
virtual unsigned FastEmitInst_(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC);
|
|
|
|
virtual unsigned FastEmitInst_r(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill);
|
|
|
|
virtual unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill);
|
2011-03-31 07:01:21 +08:00
|
|
|
virtual unsigned FastEmitInst_rrr(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
unsigned Op2, bool Op2IsKill);
|
2010-08-17 09:25:29 +08:00
|
|
|
virtual unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint64_t Imm);
|
|
|
|
virtual unsigned FastEmitInst_rf(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
const ConstantFP *FPImm);
|
|
|
|
virtual unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
uint64_t Imm);
|
2011-03-12 09:09:29 +08:00
|
|
|
virtual unsigned FastEmitInst_i(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm);
|
2011-04-30 06:07:50 +08:00
|
|
|
virtual unsigned FastEmitInst_ii(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm1, uint64_t Imm2);
|
2011-03-12 09:09:29 +08:00
|
|
|
|
2010-08-17 09:25:29 +08:00
|
|
|
virtual unsigned FastEmitInst_extractsubreg(MVT RetVT,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint32_t Idx);
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-20 08:20:31 +08:00
|
|
|
// Backend specific FastISel code.
|
2010-07-22 06:26:11 +08:00
|
|
|
virtual bool TargetSelectInstruction(const Instruction *I);
|
2010-09-02 09:48:11 +08:00
|
|
|
virtual unsigned TargetMaterializeConstant(const Constant *C);
|
2010-10-01 04:49:44 +08:00
|
|
|
virtual unsigned TargetMaterializeAlloca(const AllocaInst *AI);
|
2010-07-22 06:26:11 +08:00
|
|
|
|
|
|
|
#include "ARMGenFastISel.inc"
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-24 05:44:12 +08:00
|
|
|
// Instruction selection routines.
|
2010-09-11 07:10:30 +08:00
|
|
|
private:
|
2010-10-22 05:47:51 +08:00
|
|
|
bool SelectLoad(const Instruction *I);
|
|
|
|
bool SelectStore(const Instruction *I);
|
|
|
|
bool SelectBranch(const Instruction *I);
|
|
|
|
bool SelectCmp(const Instruction *I);
|
|
|
|
bool SelectFPExt(const Instruction *I);
|
|
|
|
bool SelectFPTrunc(const Instruction *I);
|
|
|
|
bool SelectBinaryOp(const Instruction *I, unsigned ISDOpcode);
|
|
|
|
bool SelectSIToFP(const Instruction *I);
|
|
|
|
bool SelectFPToSI(const Instruction *I);
|
|
|
|
bool SelectSDiv(const Instruction *I);
|
|
|
|
bool SelectSRem(const Instruction *I);
|
|
|
|
bool SelectCall(const Instruction *I);
|
|
|
|
bool SelectSelect(const Instruction *I);
|
2010-10-22 09:28:00 +08:00
|
|
|
bool SelectRet(const Instruction *I);
|
2011-05-26 07:49:02 +08:00
|
|
|
bool SelectIntCast(const Instruction *I);
|
2010-07-22 06:26:11 +08:00
|
|
|
|
2010-08-24 05:44:12 +08:00
|
|
|
// Utility routines.
|
2010-08-19 08:37:05 +08:00
|
|
|
private:
|
2011-07-18 12:54:35 +08:00
|
|
|
bool isTypeLegal(Type *Ty, MVT &VT);
|
|
|
|
bool isLoadTypeLegal(Type *Ty, MVT &VT);
|
2010-11-20 06:30:02 +08:00
|
|
|
bool ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr);
|
|
|
|
bool ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr);
|
|
|
|
bool ARMComputeAddress(const Value *Obj, Address &Addr);
|
|
|
|
void ARMSimplifyAddress(Address &Addr, EVT VT);
|
2010-09-09 08:19:41 +08:00
|
|
|
unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT);
|
2010-09-29 06:47:54 +08:00
|
|
|
unsigned ARMMaterializeInt(const Constant *C, EVT VT);
|
2010-10-02 07:24:42 +08:00
|
|
|
unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT);
|
2010-09-10 04:49:25 +08:00
|
|
|
unsigned ARMMoveToFPReg(EVT VT, unsigned SrcReg);
|
2010-09-10 05:44:45 +08:00
|
|
|
unsigned ARMMoveToIntReg(EVT VT, unsigned SrcReg);
|
2011-02-22 09:37:10 +08:00
|
|
|
unsigned ARMSelectCallOp(const GlobalValue *GV);
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-11 07:18:12 +08:00
|
|
|
// Call handling routines.
|
|
|
|
private:
|
2010-10-18 10:17:53 +08:00
|
|
|
bool FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src, EVT SrcVT,
|
|
|
|
unsigned &ResultReg);
|
2010-09-11 07:18:12 +08:00
|
|
|
CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool Return);
|
2010-10-11 16:38:55 +08:00
|
|
|
bool ProcessCallArgs(SmallVectorImpl<Value*> &Args,
|
2010-09-30 07:11:09 +08:00
|
|
|
SmallVectorImpl<unsigned> &ArgRegs,
|
2010-11-03 19:35:31 +08:00
|
|
|
SmallVectorImpl<MVT> &ArgVTs,
|
2010-09-30 07:11:09 +08:00
|
|
|
SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
|
|
|
|
SmallVectorImpl<unsigned> &RegArgs,
|
|
|
|
CallingConv::ID CC,
|
|
|
|
unsigned &NumBytes);
|
2010-11-03 19:35:31 +08:00
|
|
|
bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
|
2010-09-30 07:11:09 +08:00
|
|
|
const Instruction *I, CallingConv::ID CC,
|
|
|
|
unsigned &NumBytes);
|
2010-09-28 09:21:42 +08:00
|
|
|
bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call);
|
2010-09-11 07:18:12 +08:00
|
|
|
|
|
|
|
// OptionalDef handling routines.
|
|
|
|
private:
|
2011-03-12 09:09:29 +08:00
|
|
|
bool isARMNEONPred(const MachineInstr *MI);
|
2010-08-19 08:37:05 +08:00
|
|
|
bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR);
|
|
|
|
const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB);
|
2010-12-01 09:40:24 +08:00
|
|
|
void AddLoadStoreOperands(EVT VT, Address &Addr,
|
2011-05-29 04:34:49 +08:00
|
|
|
const MachineInstrBuilder &MIB,
|
|
|
|
unsigned Flags);
|
2010-08-19 08:37:05 +08:00
|
|
|
};
|
2010-07-22 06:26:11 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2010-09-11 07:18:12 +08:00
|
|
|
#include "ARMGenCallingConv.inc"
|
2010-07-22 06:26:11 +08:00
|
|
|
|
2010-08-19 08:37:05 +08:00
|
|
|
// DefinesOptionalPredicate - This is different from DefinesPredicate in that
|
|
|
|
// we don't care about implicit defs here, just places we'll need to add a
|
|
|
|
// default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR.
|
|
|
|
bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
|
|
|
if (!MCID.hasOptionalDef())
|
2010-08-19 08:37:05 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Look to see if our OptionalDef is defining CPSR or CCR.
|
|
|
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(i);
|
2010-08-20 08:36:24 +08:00
|
|
|
if (!MO.isReg() || !MO.isDef()) continue;
|
|
|
|
if (MO.getReg() == ARM::CPSR)
|
2010-08-19 08:37:05 +08:00
|
|
|
*CPSR = true;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-12 09:09:29 +08:00
|
|
|
bool ARMFastISel::isARMNEONPred(const MachineInstr *MI) {
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &MCID = MI->getDesc();
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2011-03-12 09:09:29 +08:00
|
|
|
// If we're a thumb2 or not NEON function we were handled via isPredicable.
|
2011-06-29 03:10:37 +08:00
|
|
|
if ((MCID.TSFlags & ARMII::DomainMask) != ARMII::DomainNEON ||
|
2011-03-12 09:09:29 +08:00
|
|
|
AFI->isThumb2Function())
|
|
|
|
return false;
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2011-06-29 03:10:37 +08:00
|
|
|
for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i)
|
|
|
|
if (MCID.OpInfo[i].isPredicate())
|
2011-03-12 09:09:29 +08:00
|
|
|
return true;
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2011-03-12 09:09:29 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-19 08:37:05 +08:00
|
|
|
// If the machine is predicable go ahead and add the predicate operands, if
|
|
|
|
// it needs default CC operands add those.
|
2010-11-02 09:21:28 +08:00
|
|
|
// TODO: If we want to support thumb1 then we'll need to deal with optional
|
|
|
|
// CPSR defs that need to be added before the remaining operands. See s_cc_out
|
|
|
|
// for descriptions why.
|
2010-08-19 08:37:05 +08:00
|
|
|
const MachineInstrBuilder &
|
|
|
|
ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) {
|
|
|
|
MachineInstr *MI = &*MIB;
|
|
|
|
|
2011-03-12 09:09:29 +08:00
|
|
|
// Do we use a predicate? or...
|
|
|
|
// Are we NEON in ARM mode and have a predicate operand? If so, I know
|
|
|
|
// we're not predicable but add it anyways.
|
|
|
|
if (TII.isPredicable(MI) || isARMNEONPred(MI))
|
2010-08-19 08:37:05 +08:00
|
|
|
AddDefaultPred(MIB);
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2010-08-19 08:37:05 +08:00
|
|
|
// Do we optionally set a predicate? Preds is size > 0 iff the predicate
|
|
|
|
// defines CPSR. All other OptionalDefines in ARM are the CCR register.
|
2010-08-19 23:35:27 +08:00
|
|
|
bool CPSR = false;
|
2010-08-19 08:37:05 +08:00
|
|
|
if (DefinesOptionalPredicate(MI, &CPSR)) {
|
|
|
|
if (CPSR)
|
|
|
|
AddDefaultT1CC(MIB);
|
|
|
|
else
|
|
|
|
AddDefaultCC(MIB);
|
|
|
|
}
|
|
|
|
return MIB;
|
|
|
|
}
|
|
|
|
|
2010-08-17 09:25:29 +08:00
|
|
|
unsigned ARMFastISel::FastEmitInst_(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass* RC) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-08-17 09:25:29 +08:00
|
|
|
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg));
|
2010-08-17 09:25:29 +08:00
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMFastISel::FastEmitInst_r(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-08-17 09:25:29 +08:00
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill));
|
|
|
|
else {
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill));
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-08-17 09:25:29 +08:00
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMFastISel::FastEmitInst_rr(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-08-17 09:25:29 +08:00
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addReg(Op1, Op1IsKill * RegState::Kill));
|
|
|
|
else {
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addReg(Op1, Op1IsKill * RegState::Kill));
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-08-17 09:25:29 +08:00
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2011-03-31 07:01:21 +08:00
|
|
|
unsigned ARMFastISel::FastEmitInst_rrr(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
unsigned Op2, bool Op2IsKill) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2011-03-31 07:01:21 +08:00
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addReg(Op1, Op1IsKill * RegState::Kill)
|
|
|
|
.addReg(Op2, Op2IsKill * RegState::Kill));
|
|
|
|
else {
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addReg(Op1, Op1IsKill * RegState::Kill)
|
|
|
|
.addReg(Op2, Op2IsKill * RegState::Kill));
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2010-08-17 09:25:29 +08:00
|
|
|
unsigned ARMFastISel::FastEmitInst_ri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint64_t Imm) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-08-17 09:25:29 +08:00
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addImm(Imm));
|
|
|
|
else {
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addImm(Imm));
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-08-17 09:25:29 +08:00
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMFastISel::FastEmitInst_rf(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
const ConstantFP *FPImm) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-08-17 09:25:29 +08:00
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addFPImm(FPImm));
|
|
|
|
else {
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addFPImm(FPImm));
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-08-17 09:25:29 +08:00
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMFastISel::FastEmitInst_rri(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
unsigned Op1, bool Op1IsKill,
|
|
|
|
uint64_t Imm) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-08-17 09:25:29 +08:00
|
|
|
|
|
|
|
if (II.getNumDefs() >= 1)
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addReg(Op1, Op1IsKill * RegState::Kill)
|
|
|
|
.addImm(Imm));
|
|
|
|
else {
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addReg(Op0, Op0IsKill * RegState::Kill)
|
|
|
|
.addReg(Op1, Op1IsKill * RegState::Kill)
|
|
|
|
.addImm(Imm));
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-08-17 09:25:29 +08:00
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMFastISel::FastEmitInst_i(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-17 09:25:29 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addImm(Imm));
|
|
|
|
else {
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
2010-08-17 09:25:29 +08:00
|
|
|
.addImm(Imm));
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-08-17 09:25:29 +08:00
|
|
|
TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2011-04-30 06:07:50 +08:00
|
|
|
unsigned ARMFastISel::FastEmitInst_ii(unsigned MachineInstOpcode,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
uint64_t Imm1, uint64_t Imm2) {
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II = TII.get(MachineInstOpcode);
|
2011-06-09 07:55:35 +08:00
|
|
|
|
2011-04-30 06:07:50 +08:00
|
|
|
if (II.getNumDefs() >= 1)
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II, ResultReg)
|
|
|
|
.addImm(Imm1).addImm(Imm2));
|
|
|
|
else {
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, II)
|
|
|
|
.addImm(Imm1).addImm(Imm2));
|
2011-06-09 07:55:35 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2011-04-30 06:07:50 +08:00
|
|
|
TII.get(TargetOpcode::COPY),
|
|
|
|
ResultReg)
|
|
|
|
.addReg(II.ImplicitDefs[0]));
|
|
|
|
}
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2010-08-17 09:25:29 +08:00
|
|
|
unsigned ARMFastISel::FastEmitInst_extractsubreg(MVT RetVT,
|
|
|
|
unsigned Op0, bool Op0IsKill,
|
|
|
|
uint32_t Idx) {
|
|
|
|
unsigned ResultReg = createResultReg(TLI.getRegClassFor(RetVT));
|
|
|
|
assert(TargetRegisterInfo::isVirtualRegister(Op0) &&
|
|
|
|
"Cannot yet extract from physregs");
|
2010-08-19 08:37:05 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt,
|
2010-08-17 09:25:29 +08:00
|
|
|
DL, TII.get(TargetOpcode::COPY), ResultReg)
|
|
|
|
.addReg(Op0, getKillRegState(Op0IsKill), Idx));
|
|
|
|
return ResultReg;
|
|
|
|
}
|
|
|
|
|
2010-09-10 08:34:35 +08:00
|
|
|
// TODO: Don't worry about 64-bit now, but when this is fixed remove the
|
|
|
|
// checks from the various callers.
|
2010-09-10 04:49:25 +08:00
|
|
|
unsigned ARMFastISel::ARMMoveToFPReg(EVT VT, unsigned SrcReg) {
|
2010-11-03 20:17:33 +08:00
|
|
|
if (VT == MVT::f64) return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 05:44:45 +08:00
|
|
|
unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(ARM::VMOVRS), MoveReg)
|
|
|
|
.addReg(SrcReg));
|
|
|
|
return MoveReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMFastISel::ARMMoveToIntReg(EVT VT, unsigned SrcReg) {
|
2010-11-03 20:17:33 +08:00
|
|
|
if (VT == MVT::i64) return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 04:49:25 +08:00
|
|
|
unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-09-10 05:44:45 +08:00
|
|
|
TII.get(ARM::VMOVSR), MoveReg)
|
2010-09-10 04:49:25 +08:00
|
|
|
.addReg(SrcReg));
|
|
|
|
return MoveReg;
|
|
|
|
}
|
|
|
|
|
2010-09-09 08:19:41 +08:00
|
|
|
// For double width floating point we need to materialize two constants
|
|
|
|
// (the high and the low) into integer registers then use a move to get
|
|
|
|
// the combined constant into an FP reg.
|
|
|
|
unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, EVT VT) {
|
|
|
|
const APFloat Val = CFP->getValueAPF();
|
2010-11-03 20:17:33 +08:00
|
|
|
bool is64bit = VT == MVT::f64;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:19:41 +08:00
|
|
|
// This checks to see if we can use VFP3 instructions to materialize
|
|
|
|
// a constant, otherwise we have to go through the constant pool.
|
|
|
|
if (TLI.isFPImmLegal(Val, VT)) {
|
|
|
|
unsigned Opc = is64bit ? ARM::FCONSTD : ARM::FCONSTS;
|
|
|
|
unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
|
|
|
|
DestReg)
|
|
|
|
.addFPImm(CFP));
|
|
|
|
return DestReg;
|
|
|
|
}
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 08:34:35 +08:00
|
|
|
// Require VFP2 for loading fp constants.
|
2010-09-10 07:50:00 +08:00
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 07:50:00 +08:00
|
|
|
// MachineConstantPool wants an explicit alignment.
|
|
|
|
unsigned Align = TD.getPrefTypeAlignment(CFP->getType());
|
|
|
|
if (Align == 0) {
|
|
|
|
// TODO: Figure out if this is correct.
|
|
|
|
Align = TD.getTypeAllocSize(CFP->getType());
|
|
|
|
}
|
|
|
|
unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align);
|
|
|
|
unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 08:34:35 +08:00
|
|
|
// The extra reg is for addrmode5.
|
2010-09-28 08:35:09 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
|
|
|
|
DestReg)
|
|
|
|
.addConstantPoolIndex(Idx)
|
2010-09-10 07:50:00 +08:00
|
|
|
.addReg(0));
|
|
|
|
return DestReg;
|
2010-09-09 08:19:41 +08:00
|
|
|
}
|
2010-09-03 07:43:26 +08:00
|
|
|
|
2010-09-29 06:47:54 +08:00
|
|
|
unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, EVT VT) {
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-29 06:47:54 +08:00
|
|
|
// For now 32-bit only.
|
2010-11-03 20:17:33 +08:00
|
|
|
if (VT != MVT::i32) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-11-04 04:21:17 +08:00
|
|
|
unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
|
|
|
|
// If we can do this in a single instruction without a constant pool entry
|
|
|
|
// do so now.
|
|
|
|
const ConstantInt *CI = cast<ConstantInt>(C);
|
2010-11-06 15:53:11 +08:00
|
|
|
if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getSExtValue())) {
|
2010-11-04 04:21:17 +08:00
|
|
|
unsigned Opc = isThumb ? ARM::t2MOVi16 : ARM::MOVi16;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-11-20 02:01:37 +08:00
|
|
|
TII.get(Opc), DestReg)
|
|
|
|
.addImm(CI->getSExtValue()));
|
2010-11-04 04:21:17 +08:00
|
|
|
return DestReg;
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:43:26 +08:00
|
|
|
// MachineConstantPool wants an explicit alignment.
|
|
|
|
unsigned Align = TD.getPrefTypeAlignment(C->getType());
|
|
|
|
if (Align == 0) {
|
|
|
|
// TODO: Figure out if this is correct.
|
|
|
|
Align = TD.getTypeAllocSize(C->getType());
|
|
|
|
}
|
|
|
|
unsigned Idx = MCP.getConstantPoolIndex(C, Align);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-03 07:43:26 +08:00
|
|
|
if (isThumb)
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-09-29 05:55:34 +08:00
|
|
|
TII.get(ARM::t2LDRpci), DestReg)
|
|
|
|
.addConstantPoolIndex(Idx));
|
2010-09-03 07:43:26 +08:00
|
|
|
else
|
2010-11-12 17:48:30 +08:00
|
|
|
// The extra immediate is for addrmode2.
|
2010-09-03 07:43:26 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-09-29 05:55:34 +08:00
|
|
|
TII.get(ARM::LDRcp), DestReg)
|
|
|
|
.addConstantPoolIndex(Idx)
|
2010-10-27 06:37:02 +08:00
|
|
|
.addImm(0));
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-03 07:43:26 +08:00
|
|
|
return DestReg;
|
2010-09-02 09:48:11 +08:00
|
|
|
}
|
|
|
|
|
2010-10-02 07:24:42 +08:00
|
|
|
unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, EVT VT) {
|
2010-10-02 08:32:44 +08:00
|
|
|
// For now 32-bit only.
|
2010-11-03 20:17:33 +08:00
|
|
|
if (VT != MVT::i32) return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-02 08:32:44 +08:00
|
|
|
Reloc::Model RelocM = TM.getRelocationModel();
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-02 08:32:44 +08:00
|
|
|
// TODO: Need more magic for ARM PIC.
|
|
|
|
if (!isThumb && (RelocM == Reloc::PIC_)) return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-02 08:32:44 +08:00
|
|
|
// MachineConstantPool wants an explicit alignment.
|
|
|
|
unsigned Align = TD.getPrefTypeAlignment(GV->getType());
|
|
|
|
if (Align == 0) {
|
|
|
|
// TODO: Figure out if this is correct.
|
|
|
|
Align = TD.getTypeAllocSize(GV->getType());
|
|
|
|
}
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-02 08:32:44 +08:00
|
|
|
// Grab index.
|
|
|
|
unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8);
|
2011-01-17 16:03:18 +08:00
|
|
|
unsigned Id = AFI->createPICLabelUId();
|
2010-10-02 08:32:44 +08:00
|
|
|
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, Id,
|
|
|
|
ARMCP::CPValue, PCAdj);
|
|
|
|
unsigned Idx = MCP.getConstantPoolIndex(CPV, Align);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-02 08:32:44 +08:00
|
|
|
// Load value.
|
|
|
|
MachineInstrBuilder MIB;
|
|
|
|
unsigned DestReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
if (isThumb) {
|
|
|
|
unsigned Opc = (RelocM != Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic;
|
|
|
|
MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
|
|
|
|
.addConstantPoolIndex(Idx);
|
|
|
|
if (RelocM == Reloc::PIC_)
|
|
|
|
MIB.addImm(Id);
|
|
|
|
} else {
|
2010-11-12 17:48:30 +08:00
|
|
|
// The extra immediate is for addrmode2.
|
2010-10-02 08:32:44 +08:00
|
|
|
MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRcp),
|
|
|
|
DestReg)
|
|
|
|
.addConstantPoolIndex(Idx)
|
2010-11-12 17:48:30 +08:00
|
|
|
.addImm(0);
|
2010-10-02 08:32:44 +08:00
|
|
|
}
|
|
|
|
AddOptionalDefs(MIB);
|
2011-06-03 09:13:19 +08:00
|
|
|
|
|
|
|
if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) {
|
|
|
|
unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT));
|
|
|
|
if (isThumb)
|
|
|
|
MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::t2LDRi12),
|
|
|
|
NewDestReg)
|
|
|
|
.addReg(DestReg)
|
|
|
|
.addImm(0);
|
|
|
|
else
|
|
|
|
MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(ARM::LDRi12),
|
|
|
|
NewDestReg)
|
|
|
|
.addReg(DestReg)
|
|
|
|
.addImm(0);
|
|
|
|
DestReg = NewDestReg;
|
|
|
|
AddOptionalDefs(MIB);
|
|
|
|
}
|
|
|
|
|
2010-10-02 08:32:44 +08:00
|
|
|
return DestReg;
|
2010-10-02 07:24:42 +08:00
|
|
|
}
|
|
|
|
|
2010-09-09 08:19:41 +08:00
|
|
|
unsigned ARMFastISel::TargetMaterializeConstant(const Constant *C) {
|
|
|
|
EVT VT = TLI.getValueType(C->getType(), true);
|
|
|
|
|
|
|
|
// Only handle simple types.
|
|
|
|
if (!VT.isSimple()) return 0;
|
|
|
|
|
|
|
|
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
|
|
|
|
return ARMMaterializeFP(CFP, VT);
|
2010-10-02 07:24:42 +08:00
|
|
|
else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
|
|
|
return ARMMaterializeGV(GV, VT);
|
|
|
|
else if (isa<ConstantInt>(C))
|
|
|
|
return ARMMaterializeInt(C, VT);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-02 07:24:42 +08:00
|
|
|
return 0;
|
2010-09-09 08:19:41 +08:00
|
|
|
}
|
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
unsigned ARMFastISel::TargetMaterializeAlloca(const AllocaInst *AI) {
|
|
|
|
// Don't handle dynamic allocas.
|
|
|
|
if (!FuncInfo.StaticAllocaMap.count(AI)) return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
2010-10-17 14:07:26 +08:00
|
|
|
if (!isLoadTypeLegal(AI->getType(), VT)) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
DenseMap<const AllocaInst*, int>::iterator SI =
|
|
|
|
FuncInfo.StaticAllocaMap.find(AI);
|
|
|
|
|
|
|
|
// This will get lowered later into the correct offsets and registers
|
|
|
|
// via rewriteXFrameIndex.
|
|
|
|
if (SI != FuncInfo.StaticAllocaMap.end()) {
|
|
|
|
TargetRegisterClass* RC = TLI.getRegClassFor(VT);
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(Opc), ResultReg)
|
|
|
|
.addFrameIndex(SI->second)
|
|
|
|
.addImm(0));
|
|
|
|
return ResultReg;
|
|
|
|
}
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
bool ARMFastISel::isTypeLegal(Type *Ty, MVT &VT) {
|
2010-11-03 19:35:31 +08:00
|
|
|
EVT evt = TLI.getValueType(Ty, true);
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-25 15:23:49 +08:00
|
|
|
// Only handle simple types.
|
2010-11-03 19:35:31 +08:00
|
|
|
if (evt == MVT::Other || !evt.isSimple()) return false;
|
|
|
|
VT = evt.getSimpleVT();
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-31 09:28:42 +08:00
|
|
|
// Handle all legal types, i.e. a register that will directly hold this
|
|
|
|
// value.
|
|
|
|
return TLI.isTypeLegal(VT);
|
2010-08-25 15:23:49 +08:00
|
|
|
}
|
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
bool ARMFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) {
|
2010-09-02 02:01:32 +08:00
|
|
|
if (isTypeLegal(Ty, VT)) return true;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-02 02:01:32 +08:00
|
|
|
// If this is a type than can be sign or zero-extended to a basic operation
|
|
|
|
// go ahead and accept it now.
|
|
|
|
if (VT == MVT::i8 || VT == MVT::i16)
|
|
|
|
return true;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-02 02:01:32 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-20 06:36:41 +08:00
|
|
|
// Computes the address to get to an object.
|
2010-11-20 06:30:02 +08:00
|
|
|
bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
|
2010-08-24 05:44:12 +08:00
|
|
|
// Some boilerplate from the X86 FastISel.
|
|
|
|
const User *U = NULL;
|
|
|
|
unsigned Opcode = Instruction::UserOp1;
|
2010-08-24 08:07:24 +08:00
|
|
|
if (const Instruction *I = dyn_cast<Instruction>(Obj)) {
|
2010-11-20 06:37:58 +08:00
|
|
|
// Don't walk into other basic blocks unless the object is an alloca from
|
|
|
|
// another block, otherwise it may not have a virtual register assigned.
|
2010-11-16 05:11:06 +08:00
|
|
|
if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) ||
|
|
|
|
FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) {
|
|
|
|
Opcode = I->getOpcode();
|
|
|
|
U = I;
|
|
|
|
}
|
2010-08-24 08:07:24 +08:00
|
|
|
} else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) {
|
2010-08-24 05:44:12 +08:00
|
|
|
Opcode = C->getOpcode();
|
|
|
|
U = C;
|
|
|
|
}
|
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
if (PointerType *Ty = dyn_cast<PointerType>(Obj->getType()))
|
2010-08-24 05:44:12 +08:00
|
|
|
if (Ty->getAddressSpace() > 255)
|
|
|
|
// Fast instruction selection doesn't support the special
|
|
|
|
// address spaces.
|
|
|
|
return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-24 05:44:12 +08:00
|
|
|
switch (Opcode) {
|
2010-09-09 09:06:51 +08:00
|
|
|
default:
|
2010-08-24 05:44:12 +08:00
|
|
|
break;
|
2010-10-12 08:43:21 +08:00
|
|
|
case Instruction::BitCast: {
|
|
|
|
// Look through bitcasts.
|
2010-11-20 06:30:02 +08:00
|
|
|
return ARMComputeAddress(U->getOperand(0), Addr);
|
2010-10-12 08:43:21 +08:00
|
|
|
}
|
|
|
|
case Instruction::IntToPtr: {
|
|
|
|
// Look past no-op inttoptrs.
|
|
|
|
if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy())
|
2010-11-20 06:30:02 +08:00
|
|
|
return ARMComputeAddress(U->getOperand(0), Addr);
|
2010-10-12 08:43:21 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Instruction::PtrToInt: {
|
|
|
|
// Look past no-op ptrtoints.
|
|
|
|
if (TLI.getValueType(U->getType()) == TLI.getPointerTy())
|
2010-11-20 06:30:02 +08:00
|
|
|
return ARMComputeAddress(U->getOperand(0), Addr);
|
2010-10-12 08:43:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-10-14 17:29:41 +08:00
|
|
|
case Instruction::GetElementPtr: {
|
2010-11-20 06:39:56 +08:00
|
|
|
Address SavedAddr = Addr;
|
2010-11-20 06:30:02 +08:00
|
|
|
int TmpOffset = Addr.Offset;
|
2010-10-16 02:02:07 +08:00
|
|
|
|
2010-10-14 17:29:41 +08:00
|
|
|
// Iterate through the GEP folding the constants into offsets where
|
|
|
|
// we can.
|
|
|
|
gep_type_iterator GTI = gep_type_begin(U);
|
|
|
|
for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end();
|
|
|
|
i != e; ++i, ++GTI) {
|
|
|
|
const Value *Op = *i;
|
2011-07-18 12:54:35 +08:00
|
|
|
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
|
2010-10-14 17:29:41 +08:00
|
|
|
const StructLayout *SL = TD.getStructLayout(STy);
|
|
|
|
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
|
|
|
|
TmpOffset += SL->getElementOffset(Idx);
|
|
|
|
} else {
|
2010-10-16 02:02:07 +08:00
|
|
|
uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType());
|
2011-03-23 03:39:17 +08:00
|
|
|
for (;;) {
|
2010-10-16 02:02:07 +08:00
|
|
|
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
|
|
|
|
// Constant-offset addressing.
|
|
|
|
TmpOffset += CI->getSExtValue() * S;
|
2011-03-23 03:39:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (isa<AddOperator>(Op) &&
|
|
|
|
(!isa<Instruction>(Op) ||
|
|
|
|
FuncInfo.MBBMap[cast<Instruction>(Op)->getParent()]
|
|
|
|
== FuncInfo.MBB) &&
|
|
|
|
isa<ConstantInt>(cast<AddOperator>(Op)->getOperand(1))) {
|
2011-04-29 08:03:10 +08:00
|
|
|
// An add (in the same block) with a constant operand. Fold the
|
2011-03-23 03:39:17 +08:00
|
|
|
// constant.
|
2010-10-16 02:02:07 +08:00
|
|
|
ConstantInt *CI =
|
2011-03-23 03:39:17 +08:00
|
|
|
cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
|
2010-10-16 02:02:07 +08:00
|
|
|
TmpOffset += CI->getSExtValue() * S;
|
2011-03-23 03:39:17 +08:00
|
|
|
// Iterate on the other operand.
|
|
|
|
Op = cast<AddOperator>(Op)->getOperand(0);
|
|
|
|
continue;
|
2011-04-29 08:03:10 +08:00
|
|
|
}
|
2011-03-23 03:39:17 +08:00
|
|
|
// Unsupported
|
|
|
|
goto unsupported_gep;
|
|
|
|
}
|
2010-10-14 17:29:41 +08:00
|
|
|
}
|
|
|
|
}
|
2010-10-16 02:02:07 +08:00
|
|
|
|
|
|
|
// Try to grab the base operand now.
|
2010-11-20 06:30:02 +08:00
|
|
|
Addr.Offset = TmpOffset;
|
|
|
|
if (ARMComputeAddress(U->getOperand(0), Addr)) return true;
|
2010-10-16 02:02:07 +08:00
|
|
|
|
|
|
|
// We failed, restore everything and try the other options.
|
2010-11-20 06:39:56 +08:00
|
|
|
Addr = SavedAddr;
|
2010-10-16 02:02:07 +08:00
|
|
|
|
2010-10-14 17:29:41 +08:00
|
|
|
unsupported_gep:
|
|
|
|
break;
|
|
|
|
}
|
2010-08-24 05:44:12 +08:00
|
|
|
case Instruction::Alloca: {
|
2010-10-12 13:39:06 +08:00
|
|
|
const AllocaInst *AI = cast<AllocaInst>(Obj);
|
2010-11-21 06:38:27 +08:00
|
|
|
DenseMap<const AllocaInst*, int>::iterator SI =
|
|
|
|
FuncInfo.StaticAllocaMap.find(AI);
|
|
|
|
if (SI != FuncInfo.StaticAllocaMap.end()) {
|
|
|
|
Addr.BaseType = Address::FrameIndexBase;
|
|
|
|
Addr.Base.FI = SI->second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2010-08-24 05:44:12 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-10-14 05:41:51 +08:00
|
|
|
// Materialize the global variable's address into a reg which can
|
|
|
|
// then be used later to load the variable.
|
2010-08-24 08:07:24 +08:00
|
|
|
if (const GlobalValue *GV = dyn_cast<GlobalValue>(Obj)) {
|
2010-10-13 17:11:46 +08:00
|
|
|
unsigned Tmp = ARMMaterializeGV(GV, TLI.getValueType(Obj->getType()));
|
|
|
|
if (Tmp == 0) return false;
|
2010-10-16 02:02:07 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
Addr.Base.Reg = Tmp;
|
2010-10-13 17:11:46 +08:00
|
|
|
return true;
|
2010-08-24 08:07:24 +08:00
|
|
|
}
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-24 08:07:24 +08:00
|
|
|
// Try to get this in a register if nothing else has worked.
|
2010-11-20 06:30:02 +08:00
|
|
|
if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj);
|
|
|
|
return Addr.Base.Reg != 0;
|
2010-10-14 17:29:41 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
void ARMFastISel::ARMSimplifyAddress(Address &Addr, EVT VT) {
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 03:40:30 +08:00
|
|
|
assert(VT.isSimple() && "Non-simple types are invalid here!");
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 03:40:30 +08:00
|
|
|
bool needsLowering = false;
|
|
|
|
switch (VT.getSimpleVT().SimpleTy) {
|
|
|
|
default:
|
|
|
|
assert(false && "Unhandled load/store type!");
|
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
// Integer loads/stores handle 12-bit offsets.
|
2010-11-20 06:30:02 +08:00
|
|
|
needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset);
|
2010-10-22 03:40:30 +08:00
|
|
|
break;
|
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
|
|
|
// Floating point operands handle 8-bit offsets.
|
2010-11-20 06:30:02 +08:00
|
|
|
needsLowering = ((Addr.Offset & 0xff) != Addr.Offset);
|
2010-10-22 03:40:30 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-11-21 06:38:27 +08:00
|
|
|
// If this is a stack pointer and the offset needs to be simplified then
|
|
|
|
// put the alloca address into a register, set the base type back to
|
|
|
|
// register and continue. This should almost never happen.
|
|
|
|
if (needsLowering && Addr.BaseType == Address::FrameIndexBase) {
|
|
|
|
TargetRegisterClass *RC = isThumb ? ARM::tGPRRegisterClass :
|
|
|
|
ARM::GPRRegisterClass;
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
unsigned Opc = isThumb ? ARM::t2ADDri : ARM::ADDri;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, *FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(Opc), ResultReg)
|
|
|
|
.addFrameIndex(Addr.Base.FI)
|
|
|
|
.addImm(0));
|
|
|
|
Addr.Base.Reg = ResultReg;
|
|
|
|
Addr.BaseType = Address::RegBase;
|
|
|
|
}
|
|
|
|
|
2010-10-22 03:40:30 +08:00
|
|
|
// Since the offset is too large for the load/store instruction
|
2010-09-02 08:53:56 +08:00
|
|
|
// get the reg+offset into a register.
|
2010-10-22 03:40:30 +08:00
|
|
|
if (needsLowering) {
|
2011-04-30 05:22:56 +08:00
|
|
|
Addr.Base.Reg = FastEmit_ri_(MVT::i32, ISD::ADD, Addr.Base.Reg,
|
|
|
|
/*Op0IsKill*/false, Addr.Offset, MVT::i32);
|
2010-11-20 06:30:02 +08:00
|
|
|
Addr.Offset = 0;
|
2010-09-02 08:53:56 +08:00
|
|
|
}
|
2010-08-24 05:44:12 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
void ARMFastISel::AddLoadStoreOperands(EVT VT, Address &Addr,
|
2011-05-29 04:34:49 +08:00
|
|
|
const MachineInstrBuilder &MIB,
|
|
|
|
unsigned Flags) {
|
2010-12-01 09:40:24 +08:00
|
|
|
// addrmode5 output depends on the selection dag addressing dividing the
|
|
|
|
// offset by 4 that it then later multiplies. Do this here as well.
|
|
|
|
if (VT.getSimpleVT().SimpleTy == MVT::f32 ||
|
|
|
|
VT.getSimpleVT().SimpleTy == MVT::f64)
|
|
|
|
Addr.Offset /= 4;
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// Frame base works a bit differently. Handle it separately.
|
|
|
|
if (Addr.BaseType == Address::FrameIndexBase) {
|
|
|
|
int FI = Addr.Base.FI;
|
|
|
|
int Offset = Addr.Offset;
|
|
|
|
MachineMemOperand *MMO =
|
|
|
|
FuncInfo.MF->getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getFixedStack(FI, Offset),
|
2011-05-29 04:34:49 +08:00
|
|
|
Flags,
|
2010-12-01 09:40:24 +08:00
|
|
|
MFI.getObjectSize(FI),
|
|
|
|
MFI.getObjectAlignment(FI));
|
|
|
|
// Now add the rest of the operands.
|
|
|
|
MIB.addFrameIndex(FI);
|
|
|
|
|
|
|
|
// ARM halfword load/stores need an additional operand.
|
|
|
|
if (!isThumb && VT.getSimpleVT().SimpleTy == MVT::i16) MIB.addReg(0);
|
|
|
|
|
|
|
|
MIB.addImm(Addr.Offset);
|
|
|
|
MIB.addMemOperand(MMO);
|
|
|
|
} else {
|
|
|
|
// Now add the rest of the operands.
|
|
|
|
MIB.addReg(Addr.Base.Reg);
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// ARM halfword load/stores need an additional operand.
|
|
|
|
if (!isThumb && VT.getSimpleVT().SimpleTy == MVT::i16) MIB.addReg(0);
|
|
|
|
|
|
|
|
MIB.addImm(Addr.Offset);
|
|
|
|
}
|
|
|
|
AddOptionalDefs(MIB);
|
|
|
|
}
|
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg, Address &Addr) {
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-08-25 15:23:49 +08:00
|
|
|
assert(VT.isSimple() && "Non-simple types are invalid here!");
|
2010-08-31 09:28:42 +08:00
|
|
|
unsigned Opc;
|
2010-10-07 13:50:44 +08:00
|
|
|
TargetRegisterClass *RC;
|
2010-08-25 15:23:49 +08:00
|
|
|
switch (VT.getSimpleVT().SimpleTy) {
|
2010-12-01 09:40:24 +08:00
|
|
|
// This is mostly going to be Neon/vector support.
|
|
|
|
default: return false;
|
2010-09-02 02:01:32 +08:00
|
|
|
case MVT::i16:
|
2010-10-17 09:40:27 +08:00
|
|
|
Opc = isThumb ? ARM::t2LDRHi12 : ARM::LDRH;
|
2010-10-08 09:13:17 +08:00
|
|
|
RC = ARM::GPRRegisterClass;
|
2010-09-02 02:01:32 +08:00
|
|
|
break;
|
|
|
|
case MVT::i8:
|
2010-10-27 08:19:44 +08:00
|
|
|
Opc = isThumb ? ARM::t2LDRBi12 : ARM::LDRBi12;
|
2010-10-08 09:13:17 +08:00
|
|
|
RC = ARM::GPRRegisterClass;
|
2010-09-02 02:01:32 +08:00
|
|
|
break;
|
2010-08-31 09:28:42 +08:00
|
|
|
case MVT::i32:
|
2010-10-27 06:37:02 +08:00
|
|
|
Opc = isThumb ? ARM::t2LDRi12 : ARM::LDRi12;
|
2010-10-08 09:13:17 +08:00
|
|
|
RC = ARM::GPRRegisterClass;
|
2010-08-31 09:28:42 +08:00
|
|
|
break;
|
2010-09-18 09:59:37 +08:00
|
|
|
case MVT::f32:
|
|
|
|
Opc = ARM::VLDRS;
|
2010-10-07 13:50:44 +08:00
|
|
|
RC = TLI.getRegClassFor(VT);
|
2010-09-18 09:59:37 +08:00
|
|
|
break;
|
|
|
|
case MVT::f64:
|
|
|
|
Opc = ARM::VLDRD;
|
2010-10-07 13:50:44 +08:00
|
|
|
RC = TLI.getRegClassFor(VT);
|
2010-09-18 09:59:37 +08:00
|
|
|
break;
|
2010-08-25 15:23:49 +08:00
|
|
|
}
|
2010-12-01 09:40:24 +08:00
|
|
|
// Simplify this down to something we can handle.
|
2010-11-20 06:30:02 +08:00
|
|
|
ARMSimplifyAddress(Addr, VT);
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// Create the base instruction, then add the operands.
|
|
|
|
ResultReg = createResultReg(RC);
|
|
|
|
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(Opc), ResultReg);
|
2011-05-29 04:34:49 +08:00
|
|
|
AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOLoad);
|
2010-08-31 09:28:42 +08:00
|
|
|
return true;
|
2010-08-25 15:23:49 +08:00
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectLoad(const Instruction *I) {
|
2010-09-10 08:34:35 +08:00
|
|
|
// Verify we have a legal type before going any further.
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
2010-09-10 08:34:35 +08:00
|
|
|
if (!isLoadTypeLegal(I->getType(), VT))
|
|
|
|
return false;
|
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// See if we can handle this address.
|
2010-11-20 06:30:02 +08:00
|
|
|
Address Addr;
|
2010-12-01 09:40:24 +08:00
|
|
|
if (!ARMComputeAddress(I->getOperand(0), Addr)) return false;
|
2010-09-10 08:34:35 +08:00
|
|
|
|
|
|
|
unsigned ResultReg;
|
2010-11-20 06:30:02 +08:00
|
|
|
if (!ARMEmitLoad(VT, ResultReg, Addr)) return false;
|
2010-09-10 08:34:35 +08:00
|
|
|
UpdateValueMap(I, ResultReg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
bool ARMFastISel::ARMEmitStore(EVT VT, unsigned SrcReg, Address &Addr) {
|
2010-09-02 08:53:56 +08:00
|
|
|
unsigned StrOpc;
|
|
|
|
switch (VT.getSimpleVT().SimpleTy) {
|
2010-12-01 09:40:24 +08:00
|
|
|
// This is mostly going to be Neon/vector support.
|
2010-09-02 08:53:56 +08:00
|
|
|
default: return false;
|
2010-11-03 07:59:09 +08:00
|
|
|
case MVT::i1: {
|
|
|
|
unsigned Res = createResultReg(isThumb ? ARM::tGPRRegisterClass :
|
|
|
|
ARM::GPRRegisterClass);
|
|
|
|
unsigned Opc = isThumb ? ARM::t2ANDri : ARM::ANDri;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(Opc), Res)
|
|
|
|
.addReg(SrcReg).addImm(1));
|
|
|
|
SrcReg = Res;
|
|
|
|
} // Fallthrough here.
|
2010-10-16 02:02:07 +08:00
|
|
|
case MVT::i8:
|
2010-10-28 07:12:14 +08:00
|
|
|
StrOpc = isThumb ? ARM::t2STRBi12 : ARM::STRBi12;
|
2010-10-12 13:39:06 +08:00
|
|
|
break;
|
|
|
|
case MVT::i16:
|
2010-10-17 09:40:27 +08:00
|
|
|
StrOpc = isThumb ? ARM::t2STRHi12 : ARM::STRH;
|
2010-10-12 13:39:06 +08:00
|
|
|
break;
|
2010-10-16 09:10:35 +08:00
|
|
|
case MVT::i32:
|
2010-10-28 07:12:14 +08:00
|
|
|
StrOpc = isThumb ? ARM::t2STRi12 : ARM::STRi12;
|
2010-10-16 09:10:35 +08:00
|
|
|
break;
|
2010-09-03 07:43:26 +08:00
|
|
|
case MVT::f32:
|
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
|
|
|
StrOpc = ARM::VSTRS;
|
|
|
|
break;
|
|
|
|
case MVT::f64:
|
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
|
|
|
StrOpc = ARM::VSTRD;
|
|
|
|
break;
|
2010-09-02 08:53:56 +08:00
|
|
|
}
|
2010-12-01 09:40:24 +08:00
|
|
|
// Simplify this down to something we can handle.
|
2010-11-20 06:30:02 +08:00
|
|
|
ARMSimplifyAddress(Addr, VT);
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// Create the base instruction, then add the operands.
|
|
|
|
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(StrOpc))
|
|
|
|
.addReg(SrcReg, getKillRegState(true));
|
2011-05-29 04:34:49 +08:00
|
|
|
AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOStore);
|
2010-09-02 08:53:56 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectStore(const Instruction *I) {
|
2010-09-02 08:53:56 +08:00
|
|
|
Value *Op0 = I->getOperand(0);
|
|
|
|
unsigned SrcReg = 0;
|
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// Verify we have a legal type before going any further.
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
2010-09-02 08:53:56 +08:00
|
|
|
if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT))
|
|
|
|
return false;
|
|
|
|
|
2010-09-02 09:48:11 +08:00
|
|
|
// Get the value to be stored into a register.
|
|
|
|
SrcReg = getRegForValue(Op0);
|
2010-12-01 09:40:24 +08:00
|
|
|
if (SrcReg == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-12-01 09:40:24 +08:00
|
|
|
// See if we can handle this address.
|
2010-11-20 06:30:02 +08:00
|
|
|
Address Addr;
|
|
|
|
if (!ARMComputeAddress(I->getOperand(1), Addr))
|
2010-09-02 06:16:27 +08:00
|
|
|
return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
if (!ARMEmitStore(VT, SrcReg, Addr)) return false;
|
2010-09-18 06:28:18 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) {
|
|
|
|
switch (Pred) {
|
|
|
|
// Needs two compares...
|
|
|
|
case CmpInst::FCMP_ONE:
|
2010-10-11 16:38:55 +08:00
|
|
|
case CmpInst::FCMP_UEQ:
|
2010-09-18 06:28:18 +08:00
|
|
|
default:
|
2010-11-02 09:24:49 +08:00
|
|
|
// AL is our "false" for now. The other two need more compares.
|
2010-09-18 06:28:18 +08:00
|
|
|
return ARMCC::AL;
|
|
|
|
case CmpInst::ICMP_EQ:
|
|
|
|
case CmpInst::FCMP_OEQ:
|
|
|
|
return ARMCC::EQ;
|
|
|
|
case CmpInst::ICMP_SGT:
|
|
|
|
case CmpInst::FCMP_OGT:
|
|
|
|
return ARMCC::GT;
|
|
|
|
case CmpInst::ICMP_SGE:
|
|
|
|
case CmpInst::FCMP_OGE:
|
|
|
|
return ARMCC::GE;
|
|
|
|
case CmpInst::ICMP_UGT:
|
|
|
|
case CmpInst::FCMP_UGT:
|
|
|
|
return ARMCC::HI;
|
|
|
|
case CmpInst::FCMP_OLT:
|
|
|
|
return ARMCC::MI;
|
|
|
|
case CmpInst::ICMP_ULE:
|
|
|
|
case CmpInst::FCMP_OLE:
|
|
|
|
return ARMCC::LS;
|
|
|
|
case CmpInst::FCMP_ORD:
|
|
|
|
return ARMCC::VC;
|
|
|
|
case CmpInst::FCMP_UNO:
|
|
|
|
return ARMCC::VS;
|
|
|
|
case CmpInst::FCMP_UGE:
|
|
|
|
return ARMCC::PL;
|
|
|
|
case CmpInst::ICMP_SLT:
|
|
|
|
case CmpInst::FCMP_ULT:
|
2010-10-11 16:38:55 +08:00
|
|
|
return ARMCC::LT;
|
2010-09-18 06:28:18 +08:00
|
|
|
case CmpInst::ICMP_SLE:
|
|
|
|
case CmpInst::FCMP_ULE:
|
|
|
|
return ARMCC::LE;
|
|
|
|
case CmpInst::FCMP_UNE:
|
|
|
|
case CmpInst::ICMP_NE:
|
|
|
|
return ARMCC::NE;
|
|
|
|
case CmpInst::ICMP_UGE:
|
|
|
|
return ARMCC::HS;
|
|
|
|
case CmpInst::ICMP_ULT:
|
|
|
|
return ARMCC::LO;
|
|
|
|
}
|
2010-09-02 06:16:27 +08:00
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectBranch(const Instruction *I) {
|
2010-09-03 08:35:47 +08:00
|
|
|
const BranchInst *BI = cast<BranchInst>(I);
|
|
|
|
MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)];
|
|
|
|
MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)];
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-03 08:35:47 +08:00
|
|
|
// Simple branch support.
|
2010-11-10 03:22:26 +08:00
|
|
|
|
2010-10-30 05:08:19 +08:00
|
|
|
// If we can, avoid recomputing the compare - redoing it could lead to wonky
|
|
|
|
// behavior.
|
|
|
|
// TODO: Factor this out.
|
|
|
|
if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) {
|
2011-04-30 05:56:31 +08:00
|
|
|
MVT SourceVT;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *Ty = CI->getOperand(0)->getType();
|
2011-04-30 05:56:31 +08:00
|
|
|
if (CI->hasOneUse() && (CI->getParent() == I->getParent())
|
|
|
|
&& isTypeLegal(Ty, SourceVT)) {
|
2010-10-30 05:08:19 +08:00
|
|
|
bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
|
|
|
|
if (isFloat && !Subtarget->hasVFP2())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned CmpOpc;
|
2011-04-30 05:56:31 +08:00
|
|
|
switch (SourceVT.SimpleTy) {
|
2010-10-30 05:08:19 +08:00
|
|
|
default: return false;
|
|
|
|
// TODO: Verify compares.
|
|
|
|
case MVT::f32:
|
|
|
|
CmpOpc = ARM::VCMPES;
|
|
|
|
break;
|
|
|
|
case MVT::f64:
|
|
|
|
CmpOpc = ARM::VCMPED;
|
|
|
|
break;
|
|
|
|
case MVT::i32:
|
|
|
|
CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the compare predicate.
|
2011-04-30 05:56:31 +08:00
|
|
|
// Try to take advantage of fallthrough opportunities.
|
|
|
|
CmpInst::Predicate Predicate = CI->getPredicate();
|
|
|
|
if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
|
|
|
|
std::swap(TBB, FBB);
|
|
|
|
Predicate = CmpInst::getInversePredicate(Predicate);
|
|
|
|
}
|
|
|
|
|
|
|
|
ARMCC::CondCodes ARMPred = getComparePred(Predicate);
|
2010-10-30 05:08:19 +08:00
|
|
|
|
|
|
|
// We may not handle every CC for now.
|
|
|
|
if (ARMPred == ARMCC::AL) return false;
|
|
|
|
|
|
|
|
unsigned Arg1 = getRegForValue(CI->getOperand(0));
|
|
|
|
if (Arg1 == 0) return false;
|
|
|
|
|
|
|
|
unsigned Arg2 = getRegForValue(CI->getOperand(1));
|
|
|
|
if (Arg2 == 0) return false;
|
|
|
|
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(CmpOpc))
|
|
|
|
.addReg(Arg1).addReg(Arg2));
|
2010-11-10 03:22:26 +08:00
|
|
|
|
2010-10-30 05:08:19 +08:00
|
|
|
// For floating point we need to move the result to a comparison register
|
|
|
|
// that we can then use for branches.
|
|
|
|
if (isFloat)
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(ARM::FMSTAT)));
|
2010-11-10 03:22:26 +08:00
|
|
|
|
2010-10-30 05:08:19 +08:00
|
|
|
unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
|
|
|
|
.addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR);
|
2011-04-30 04:02:39 +08:00
|
|
|
FastEmitBranch(FBB, DL);
|
|
|
|
FuncInfo.MBB->addSuccessor(TBB);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) {
|
|
|
|
MVT SourceVT;
|
|
|
|
if (TI->hasOneUse() && TI->getParent() == I->getParent() &&
|
2011-05-26 07:49:02 +08:00
|
|
|
(isLoadTypeLegal(TI->getOperand(0)->getType(), SourceVT))) {
|
2011-04-30 04:02:39 +08:00
|
|
|
unsigned TstOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
|
|
|
|
unsigned OpReg = getRegForValue(TI->getOperand(0));
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(TstOpc))
|
|
|
|
.addReg(OpReg).addImm(1));
|
|
|
|
|
|
|
|
unsigned CCMode = ARMCC::NE;
|
|
|
|
if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
|
|
|
|
std::swap(TBB, FBB);
|
|
|
|
CCMode = ARMCC::EQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
|
|
|
|
.addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
|
|
|
|
|
2010-10-30 05:08:19 +08:00
|
|
|
FastEmitBranch(FBB, DL);
|
|
|
|
FuncInfo.MBB->addSuccessor(TBB);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-11-10 03:22:26 +08:00
|
|
|
|
2010-10-30 05:08:19 +08:00
|
|
|
unsigned CmpReg = getRegForValue(BI->getCondition());
|
|
|
|
if (CmpReg == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2011-04-16 11:31:26 +08:00
|
|
|
// We've been divorced from our compare! Our block was split, and
|
|
|
|
// now our compare lives in a predecessor block. We musn't
|
|
|
|
// re-compare here, as the children of the compare aren't guaranteed
|
|
|
|
// live across the block boundary (we *could* check for this).
|
|
|
|
// Regardless, the compare has been done in the predecessor block,
|
|
|
|
// and it left a value for us in a virtual register. Ergo, we test
|
|
|
|
// the one-bit value left in the virtual register.
|
|
|
|
unsigned TstOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TstOpc))
|
|
|
|
.addReg(CmpReg).addImm(1));
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2011-04-29 00:52:09 +08:00
|
|
|
unsigned CCMode = ARMCC::NE;
|
|
|
|
if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
|
|
|
|
std::swap(TBB, FBB);
|
|
|
|
CCMode = ARMCC::EQ;
|
|
|
|
}
|
|
|
|
|
2010-09-03 08:35:47 +08:00
|
|
|
unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
|
2011-04-29 00:52:09 +08:00
|
|
|
.addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
|
2010-09-03 08:35:47 +08:00
|
|
|
FastEmitBranch(FBB, DL);
|
|
|
|
FuncInfo.MBB->addSuccessor(TBB);
|
2010-10-11 16:38:55 +08:00
|
|
|
return true;
|
2010-09-03 08:35:47 +08:00
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectCmp(const Instruction *I) {
|
2010-09-09 07:13:45 +08:00
|
|
|
const CmpInst *CI = cast<CmpInst>(I);
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *Ty = CI->getOperand(0)->getType();
|
2010-09-09 07:13:45 +08:00
|
|
|
if (!isTypeLegal(Ty, VT))
|
|
|
|
return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 07:13:45 +08:00
|
|
|
bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
|
|
|
|
if (isFloat && !Subtarget->hasVFP2())
|
|
|
|
return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 07:13:45 +08:00
|
|
|
unsigned CmpOpc;
|
2010-09-29 09:14:47 +08:00
|
|
|
unsigned CondReg;
|
2010-11-03 19:35:31 +08:00
|
|
|
switch (VT.SimpleTy) {
|
2010-09-09 07:13:45 +08:00
|
|
|
default: return false;
|
|
|
|
// TODO: Verify compares.
|
|
|
|
case MVT::f32:
|
|
|
|
CmpOpc = ARM::VCMPES;
|
2010-09-29 09:14:47 +08:00
|
|
|
CondReg = ARM::FPSCR;
|
2010-09-09 07:13:45 +08:00
|
|
|
break;
|
|
|
|
case MVT::f64:
|
|
|
|
CmpOpc = ARM::VCMPED;
|
2010-09-29 09:14:47 +08:00
|
|
|
CondReg = ARM::FPSCR;
|
2010-09-09 07:13:45 +08:00
|
|
|
break;
|
|
|
|
case MVT::i32:
|
|
|
|
CmpOpc = isThumb ? ARM::t2CMPrr : ARM::CMPrr;
|
2010-09-29 09:14:47 +08:00
|
|
|
CondReg = ARM::CPSR;
|
2010-09-09 07:13:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-09-29 09:14:47 +08:00
|
|
|
// Get the compare predicate.
|
|
|
|
ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate());
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-29 09:14:47 +08:00
|
|
|
// We may not handle every CC for now.
|
|
|
|
if (ARMPred == ARMCC::AL) return false;
|
|
|
|
|
2010-09-09 07:13:45 +08:00
|
|
|
unsigned Arg1 = getRegForValue(CI->getOperand(0));
|
|
|
|
if (Arg1 == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 07:13:45 +08:00
|
|
|
unsigned Arg2 = getRegForValue(CI->getOperand(1));
|
|
|
|
if (Arg2 == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 07:13:45 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
|
|
|
|
.addReg(Arg1).addReg(Arg2));
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-10 08:34:35 +08:00
|
|
|
// For floating point we need to move the result to a comparison register
|
|
|
|
// that we can then use for branches.
|
2010-09-09 07:13:45 +08:00
|
|
|
if (isFloat)
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(ARM::FMSTAT)));
|
2010-09-10 04:26:31 +08:00
|
|
|
|
2010-09-29 09:14:47 +08:00
|
|
|
// Now set a register based on the comparison. Explicitly set the predicates
|
|
|
|
// here.
|
2010-10-07 13:31:49 +08:00
|
|
|
unsigned MovCCOpc = isThumb ? ARM::t2MOVCCi : ARM::MOVCCi;
|
2010-10-11 16:38:55 +08:00
|
|
|
TargetRegisterClass *RC = isThumb ? ARM::rGPRRegisterClass
|
2010-10-07 13:39:19 +08:00
|
|
|
: ARM::GPRRegisterClass;
|
|
|
|
unsigned DestReg = createResultReg(RC);
|
2010-10-11 16:38:55 +08:00
|
|
|
Constant *Zero
|
2010-09-30 06:24:45 +08:00
|
|
|
= ConstantInt::get(Type::getInt32Ty(*Context), 0);
|
2010-09-29 09:14:47 +08:00
|
|
|
unsigned ZeroReg = TargetMaterializeConstant(Zero);
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), DestReg)
|
|
|
|
.addReg(ZeroReg).addImm(1)
|
|
|
|
.addImm(ARMPred).addReg(CondReg);
|
|
|
|
|
2010-09-18 06:28:18 +08:00
|
|
|
UpdateValueMap(I, DestReg);
|
2010-09-09 07:13:45 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectFPExt(const Instruction *I) {
|
2010-09-09 08:26:48 +08:00
|
|
|
// Make sure we have VFP and that we're extending float to double.
|
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:26:48 +08:00
|
|
|
Value *V = I->getOperand(0);
|
|
|
|
if (!I->getType()->isDoubleTy() ||
|
|
|
|
!V->getType()->isFloatTy()) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:26:48 +08:00
|
|
|
unsigned Op = getRegForValue(V);
|
|
|
|
if (Op == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:26:48 +08:00
|
|
|
unsigned Result = createResultReg(ARM::DPRRegisterClass);
|
2010-09-10 04:26:31 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-09-10 04:36:19 +08:00
|
|
|
TII.get(ARM::VCVTDS), Result)
|
2010-09-10 04:26:31 +08:00
|
|
|
.addReg(Op));
|
|
|
|
UpdateValueMap(I, Result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectFPTrunc(const Instruction *I) {
|
2010-09-10 04:26:31 +08:00
|
|
|
// Make sure we have VFP and that we're truncating double to float.
|
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
|
|
|
|
|
|
|
Value *V = I->getOperand(0);
|
2010-10-06 07:13:24 +08:00
|
|
|
if (!(I->getType()->isFloatTy() &&
|
|
|
|
V->getType()->isDoubleTy())) return false;
|
2010-09-10 04:26:31 +08:00
|
|
|
|
|
|
|
unsigned Op = getRegForValue(V);
|
|
|
|
if (Op == 0) return false;
|
|
|
|
|
|
|
|
unsigned Result = createResultReg(ARM::SPRRegisterClass);
|
2010-09-09 09:06:51 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
2010-09-10 04:36:19 +08:00
|
|
|
TII.get(ARM::VCVTSD), Result)
|
2010-09-09 08:26:48 +08:00
|
|
|
.addReg(Op));
|
|
|
|
UpdateValueMap(I, Result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectSIToFP(const Instruction *I) {
|
2010-09-10 02:54:59 +08:00
|
|
|
// Make sure we have VFP.
|
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT DstVT;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *Ty = I->getType();
|
2010-09-10 05:44:45 +08:00
|
|
|
if (!isTypeLegal(Ty, DstVT))
|
2010-09-10 02:54:59 +08:00
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2011-05-26 03:09:45 +08:00
|
|
|
// FIXME: Handle sign-extension where necessary.
|
|
|
|
if (!I->getOperand(0)->getType()->isIntegerTy(32))
|
|
|
|
return false;
|
|
|
|
|
2010-09-10 02:54:59 +08:00
|
|
|
unsigned Op = getRegForValue(I->getOperand(0));
|
|
|
|
if (Op == 0) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 08:34:35 +08:00
|
|
|
// The conversion routine works on fp-reg to fp-reg and the operand above
|
|
|
|
// was an integer, move it to the fp registers if possible.
|
2010-10-06 07:13:24 +08:00
|
|
|
unsigned FP = ARMMoveToFPReg(MVT::f32, Op);
|
2010-09-10 05:44:45 +08:00
|
|
|
if (FP == 0) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 02:54:59 +08:00
|
|
|
unsigned Opc;
|
|
|
|
if (Ty->isFloatTy()) Opc = ARM::VSITOS;
|
|
|
|
else if (Ty->isDoubleTy()) Opc = ARM::VSITOD;
|
|
|
|
else return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 05:44:45 +08:00
|
|
|
unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT));
|
2010-09-10 02:54:59 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
|
|
|
|
ResultReg)
|
2010-09-10 05:44:45 +08:00
|
|
|
.addReg(FP));
|
2010-09-10 04:26:31 +08:00
|
|
|
UpdateValueMap(I, ResultReg);
|
2010-09-10 02:54:59 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectFPToSI(const Instruction *I) {
|
2010-09-10 02:54:59 +08:00
|
|
|
// Make sure we have VFP.
|
|
|
|
if (!Subtarget->hasVFP2()) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT DstVT;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *RetTy = I->getType();
|
2010-09-10 08:35:09 +08:00
|
|
|
if (!isTypeLegal(RetTy, DstVT))
|
2010-09-10 02:54:59 +08:00
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 02:54:59 +08:00
|
|
|
unsigned Op = getRegForValue(I->getOperand(0));
|
|
|
|
if (Op == 0) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 02:54:59 +08:00
|
|
|
unsigned Opc;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *OpTy = I->getOperand(0)->getType();
|
2010-09-10 02:54:59 +08:00
|
|
|
if (OpTy->isFloatTy()) Opc = ARM::VTOSIZS;
|
|
|
|
else if (OpTy->isDoubleTy()) Opc = ARM::VTOSIZD;
|
|
|
|
else return 0;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-06 07:13:24 +08:00
|
|
|
// f64->s32 or f32->s32 both need an intermediate f32 reg.
|
|
|
|
unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32));
|
2010-09-10 02:54:59 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc),
|
|
|
|
ResultReg)
|
|
|
|
.addReg(Op));
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 05:44:45 +08:00
|
|
|
// This result needs to be in an integer register, but the conversion only
|
|
|
|
// takes place in fp-regs.
|
2010-09-10 08:34:35 +08:00
|
|
|
unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg);
|
2010-09-10 05:44:45 +08:00
|
|
|
if (IntReg == 0) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-10 05:44:45 +08:00
|
|
|
UpdateValueMap(I, IntReg);
|
2010-09-10 02:54:59 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-11 16:27:59 +08:00
|
|
|
bool ARMFastISel::SelectSelect(const Instruction *I) {
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
|
|
|
if (!isTypeLegal(I->getType(), VT))
|
2010-10-11 16:27:59 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Things need to be register sized for register moves.
|
2010-11-03 19:35:31 +08:00
|
|
|
if (VT != MVT::i32) return false;
|
2010-10-11 16:27:59 +08:00
|
|
|
const TargetRegisterClass *RC = TLI.getRegClassFor(VT);
|
|
|
|
|
|
|
|
unsigned CondReg = getRegForValue(I->getOperand(0));
|
|
|
|
if (CondReg == 0) return false;
|
|
|
|
unsigned Op1Reg = getRegForValue(I->getOperand(1));
|
|
|
|
if (Op1Reg == 0) return false;
|
|
|
|
unsigned Op2Reg = getRegForValue(I->getOperand(2));
|
|
|
|
if (Op2Reg == 0) return false;
|
|
|
|
|
|
|
|
unsigned CmpOpc = isThumb ? ARM::t2TSTri : ARM::TSTri;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(CmpOpc))
|
|
|
|
.addReg(CondReg).addImm(1));
|
|
|
|
unsigned ResultReg = createResultReg(RC);
|
|
|
|
unsigned MovCCOpc = isThumb ? ARM::t2MOVCCr : ARM::MOVCCr;
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(MovCCOpc), ResultReg)
|
|
|
|
.addReg(Op1Reg).addReg(Op2Reg)
|
|
|
|
.addImm(ARMCC::EQ).addReg(ARM::CPSR);
|
|
|
|
UpdateValueMap(I, ResultReg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-01 06:34:19 +08:00
|
|
|
bool ARMFastISel::SelectSDiv(const Instruction *I) {
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *Ty = I->getType();
|
2010-10-01 06:34:19 +08:00
|
|
|
if (!isTypeLegal(Ty, VT))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If we have integer div support we should have selected this automagically.
|
|
|
|
// In case we have a real miss go ahead and return false and we'll pick
|
|
|
|
// it up later.
|
2010-10-11 16:38:55 +08:00
|
|
|
if (Subtarget->hasDivide()) return false;
|
|
|
|
|
2010-10-01 06:34:19 +08:00
|
|
|
// Otherwise emit a libcall.
|
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
2010-10-11 16:31:54 +08:00
|
|
|
if (VT == MVT::i8)
|
|
|
|
LC = RTLIB::SDIV_I8;
|
|
|
|
else if (VT == MVT::i16)
|
2010-10-01 06:34:19 +08:00
|
|
|
LC = RTLIB::SDIV_I16;
|
|
|
|
else if (VT == MVT::i32)
|
|
|
|
LC = RTLIB::SDIV_I32;
|
|
|
|
else if (VT == MVT::i64)
|
|
|
|
LC = RTLIB::SDIV_I64;
|
|
|
|
else if (VT == MVT::i128)
|
|
|
|
LC = RTLIB::SDIV_I128;
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!");
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 06:34:19 +08:00
|
|
|
return ARMEmitLibcall(I, LC);
|
|
|
|
}
|
|
|
|
|
2010-10-11 16:37:26 +08:00
|
|
|
bool ARMFastISel::SelectSRem(const Instruction *I) {
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT VT;
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *Ty = I->getType();
|
2010-10-11 16:37:26 +08:00
|
|
|
if (!isTypeLegal(Ty, VT))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
|
|
|
|
if (VT == MVT::i8)
|
|
|
|
LC = RTLIB::SREM_I8;
|
|
|
|
else if (VT == MVT::i16)
|
|
|
|
LC = RTLIB::SREM_I16;
|
|
|
|
else if (VT == MVT::i32)
|
|
|
|
LC = RTLIB::SREM_I32;
|
|
|
|
else if (VT == MVT::i64)
|
|
|
|
LC = RTLIB::SREM_I64;
|
|
|
|
else if (VT == MVT::i128)
|
|
|
|
LC = RTLIB::SREM_I128;
|
2010-10-11 16:40:05 +08:00
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!");
|
2010-10-16 02:02:07 +08:00
|
|
|
|
2010-10-11 16:37:26 +08:00
|
|
|
return ARMEmitLibcall(I, LC);
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:02:23 +08:00
|
|
|
bool ARMFastISel::SelectBinaryOp(const Instruction *I, unsigned ISDOpcode) {
|
2010-09-09 09:02:03 +08:00
|
|
|
EVT VT = TLI.getValueType(I->getType(), true);
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:53:57 +08:00
|
|
|
// We can get here in the case when we want to use NEON for our fp
|
|
|
|
// operations, but can't figure out how to. Just use the vfp instructions
|
|
|
|
// if we have them.
|
|
|
|
// FIXME: It'd be nice to use NEON instructions.
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *Ty = I->getType();
|
2010-09-09 09:02:03 +08:00
|
|
|
bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy());
|
|
|
|
if (isFloat && !Subtarget->hasVFP2())
|
|
|
|
return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:53:57 +08:00
|
|
|
unsigned Op1 = getRegForValue(I->getOperand(0));
|
|
|
|
if (Op1 == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:53:57 +08:00
|
|
|
unsigned Op2 = getRegForValue(I->getOperand(1));
|
|
|
|
if (Op2 == 0) return false;
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-09-09 08:53:57 +08:00
|
|
|
unsigned Opc;
|
2010-11-03 20:17:33 +08:00
|
|
|
bool is64bit = VT == MVT::f64 || VT == MVT::i64;
|
2010-09-09 08:53:57 +08:00
|
|
|
switch (ISDOpcode) {
|
|
|
|
default: return false;
|
|
|
|
case ISD::FADD:
|
2010-09-09 09:02:03 +08:00
|
|
|
Opc = is64bit ? ARM::VADDD : ARM::VADDS;
|
2010-09-09 08:53:57 +08:00
|
|
|
break;
|
|
|
|
case ISD::FSUB:
|
2010-09-09 09:02:03 +08:00
|
|
|
Opc = is64bit ? ARM::VSUBD : ARM::VSUBS;
|
2010-09-09 08:53:57 +08:00
|
|
|
break;
|
|
|
|
case ISD::FMUL:
|
2010-09-09 09:02:03 +08:00
|
|
|
Opc = is64bit ? ARM::VMULD : ARM::VMULS;
|
2010-09-09 08:53:57 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-09-09 09:02:03 +08:00
|
|
|
unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT));
|
2010-09-09 08:53:57 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(Opc), ResultReg)
|
|
|
|
.addReg(Op1).addReg(Op2));
|
2010-09-10 04:26:31 +08:00
|
|
|
UpdateValueMap(I, ResultReg);
|
2010-09-09 08:53:57 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-11 07:18:12 +08:00
|
|
|
// Call Handling Code
|
|
|
|
|
2010-10-18 10:17:53 +08:00
|
|
|
bool ARMFastISel::FastEmitExtend(ISD::NodeType Opc, EVT DstVT, unsigned Src,
|
|
|
|
EVT SrcVT, unsigned &ResultReg) {
|
|
|
|
unsigned RR = FastEmit_r(SrcVT.getSimpleVT(), DstVT.getSimpleVT(), Opc,
|
|
|
|
Src, /*TODO: Kill=*/false);
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-18 10:17:53 +08:00
|
|
|
if (RR != 0) {
|
|
|
|
ResultReg = RR;
|
|
|
|
return true;
|
|
|
|
} else
|
2010-10-28 05:39:08 +08:00
|
|
|
return false;
|
2010-10-18 10:17:53 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 07:18:12 +08:00
|
|
|
// This is largely taken directly from CCAssignFnForNode - we don't support
|
|
|
|
// varargs in FastISel so that part has been removed.
|
|
|
|
// TODO: We may not support all of this.
|
|
|
|
CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, bool Return) {
|
|
|
|
switch (CC) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported calling convention");
|
|
|
|
case CallingConv::Fast:
|
2010-10-23 02:57:05 +08:00
|
|
|
// Ignore fastcc. Silence compiler warnings.
|
|
|
|
(void)RetFastCC_ARM_APCS;
|
|
|
|
(void)FastCC_ARM_APCS;
|
|
|
|
// Fallthrough
|
|
|
|
case CallingConv::C:
|
2010-09-11 07:18:12 +08:00
|
|
|
// Use target triple & subtarget features to do actual dispatch.
|
|
|
|
if (Subtarget->isAAPCS_ABI()) {
|
|
|
|
if (Subtarget->hasVFP2() &&
|
|
|
|
FloatABIType == FloatABI::Hard)
|
|
|
|
return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
|
|
|
|
else
|
|
|
|
return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
|
|
|
|
} else
|
|
|
|
return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
|
|
|
|
case CallingConv::ARM_AAPCS_VFP:
|
|
|
|
return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP);
|
|
|
|
case CallingConv::ARM_AAPCS:
|
|
|
|
return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
|
|
|
|
case CallingConv::ARM_APCS:
|
|
|
|
return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-30 07:11:09 +08:00
|
|
|
bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
|
|
|
|
SmallVectorImpl<unsigned> &ArgRegs,
|
2010-11-03 19:35:31 +08:00
|
|
|
SmallVectorImpl<MVT> &ArgVTs,
|
2010-09-30 07:11:09 +08:00
|
|
|
SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags,
|
|
|
|
SmallVectorImpl<unsigned> &RegArgs,
|
|
|
|
CallingConv::ID CC,
|
|
|
|
unsigned &NumBytes) {
|
|
|
|
SmallVector<CCValAssign, 16> ArgLocs;
|
2011-06-09 07:55:35 +08:00
|
|
|
CCState CCInfo(CC, false, *FuncInfo.MF, TM, ArgLocs, *Context);
|
2010-09-30 07:11:09 +08:00
|
|
|
CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, CCAssignFnForCall(CC, false));
|
|
|
|
|
|
|
|
// Get a count of how many bytes are to be pushed on the stack.
|
|
|
|
NumBytes = CCInfo.getNextStackOffset();
|
|
|
|
|
|
|
|
// Issue CALLSEQ_START
|
2011-06-29 05:14:33 +08:00
|
|
|
unsigned AdjStackDown = TII.getCallFrameSetupOpcode();
|
2010-10-12 05:20:02 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(AdjStackDown))
|
|
|
|
.addImm(NumBytes));
|
2010-09-30 07:11:09 +08:00
|
|
|
|
|
|
|
// Process the args.
|
|
|
|
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
|
|
|
|
CCValAssign &VA = ArgLocs[i];
|
|
|
|
unsigned Arg = ArgRegs[VA.getValNo()];
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT ArgVT = ArgVTs[VA.getValNo()];
|
2010-09-30 07:11:09 +08:00
|
|
|
|
2011-01-27 13:44:56 +08:00
|
|
|
// We don't handle NEON/vector parameters yet.
|
|
|
|
if (ArgVT.isVector() || ArgVT.getSizeInBits() > 64)
|
2010-10-23 17:37:17 +08:00
|
|
|
return false;
|
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Handle arg promotion, etc.
|
2010-09-30 07:11:09 +08:00
|
|
|
switch (VA.getLocInfo()) {
|
|
|
|
case CCValAssign::Full: break;
|
2010-10-18 10:17:53 +08:00
|
|
|
case CCValAssign::SExt: {
|
|
|
|
bool Emitted = FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
|
|
|
|
Arg, ArgVT, Arg);
|
2011-01-06 02:41:05 +08:00
|
|
|
assert(Emitted && "Failed to emit a sext!"); (void)Emitted;
|
2010-10-18 10:17:53 +08:00
|
|
|
Emitted = true;
|
|
|
|
ArgVT = VA.getLocVT();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CCValAssign::ZExt: {
|
|
|
|
bool Emitted = FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(),
|
|
|
|
Arg, ArgVT, Arg);
|
2011-01-06 02:41:05 +08:00
|
|
|
assert(Emitted && "Failed to emit a zext!"); (void)Emitted;
|
2010-10-18 10:17:53 +08:00
|
|
|
Emitted = true;
|
|
|
|
ArgVT = VA.getLocVT();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CCValAssign::AExt: {
|
|
|
|
bool Emitted = FastEmitExtend(ISD::ANY_EXTEND, VA.getLocVT(),
|
|
|
|
Arg, ArgVT, Arg);
|
|
|
|
if (!Emitted)
|
|
|
|
Emitted = FastEmitExtend(ISD::ZERO_EXTEND, VA.getLocVT(),
|
|
|
|
Arg, ArgVT, Arg);
|
|
|
|
if (!Emitted)
|
|
|
|
Emitted = FastEmitExtend(ISD::SIGN_EXTEND, VA.getLocVT(),
|
|
|
|
Arg, ArgVT, Arg);
|
|
|
|
|
2011-01-06 02:41:05 +08:00
|
|
|
assert(Emitted && "Failed to emit a aext!"); (void)Emitted;
|
2010-10-18 10:17:53 +08:00
|
|
|
ArgVT = VA.getLocVT();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CCValAssign::BCvt: {
|
2010-11-23 11:31:01 +08:00
|
|
|
unsigned BC = FastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg,
|
2010-11-03 19:35:31 +08:00
|
|
|
/*TODO: Kill=*/false);
|
2010-10-18 10:17:53 +08:00
|
|
|
assert(BC != 0 && "Failed to emit a bitcast!");
|
|
|
|
Arg = BC;
|
|
|
|
ArgVT = VA.getLocVT();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: llvm_unreachable("Unknown arg promotion!");
|
2010-09-30 07:11:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now copy/store arg to correct locations.
|
2010-10-12 05:20:02 +08:00
|
|
|
if (VA.isRegLoc() && !VA.needsCustom()) {
|
2010-09-30 07:11:09 +08:00
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
|
2010-10-01 04:49:44 +08:00
|
|
|
VA.getLocReg())
|
|
|
|
.addReg(Arg);
|
2010-09-30 07:11:09 +08:00
|
|
|
RegArgs.push_back(VA.getLocReg());
|
2010-10-21 08:01:47 +08:00
|
|
|
} else if (VA.needsCustom()) {
|
|
|
|
// TODO: We need custom lowering for vector (v2f64) args.
|
|
|
|
if (VA.getLocVT() != MVT::f64) return false;
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-21 08:01:47 +08:00
|
|
|
CCValAssign &NextVA = ArgLocs[++i];
|
|
|
|
|
|
|
|
// TODO: Only handle register args for now.
|
|
|
|
if(!(VA.isRegLoc() && NextVA.isRegLoc())) return false;
|
|
|
|
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(ARM::VMOVRRD), VA.getLocReg())
|
|
|
|
.addReg(NextVA.getLocReg(), RegState::Define)
|
|
|
|
.addReg(Arg));
|
|
|
|
RegArgs.push_back(VA.getLocReg());
|
|
|
|
RegArgs.push_back(NextVA.getLocReg());
|
2010-09-30 07:11:09 +08:00
|
|
|
} else {
|
2010-10-22 04:09:54 +08:00
|
|
|
assert(VA.isMemLoc());
|
|
|
|
// Need to store on the stack.
|
2010-11-20 06:30:02 +08:00
|
|
|
Address Addr;
|
|
|
|
Addr.BaseType = Address::RegBase;
|
|
|
|
Addr.Base.Reg = ARM::SP;
|
|
|
|
Addr.Offset = VA.getLocMemOffset();
|
2010-10-22 04:09:54 +08:00
|
|
|
|
2010-11-20 06:30:02 +08:00
|
|
|
if (!ARMEmitStore(ArgVT, Arg, Addr)) return false;
|
2010-09-30 07:11:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-03 19:35:31 +08:00
|
|
|
bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs,
|
2010-09-30 07:11:09 +08:00
|
|
|
const Instruction *I, CallingConv::ID CC,
|
|
|
|
unsigned &NumBytes) {
|
|
|
|
// Issue CALLSEQ_END
|
2011-06-29 05:14:33 +08:00
|
|
|
unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
|
2010-10-12 05:20:02 +08:00
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(AdjStackUp))
|
|
|
|
.addImm(NumBytes).addImm(0));
|
2010-09-30 07:11:09 +08:00
|
|
|
|
|
|
|
// Now the return value.
|
2010-11-03 19:35:31 +08:00
|
|
|
if (RetVT != MVT::isVoid) {
|
2010-09-30 07:11:09 +08:00
|
|
|
SmallVector<CCValAssign, 16> RVLocs;
|
2011-06-09 07:55:35 +08:00
|
|
|
CCState CCInfo(CC, false, *FuncInfo.MF, TM, RVLocs, *Context);
|
2010-09-30 07:11:09 +08:00
|
|
|
CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true));
|
|
|
|
|
|
|
|
// Copy all of the result registers out of their specified physreg.
|
2010-11-03 19:35:31 +08:00
|
|
|
if (RVLocs.size() == 2 && RetVT == MVT::f64) {
|
2010-10-01 08:00:11 +08:00
|
|
|
// For this move we copy into two registers and then move into the
|
|
|
|
// double fp reg we want.
|
|
|
|
EVT DestVT = RVLocs[0].getValVT();
|
|
|
|
TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT);
|
|
|
|
unsigned ResultReg = createResultReg(DstRC);
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(ARM::VMOVDRR), ResultReg)
|
2010-10-20 16:02:24 +08:00
|
|
|
.addReg(RVLocs[0].getLocReg())
|
|
|
|
.addReg(RVLocs[1].getLocReg()));
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-20 16:02:24 +08:00
|
|
|
UsedRegs.push_back(RVLocs[0].getLocReg());
|
|
|
|
UsedRegs.push_back(RVLocs[1].getLocReg());
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-11 16:38:55 +08:00
|
|
|
// Finally update the result.
|
2010-10-01 08:00:11 +08:00
|
|
|
UpdateValueMap(I, ResultReg);
|
|
|
|
} else {
|
2010-10-14 07:34:31 +08:00
|
|
|
assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!");
|
2010-10-01 08:00:11 +08:00
|
|
|
EVT CopyVT = RVLocs[0].getValVT();
|
|
|
|
TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT);
|
2010-09-30 07:11:09 +08:00
|
|
|
|
2010-10-01 08:00:11 +08:00
|
|
|
unsigned ResultReg = createResultReg(DstRC);
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
|
|
|
|
ResultReg).addReg(RVLocs[0].getLocReg());
|
|
|
|
UsedRegs.push_back(RVLocs[0].getLocReg());
|
2010-09-30 07:11:09 +08:00
|
|
|
|
2010-10-11 16:38:55 +08:00
|
|
|
// Finally update the result.
|
2010-10-01 08:00:11 +08:00
|
|
|
UpdateValueMap(I, ResultReg);
|
|
|
|
}
|
2010-09-30 07:11:09 +08:00
|
|
|
}
|
|
|
|
|
2010-10-11 16:38:55 +08:00
|
|
|
return true;
|
2010-09-30 07:11:09 +08:00
|
|
|
}
|
|
|
|
|
2010-10-22 09:28:00 +08:00
|
|
|
bool ARMFastISel::SelectRet(const Instruction *I) {
|
|
|
|
const ReturnInst *Ret = cast<ReturnInst>(I);
|
|
|
|
const Function &F = *I->getParent()->getParent();
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 09:28:00 +08:00
|
|
|
if (!FuncInfo.CanLowerReturn)
|
|
|
|
return false;
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 09:28:00 +08:00
|
|
|
if (F.isVarArg())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CallingConv::ID CC = F.getCallingConv();
|
|
|
|
if (Ret->getNumOperands() > 0) {
|
|
|
|
SmallVector<ISD::OutputArg, 4> Outs;
|
|
|
|
GetReturnInfo(F.getReturnType(), F.getAttributes().getRetAttributes(),
|
|
|
|
Outs, TLI);
|
|
|
|
|
|
|
|
// Analyze operands of the call, assigning locations to each operand.
|
|
|
|
SmallVector<CCValAssign, 16> ValLocs;
|
2011-06-09 07:55:35 +08:00
|
|
|
CCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, TM, ValLocs, I->getContext());
|
2010-10-22 09:28:00 +08:00
|
|
|
CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */));
|
|
|
|
|
|
|
|
const Value *RV = Ret->getOperand(0);
|
|
|
|
unsigned Reg = getRegForValue(RV);
|
|
|
|
if (Reg == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Only handle a single return value for now.
|
|
|
|
if (ValLocs.size() != 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CCValAssign &VA = ValLocs[0];
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 09:28:00 +08:00
|
|
|
// Don't bother handling odd stuff for now.
|
|
|
|
if (VA.getLocInfo() != CCValAssign::Full)
|
|
|
|
return false;
|
|
|
|
// Only handle register returns for now.
|
|
|
|
if (!VA.isRegLoc())
|
|
|
|
return false;
|
|
|
|
// TODO: For now, don't try to handle cases where getLocInfo()
|
|
|
|
// says Full but the types don't match.
|
2010-11-04 18:49:57 +08:00
|
|
|
if (TLI.getValueType(RV->getType()) != VA.getValVT())
|
2010-10-22 09:28:00 +08:00
|
|
|
return false;
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 09:28:00 +08:00
|
|
|
// Make the copy.
|
|
|
|
unsigned SrcReg = Reg + VA.getValNo();
|
|
|
|
unsigned DstReg = VA.getLocReg();
|
|
|
|
const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg);
|
|
|
|
// Avoid a cross-class copy. This is very unlikely.
|
|
|
|
if (!SrcRC->contains(DstReg))
|
|
|
|
return false;
|
|
|
|
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY),
|
|
|
|
DstReg).addReg(SrcReg);
|
|
|
|
|
|
|
|
// Mark the register as live out of the function.
|
|
|
|
MRI.addLiveOut(VA.getLocReg());
|
|
|
|
}
|
2010-10-28 05:39:08 +08:00
|
|
|
|
2010-10-22 09:28:00 +08:00
|
|
|
unsigned RetOpc = isThumb ? ARM::tBX_RET : ARM::BX_RET;
|
|
|
|
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(RetOpc)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-22 09:37:10 +08:00
|
|
|
unsigned ARMFastISel::ARMSelectCallOp(const GlobalValue *GV) {
|
|
|
|
|
|
|
|
// Darwin needs the r9 versions of the opcodes.
|
|
|
|
bool isDarwin = Subtarget->isTargetDarwin();
|
2011-04-05 08:39:26 +08:00
|
|
|
if (isThumb) {
|
2011-02-22 09:37:10 +08:00
|
|
|
return isDarwin ? ARM::tBLr9 : ARM::tBL;
|
|
|
|
} else {
|
|
|
|
return isDarwin ? ARM::BLr9 : ARM::BL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
// A quick function that will emit a call for a named libcall in F with the
|
|
|
|
// vector of passed arguments for the Instruction in I. We can assume that we
|
2010-10-11 16:38:55 +08:00
|
|
|
// can emit a call for any libcall we can produce. This is an abridged version
|
|
|
|
// of the full call infrastructure since we won't need to worry about things
|
2010-09-15 07:03:37 +08:00
|
|
|
// like computed function pointers or strange arguments at call sites.
|
|
|
|
// TODO: Try to unify this and the normal call bits for ARM, then try to unify
|
|
|
|
// with X86.
|
2010-09-28 09:21:42 +08:00
|
|
|
bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) {
|
|
|
|
CallingConv::ID CC = TLI.getLibcallCallingConv(Call);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
// Handle *simple* calls for now.
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *RetTy = I->getType();
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT RetVT;
|
2010-09-15 07:03:37 +08:00
|
|
|
if (RetTy->isVoidTy())
|
|
|
|
RetVT = MVT::isVoid;
|
|
|
|
else if (!isTypeLegal(RetTy, RetVT))
|
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-12-16 07:47:29 +08:00
|
|
|
// TODO: For now if we have long calls specified we don't handle the call.
|
|
|
|
if (EnableARMLongCalls) return false;
|
|
|
|
|
2010-09-30 07:11:09 +08:00
|
|
|
// Set up the argument vectors.
|
2010-09-15 07:03:37 +08:00
|
|
|
SmallVector<Value*, 8> Args;
|
|
|
|
SmallVector<unsigned, 8> ArgRegs;
|
2010-11-03 19:35:31 +08:00
|
|
|
SmallVector<MVT, 8> ArgVTs;
|
2010-09-15 07:03:37 +08:00
|
|
|
SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
|
|
|
|
Args.reserve(I->getNumOperands());
|
|
|
|
ArgRegs.reserve(I->getNumOperands());
|
|
|
|
ArgVTs.reserve(I->getNumOperands());
|
|
|
|
ArgFlags.reserve(I->getNumOperands());
|
2010-09-28 09:21:42 +08:00
|
|
|
for (unsigned i = 0; i < I->getNumOperands(); ++i) {
|
2010-09-15 07:03:37 +08:00
|
|
|
Value *Op = I->getOperand(i);
|
|
|
|
unsigned Arg = getRegForValue(Op);
|
|
|
|
if (Arg == 0) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *ArgTy = Op->getType();
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT ArgVT;
|
2010-09-15 07:03:37 +08:00
|
|
|
if (!isTypeLegal(ArgTy, ArgVT)) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
ISD::ArgFlagsTy Flags;
|
|
|
|
unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
|
|
|
|
Flags.setOrigAlign(OriginalAlignment);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
Args.push_back(Op);
|
|
|
|
ArgRegs.push_back(Arg);
|
|
|
|
ArgVTs.push_back(ArgVT);
|
|
|
|
ArgFlags.push_back(Flags);
|
|
|
|
}
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-30 07:11:09 +08:00
|
|
|
// Handle the arguments now that we've gotten them.
|
2010-09-15 07:03:37 +08:00
|
|
|
SmallVector<unsigned, 4> RegArgs;
|
2010-09-30 07:11:09 +08:00
|
|
|
unsigned NumBytes;
|
|
|
|
if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes))
|
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2011-04-29 08:07:20 +08:00
|
|
|
// Issue the call, BLr9 for darwin, BL otherwise.
|
2010-10-11 16:38:55 +08:00
|
|
|
// TODO: Turn this into the table of arm call ops.
|
2010-09-15 07:03:37 +08:00
|
|
|
MachineInstrBuilder MIB;
|
2011-02-22 09:37:10 +08:00
|
|
|
unsigned CallOpc = ARMSelectCallOp(NULL);
|
|
|
|
if(isThumb)
|
2010-12-21 11:50:43 +08:00
|
|
|
// Explicitly adding the predicate here.
|
|
|
|
MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(CallOpc)))
|
|
|
|
.addExternalSymbol(TLI.getLibcallName(Call));
|
2011-02-22 09:37:10 +08:00
|
|
|
else
|
2010-12-21 11:50:43 +08:00
|
|
|
// Explicitly adding the predicate here.
|
|
|
|
MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(CallOpc))
|
|
|
|
.addExternalSymbol(TLI.getLibcallName(Call)));
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
// Add implicit physical register uses to the call.
|
|
|
|
for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
|
|
|
|
MIB.addReg(RegArgs[i]);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-30 07:11:09 +08:00
|
|
|
// Finish off the call including any return values.
|
2010-10-11 16:38:55 +08:00
|
|
|
SmallVector<unsigned, 4> UsedRegs;
|
2010-09-30 07:11:09 +08:00
|
|
|
if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
// Set all unused physreg defs as dead.
|
|
|
|
static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-09-15 07:03:37 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
bool ARMFastISel::SelectCall(const Instruction *I) {
|
|
|
|
const CallInst *CI = cast<CallInst>(I);
|
|
|
|
const Value *Callee = CI->getCalledValue();
|
|
|
|
|
|
|
|
// Can't handle inline asm or worry about intrinsics yet.
|
|
|
|
if (isa<InlineAsm>(Callee) || isa<IntrinsicInst>(CI)) return false;
|
|
|
|
|
2011-05-03 04:16:33 +08:00
|
|
|
// Only handle global variable Callees.
|
2010-10-01 04:49:44 +08:00
|
|
|
const GlobalValue *GV = dyn_cast<GlobalValue>(Callee);
|
2011-05-03 04:16:33 +08:00
|
|
|
if (!GV)
|
2010-10-02 05:33:12 +08:00
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Check the calling convention.
|
|
|
|
ImmutableCallSite CS(CI);
|
|
|
|
CallingConv::ID CC = CS.getCallingConv();
|
2010-10-18 14:49:12 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// TODO: Avoid some calling conventions?
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Let SDISel handle vararg functions.
|
2011-07-18 12:54:35 +08:00
|
|
|
PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType());
|
|
|
|
FunctionType *FTy = cast<FunctionType>(PT->getElementType());
|
2010-10-01 04:49:44 +08:00
|
|
|
if (FTy->isVarArg())
|
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Handle *simple* calls for now.
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *RetTy = I->getType();
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT RetVT;
|
2010-10-01 04:49:44 +08:00
|
|
|
if (RetTy->isVoidTy())
|
|
|
|
RetVT = MVT::isVoid;
|
|
|
|
else if (!isTypeLegal(RetTy, RetVT))
|
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-12-16 07:47:29 +08:00
|
|
|
// TODO: For now if we have long calls specified we don't handle the call.
|
|
|
|
if (EnableARMLongCalls) return false;
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Set up the argument vectors.
|
|
|
|
SmallVector<Value*, 8> Args;
|
|
|
|
SmallVector<unsigned, 8> ArgRegs;
|
2010-11-03 19:35:31 +08:00
|
|
|
SmallVector<MVT, 8> ArgVTs;
|
2010-10-01 04:49:44 +08:00
|
|
|
SmallVector<ISD::ArgFlagsTy, 8> ArgFlags;
|
|
|
|
Args.reserve(CS.arg_size());
|
|
|
|
ArgRegs.reserve(CS.arg_size());
|
|
|
|
ArgVTs.reserve(CS.arg_size());
|
|
|
|
ArgFlags.reserve(CS.arg_size());
|
|
|
|
for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end();
|
|
|
|
i != e; ++i) {
|
|
|
|
unsigned Arg = getRegForValue(*i);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
if (Arg == 0)
|
|
|
|
return false;
|
|
|
|
ISD::ArgFlagsTy Flags;
|
|
|
|
unsigned AttrInd = i - CS.arg_begin() + 1;
|
|
|
|
if (CS.paramHasAttr(AttrInd, Attribute::SExt))
|
|
|
|
Flags.setSExt();
|
|
|
|
if (CS.paramHasAttr(AttrInd, Attribute::ZExt))
|
|
|
|
Flags.setZExt();
|
|
|
|
|
|
|
|
// FIXME: Only handle *easy* calls for now.
|
|
|
|
if (CS.paramHasAttr(AttrInd, Attribute::InReg) ||
|
|
|
|
CS.paramHasAttr(AttrInd, Attribute::StructRet) ||
|
|
|
|
CS.paramHasAttr(AttrInd, Attribute::Nest) ||
|
|
|
|
CS.paramHasAttr(AttrInd, Attribute::ByVal))
|
|
|
|
return false;
|
|
|
|
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *ArgTy = (*i)->getType();
|
2010-11-03 19:35:31 +08:00
|
|
|
MVT ArgVT;
|
2010-10-01 04:49:44 +08:00
|
|
|
if (!isTypeLegal(ArgTy, ArgVT))
|
|
|
|
return false;
|
|
|
|
unsigned OriginalAlignment = TD.getABITypeAlignment(ArgTy);
|
|
|
|
Flags.setOrigAlign(OriginalAlignment);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
Args.push_back(*i);
|
|
|
|
ArgRegs.push_back(Arg);
|
|
|
|
ArgVTs.push_back(ArgVT);
|
|
|
|
ArgFlags.push_back(Flags);
|
|
|
|
}
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Handle the arguments now that we've gotten them.
|
|
|
|
SmallVector<unsigned, 4> RegArgs;
|
|
|
|
unsigned NumBytes;
|
|
|
|
if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, RegArgs, CC, NumBytes))
|
|
|
|
return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2011-04-29 08:07:20 +08:00
|
|
|
// Issue the call, BLr9 for darwin, BL otherwise.
|
2010-10-11 16:38:55 +08:00
|
|
|
// TODO: Turn this into the table of arm call ops.
|
2010-10-01 04:49:44 +08:00
|
|
|
MachineInstrBuilder MIB;
|
2011-02-22 09:37:10 +08:00
|
|
|
unsigned CallOpc = ARMSelectCallOp(GV);
|
2010-12-21 11:50:43 +08:00
|
|
|
// Explicitly adding the predicate here.
|
2011-02-22 09:37:10 +08:00
|
|
|
if(isThumb)
|
2010-12-21 11:50:43 +08:00
|
|
|
// Explicitly adding the predicate here.
|
|
|
|
MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(CallOpc)))
|
|
|
|
.addGlobalAddress(GV, 0, 0);
|
2011-02-22 09:37:10 +08:00
|
|
|
else
|
2010-12-21 11:50:43 +08:00
|
|
|
// Explicitly adding the predicate here.
|
|
|
|
MIB = AddDefaultPred(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
|
|
|
TII.get(CallOpc))
|
|
|
|
.addGlobalAddress(GV, 0, 0));
|
2011-04-29 08:03:10 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Add implicit physical register uses to the call.
|
|
|
|
for (unsigned i = 0, e = RegArgs.size(); i != e; ++i)
|
|
|
|
MIB.addReg(RegArgs[i]);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Finish off the call including any return values.
|
2010-10-11 16:38:55 +08:00
|
|
|
SmallVector<unsigned, 4> UsedRegs;
|
2010-10-01 04:49:44 +08:00
|
|
|
if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes)) return false;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
// Set all unused physreg defs as dead.
|
|
|
|
static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI);
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
return true;
|
2010-10-11 16:38:55 +08:00
|
|
|
|
2010-10-01 04:49:44 +08:00
|
|
|
}
|
|
|
|
|
2011-05-26 07:49:02 +08:00
|
|
|
bool ARMFastISel::SelectIntCast(const Instruction *I) {
|
|
|
|
// On ARM, in general, integer casts don't involve legal types; this code
|
|
|
|
// handles promotable integers. The high bits for a type smaller than
|
|
|
|
// the register size are assumed to be undefined.
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *DestTy = I->getType();
|
2011-05-26 07:49:02 +08:00
|
|
|
Value *Op = I->getOperand(0);
|
2011-07-18 12:54:35 +08:00
|
|
|
Type *SrcTy = Op->getType();
|
2011-05-26 07:49:02 +08:00
|
|
|
|
|
|
|
EVT SrcVT, DestVT;
|
|
|
|
SrcVT = TLI.getValueType(SrcTy, true);
|
|
|
|
DestVT = TLI.getValueType(DestTy, true);
|
|
|
|
|
|
|
|
if (isa<TruncInst>(I)) {
|
|
|
|
if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8)
|
|
|
|
return false;
|
|
|
|
if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned SrcReg = getRegForValue(Op);
|
|
|
|
if (!SrcReg) return false;
|
|
|
|
|
|
|
|
// Because the high bits are undefined, a truncate doesn't generate
|
|
|
|
// any code.
|
|
|
|
UpdateValueMap(I, SrcReg);
|
|
|
|
return true;
|
2011-06-09 07:55:35 +08:00
|
|
|
}
|
2011-05-26 07:49:02 +08:00
|
|
|
if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned Opc;
|
|
|
|
bool isZext = isa<ZExtInst>(I);
|
|
|
|
bool isBoolZext = false;
|
2011-05-28 02:02:04 +08:00
|
|
|
if (!SrcVT.isSimple())
|
|
|
|
return false;
|
2011-05-26 07:49:02 +08:00
|
|
|
switch (SrcVT.getSimpleVT().SimpleTy) {
|
|
|
|
default: return false;
|
|
|
|
case MVT::i16:
|
|
|
|
if (isZext)
|
2011-07-28 00:47:19 +08:00
|
|
|
Opc = isThumb ? ARM::t2UXTH : ARM::UXTH;
|
2011-05-26 07:49:02 +08:00
|
|
|
else
|
2011-07-28 00:47:19 +08:00
|
|
|
Opc = isThumb ? ARM::t2SXTH : ARM::SXTH;
|
2011-05-26 07:49:02 +08:00
|
|
|
break;
|
|
|
|
case MVT::i8:
|
|
|
|
if (isZext)
|
2011-07-28 00:47:19 +08:00
|
|
|
Opc = isThumb ? ARM::t2UXTB : ARM::UXTB;
|
2011-05-26 07:49:02 +08:00
|
|
|
else
|
2011-07-28 00:47:19 +08:00
|
|
|
Opc = isThumb ? ARM::t2SXTB : ARM::SXTB;
|
2011-05-26 07:49:02 +08:00
|
|
|
break;
|
|
|
|
case MVT::i1:
|
|
|
|
if (isZext) {
|
|
|
|
Opc = isThumb ? ARM::t2ANDri : ARM::ANDri;
|
|
|
|
isBoolZext = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We could save an instruction in many cases by special-casing
|
|
|
|
// load instructions.
|
|
|
|
unsigned SrcReg = getRegForValue(Op);
|
|
|
|
if (!SrcReg) return false;
|
|
|
|
|
|
|
|
unsigned DestReg = createResultReg(TLI.getRegClassFor(MVT::i32));
|
|
|
|
MachineInstrBuilder MIB;
|
|
|
|
MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(Opc), DestReg)
|
|
|
|
.addReg(SrcReg);
|
|
|
|
if (isBoolZext)
|
|
|
|
MIB.addImm(1);
|
2011-07-28 00:47:19 +08:00
|
|
|
else
|
|
|
|
MIB.addImm(0);
|
2011-05-26 07:49:02 +08:00
|
|
|
AddOptionalDefs(MIB);
|
|
|
|
UpdateValueMap(I, DestReg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:43:26 +08:00
|
|
|
// TODO: SoftFP support.
|
2010-07-22 06:26:11 +08:00
|
|
|
bool ARMFastISel::TargetSelectInstruction(const Instruction *I) {
|
2010-09-09 09:06:51 +08:00
|
|
|
|
2010-07-22 06:26:11 +08:00
|
|
|
switch (I->getOpcode()) {
|
2010-08-24 05:44:12 +08:00
|
|
|
case Instruction::Load:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectLoad(I);
|
2010-09-02 06:16:27 +08:00
|
|
|
case Instruction::Store:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectStore(I);
|
2010-09-03 08:35:47 +08:00
|
|
|
case Instruction::Br:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectBranch(I);
|
2010-09-09 07:13:45 +08:00
|
|
|
case Instruction::ICmp:
|
|
|
|
case Instruction::FCmp:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectCmp(I);
|
2010-09-09 08:26:48 +08:00
|
|
|
case Instruction::FPExt:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectFPExt(I);
|
2010-09-10 04:26:31 +08:00
|
|
|
case Instruction::FPTrunc:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectFPTrunc(I);
|
2010-09-10 02:54:59 +08:00
|
|
|
case Instruction::SIToFP:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectSIToFP(I);
|
2010-09-10 02:54:59 +08:00
|
|
|
case Instruction::FPToSI:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectFPToSI(I);
|
2010-09-09 08:53:57 +08:00
|
|
|
case Instruction::FAdd:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectBinaryOp(I, ISD::FADD);
|
2010-09-09 08:53:57 +08:00
|
|
|
case Instruction::FSub:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectBinaryOp(I, ISD::FSUB);
|
2010-09-09 08:53:57 +08:00
|
|
|
case Instruction::FMul:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectBinaryOp(I, ISD::FMUL);
|
2010-09-15 07:03:37 +08:00
|
|
|
case Instruction::SDiv:
|
2010-09-27 14:02:23 +08:00
|
|
|
return SelectSDiv(I);
|
2010-10-11 16:37:26 +08:00
|
|
|
case Instruction::SRem:
|
|
|
|
return SelectSRem(I);
|
2010-10-01 04:49:44 +08:00
|
|
|
case Instruction::Call:
|
|
|
|
return SelectCall(I);
|
2010-10-11 16:27:59 +08:00
|
|
|
case Instruction::Select:
|
|
|
|
return SelectSelect(I);
|
2010-10-22 09:28:00 +08:00
|
|
|
case Instruction::Ret:
|
|
|
|
return SelectRet(I);
|
2011-05-26 07:49:02 +08:00
|
|
|
case Instruction::Trunc:
|
|
|
|
case Instruction::ZExt:
|
|
|
|
case Instruction::SExt:
|
|
|
|
return SelectIntCast(I);
|
2010-07-22 06:26:11 +08:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
llvm::FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo) {
|
2010-10-12 04:05:22 +08:00
|
|
|
// Completely untested on non-darwin.
|
|
|
|
const TargetMachine &TM = funcInfo.MF->getTarget();
|
2010-11-10 03:22:26 +08:00
|
|
|
|
2010-11-02 09:21:28 +08:00
|
|
|
// Darwin and thumb1 only for now.
|
2010-10-12 04:05:22 +08:00
|
|
|
const ARMSubtarget *Subtarget = &TM.getSubtarget<ARMSubtarget>();
|
2010-11-10 03:22:26 +08:00
|
|
|
if (Subtarget->isTargetDarwin() && !Subtarget->isThumb1Only() &&
|
2010-11-02 09:21:28 +08:00
|
|
|
!DisableARMFastISel)
|
2010-10-12 04:05:22 +08:00
|
|
|
return new ARMFastISel(funcInfo);
|
2010-07-27 02:32:55 +08:00
|
|
|
return 0;
|
2010-07-22 06:26:11 +08:00
|
|
|
}
|
|
|
|
}
|