2006-05-15 06:18:28 +08:00
|
|
|
//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines an instruction selector for the ARM target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
2006-07-16 09:02:57 +08:00
|
|
|
#include "llvm/CallingConv.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Function.h"
|
2006-09-21 19:29:52 +08:00
|
|
|
#include "llvm/Constants.h"
|
2006-05-15 06:18:28 +08:00
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
|
|
|
#include "llvm/CodeGen/SSARegMap.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include <iostream>
|
2006-10-06 00:48:49 +08:00
|
|
|
#include <vector>
|
2006-05-15 06:18:28 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class ARMTargetLowering : public TargetLowering {
|
2006-08-26 01:55:16 +08:00
|
|
|
int VarArgsFrameIndex; // FrameIndex for start of varargs area.
|
2006-05-15 06:18:28 +08:00
|
|
|
public:
|
|
|
|
ARMTargetLowering(TargetMachine &TM);
|
|
|
|
virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
|
2006-07-16 09:02:57 +08:00
|
|
|
virtual const char *getTargetNodeName(unsigned Opcode) const;
|
2006-05-15 06:18:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ARMTargetLowering::ARMTargetLowering(TargetMachine &TM)
|
|
|
|
: TargetLowering(TM) {
|
2006-08-20 09:49:49 +08:00
|
|
|
addRegisterClass(MVT::i32, ARM::IntRegsRegisterClass);
|
2006-09-30 05:20:16 +08:00
|
|
|
addRegisterClass(MVT::f32, ARM::FPRegsRegisterClass);
|
|
|
|
addRegisterClass(MVT::f64, ARM::DFPRegsRegisterClass);
|
2006-08-20 09:49:49 +08:00
|
|
|
|
2006-10-09 22:13:40 +08:00
|
|
|
setLoadXAction(ISD::EXTLOAD, MVT::f32, Expand);
|
|
|
|
|
2006-10-11 02:55:14 +08:00
|
|
|
setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
|
2006-09-30 05:20:16 +08:00
|
|
|
setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
|
2006-08-20 09:49:49 +08:00
|
|
|
|
2006-10-11 04:38:57 +08:00
|
|
|
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
|
2006-10-07 22:24:52 +08:00
|
|
|
setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom);
|
|
|
|
|
2006-08-01 20:58:43 +08:00
|
|
|
setOperationAction(ISD::RET, MVT::Other, Custom);
|
|
|
|
setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
|
2006-08-04 20:48:42 +08:00
|
|
|
|
2006-10-10 00:28:33 +08:00
|
|
|
setOperationAction(ISD::SELECT, MVT::i32, Expand);
|
|
|
|
|
2006-08-22 06:00:32 +08:00
|
|
|
setOperationAction(ISD::SETCC, MVT::i32, Expand);
|
2006-10-10 20:56:00 +08:00
|
|
|
setOperationAction(ISD::SETCC, MVT::f32, Expand);
|
|
|
|
setOperationAction(ISD::SETCC, MVT::f64, Expand);
|
|
|
|
|
2006-08-22 06:00:32 +08:00
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
|
2006-08-24 21:45:55 +08:00
|
|
|
setOperationAction(ISD::BR_CC, MVT::i32, Custom);
|
2006-10-10 20:56:00 +08:00
|
|
|
setOperationAction(ISD::BR_CC, MVT::f32, Custom);
|
|
|
|
setOperationAction(ISD::BR_CC, MVT::f64, Custom);
|
2006-08-22 06:00:32 +08:00
|
|
|
|
2006-10-15 01:59:54 +08:00
|
|
|
setOperationAction(ISD::BRCOND, MVT::Other, Expand);
|
|
|
|
|
2006-10-17 05:10:32 +08:00
|
|
|
setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
|
2006-10-18 05:05:33 +08:00
|
|
|
setOperationAction(ISD::SDIV, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::UDIV, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SREM, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::UREM, MVT::i32, Expand);
|
2006-10-17 05:10:32 +08:00
|
|
|
|
2006-08-26 01:55:16 +08:00
|
|
|
setOperationAction(ISD::VASTART, MVT::Other, Custom);
|
|
|
|
setOperationAction(ISD::VAEND, MVT::Other, Expand);
|
|
|
|
|
2006-10-04 01:27:58 +08:00
|
|
|
setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
|
|
|
|
|
2006-08-04 20:48:42 +08:00
|
|
|
setSchedulingPreference(SchedulingForRegPressure);
|
2006-08-20 09:49:49 +08:00
|
|
|
computeRegisterProperties();
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
2006-07-16 09:02:57 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace ARMISD {
|
|
|
|
enum NodeType {
|
|
|
|
// Start the numbering where the builting ops and target ops leave off.
|
|
|
|
FIRST_NUMBER = ISD::BUILTIN_OP_END+ARM::INSTRUCTION_LIST_END,
|
|
|
|
/// CALL - A direct function call.
|
2006-08-04 01:02:20 +08:00
|
|
|
CALL,
|
|
|
|
|
|
|
|
/// Return with a flag operand.
|
2006-08-22 06:00:32 +08:00
|
|
|
RET_FLAG,
|
|
|
|
|
|
|
|
CMP,
|
|
|
|
|
2006-08-24 21:45:55 +08:00
|
|
|
SELECT,
|
|
|
|
|
2006-09-30 05:20:16 +08:00
|
|
|
BR,
|
|
|
|
|
2006-10-03 03:30:56 +08:00
|
|
|
FSITOS,
|
2006-10-11 02:55:14 +08:00
|
|
|
FTOSIS,
|
2006-10-03 03:30:56 +08:00
|
|
|
|
|
|
|
FSITOD,
|
2006-10-11 02:55:14 +08:00
|
|
|
FTOSID,
|
2006-10-03 03:30:56 +08:00
|
|
|
|
2006-10-07 22:24:52 +08:00
|
|
|
FUITOS,
|
2006-10-11 04:38:57 +08:00
|
|
|
FTOUIS,
|
2006-10-07 22:24:52 +08:00
|
|
|
|
|
|
|
FUITOD,
|
2006-10-11 04:38:57 +08:00
|
|
|
FTOUID,
|
2006-10-07 22:24:52 +08:00
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
FMRRD,
|
|
|
|
|
2006-10-10 20:56:00 +08:00
|
|
|
FMDRR,
|
|
|
|
|
|
|
|
FMSTAT
|
2006-07-16 09:02:57 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-13 21:14:59 +08:00
|
|
|
/// DAGFPCCToARMCC - Convert a DAG fp condition code to an ARM CC
|
2006-10-14 21:42:53 +08:00
|
|
|
// Unordered = !N & !Z & C & V = V
|
|
|
|
// Ordered = N | Z | !C | !V = N | Z | !V
|
2006-10-13 21:14:59 +08:00
|
|
|
static ARMCC::CondCodes DAGFPCCToARMCC(ISD::CondCode CC) {
|
2006-08-25 00:13:15 +08:00
|
|
|
switch (CC) {
|
2006-09-21 21:06:26 +08:00
|
|
|
default:
|
2006-10-13 21:14:59 +08:00
|
|
|
assert(0 && "Unknown fp condition code!");
|
2006-10-14 21:42:53 +08:00
|
|
|
// SETOEQ = (N | Z | !V) & Z = Z = EQ
|
|
|
|
case ISD::SETEQ:
|
2006-10-10 20:56:00 +08:00
|
|
|
case ISD::SETOEQ: return ARMCC::EQ;
|
2006-10-14 21:42:53 +08:00
|
|
|
// SETOGT = (N | Z | !V) & !N & !Z = !V &!N &!Z = (N = V) & !Z = GT
|
|
|
|
case ISD::SETGT:
|
2006-10-13 21:14:59 +08:00
|
|
|
case ISD::SETOGT: return ARMCC::GT;
|
2006-10-14 21:42:53 +08:00
|
|
|
// SETOGE = (N | Z | !V) & !N = (Z | !V) & !N = !V & !N = GE
|
|
|
|
case ISD::SETGE:
|
2006-10-10 20:56:00 +08:00
|
|
|
case ISD::SETOGE: return ARMCC::GE;
|
2006-10-14 21:42:53 +08:00
|
|
|
// SETOLT = (N | Z | !V) & N = N = MI
|
|
|
|
case ISD::SETLT:
|
|
|
|
case ISD::SETOLT: return ARMCC::MI;
|
|
|
|
// SETOLE = (N | Z | !V) & (N | Z) = N | Z = !C | Z = LS
|
|
|
|
case ISD::SETLE:
|
|
|
|
case ISD::SETOLE: return ARMCC::LS;
|
|
|
|
// SETONE = (N | Z | !V) & !Z = (N | !V) & Z = !V & Z = Z = NE
|
|
|
|
case ISD::SETNE:
|
2006-10-13 21:14:59 +08:00
|
|
|
case ISD::SETONE: return ARMCC::NE;
|
2006-10-14 21:42:53 +08:00
|
|
|
// SETO = N | Z | !V = Z | !V = !V = VC
|
|
|
|
case ISD::SETO: return ARMCC::VC;
|
|
|
|
// SETUO = V = VS
|
|
|
|
case ISD::SETUO: return ARMCC::VS;
|
|
|
|
// SETUEQ = V | Z = ??
|
|
|
|
// SETUGT = V | (!Z & !N) = !Z & !N = !Z & C = HI
|
|
|
|
case ISD::SETUGT: return ARMCC::HI;
|
|
|
|
// SETUGE = V | !N = !N = PL
|
2006-10-13 21:14:59 +08:00
|
|
|
case ISD::SETUGE: return ARMCC::PL;
|
2006-10-14 21:42:53 +08:00
|
|
|
// SETULT = V | N = ??
|
|
|
|
// SETULE = V | Z | N = ??
|
|
|
|
// SETUNE = V | !Z = !Z = NE
|
2006-10-13 21:14:59 +08:00
|
|
|
case ISD::SETUNE: return ARMCC::NE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// DAGIntCCToARMCC - Convert a DAG integer condition code to an ARM CC
|
|
|
|
static ARMCC::CondCodes DAGIntCCToARMCC(ISD::CondCode CC) {
|
|
|
|
switch (CC) {
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown integer condition code!");
|
|
|
|
case ISD::SETEQ: return ARMCC::EQ;
|
|
|
|
case ISD::SETNE: return ARMCC::NE;
|
|
|
|
case ISD::SETLT: return ARMCC::LT;
|
|
|
|
case ISD::SETLE: return ARMCC::LE;
|
|
|
|
case ISD::SETGT: return ARMCC::GT;
|
|
|
|
case ISD::SETGE: return ARMCC::GE;
|
2006-09-03 21:19:16 +08:00
|
|
|
case ISD::SETULT: return ARMCC::CC;
|
2006-10-13 21:14:59 +08:00
|
|
|
case ISD::SETULE: return ARMCC::LS;
|
|
|
|
case ISD::SETUGT: return ARMCC::HI;
|
|
|
|
case ISD::SETUGE: return ARMCC::CS;
|
2006-08-25 00:13:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-16 09:02:57 +08:00
|
|
|
const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const {
|
|
|
|
switch (Opcode) {
|
|
|
|
default: return 0;
|
|
|
|
case ARMISD::CALL: return "ARMISD::CALL";
|
2006-08-04 01:02:20 +08:00
|
|
|
case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG";
|
2006-08-22 06:00:32 +08:00
|
|
|
case ARMISD::SELECT: return "ARMISD::SELECT";
|
|
|
|
case ARMISD::CMP: return "ARMISD::CMP";
|
2006-08-24 21:45:55 +08:00
|
|
|
case ARMISD::BR: return "ARMISD::BR";
|
2006-09-30 05:20:16 +08:00
|
|
|
case ARMISD::FSITOS: return "ARMISD::FSITOS";
|
2006-10-11 02:55:14 +08:00
|
|
|
case ARMISD::FTOSIS: return "ARMISD::FTOSIS";
|
2006-10-03 03:30:56 +08:00
|
|
|
case ARMISD::FSITOD: return "ARMISD::FSITOD";
|
2006-10-11 02:55:14 +08:00
|
|
|
case ARMISD::FTOSID: return "ARMISD::FTOSID";
|
2006-10-07 22:24:52 +08:00
|
|
|
case ARMISD::FUITOS: return "ARMISD::FUITOS";
|
2006-10-11 04:38:57 +08:00
|
|
|
case ARMISD::FTOUIS: return "ARMISD::FTOUIS";
|
2006-10-07 22:24:52 +08:00
|
|
|
case ARMISD::FUITOD: return "ARMISD::FUITOD";
|
2006-10-11 04:38:57 +08:00
|
|
|
case ARMISD::FTOUID: return "ARMISD::FTOUID";
|
2006-10-03 03:30:56 +08:00
|
|
|
case ARMISD::FMRRD: return "ARMISD::FMRRD";
|
2006-10-06 00:48:49 +08:00
|
|
|
case ARMISD::FMDRR: return "ARMISD::FMDRR";
|
2006-10-10 20:56:00 +08:00
|
|
|
case ARMISD::FMSTAT: return "ARMISD::FMSTAT";
|
2006-07-16 09:02:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
class ArgumentLayout {
|
|
|
|
std::vector<bool> is_reg;
|
|
|
|
std::vector<unsigned> pos;
|
|
|
|
std::vector<MVT::ValueType> types;
|
|
|
|
public:
|
2006-10-06 01:46:48 +08:00
|
|
|
ArgumentLayout(const std::vector<MVT::ValueType> &Types) {
|
2006-10-06 00:48:49 +08:00
|
|
|
types = Types;
|
|
|
|
|
|
|
|
unsigned RegNum = 0;
|
|
|
|
unsigned StackOffset = 0;
|
2006-10-06 01:46:48 +08:00
|
|
|
for(std::vector<MVT::ValueType>::const_iterator I = Types.begin();
|
2006-10-06 00:48:49 +08:00
|
|
|
I != Types.end();
|
|
|
|
++I) {
|
|
|
|
MVT::ValueType VT = *I;
|
|
|
|
assert(VT == MVT::i32 || VT == MVT::f32 || VT == MVT::f64);
|
|
|
|
unsigned size = MVT::getSizeInBits(VT)/32;
|
|
|
|
|
|
|
|
RegNum = ((RegNum + size - 1) / size) * size;
|
|
|
|
if (RegNum < 4) {
|
|
|
|
pos.push_back(RegNum);
|
|
|
|
is_reg.push_back(true);
|
|
|
|
RegNum += size;
|
|
|
|
} else {
|
|
|
|
unsigned bytes = size * 32/8;
|
|
|
|
StackOffset = ((StackOffset + bytes - 1) / bytes) * bytes;
|
|
|
|
pos.push_back(StackOffset);
|
|
|
|
is_reg.push_back(false);
|
|
|
|
StackOffset += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsigned getRegisterNum(unsigned argNum) {
|
|
|
|
assert(isRegister(argNum));
|
|
|
|
return pos[argNum];
|
|
|
|
}
|
|
|
|
unsigned getOffset(unsigned argNum) {
|
|
|
|
assert(isOffset(argNum));
|
|
|
|
return pos[argNum];
|
|
|
|
}
|
|
|
|
unsigned isRegister(unsigned argNum) {
|
|
|
|
assert(argNum < is_reg.size());
|
|
|
|
return is_reg[argNum];
|
|
|
|
}
|
|
|
|
unsigned isOffset(unsigned argNum) {
|
|
|
|
return !isRegister(argNum);
|
|
|
|
}
|
|
|
|
MVT::ValueType getType(unsigned argNum) {
|
|
|
|
assert(argNum < types.size());
|
|
|
|
return types[argNum];
|
|
|
|
}
|
|
|
|
unsigned getStackSize(void) {
|
|
|
|
int last = is_reg.size() - 1;
|
2006-10-07 01:26:30 +08:00
|
|
|
if (last < 0)
|
|
|
|
return 0;
|
2006-10-06 00:48:49 +08:00
|
|
|
if (isRegister(last))
|
|
|
|
return 0;
|
|
|
|
return getOffset(last) + MVT::getSizeInBits(getType(last))/8;
|
|
|
|
}
|
|
|
|
int lastRegArg(void) {
|
|
|
|
int size = is_reg.size();
|
|
|
|
int last = 0;
|
|
|
|
while(last < size && isRegister(last))
|
|
|
|
last++;
|
|
|
|
last--;
|
|
|
|
return last;
|
|
|
|
}
|
2006-10-07 01:26:30 +08:00
|
|
|
int lastRegNum(void) {
|
2006-10-06 00:48:49 +08:00
|
|
|
int l = lastRegArg();
|
|
|
|
if (l < 0)
|
|
|
|
return -1;
|
|
|
|
unsigned r = getRegisterNum(l);
|
|
|
|
MVT::ValueType t = getType(l);
|
|
|
|
assert(t == MVT::i32 || t == MVT::f32 || t == MVT::f64);
|
|
|
|
if (t == MVT::f64)
|
|
|
|
return r + 1;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-07-16 09:02:57 +08:00
|
|
|
// This transforms a ISD::CALL node into a
|
|
|
|
// callseq_star <- ARMISD:CALL <- callseq_end
|
|
|
|
// chain
|
2006-05-25 19:00:18 +08:00
|
|
|
static SDOperand LowerCALL(SDOperand Op, SelectionDAG &DAG) {
|
2006-07-16 09:02:57 +08:00
|
|
|
SDOperand Chain = Op.getOperand(0);
|
|
|
|
unsigned CallConv = cast<ConstantSDNode>(Op.getOperand(1))->getValue();
|
2006-10-18 20:03:07 +08:00
|
|
|
assert((CallConv == CallingConv::C ||
|
|
|
|
CallConv == CallingConv::Fast)
|
|
|
|
&& "unknown calling convention");
|
2006-07-16 09:02:57 +08:00
|
|
|
bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
|
|
|
|
bool isTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0;
|
|
|
|
SDOperand Callee = Op.getOperand(4);
|
|
|
|
unsigned NumOps = (Op.getNumOperands() - 5) / 2;
|
2006-10-06 00:48:49 +08:00
|
|
|
SDOperand StackPtr = DAG.getRegister(ARM::R13, MVT::i32);
|
|
|
|
static const unsigned regs[] = {
|
|
|
|
ARM::R0, ARM::R1, ARM::R2, ARM::R3
|
|
|
|
};
|
2006-07-16 09:02:57 +08:00
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
std::vector<MVT::ValueType> Types;
|
|
|
|
for (unsigned i = 0; i < NumOps; ++i) {
|
|
|
|
MVT::ValueType VT = Op.getOperand(5+2*i).getValueType();
|
|
|
|
Types.push_back(VT);
|
|
|
|
}
|
|
|
|
ArgumentLayout Layout(Types);
|
2006-07-16 09:02:57 +08:00
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
unsigned NumBytes = Layout.getStackSize();
|
2006-07-26 04:17:20 +08:00
|
|
|
|
2006-07-16 09:02:57 +08:00
|
|
|
Chain = DAG.getCALLSEQ_START(Chain,
|
|
|
|
DAG.getConstant(NumBytes, MVT::i32));
|
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
//Build a sequence of stores
|
2006-08-08 21:02:29 +08:00
|
|
|
std::vector<SDOperand> MemOpChains;
|
2006-10-06 00:48:49 +08:00
|
|
|
for (unsigned i = Layout.lastRegArg() + 1; i < NumOps; ++i) {
|
|
|
|
SDOperand Arg = Op.getOperand(5+2*i);
|
|
|
|
unsigned ArgOffset = Layout.getOffset(i);
|
|
|
|
SDOperand PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType());
|
|
|
|
PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
|
2006-10-14 05:14:26 +08:00
|
|
|
MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0));
|
2006-07-26 04:17:20 +08:00
|
|
|
}
|
2006-08-08 21:02:29 +08:00
|
|
|
if (!MemOpChains.empty())
|
2006-08-12 01:38:39 +08:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, MVT::Other,
|
|
|
|
&MemOpChains[0], MemOpChains.size());
|
2006-07-26 04:17:20 +08:00
|
|
|
|
2006-10-17 05:10:32 +08:00
|
|
|
// If the callee is a GlobalAddress node (quite common, every direct call is)
|
|
|
|
// turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
|
|
|
|
// Likewise ExternalSymbol -> TargetExternalSymbol.
|
|
|
|
assert(Callee.getValueType() == MVT::i32);
|
2006-07-16 09:02:57 +08:00
|
|
|
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
|
2006-10-17 05:10:32 +08:00
|
|
|
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), MVT::i32);
|
|
|
|
else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
|
|
|
|
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
|
2006-07-16 09:02:57 +08:00
|
|
|
|
|
|
|
// If this is a direct call, pass the chain and the callee.
|
|
|
|
assert (Callee.Val);
|
|
|
|
std::vector<SDOperand> Ops;
|
|
|
|
Ops.push_back(Chain);
|
|
|
|
Ops.push_back(Callee);
|
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
// Build a sequence of copy-to-reg nodes chained together with token chain
|
|
|
|
// and flag operands which copy the outgoing args into the appropriate regs.
|
|
|
|
SDOperand InFlag;
|
2006-10-07 01:26:30 +08:00
|
|
|
for (int i = 0, e = Layout.lastRegArg(); i <= e; ++i) {
|
2006-10-06 20:50:22 +08:00
|
|
|
SDOperand Arg = Op.getOperand(5+2*i);
|
|
|
|
unsigned RegNum = Layout.getRegisterNum(i);
|
|
|
|
unsigned Reg1 = regs[RegNum];
|
|
|
|
MVT::ValueType VT = Layout.getType(i);
|
|
|
|
assert(VT == Arg.getValueType());
|
|
|
|
assert(VT == MVT::i32 || VT == MVT::f32 || VT == MVT::f64);
|
2006-10-06 00:48:49 +08:00
|
|
|
|
|
|
|
// Add argument register to the end of the list so that it is known live
|
|
|
|
// into the call.
|
2006-10-06 20:50:22 +08:00
|
|
|
Ops.push_back(DAG.getRegister(Reg1, MVT::i32));
|
|
|
|
if (VT == MVT::f64) {
|
|
|
|
unsigned Reg2 = regs[RegNum + 1];
|
|
|
|
SDOperand SDReg1 = DAG.getRegister(Reg1, MVT::i32);
|
|
|
|
SDOperand SDReg2 = DAG.getRegister(Reg2, MVT::i32);
|
|
|
|
|
|
|
|
Ops.push_back(DAG.getRegister(Reg2, MVT::i32));
|
|
|
|
SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Flag);
|
2006-10-07 04:33:26 +08:00
|
|
|
SDOperand Ops[] = {Chain, SDReg1, SDReg2, Arg, InFlag};
|
|
|
|
Chain = DAG.getNode(ARMISD::FMRRD, VTs, Ops, InFlag.Val ? 5 : 4);
|
2006-10-06 20:50:22 +08:00
|
|
|
} else {
|
|
|
|
if (VT == MVT::f32)
|
|
|
|
Arg = DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Arg);
|
|
|
|
Chain = DAG.getCopyToReg(Chain, Reg1, Arg, InFlag);
|
|
|
|
}
|
|
|
|
InFlag = Chain.getValue(1);
|
2006-10-06 00:48:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MVT::ValueType> NodeTys;
|
|
|
|
NodeTys.push_back(MVT::Other); // Returns a chain
|
|
|
|
NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
|
2006-08-10 00:41:12 +08:00
|
|
|
|
2006-07-16 09:02:57 +08:00
|
|
|
unsigned CallOpc = ARMISD::CALL;
|
2006-07-26 04:17:20 +08:00
|
|
|
if (InFlag.Val)
|
|
|
|
Ops.push_back(InFlag);
|
2006-08-12 01:22:35 +08:00
|
|
|
Chain = DAG.getNode(CallOpc, NodeTys, &Ops[0], Ops.size());
|
2006-07-26 04:17:20 +08:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
|
|
|
std::vector<SDOperand> ResultVals;
|
|
|
|
NodeTys.clear();
|
|
|
|
|
|
|
|
// If the call has results, copy the values out of the ret val registers.
|
2006-10-07 03:10:05 +08:00
|
|
|
MVT::ValueType VT = Op.Val->getValueType(0);
|
|
|
|
if (VT != MVT::Other) {
|
|
|
|
assert(VT == MVT::i32 || VT == MVT::f32 || VT == MVT::f64);
|
|
|
|
|
|
|
|
SDOperand Value1 = DAG.getCopyFromReg(Chain, ARM::R0, MVT::i32, InFlag);
|
|
|
|
Chain = Value1.getValue(1);
|
|
|
|
InFlag = Value1.getValue(2);
|
2006-10-14 00:47:22 +08:00
|
|
|
NodeTys.push_back(VT);
|
|
|
|
if (VT == MVT::i32) {
|
|
|
|
ResultVals.push_back(Value1);
|
|
|
|
if (Op.Val->getValueType(1) == MVT::i32) {
|
|
|
|
SDOperand Value2 = DAG.getCopyFromReg(Chain, ARM::R1, MVT::i32, InFlag);
|
|
|
|
Chain = Value2.getValue(1);
|
|
|
|
ResultVals.push_back(Value2);
|
|
|
|
NodeTys.push_back(VT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (VT == MVT::f32) {
|
|
|
|
SDOperand Value = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, Value1);
|
|
|
|
ResultVals.push_back(Value);
|
|
|
|
}
|
2006-10-07 03:10:05 +08:00
|
|
|
if (VT == MVT::f64) {
|
|
|
|
SDOperand Value2 = DAG.getCopyFromReg(Chain, ARM::R1, MVT::i32, InFlag);
|
|
|
|
Chain = Value2.getValue(1);
|
2006-10-14 00:47:22 +08:00
|
|
|
SDOperand Value = DAG.getNode(ARMISD::FMDRR, MVT::f64, Value1, Value2);
|
|
|
|
ResultVals.push_back(Value);
|
2006-10-07 03:10:05 +08:00
|
|
|
}
|
2006-07-26 04:17:20 +08:00
|
|
|
}
|
2006-07-16 09:02:57 +08:00
|
|
|
|
|
|
|
Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
|
|
|
|
DAG.getConstant(NumBytes, MVT::i32));
|
2006-07-26 04:17:20 +08:00
|
|
|
NodeTys.push_back(MVT::Other);
|
|
|
|
|
|
|
|
if (ResultVals.empty())
|
|
|
|
return Chain;
|
2006-07-16 09:02:57 +08:00
|
|
|
|
2006-07-26 04:17:20 +08:00
|
|
|
ResultVals.push_back(Chain);
|
2006-08-12 01:22:35 +08:00
|
|
|
SDOperand Res = DAG.getNode(ISD::MERGE_VALUES, NodeTys, &ResultVals[0],
|
|
|
|
ResultVals.size());
|
2006-07-26 04:17:20 +08:00
|
|
|
return Res.getValue(Op.ResNo);
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static SDOperand LowerRET(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
SDOperand Copy;
|
2006-06-06 06:26:14 +08:00
|
|
|
SDOperand Chain = Op.getOperand(0);
|
2006-10-03 03:30:56 +08:00
|
|
|
SDOperand R0 = DAG.getRegister(ARM::R0, MVT::i32);
|
|
|
|
SDOperand R1 = DAG.getRegister(ARM::R1, MVT::i32);
|
|
|
|
|
2006-05-15 06:18:28 +08:00
|
|
|
switch(Op.getNumOperands()) {
|
|
|
|
default:
|
|
|
|
assert(0 && "Do not know how to return this many arguments!");
|
|
|
|
abort();
|
2006-06-06 06:26:14 +08:00
|
|
|
case 1: {
|
|
|
|
SDOperand LR = DAG.getRegister(ARM::R14, MVT::i32);
|
2006-08-04 06:50:11 +08:00
|
|
|
return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Chain);
|
2006-06-06 06:26:14 +08:00
|
|
|
}
|
2006-09-30 05:20:16 +08:00
|
|
|
case 3: {
|
|
|
|
SDOperand Val = Op.getOperand(1);
|
|
|
|
assert(Val.getValueType() == MVT::i32 ||
|
2006-10-03 03:30:56 +08:00
|
|
|
Val.getValueType() == MVT::f32 ||
|
|
|
|
Val.getValueType() == MVT::f64);
|
|
|
|
|
|
|
|
if (Val.getValueType() == MVT::f64) {
|
|
|
|
SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Flag);
|
|
|
|
SDOperand Ops[] = {Chain, R0, R1, Val};
|
|
|
|
Copy = DAG.getNode(ARMISD::FMRRD, VTs, Ops, 4);
|
|
|
|
} else {
|
|
|
|
if (Val.getValueType() == MVT::f32)
|
|
|
|
Val = DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Val);
|
|
|
|
Copy = DAG.getCopyToReg(Chain, R0, Val, SDOperand());
|
|
|
|
}
|
2006-09-30 05:20:16 +08:00
|
|
|
|
2006-10-03 03:30:56 +08:00
|
|
|
if (DAG.getMachineFunction().liveout_empty()) {
|
2006-06-06 06:26:14 +08:00
|
|
|
DAG.getMachineFunction().addLiveOut(ARM::R0);
|
2006-10-03 03:30:56 +08:00
|
|
|
if (Val.getValueType() == MVT::f64)
|
|
|
|
DAG.getMachineFunction().addLiveOut(ARM::R1);
|
|
|
|
}
|
2006-05-15 06:18:28 +08:00
|
|
|
break;
|
2006-09-30 05:20:16 +08:00
|
|
|
}
|
2006-09-05 03:05:01 +08:00
|
|
|
case 5:
|
|
|
|
Copy = DAG.getCopyToReg(Chain, ARM::R1, Op.getOperand(3), SDOperand());
|
|
|
|
Copy = DAG.getCopyToReg(Copy, ARM::R0, Op.getOperand(1), Copy.getValue(1));
|
|
|
|
// If we haven't noted the R0+R1 are live out, do so now.
|
|
|
|
if (DAG.getMachineFunction().liveout_empty()) {
|
|
|
|
DAG.getMachineFunction().addLiveOut(ARM::R0);
|
|
|
|
DAG.getMachineFunction().addLiveOut(ARM::R1);
|
|
|
|
}
|
|
|
|
break;
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
2006-06-06 06:26:14 +08:00
|
|
|
|
2006-08-04 01:02:20 +08:00
|
|
|
//We must use RET_FLAG instead of BRIND because BRIND doesn't have a flag
|
|
|
|
return DAG.getNode(ARMISD::RET_FLAG, MVT::Other, Copy, Copy.getValue(1));
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
2006-08-01 20:58:43 +08:00
|
|
|
static SDOperand LowerConstantPool(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
MVT::ValueType PtrVT = Op.getValueType();
|
|
|
|
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
|
2006-09-13 05:04:05 +08:00
|
|
|
Constant *C = CP->getConstVal();
|
2006-08-01 20:58:43 +08:00
|
|
|
SDOperand CPI = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment());
|
|
|
|
|
|
|
|
return CPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SDOperand LowerGlobalAddress(SDOperand Op,
|
|
|
|
SelectionDAG &DAG) {
|
|
|
|
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
2006-08-15 03:01:24 +08:00
|
|
|
int alignment = 2;
|
|
|
|
SDOperand CPAddr = DAG.getConstantPool(GV, MVT::i32, alignment);
|
2006-10-10 04:57:25 +08:00
|
|
|
return DAG.getLoad(MVT::i32, DAG.getEntryNode(), CPAddr, NULL, 0);
|
2006-08-01 20:58:43 +08:00
|
|
|
}
|
|
|
|
|
2006-08-26 01:55:16 +08:00
|
|
|
static SDOperand LowerVASTART(SDOperand Op, SelectionDAG &DAG,
|
|
|
|
unsigned VarArgsFrameIndex) {
|
|
|
|
// vastart just stores the address of the VarArgsFrameIndex slot into the
|
|
|
|
// memory location argument.
|
|
|
|
MVT::ValueType PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
|
|
|
SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT);
|
2006-10-14 05:14:26 +08:00
|
|
|
SrcValueSDNode *SV = cast<SrcValueSDNode>(Op.getOperand(2));
|
|
|
|
return DAG.getStore(Op.getOperand(0), FR, Op.getOperand(1), SV->getValue(),
|
|
|
|
SV->getOffset());
|
2006-08-26 01:55:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static SDOperand LowerFORMAL_ARGUMENTS(SDOperand Op, SelectionDAG &DAG,
|
|
|
|
int &VarArgsFrameIndex) {
|
2006-10-06 00:48:49 +08:00
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
SSARegMap *RegMap = MF.getSSARegMap();
|
|
|
|
unsigned NumArgs = Op.Val->getNumValues()-1;
|
|
|
|
SDOperand Root = Op.getOperand(0);
|
|
|
|
bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0;
|
|
|
|
static const unsigned REGS[] = {
|
|
|
|
ARM::R0, ARM::R1, ARM::R2, ARM::R3
|
|
|
|
};
|
2006-05-23 10:48:20 +08:00
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
std::vector<MVT::ValueType> Types(Op.Val->value_begin(), Op.Val->value_end() - 1);
|
|
|
|
ArgumentLayout Layout(Types);
|
2006-05-23 10:48:20 +08:00
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
std::vector<SDOperand> ArgValues;
|
|
|
|
for (unsigned ArgNo = 0; ArgNo < NumArgs; ++ArgNo) {
|
|
|
|
MVT::ValueType VT = Types[ArgNo];
|
|
|
|
|
|
|
|
SDOperand Value;
|
|
|
|
if (Layout.isRegister(ArgNo)) {
|
|
|
|
assert(VT == MVT::i32 || VT == MVT::f32 || VT == MVT::f64);
|
|
|
|
unsigned RegNum = Layout.getRegisterNum(ArgNo);
|
|
|
|
unsigned Reg1 = REGS[RegNum];
|
|
|
|
unsigned VReg1 = RegMap->createVirtualRegister(&ARM::IntRegsRegClass);
|
|
|
|
SDOperand Value1 = DAG.getCopyFromReg(Root, VReg1, MVT::i32);
|
|
|
|
MF.addLiveIn(Reg1, VReg1);
|
|
|
|
if (VT == MVT::f64) {
|
|
|
|
unsigned Reg2 = REGS[RegNum + 1];
|
|
|
|
unsigned VReg2 = RegMap->createVirtualRegister(&ARM::IntRegsRegClass);
|
|
|
|
SDOperand Value2 = DAG.getCopyFromReg(Root, VReg2, MVT::i32);
|
|
|
|
MF.addLiveIn(Reg2, VReg2);
|
|
|
|
Value = DAG.getNode(ARMISD::FMDRR, MVT::f64, Value1, Value2);
|
|
|
|
} else {
|
|
|
|
Value = Value1;
|
|
|
|
if (VT == MVT::f32)
|
|
|
|
Value = DAG.getNode(ISD::BIT_CONVERT, VT, Value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the argument is actually used, emit a load from the right stack
|
|
|
|
// slot.
|
|
|
|
if (!Op.Val->hasNUsesOfValue(0, ArgNo)) {
|
|
|
|
unsigned Offset = Layout.getOffset(ArgNo);
|
|
|
|
unsigned Size = MVT::getSizeInBits(VT)/8;
|
|
|
|
int FI = MFI->CreateFixedObject(Size, Offset);
|
|
|
|
SDOperand FIN = DAG.getFrameIndex(FI, VT);
|
2006-10-10 04:57:25 +08:00
|
|
|
Value = DAG.getLoad(VT, Root, FIN, NULL, 0);
|
2006-10-06 00:48:49 +08:00
|
|
|
} else {
|
|
|
|
Value = DAG.getNode(ISD::UNDEF, VT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ArgValues.push_back(Value);
|
2006-05-23 10:48:20 +08:00
|
|
|
}
|
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
unsigned NextRegNum = Layout.lastRegNum() + 1;
|
|
|
|
|
2006-08-26 01:55:16 +08:00
|
|
|
if (isVarArg) {
|
2006-10-06 00:48:49 +08:00
|
|
|
//If this function is vararg we must store the remaing
|
|
|
|
//registers so that they can be acessed with va_start
|
2006-08-26 01:55:16 +08:00
|
|
|
VarArgsFrameIndex = MFI->CreateFixedObject(MVT::getSizeInBits(MVT::i32)/8,
|
2006-10-06 00:48:49 +08:00
|
|
|
-16 + NextRegNum * 4);
|
2006-08-26 01:55:16 +08:00
|
|
|
|
|
|
|
SmallVector<SDOperand, 4> MemOps;
|
2006-10-06 00:48:49 +08:00
|
|
|
for (unsigned RegNo = NextRegNum; RegNo < 4; ++RegNo) {
|
|
|
|
int RegOffset = - (4 - RegNo) * 4;
|
2006-08-26 01:55:16 +08:00
|
|
|
int FI = MFI->CreateFixedObject(MVT::getSizeInBits(MVT::i32)/8,
|
2006-10-06 00:48:49 +08:00
|
|
|
RegOffset);
|
2006-08-26 01:55:16 +08:00
|
|
|
SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
|
|
|
|
|
2006-10-06 00:48:49 +08:00
|
|
|
unsigned VReg = RegMap->createVirtualRegister(&ARM::IntRegsRegClass);
|
|
|
|
MF.addLiveIn(REGS[RegNo], VReg);
|
2006-08-26 01:55:16 +08:00
|
|
|
|
|
|
|
SDOperand Val = DAG.getCopyFromReg(Root, VReg, MVT::i32);
|
2006-10-14 05:14:26 +08:00
|
|
|
SDOperand Store = DAG.getStore(Val.getValue(1), Val, FIN, NULL, 0);
|
2006-08-26 01:55:16 +08:00
|
|
|
MemOps.push_back(Store);
|
|
|
|
}
|
|
|
|
Root = DAG.getNode(ISD::TokenFactor, MVT::Other,&MemOps[0],MemOps.size());
|
|
|
|
}
|
2006-05-23 10:48:20 +08:00
|
|
|
|
|
|
|
ArgValues.push_back(Root);
|
|
|
|
|
|
|
|
// Return the new list of results.
|
|
|
|
std::vector<MVT::ValueType> RetVT(Op.Val->value_begin(),
|
|
|
|
Op.Val->value_end());
|
2006-08-12 01:22:35 +08:00
|
|
|
return DAG.getNode(ISD::MERGE_VALUES, RetVT, &ArgValues[0], ArgValues.size());
|
2006-05-19 05:45:49 +08:00
|
|
|
}
|
|
|
|
|
2006-10-10 20:56:00 +08:00
|
|
|
static SDOperand GetCMP(ISD::CondCode CC, SDOperand LHS, SDOperand RHS,
|
|
|
|
SelectionDAG &DAG) {
|
|
|
|
MVT::ValueType vt = LHS.getValueType();
|
2006-10-11 00:33:47 +08:00
|
|
|
assert(vt == MVT::i32 || vt == MVT::f32 || vt == MVT::f64);
|
2006-10-10 20:56:00 +08:00
|
|
|
|
2006-10-14 21:42:53 +08:00
|
|
|
SDOperand Cmp = DAG.getNode(ARMISD::CMP, MVT::Flag, LHS, RHS);
|
2006-10-13 21:14:59 +08:00
|
|
|
|
2006-10-10 20:56:00 +08:00
|
|
|
if (vt != MVT::i32)
|
|
|
|
Cmp = DAG.getNode(ARMISD::FMSTAT, MVT::Flag, Cmp);
|
|
|
|
return Cmp;
|
|
|
|
}
|
|
|
|
|
2006-10-13 21:14:59 +08:00
|
|
|
static SDOperand GetARMCC(ISD::CondCode CC, MVT::ValueType vt,
|
|
|
|
SelectionDAG &DAG) {
|
|
|
|
assert(vt == MVT::i32 || vt == MVT::f32 || vt == MVT::f64);
|
|
|
|
if (vt == MVT::i32)
|
|
|
|
return DAG.getConstant(DAGIntCCToARMCC(CC), MVT::i32);
|
|
|
|
else
|
|
|
|
return DAG.getConstant(DAGFPCCToARMCC(CC), MVT::i32);
|
|
|
|
}
|
|
|
|
|
2006-08-22 06:00:32 +08:00
|
|
|
static SDOperand LowerSELECT_CC(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
SDOperand LHS = Op.getOperand(0);
|
|
|
|
SDOperand RHS = Op.getOperand(1);
|
|
|
|
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
|
|
|
|
SDOperand TrueVal = Op.getOperand(2);
|
|
|
|
SDOperand FalseVal = Op.getOperand(3);
|
2006-10-10 20:56:00 +08:00
|
|
|
SDOperand Cmp = GetCMP(CC, LHS, RHS, DAG);
|
2006-10-13 21:14:59 +08:00
|
|
|
SDOperand ARMCC = GetARMCC(CC, LHS.getValueType(), DAG);
|
2006-09-12 01:25:40 +08:00
|
|
|
return DAG.getNode(ARMISD::SELECT, MVT::i32, TrueVal, FalseVal, ARMCC, Cmp);
|
2006-08-22 06:00:32 +08:00
|
|
|
}
|
|
|
|
|
2006-08-24 21:45:55 +08:00
|
|
|
static SDOperand LowerBR_CC(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
SDOperand Chain = Op.getOperand(0);
|
|
|
|
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
|
|
|
|
SDOperand LHS = Op.getOperand(2);
|
|
|
|
SDOperand RHS = Op.getOperand(3);
|
|
|
|
SDOperand Dest = Op.getOperand(4);
|
2006-10-10 20:56:00 +08:00
|
|
|
SDOperand Cmp = GetCMP(CC, LHS, RHS, DAG);
|
2006-10-13 21:14:59 +08:00
|
|
|
SDOperand ARMCC = GetARMCC(CC, LHS.getValueType(), DAG);
|
2006-08-25 00:13:15 +08:00
|
|
|
return DAG.getNode(ARMISD::BR, MVT::Other, Chain, Dest, ARMCC, Cmp);
|
2006-08-24 21:45:55 +08:00
|
|
|
}
|
|
|
|
|
2006-09-30 05:20:16 +08:00
|
|
|
static SDOperand LowerSINT_TO_FP(SDOperand Op, SelectionDAG &DAG) {
|
2006-10-03 03:30:56 +08:00
|
|
|
SDOperand IntVal = Op.getOperand(0);
|
2006-09-30 05:20:16 +08:00
|
|
|
assert(IntVal.getValueType() == MVT::i32);
|
2006-10-03 03:30:56 +08:00
|
|
|
MVT::ValueType vt = Op.getValueType();
|
|
|
|
assert(vt == MVT::f32 ||
|
|
|
|
vt == MVT::f64);
|
2006-09-30 05:20:16 +08:00
|
|
|
|
|
|
|
SDOperand Tmp = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, IntVal);
|
2006-10-03 03:30:56 +08:00
|
|
|
ARMISD::NodeType op = vt == MVT::f32 ? ARMISD::FSITOS : ARMISD::FSITOD;
|
|
|
|
return DAG.getNode(op, vt, Tmp);
|
2006-09-30 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
2006-10-11 02:55:14 +08:00
|
|
|
static SDOperand LowerFP_TO_SINT(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
assert(Op.getValueType() == MVT::i32);
|
|
|
|
SDOperand FloatVal = Op.getOperand(0);
|
|
|
|
MVT::ValueType vt = FloatVal.getValueType();
|
|
|
|
assert(vt == MVT::f32 || vt == MVT::f64);
|
|
|
|
|
|
|
|
ARMISD::NodeType op = vt == MVT::f32 ? ARMISD::FTOSIS : ARMISD::FTOSID;
|
|
|
|
SDOperand Tmp = DAG.getNode(op, MVT::f32, FloatVal);
|
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Tmp);
|
|
|
|
}
|
|
|
|
|
2006-10-07 22:24:52 +08:00
|
|
|
static SDOperand LowerUINT_TO_FP(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
SDOperand IntVal = Op.getOperand(0);
|
|
|
|
assert(IntVal.getValueType() == MVT::i32);
|
|
|
|
MVT::ValueType vt = Op.getValueType();
|
|
|
|
assert(vt == MVT::f32 ||
|
|
|
|
vt == MVT::f64);
|
|
|
|
|
|
|
|
SDOperand Tmp = DAG.getNode(ISD::BIT_CONVERT, MVT::f32, IntVal);
|
|
|
|
ARMISD::NodeType op = vt == MVT::f32 ? ARMISD::FUITOS : ARMISD::FUITOD;
|
|
|
|
return DAG.getNode(op, vt, Tmp);
|
|
|
|
}
|
|
|
|
|
2006-10-11 04:38:57 +08:00
|
|
|
static SDOperand LowerFP_TO_UINT(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
assert(Op.getValueType() == MVT::i32);
|
|
|
|
SDOperand FloatVal = Op.getOperand(0);
|
|
|
|
MVT::ValueType vt = FloatVal.getValueType();
|
|
|
|
assert(vt == MVT::f32 || vt == MVT::f64);
|
|
|
|
|
|
|
|
ARMISD::NodeType op = vt == MVT::f32 ? ARMISD::FTOUIS : ARMISD::FTOUID;
|
|
|
|
SDOperand Tmp = DAG.getNode(op, MVT::f32, FloatVal);
|
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, MVT::i32, Tmp);
|
|
|
|
}
|
|
|
|
|
2006-05-15 06:18:28 +08:00
|
|
|
SDOperand ARMTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
switch (Op.getOpcode()) {
|
|
|
|
default:
|
|
|
|
assert(0 && "Should not custom lower this!");
|
2006-05-16 06:34:39 +08:00
|
|
|
abort();
|
2006-08-01 20:58:43 +08:00
|
|
|
case ISD::ConstantPool:
|
|
|
|
return LowerConstantPool(Op, DAG);
|
|
|
|
case ISD::GlobalAddress:
|
|
|
|
return LowerGlobalAddress(Op, DAG);
|
2006-10-11 02:55:14 +08:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
return LowerFP_TO_SINT(Op, DAG);
|
2006-09-30 05:20:16 +08:00
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
return LowerSINT_TO_FP(Op, DAG);
|
2006-10-11 04:38:57 +08:00
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
return LowerFP_TO_UINT(Op, DAG);
|
2006-10-07 22:24:52 +08:00
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
return LowerUINT_TO_FP(Op, DAG);
|
2006-05-19 05:45:49 +08:00
|
|
|
case ISD::FORMAL_ARGUMENTS:
|
2006-08-26 01:55:16 +08:00
|
|
|
return LowerFORMAL_ARGUMENTS(Op, DAG, VarArgsFrameIndex);
|
2006-05-25 19:00:18 +08:00
|
|
|
case ISD::CALL:
|
|
|
|
return LowerCALL(Op, DAG);
|
2006-05-15 06:18:28 +08:00
|
|
|
case ISD::RET:
|
|
|
|
return LowerRET(Op, DAG);
|
2006-08-22 06:00:32 +08:00
|
|
|
case ISD::SELECT_CC:
|
|
|
|
return LowerSELECT_CC(Op, DAG);
|
2006-08-24 21:45:55 +08:00
|
|
|
case ISD::BR_CC:
|
|
|
|
return LowerBR_CC(Op, DAG);
|
2006-08-26 01:55:16 +08:00
|
|
|
case ISD::VASTART:
|
|
|
|
return LowerVASTART(Op, DAG, VarArgsFrameIndex);
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Selector Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// ARMDAGToDAGISel - ARM specific code to select ARM machine
|
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
///
|
|
|
|
namespace {
|
|
|
|
class ARMDAGToDAGISel : public SelectionDAGISel {
|
|
|
|
ARMTargetLowering Lowering;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ARMDAGToDAGISel(TargetMachine &TM)
|
|
|
|
: SelectionDAGISel(Lowering), Lowering(TM) {
|
|
|
|
}
|
|
|
|
|
2006-08-26 13:34:46 +08:00
|
|
|
SDNode *Select(SDOperand Op);
|
2006-05-15 06:18:28 +08:00
|
|
|
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
|
2006-07-11 19:36:48 +08:00
|
|
|
bool SelectAddrRegImm(SDOperand N, SDOperand &Offset, SDOperand &Base);
|
2006-09-13 20:09:43 +08:00
|
|
|
bool SelectAddrMode1(SDOperand N, SDOperand &Arg, SDOperand &Shift,
|
|
|
|
SDOperand &ShiftType);
|
2006-10-18 02:04:53 +08:00
|
|
|
bool SelectAddrMode5(SDOperand N, SDOperand &Arg, SDOperand &Offset);
|
2006-05-15 06:18:28 +08:00
|
|
|
|
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "ARMGenDAGISel.inc"
|
|
|
|
};
|
|
|
|
|
|
|
|
void ARMDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
|
|
|
DEBUG(BB->dump());
|
|
|
|
|
|
|
|
DAG.setRoot(SelectRoot(DAG.getRoot()));
|
|
|
|
DAG.RemoveDeadNodes();
|
|
|
|
|
|
|
|
ScheduleAndEmitDAG(DAG);
|
|
|
|
}
|
|
|
|
|
2006-08-15 03:01:24 +08:00
|
|
|
static bool isInt12Immediate(SDNode *N, short &Imm) {
|
|
|
|
if (N->getOpcode() != ISD::Constant)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int32_t t = cast<ConstantSDNode>(N)->getValue();
|
2006-09-21 19:29:52 +08:00
|
|
|
int max = 1<<12;
|
2006-08-15 03:01:24 +08:00
|
|
|
int min = -max;
|
|
|
|
if (t > min && t < max) {
|
|
|
|
Imm = t;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInt12Immediate(SDOperand Op, short &Imm) {
|
|
|
|
return isInt12Immediate(Op.Val, Imm);
|
|
|
|
}
|
|
|
|
|
2006-09-21 19:29:52 +08:00
|
|
|
static uint32_t rotateL(uint32_t x) {
|
|
|
|
uint32_t bit31 = (x & (1 << 31)) >> 31;
|
|
|
|
uint32_t t = x << 1;
|
|
|
|
return t | bit31;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isUInt8Immediate(uint32_t x) {
|
|
|
|
return x < (1 << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isRotInt8Immediate(uint32_t x) {
|
|
|
|
int r;
|
|
|
|
for (r = 0; r < 16; r++) {
|
|
|
|
if (isUInt8Immediate(x))
|
|
|
|
return true;
|
|
|
|
x = rotateL(rotateL(x));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-09-12 01:25:40 +08:00
|
|
|
bool ARMDAGToDAGISel::SelectAddrMode1(SDOperand N,
|
2006-09-13 20:09:43 +08:00
|
|
|
SDOperand &Arg,
|
|
|
|
SDOperand &Shift,
|
|
|
|
SDOperand &ShiftType) {
|
2006-09-12 01:25:40 +08:00
|
|
|
switch(N.getOpcode()) {
|
|
|
|
case ISD::Constant: {
|
2006-09-21 19:29:52 +08:00
|
|
|
uint32_t val = cast<ConstantSDNode>(N)->getValue();
|
|
|
|
if(!isRotInt8Immediate(val)) {
|
|
|
|
const Type *t = MVT::getTypeForValueType(MVT::i32);
|
|
|
|
Constant *C = ConstantUInt::get(t, val);
|
|
|
|
int alignment = 2;
|
|
|
|
SDOperand Addr = CurDAG->getTargetConstantPool(C, MVT::i32, alignment);
|
|
|
|
SDOperand Z = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
SDNode *n = CurDAG->getTargetNode(ARM::ldr, MVT::i32, Z, Addr);
|
|
|
|
Arg = SDOperand(n, 0);
|
|
|
|
} else
|
|
|
|
Arg = CurDAG->getTargetConstant(val, MVT::i32);
|
|
|
|
|
2006-09-13 20:09:43 +08:00
|
|
|
Shift = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
ShiftType = CurDAG->getTargetConstant(ARMShift::LSL, MVT::i32);
|
2006-09-12 01:25:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
2006-09-13 20:09:43 +08:00
|
|
|
case ISD::SRA:
|
|
|
|
Arg = N.getOperand(0);
|
|
|
|
Shift = N.getOperand(1);
|
|
|
|
ShiftType = CurDAG->getTargetConstant(ARMShift::ASR, MVT::i32);
|
|
|
|
return true;
|
|
|
|
case ISD::SRL:
|
|
|
|
Arg = N.getOperand(0);
|
|
|
|
Shift = N.getOperand(1);
|
|
|
|
ShiftType = CurDAG->getTargetConstant(ARMShift::LSR, MVT::i32);
|
|
|
|
return true;
|
|
|
|
case ISD::SHL:
|
|
|
|
Arg = N.getOperand(0);
|
|
|
|
Shift = N.getOperand(1);
|
|
|
|
ShiftType = CurDAG->getTargetConstant(ARMShift::LSL, MVT::i32);
|
|
|
|
return true;
|
2006-09-12 01:25:40 +08:00
|
|
|
}
|
2006-09-12 03:23:32 +08:00
|
|
|
|
2006-09-13 20:09:43 +08:00
|
|
|
Arg = N;
|
|
|
|
Shift = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
ShiftType = CurDAG->getTargetConstant(ARMShift::LSL, MVT::i32);
|
2006-09-12 03:23:32 +08:00
|
|
|
return true;
|
2006-09-12 01:25:40 +08:00
|
|
|
}
|
|
|
|
|
2006-10-18 02:04:53 +08:00
|
|
|
bool ARMDAGToDAGISel::SelectAddrMode5(SDOperand N, SDOperand &Arg,
|
|
|
|
SDOperand &Offset) {
|
|
|
|
//TODO: detect offset
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
Arg = N;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-11 19:36:48 +08:00
|
|
|
//register plus/minus 12 bit offset
|
|
|
|
bool ARMDAGToDAGISel::SelectAddrRegImm(SDOperand N, SDOperand &Offset,
|
|
|
|
SDOperand &Base) {
|
2006-08-18 01:09:40 +08:00
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(N)) {
|
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
return true;
|
|
|
|
}
|
2006-08-15 03:01:24 +08:00
|
|
|
if (N.getOpcode() == ISD::ADD) {
|
|
|
|
short imm = 0;
|
|
|
|
if (isInt12Immediate(N.getOperand(1), imm)) {
|
|
|
|
Offset = CurDAG->getTargetConstant(imm, MVT::i32);
|
|
|
|
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N.getOperand(0))) {
|
|
|
|
Base = CurDAG->getTargetFrameIndex(FI->getIndex(), N.getValueType());
|
|
|
|
} else {
|
|
|
|
Base = N.getOperand(0);
|
|
|
|
}
|
|
|
|
return true; // [r+i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-11 19:36:48 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
2006-07-10 09:41:35 +08:00
|
|
|
if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(N)) {
|
|
|
|
Base = CurDAG->getTargetFrameIndex(FI->getIndex(), N.getValueType());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Base = N;
|
|
|
|
return true; //any address fits in a register
|
2006-06-12 20:28:08 +08:00
|
|
|
}
|
|
|
|
|
2006-08-26 13:34:46 +08:00
|
|
|
SDNode *ARMDAGToDAGISel::Select(SDOperand Op) {
|
2006-06-12 20:28:08 +08:00
|
|
|
SDNode *N = Op.Val;
|
|
|
|
|
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default:
|
2006-08-26 13:34:46 +08:00
|
|
|
return SelectCode(Op);
|
2006-06-12 20:28:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2006-08-11 17:08:15 +08:00
|
|
|
return NULL;
|
2006-05-15 06:18:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// createARMISelDag - This pass converts a legalized DAG into a
|
|
|
|
/// ARM-specific DAG, ready for instruction scheduling.
|
|
|
|
///
|
|
|
|
FunctionPass *llvm::createARMISelDag(TargetMachine &TM) {
|
|
|
|
return new ARMDAGToDAGISel(TM);
|
|
|
|
}
|