2005-02-05 03:24:26 +01:00
|
|
|
//===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===//
|
2005-04-22 01:13:11 +02:00
|
|
|
//
|
2005-01-23 00:41:55 +01:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 01:13:11 +02:00
|
|
|
//
|
2005-01-23 00:41:55 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a pattern matching instruction selector for Alpha.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Alpha.h"
|
|
|
|
#include "AlphaRegisterInfo.h"
|
|
|
|
#include "llvm/Constants.h" // FIXME: REMOVE
|
|
|
|
#include "llvm/Function.h"
|
2005-06-22 19:19:45 +02:00
|
|
|
#include "llvm/Module.h"
|
2005-01-23 00:41:55 +01:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
|
|
|
#include "llvm/CodeGen/SSARegMap.h"
|
|
|
|
#include "llvm/Target/TargetData.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
2005-02-22 22:59:48 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2005-03-31 23:24:06 +02:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2005-01-23 00:41:55 +01:00
|
|
|
#include <set>
|
2005-01-30 01:35:27 +01:00
|
|
|
#include <algorithm>
|
2005-01-23 00:41:55 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2005-03-31 23:24:06 +02:00
|
|
|
namespace llvm {
|
2005-04-22 01:13:11 +02:00
|
|
|
cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv",
|
2005-06-27 19:39:17 +02:00
|
|
|
cl::desc("Use the FP div instruction for integer div when possible"),
|
2005-03-31 23:24:06 +02:00
|
|
|
cl::Hidden);
|
2005-05-04 21:12:09 +02:00
|
|
|
cl::opt<bool> EnableAlphaFTOI("enable-alpha-FTOI",
|
2005-06-27 19:39:17 +02:00
|
|
|
cl::desc("Enable use of ftoi* and itof* instructions (ev6 and higher)"),
|
2005-03-31 23:24:06 +02:00
|
|
|
cl::Hidden);
|
2005-05-04 21:12:09 +02:00
|
|
|
cl::opt<bool> EnableAlphaCT("enable-alpha-CT",
|
2005-06-27 19:39:17 +02:00
|
|
|
cl::desc("Enable use of the ctpop, ctlz, and cttz instructions"),
|
2005-05-04 21:12:09 +02:00
|
|
|
cl::Hidden);
|
2005-04-22 01:13:11 +02:00
|
|
|
cl::opt<bool> EnableAlphaCount("enable-alpha-count",
|
2005-06-27 19:39:17 +02:00
|
|
|
cl::desc("Print estimates on live ins and outs"),
|
|
|
|
cl::Hidden);
|
2005-06-06 21:03:55 +02:00
|
|
|
cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark",
|
2005-06-27 19:39:17 +02:00
|
|
|
cl::desc("Emit symbols to correlate Mem ops to LLVM Values"),
|
|
|
|
cl::Hidden);
|
2005-03-31 23:24:06 +02:00
|
|
|
}
|
|
|
|
|
2005-05-31 21:49:34 +02:00
|
|
|
namespace {
|
|
|
|
// Alpha Specific DAG Nodes
|
|
|
|
namespace AlphaISD {
|
|
|
|
enum NodeType {
|
|
|
|
// Start the numbering where the builtin ops leave off.
|
|
|
|
FIRST_NUMBER = ISD::BUILTIN_OP_END,
|
|
|
|
|
|
|
|
//Convert an int bit pattern in an FP reg to a Double or Float
|
|
|
|
//Has a dest type and a source
|
|
|
|
CVTQ,
|
|
|
|
//Move an Ireg to a FPreg
|
|
|
|
ITOF,
|
|
|
|
//Move a FPreg to an Ireg
|
|
|
|
FTOI,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// AlphaTargetLowering - Alpha Implementation of the TargetLowering interface
|
|
|
|
namespace {
|
|
|
|
class AlphaTargetLowering : public TargetLowering {
|
2005-06-18 20:34:52 +02:00
|
|
|
int VarArgsOffset; // What is the offset to the first vaarg
|
|
|
|
int VarArgsBase; // What is the base FrameIndex
|
2005-01-23 00:41:55 +01:00
|
|
|
unsigned GP; //GOT vreg
|
2005-06-24 01:42:05 +02:00
|
|
|
unsigned RA; //Return Address
|
2005-01-23 00:41:55 +01:00
|
|
|
public:
|
|
|
|
AlphaTargetLowering(TargetMachine &TM) : TargetLowering(TM) {
|
|
|
|
// Set up the TargetLowering object.
|
2005-01-27 04:49:45 +01:00
|
|
|
//I am having problems with shr n ubyte 1
|
2005-02-02 18:00:21 +01:00
|
|
|
setShiftAmountType(MVT::i64);
|
|
|
|
setSetCCResultType(MVT::i64);
|
2005-04-07 22:11:32 +02:00
|
|
|
setSetCCResultContents(ZeroOrOneSetCCResult);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
addRegisterClass(MVT::i64, Alpha::GPRCRegisterClass);
|
|
|
|
addRegisterClass(MVT::f64, Alpha::FPRCRegisterClass);
|
2005-01-27 04:49:45 +01:00
|
|
|
addRegisterClass(MVT::f32, Alpha::FPRCRegisterClass);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-09 05:22:37 +02:00
|
|
|
setOperationAction(ISD::BRCONDTWOWAY, MVT::Other, Expand);
|
2005-01-25 01:35:34 +01:00
|
|
|
|
2005-06-27 00:23:06 +02:00
|
|
|
setOperationAction(ISD::EXTLOAD, MVT::i1, Promote);
|
2005-06-29 02:31:08 +02:00
|
|
|
setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
|
2005-06-28 01:24:11 +02:00
|
|
|
|
2005-07-07 21:52:58 +02:00
|
|
|
setOperationAction(ISD::ZEXTLOAD, MVT::i1, Promote);
|
2005-06-29 02:31:08 +02:00
|
|
|
setOperationAction(ISD::ZEXTLOAD, MVT::i32, Expand);
|
2005-01-23 00:41:55 +01:00
|
|
|
|
2005-07-07 21:52:58 +02:00
|
|
|
setOperationAction(ISD::SEXTLOAD, MVT::i1, Promote);
|
2005-06-27 00:23:06 +02:00
|
|
|
setOperationAction(ISD::SEXTLOAD, MVT::i8, Expand);
|
|
|
|
setOperationAction(ISD::SEXTLOAD, MVT::i16, Expand);
|
|
|
|
|
|
|
|
setOperationAction(ISD::SREM, MVT::f32, Expand);
|
|
|
|
setOperationAction(ISD::SREM, MVT::f64, Expand);
|
|
|
|
|
|
|
|
setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand);
|
2005-01-26 02:24:38 +01:00
|
|
|
|
2005-05-04 21:12:09 +02:00
|
|
|
if (!EnableAlphaCT) {
|
|
|
|
setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
|
|
|
|
setOperationAction(ISD::CTTZ , MVT::i64 , Expand);
|
2005-05-04 21:25:37 +02:00
|
|
|
setOperationAction(ISD::CTLZ , MVT::i64 , Expand);
|
2005-05-04 21:12:09 +02:00
|
|
|
}
|
2005-05-03 19:19:30 +02:00
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
//If this didn't legalize into a div....
|
|
|
|
// setOperationAction(ISD::SREM , MVT::i64, Expand);
|
|
|
|
// setOperationAction(ISD::UREM , MVT::i64, Expand);
|
|
|
|
|
|
|
|
setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::MEMSET , MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::MEMCPY , MVT::Other, Expand);
|
2005-02-05 14:19:12 +01:00
|
|
|
|
2005-04-30 06:26:06 +02:00
|
|
|
// We don't support sin/cos/sqrt
|
|
|
|
setOperationAction(ISD::FSIN , MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FCOS , MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FSQRT, MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FSIN , MVT::f32, Expand);
|
|
|
|
setOperationAction(ISD::FCOS , MVT::f32, Expand);
|
|
|
|
setOperationAction(ISD::FSQRT, MVT::f32, Expand);
|
|
|
|
|
2005-03-04 21:09:23 +01:00
|
|
|
//Doesn't work yet
|
2005-04-30 06:26:06 +02:00
|
|
|
setOperationAction(ISD::SETCC, MVT::f32, Promote);
|
2005-02-14 06:41:43 +01:00
|
|
|
|
2005-05-31 21:49:34 +02:00
|
|
|
//Try a couple things with a custom expander
|
|
|
|
//setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom);
|
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
computeRegisterProperties();
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
addLegalFPImmediate(+0.0); //F31
|
|
|
|
addLegalFPImmediate(-0.0); //-F31
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
|
2005-05-31 21:49:34 +02:00
|
|
|
/// LowerOperation - Provide custom lowering hooks for some operations.
|
|
|
|
///
|
|
|
|
virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
|
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
/// LowerArguments - This hook must be implemented to indicate how we should
|
|
|
|
/// lower the arguments for the specified function, into the specified DAG.
|
|
|
|
virtual std::vector<SDOperand>
|
|
|
|
LowerArguments(Function &F, SelectionDAG &DAG);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
/// LowerCallTo - This hook lowers an abstract call to a function into an
|
|
|
|
/// actual call.
|
|
|
|
virtual std::pair<SDOperand, SDOperand>
|
2005-05-12 21:56:45 +02:00
|
|
|
LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
|
2005-05-13 20:50:42 +02:00
|
|
|
bool isTailCall, SDOperand Callee, ArgListTy &Args,
|
|
|
|
SelectionDAG &DAG);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-07-05 21:58:54 +02:00
|
|
|
virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP,
|
|
|
|
Value *VAListV, SelectionDAG &DAG);
|
|
|
|
virtual SDOperand LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV,
|
|
|
|
SDOperand DestP, Value *DestV,
|
|
|
|
SelectionDAG &DAG);
|
2005-01-23 00:41:55 +01:00
|
|
|
virtual std::pair<SDOperand,SDOperand>
|
2005-07-05 21:58:54 +02:00
|
|
|
LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
|
|
|
|
const Type *ArgTy, SelectionDAG &DAG);
|
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
void restoreGP(MachineBasicBlock* BB)
|
|
|
|
{
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R29).addReg(GP).addReg(GP);
|
|
|
|
}
|
2005-06-24 01:42:05 +02:00
|
|
|
void restoreRA(MachineBasicBlock* BB)
|
|
|
|
{
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R26).addReg(RA).addReg(RA);
|
|
|
|
}
|
2005-06-27 17:36:48 +02:00
|
|
|
unsigned getRA()
|
|
|
|
{
|
|
|
|
return RA;
|
|
|
|
}
|
2005-06-24 01:42:05 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-05-31 21:49:34 +02:00
|
|
|
/// LowerOperation - Provide custom lowering hooks for some operations.
|
|
|
|
///
|
|
|
|
SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
switch (Op.getOpcode()) {
|
|
|
|
default: assert(0 && "Should not custom lower this!");
|
2005-06-06 19:39:46 +02:00
|
|
|
#if 0
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
{
|
|
|
|
assert (Op.getOperand(0).getValueType() == MVT::i64
|
|
|
|
&& "only quads can be loaded from");
|
|
|
|
SDOperand SRC;
|
|
|
|
if (EnableAlphaFTOI)
|
|
|
|
{
|
|
|
|
std::vector<MVT::ValueType> RTs;
|
|
|
|
RTs.push_back(Op.getValueType());
|
|
|
|
std::vector<SDOperand> Ops;
|
|
|
|
Ops.push_back(Op.getOperand(0));
|
|
|
|
SRC = DAG.getNode(AlphaISD::ITOF, RTs, Ops);
|
|
|
|
} else {
|
|
|
|
int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
|
|
|
|
SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
|
2005-06-27 19:39:17 +02:00
|
|
|
SDOperand Store = DAG.getNode(ISD::STORE, MVT::Other,
|
|
|
|
DAG.getEntryNode(), Op.getOperand(0),
|
|
|
|
StackSlot, DAG.getSrcValue(NULL));
|
2005-06-06 19:39:46 +02:00
|
|
|
SRC = DAG.getLoad(Op.getValueType(), Store.getValue(0), StackSlot,
|
|
|
|
DAG.getSrcValue(NULL));
|
|
|
|
}
|
|
|
|
std::vector<MVT::ValueType> RTs;
|
|
|
|
RTs.push_back(Op.getValueType());
|
|
|
|
std::vector<SDOperand> Ops;
|
|
|
|
Ops.push_back(SRC);
|
|
|
|
return DAG.getNode(AlphaISD::CVTQ, RTs, Ops);
|
|
|
|
}
|
|
|
|
#endif
|
2005-05-31 21:49:34 +02:00
|
|
|
}
|
2005-06-06 19:39:46 +02:00
|
|
|
return SDOperand();
|
2005-05-31 21:49:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-31 20:35:43 +02:00
|
|
|
/// AddLiveIn - This helper function adds the specified physical register to the
|
|
|
|
/// MachineFunction as a live in value. It also creates a corresponding virtual
|
|
|
|
/// register for it.
|
|
|
|
static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
|
|
|
|
TargetRegisterClass *RC) {
|
|
|
|
assert(RC->contains(PReg) && "Not the correct regclass!");
|
|
|
|
unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
|
|
|
|
MF.addLiveIn(PReg, VReg);
|
|
|
|
return VReg;
|
|
|
|
}
|
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
//http://www.cs.arizona.edu/computer.help/policy/DIGITAL_unix/AA-PY8AC-TET1_html/callCH3.html#BLOCK21
|
|
|
|
|
|
|
|
//For now, just use variable size stack frame format
|
|
|
|
|
|
|
|
//In a standard call, the first six items are passed in registers $16
|
|
|
|
//- $21 and/or registers $f16 - $f21. (See Section 4.1.2 for details
|
|
|
|
//of argument-to-register correspondence.) The remaining items are
|
|
|
|
//collected in a memory argument list that is a naturally aligned
|
|
|
|
//array of quadwords. In a standard call, this list, if present, must
|
|
|
|
//be passed at 0(SP).
|
2005-04-22 19:54:37 +02:00
|
|
|
//7 ... n 0(SP) ... (n-7)*8(SP)
|
2005-01-23 00:41:55 +01:00
|
|
|
|
2005-04-05 22:51:46 +02:00
|
|
|
// //#define FP $15
|
|
|
|
// //#define RA $26
|
|
|
|
// //#define PV $27
|
|
|
|
// //#define GP $29
|
|
|
|
// //#define SP $30
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
std::vector<SDOperand>
|
2005-04-22 01:13:11 +02:00
|
|
|
AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
|
2005-01-23 00:41:55 +01:00
|
|
|
{
|
|
|
|
std::vector<SDOperand> ArgValues;
|
2005-04-05 22:51:46 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
2005-02-07 06:07:00 +01:00
|
|
|
MachineFrameInfo*MFI = MF.getFrameInfo();
|
2005-01-23 00:41:55 +01:00
|
|
|
|
|
|
|
MachineBasicBlock& BB = MF.front();
|
|
|
|
|
2005-04-22 01:13:11 +02:00
|
|
|
unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
|
2005-04-22 19:54:37 +02:00
|
|
|
Alpha::R19, Alpha::R20, Alpha::R21};
|
2005-04-22 01:13:11 +02:00
|
|
|
unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
|
2005-04-22 19:54:37 +02:00
|
|
|
Alpha::F19, Alpha::F20, Alpha::F21};
|
2005-01-23 00:41:55 +01:00
|
|
|
int count = 0;
|
2005-02-06 22:07:31 +01:00
|
|
|
|
2005-05-31 20:35:43 +02:00
|
|
|
GP = AddLiveIn(MF, Alpha::R29, getRegClassFor(MVT::i64));
|
2005-06-24 01:42:05 +02:00
|
|
|
RA = AddLiveIn(MF, Alpha::R26, getRegClassFor(MVT::i64));
|
2005-04-05 22:51:46 +02:00
|
|
|
|
2005-03-15 05:54:21 +01:00
|
|
|
for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
2005-05-31 20:35:43 +02:00
|
|
|
SDOperand argt;
|
2005-02-10 07:25:22 +01:00
|
|
|
if (count < 6) {
|
2005-04-05 22:51:46 +02:00
|
|
|
unsigned Vreg;
|
|
|
|
MVT::ValueType VT = getValueType(I->getType());
|
2005-05-31 20:35:43 +02:00
|
|
|
switch (VT) {
|
2005-04-22 01:13:11 +02:00
|
|
|
default:
|
|
|
|
std::cerr << "Unknown Type " << VT << "\n";
|
2005-02-10 07:25:22 +01:00
|
|
|
abort();
|
|
|
|
case MVT::f64:
|
|
|
|
case MVT::f32:
|
2005-05-31 20:35:43 +02:00
|
|
|
args_float[count] = AddLiveIn(MF,args_float[count], getRegClassFor(VT));
|
|
|
|
argt = DAG.getCopyFromReg(args_float[count], VT, DAG.getRoot());
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
2005-06-27 19:39:17 +02:00
|
|
|
args_int[count] = AddLiveIn(MF, args_int[count],
|
|
|
|
getRegClassFor(MVT::i64));
|
2005-05-31 20:35:43 +02:00
|
|
|
argt = DAG.getCopyFromReg(args_int[count], VT, DAG.getRoot());
|
2005-05-31 20:37:16 +02:00
|
|
|
if (VT != MVT::i64)
|
|
|
|
argt = DAG.getNode(ISD::TRUNCATE, VT, argt);
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
2005-01-28 07:57:18 +01:00
|
|
|
}
|
2005-05-31 20:35:43 +02:00
|
|
|
DAG.setRoot(argt.getValue(1));
|
2005-02-10 07:25:22 +01:00
|
|
|
} else { //more args
|
|
|
|
// Create the frame index object for this incoming parameter...
|
|
|
|
int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
|
|
|
// Create the SelectionDAG nodes corresponding to a load
|
2005-02-10 07:25:22 +01:00
|
|
|
//from this parameter
|
|
|
|
SDOperand FIN = DAG.getFrameIndex(FI, MVT::i64);
|
2005-05-31 20:35:43 +02:00
|
|
|
argt = DAG.getLoad(getValueType(I->getType()),
|
|
|
|
DAG.getEntryNode(), FIN, DAG.getSrcValue(NULL));
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-02-22 22:59:48 +01:00
|
|
|
++count;
|
2005-02-10 07:25:22 +01:00
|
|
|
ArgValues.push_back(argt);
|
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
|
2005-04-05 22:51:46 +02:00
|
|
|
// If the functions takes variable number of arguments, copy all regs to stack
|
2005-05-31 20:35:43 +02:00
|
|
|
if (F.isVarArg()) {
|
2005-06-18 20:34:52 +02:00
|
|
|
VarArgsOffset = count * 8;
|
2005-05-31 20:35:43 +02:00
|
|
|
std::vector<SDOperand> LS;
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
if (args_int[i] < 1024)
|
|
|
|
args_int[i] = AddLiveIn(MF,args_int[i], getRegClassFor(MVT::i64));
|
|
|
|
SDOperand argt = DAG.getCopyFromReg(args_int[i], MVT::i64, DAG.getRoot());
|
2005-04-05 22:51:46 +02:00
|
|
|
int FI = MFI->CreateFixedObject(8, -8 * (6 - i));
|
2005-06-18 20:34:52 +02:00
|
|
|
if (i == 0) VarArgsBase = FI;
|
2005-04-05 22:51:46 +02:00
|
|
|
SDOperand SDFI = DAG.getFrameIndex(FI, MVT::i64);
|
2005-06-27 19:39:17 +02:00
|
|
|
LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
|
|
|
|
SDFI, DAG.getSrcValue(NULL)));
|
2005-05-31 20:35:43 +02:00
|
|
|
|
|
|
|
if (args_float[i] < 1024)
|
|
|
|
args_float[i] = AddLiveIn(MF,args_float[i], getRegClassFor(MVT::f64));
|
|
|
|
argt = DAG.getCopyFromReg(args_float[i], MVT::f64, DAG.getRoot());
|
2005-04-05 22:51:46 +02:00
|
|
|
FI = MFI->CreateFixedObject(8, - 8 * (12 - i));
|
|
|
|
SDFI = DAG.getFrameIndex(FI, MVT::i64);
|
2005-06-27 19:39:17 +02:00
|
|
|
LS.push_back(DAG.getNode(ISD::STORE, MVT::Other, DAG.getRoot(), argt,
|
|
|
|
SDFI, DAG.getSrcValue(NULL)));
|
2005-04-05 22:51:46 +02:00
|
|
|
}
|
|
|
|
|
2005-05-31 20:35:43 +02:00
|
|
|
//Set up a token factor with all the stack traffic
|
|
|
|
DAG.setRoot(DAG.getNode(ISD::TokenFactor, MVT::Other, LS));
|
|
|
|
}
|
2005-04-12 19:35:16 +02:00
|
|
|
|
|
|
|
// Finally, inform the code generator which regs we return values in.
|
|
|
|
switch (getValueType(F.getReturnType())) {
|
|
|
|
default: assert(0 && "Unknown type!");
|
|
|
|
case MVT::isVoid: break;
|
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
|
|
|
MF.addLiveOut(Alpha::R0);
|
|
|
|
break;
|
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
|
|
|
MF.addLiveOut(Alpha::F0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-05 22:51:46 +02:00
|
|
|
//return the arguments
|
2005-01-23 00:41:55 +01:00
|
|
|
return ArgValues;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<SDOperand, SDOperand>
|
|
|
|
AlphaTargetLowering::LowerCallTo(SDOperand Chain,
|
2005-04-22 19:54:37 +02:00
|
|
|
const Type *RetTy, bool isVarArg,
|
2005-05-13 20:50:42 +02:00
|
|
|
unsigned CallingConv, bool isTailCall,
|
2005-04-22 19:54:37 +02:00
|
|
|
SDOperand Callee, ArgListTy &Args,
|
|
|
|
SelectionDAG &DAG) {
|
2005-01-23 00:41:55 +01:00
|
|
|
int NumBytes = 0;
|
2005-01-30 01:35:27 +01:00
|
|
|
if (Args.size() > 6)
|
|
|
|
NumBytes = (Args.size() - 6) * 8;
|
|
|
|
|
2005-05-13 01:24:06 +02:00
|
|
|
Chain = DAG.getNode(ISD::CALLSEQ_START, MVT::Other, Chain,
|
2005-04-22 19:54:37 +02:00
|
|
|
DAG.getConstant(NumBytes, getPointerTy()));
|
2005-01-23 00:41:55 +01:00
|
|
|
std::vector<SDOperand> args_to_use;
|
|
|
|
for (unsigned i = 0, e = Args.size(); i != e; ++i)
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
|
|
|
switch (getValueType(Args[i].second)) {
|
|
|
|
default: assert(0 && "Unexpected ValueType for argument!");
|
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
// Promote the integer to 64 bits. If the input type is signed use a
|
|
|
|
// sign extend, otherwise use a zero extend.
|
|
|
|
if (Args[i].second->isSigned())
|
|
|
|
Args[i].first = DAG.getNode(ISD::SIGN_EXTEND, MVT::i64, Args[i].first);
|
|
|
|
else
|
|
|
|
Args[i].first = DAG.getNode(ISD::ZERO_EXTEND, MVT::i64, Args[i].first);
|
|
|
|
break;
|
|
|
|
case MVT::i64:
|
|
|
|
case MVT::f64:
|
|
|
|
case MVT::f32:
|
|
|
|
break;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
args_to_use.push_back(Args[i].first);
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
std::vector<MVT::ValueType> RetVals;
|
|
|
|
MVT::ValueType RetTyVT = getValueType(RetTy);
|
|
|
|
if (RetTyVT != MVT::isVoid)
|
|
|
|
RetVals.push_back(RetTyVT);
|
|
|
|
RetVals.push_back(MVT::Other);
|
|
|
|
|
2005-04-22 01:13:11 +02:00
|
|
|
SDOperand TheCall = SDOperand(DAG.getCall(RetVals,
|
2005-02-10 07:25:22 +01:00
|
|
|
Chain, Callee, args_to_use), 0);
|
2005-01-23 00:41:55 +01:00
|
|
|
Chain = TheCall.getValue(RetTyVT != MVT::isVoid);
|
2005-05-13 01:24:06 +02:00
|
|
|
Chain = DAG.getNode(ISD::CALLSEQ_END, MVT::Other, Chain,
|
2005-01-23 00:41:55 +01:00
|
|
|
DAG.getConstant(NumBytes, getPointerTy()));
|
2005-02-10 07:25:22 +01:00
|
|
|
return std::make_pair(TheCall, Chain);
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
|
2005-07-05 21:58:54 +02:00
|
|
|
SDOperand AlphaTargetLowering::LowerVAStart(SDOperand Chain, SDOperand VAListP,
|
|
|
|
Value *VAListV, SelectionDAG &DAG) {
|
|
|
|
// vastart stores the address of the VarArgsBase and VarArgsOffset
|
2005-06-23 18:48:51 +02:00
|
|
|
SDOperand FR = DAG.getFrameIndex(VarArgsBase, MVT::i64);
|
2005-07-05 21:58:54 +02:00
|
|
|
SDOperand S1 = DAG.getNode(ISD::STORE, MVT::Other, Chain, FR, VAListP,
|
|
|
|
DAG.getSrcValue(VAListV));
|
|
|
|
SDOperand SA2 = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
|
2005-06-27 19:39:17 +02:00
|
|
|
DAG.getConstant(8, MVT::i64));
|
2005-07-05 21:58:54 +02:00
|
|
|
return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, S1,
|
|
|
|
DAG.getConstant(VarArgsOffset, MVT::i64), SA2,
|
2005-07-10 02:29:18 +02:00
|
|
|
DAG.getSrcValue(VAListV, 8), DAG.getValueType(MVT::i32));
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<SDOperand,SDOperand> AlphaTargetLowering::
|
2005-07-05 21:58:54 +02:00
|
|
|
LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
|
|
|
|
const Type *ArgTy, SelectionDAG &DAG) {
|
|
|
|
SDOperand Base = DAG.getLoad(MVT::i64, Chain, VAListP,
|
|
|
|
DAG.getSrcValue(VAListV));
|
|
|
|
SDOperand Tmp = DAG.getNode(ISD::ADD, MVT::i64, VAListP,
|
2005-06-18 20:34:52 +02:00
|
|
|
DAG.getConstant(8, MVT::i64));
|
2005-06-27 19:39:17 +02:00
|
|
|
SDOperand Offset = DAG.getNode(ISD::SEXTLOAD, MVT::i64, Base.getValue(1),
|
2005-07-05 21:58:54 +02:00
|
|
|
Tmp, DAG.getSrcValue(VAListV, 8), MVT::i32);
|
2005-06-18 20:34:52 +02:00
|
|
|
SDOperand DataPtr = DAG.getNode(ISD::ADD, MVT::i64, Base, Offset);
|
2005-06-23 01:04:28 +02:00
|
|
|
if (ArgTy->isFloatingPoint())
|
|
|
|
{
|
|
|
|
//if fp && Offset < 6*8, then subtract 6*8 from DataPtr
|
|
|
|
SDOperand FPDataPtr = DAG.getNode(ISD::SUB, MVT::i64, DataPtr,
|
2005-07-05 21:58:54 +02:00
|
|
|
DAG.getConstant(8*6, MVT::i64));
|
2005-06-23 01:04:28 +02:00
|
|
|
SDOperand CC = DAG.getSetCC(ISD::SETLT, MVT::i64,
|
|
|
|
Offset, DAG.getConstant(8*6, MVT::i64));
|
|
|
|
DataPtr = DAG.getNode(ISD::SELECT, MVT::i64, CC, FPDataPtr, DataPtr);
|
|
|
|
}
|
|
|
|
|
2005-06-23 18:48:51 +02:00
|
|
|
SDOperand Result;
|
|
|
|
if (ArgTy == Type::IntTy)
|
2005-06-24 01:42:05 +02:00
|
|
|
Result = DAG.getNode(ISD::SEXTLOAD, MVT::i64, Offset.getValue(1), DataPtr,
|
2005-06-23 18:48:51 +02:00
|
|
|
DAG.getSrcValue(NULL), MVT::i32);
|
|
|
|
else if (ArgTy == Type::UIntTy)
|
2005-06-24 01:42:05 +02:00
|
|
|
Result = DAG.getNode(ISD::ZEXTLOAD, MVT::i64, Offset.getValue(1), DataPtr,
|
2005-06-23 18:48:51 +02:00
|
|
|
DAG.getSrcValue(NULL), MVT::i32);
|
|
|
|
else
|
2005-06-24 01:42:05 +02:00
|
|
|
Result = DAG.getLoad(getValueType(ArgTy), Offset.getValue(1), DataPtr,
|
2005-06-23 18:48:51 +02:00
|
|
|
DAG.getSrcValue(NULL));
|
|
|
|
|
2005-06-18 20:34:52 +02:00
|
|
|
SDOperand NewOffset = DAG.getNode(ISD::ADD, MVT::i64, Offset,
|
|
|
|
DAG.getConstant(8, MVT::i64));
|
2005-06-27 19:39:17 +02:00
|
|
|
SDOperand Update = DAG.getNode(ISD::TRUNCSTORE, MVT::Other,
|
|
|
|
Result.getValue(1), NewOffset,
|
2005-07-10 02:29:18 +02:00
|
|
|
Tmp, DAG.getSrcValue(VAListV, 8),
|
|
|
|
DAG.getValueType(MVT::i32));
|
2005-06-23 18:48:51 +02:00
|
|
|
Result = DAG.getNode(ISD::TRUNCATE, getValueType(ArgTy), Result);
|
|
|
|
|
2005-06-18 20:34:52 +02:00
|
|
|
return std::make_pair(Result, Update);
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-07-05 21:58:54 +02:00
|
|
|
|
|
|
|
SDOperand AlphaTargetLowering::
|
|
|
|
LowerVACopy(SDOperand Chain, SDOperand SrcP, Value *SrcV, SDOperand DestP,
|
|
|
|
Value *DestV, SelectionDAG &DAG) {
|
|
|
|
SDOperand Val = DAG.getLoad(getPointerTy(), Chain, SrcP,
|
|
|
|
DAG.getSrcValue(SrcV));
|
2005-06-23 01:04:28 +02:00
|
|
|
SDOperand Result = DAG.getNode(ISD::STORE, MVT::Other, Val.getValue(1),
|
2005-07-05 21:58:54 +02:00
|
|
|
Val, DestP, DAG.getSrcValue(DestV));
|
|
|
|
SDOperand NP = DAG.getNode(ISD::ADD, MVT::i64, SrcP,
|
2005-06-23 01:04:28 +02:00
|
|
|
DAG.getConstant(8, MVT::i64));
|
2005-07-05 21:58:54 +02:00
|
|
|
Val = DAG.getNode(ISD::SEXTLOAD, MVT::i64, Result, NP,
|
|
|
|
DAG.getSrcValue(SrcV, 8), MVT::i32);
|
|
|
|
SDOperand NPD = DAG.getNode(ISD::ADD, MVT::i64, DestP,
|
2005-06-24 01:42:05 +02:00
|
|
|
DAG.getConstant(8, MVT::i64));
|
2005-07-05 21:58:54 +02:00
|
|
|
return DAG.getNode(ISD::TRUNCSTORE, MVT::Other, Val.getValue(1),
|
2005-07-10 02:29:18 +02:00
|
|
|
Val, NPD, DAG.getSrcValue(DestV, 8),
|
|
|
|
DAG.getValueType(MVT::i32));
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// ISel - Alpha specific code to select Alpha machine instructions for
|
|
|
|
/// SelectionDAG operations.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2005-06-22 19:19:45 +02:00
|
|
|
class AlphaISel : public SelectionDAGISel {
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
/// AlphaLowering - This object fully describes how to lower LLVM code to an
|
|
|
|
/// Alpha-specific SelectionDAG.
|
|
|
|
AlphaTargetLowering AlphaLowering;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
SelectionDAG *ISelDAG; // Hack to support us having a dag->dag transform
|
|
|
|
// for sdiv and udiv until it is put into the future
|
|
|
|
// dag combiner.
|
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
/// ExprMap - As shared expressions are codegen'd, we keep track of which
|
|
|
|
/// vreg the value is produced in, so we only emit one copy of each compiled
|
|
|
|
/// tree.
|
|
|
|
static const unsigned notIn = (unsigned)(-1);
|
|
|
|
std::map<SDOperand, unsigned> ExprMap;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
//CCInvMap sometimes (SetNE) we have the inverse CC code for free
|
|
|
|
std::map<SDOperand, unsigned> CCInvMap;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-08 19:28:49 +02:00
|
|
|
int count_ins;
|
|
|
|
int count_outs;
|
|
|
|
bool has_sym;
|
2005-04-22 15:35:18 +02:00
|
|
|
int max_depth;
|
2005-04-08 19:28:49 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
public:
|
2005-06-27 19:39:17 +02:00
|
|
|
AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering),
|
|
|
|
AlphaLowering(TM)
|
2005-02-10 07:25:22 +01:00
|
|
|
{}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
/// InstructionSelectBasicBlock - This callback is invoked by
|
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
|
|
|
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
2005-02-22 22:59:48 +01:00
|
|
|
DEBUG(BB->dump());
|
2005-04-08 19:28:49 +02:00
|
|
|
count_ins = 0;
|
|
|
|
count_outs = 0;
|
2005-04-22 15:35:18 +02:00
|
|
|
max_depth = 0;
|
2005-04-08 19:28:49 +02:00
|
|
|
has_sym = false;
|
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
// Codegen the basic block.
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG = &DAG;
|
2005-04-22 15:35:18 +02:00
|
|
|
max_depth = DAG.getRoot().getNodeDepth();
|
2005-02-10 07:25:22 +01:00
|
|
|
Select(DAG.getRoot());
|
2005-04-08 19:28:49 +02:00
|
|
|
|
|
|
|
if(has_sym)
|
|
|
|
++count_ins;
|
|
|
|
if(EnableAlphaCount)
|
2005-06-27 19:39:17 +02:00
|
|
|
std::cerr << "COUNT: "
|
|
|
|
<< BB->getParent()->getFunction ()->getName() << " "
|
2005-04-22 15:35:18 +02:00
|
|
|
<< BB->getNumber() << " "
|
|
|
|
<< max_depth << " "
|
2005-04-08 19:28:49 +02:00
|
|
|
<< count_ins << " "
|
|
|
|
<< count_outs << "\n";
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
// Clear state used for selection.
|
|
|
|
ExprMap.clear();
|
|
|
|
CCInvMap.clear();
|
|
|
|
}
|
2005-05-31 20:35:43 +02:00
|
|
|
|
|
|
|
virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
unsigned SelectExpr(SDOperand N);
|
|
|
|
void Select(SDOperand N);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
|
|
|
|
void SelectBranchCC(SDOperand N);
|
2005-04-02 23:06:51 +02:00
|
|
|
void MoveFP2Int(unsigned src, unsigned dst, bool isDouble);
|
|
|
|
void MoveInt2FP(unsigned src, unsigned dst, bool isDouble);
|
2005-04-03 00:32:39 +02:00
|
|
|
//returns whether the sense of the comparison was inverted
|
|
|
|
bool SelectFPSetCC(SDOperand N, unsigned dst);
|
2005-04-06 22:25:34 +02:00
|
|
|
|
|
|
|
// dag -> dag expanders for integer divide by constant
|
|
|
|
SDOperand BuildSDIVSequence(SDOperand N);
|
|
|
|
SDOperand BuildUDIVSequence(SDOperand N);
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
void AlphaISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
|
2005-05-31 20:35:43 +02:00
|
|
|
// If this function has live-in values, emit the copies from pregs to vregs at
|
|
|
|
// the top of the function, before anything else.
|
|
|
|
MachineBasicBlock *BB = MF.begin();
|
|
|
|
if (MF.livein_begin() != MF.livein_end()) {
|
|
|
|
SSARegMap *RegMap = MF.getSSARegMap();
|
|
|
|
for (MachineFunction::livein_iterator LI = MF.livein_begin(),
|
|
|
|
E = MF.livein_end(); LI != E; ++LI) {
|
|
|
|
const TargetRegisterClass *RC = RegMap->getRegClass(LI->second);
|
|
|
|
if (RC == Alpha::GPRCRegisterClass) {
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, LI->second).addReg(LI->first)
|
|
|
|
.addReg(LI->first);
|
2005-05-31 20:35:43 +02:00
|
|
|
} else if (RC == Alpha::FPRCRegisterClass) {
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, LI->second).addReg(LI->first)
|
|
|
|
.addReg(LI->first);
|
2005-05-31 20:35:43 +02:00
|
|
|
} else {
|
|
|
|
assert(0 && "Unknown regclass!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-29 20:54:02 +02:00
|
|
|
static void getValueInfo(const Value* v, int& type, int& fun, int& offset)
|
2005-06-06 21:03:55 +02:00
|
|
|
{
|
2005-06-29 20:54:02 +02:00
|
|
|
if (v == NULL) {
|
|
|
|
type = 0;
|
|
|
|
fun = 0;
|
|
|
|
offset = 0;
|
|
|
|
} else if (const GlobalValue* GV = dyn_cast<GlobalValue>(v)) {
|
|
|
|
type = 1;
|
2005-07-01 21:12:13 +02:00
|
|
|
fun = 0;
|
2005-06-29 20:54:02 +02:00
|
|
|
const Module* M = GV->getParent();
|
|
|
|
int i = 0;
|
|
|
|
for(Module::const_global_iterator ii = M->global_begin(); &*ii != GV; ++ii)
|
|
|
|
++i;
|
|
|
|
offset = i;
|
|
|
|
} else if (const Argument* Arg = dyn_cast<Argument>(v)) {
|
|
|
|
type = 2;
|
|
|
|
const Function* F = Arg->getParent();
|
|
|
|
const Module* M = F->getParent();
|
|
|
|
int i = 0;
|
|
|
|
for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
|
|
|
|
++i;
|
|
|
|
fun = i;
|
|
|
|
i = 0;
|
|
|
|
for(Function::const_arg_iterator ii = F->arg_begin(); &*ii != Arg; ++ii)
|
|
|
|
++i;
|
|
|
|
offset = i;
|
|
|
|
} else if (const Instruction* I = dyn_cast<Instruction>(v)) {
|
2005-07-07 21:52:58 +02:00
|
|
|
assert(dyn_cast<PointerType>(I->getType()));
|
2005-06-29 20:54:02 +02:00
|
|
|
type = 3;
|
|
|
|
const BasicBlock* bb = I->getParent();
|
|
|
|
const Function* F = bb->getParent();
|
|
|
|
const Module* M = F->getParent();
|
|
|
|
int i = 0;
|
|
|
|
for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
|
|
|
|
++i;
|
|
|
|
fun = i;
|
|
|
|
i = 0;
|
|
|
|
for(Function::const_iterator ii = F->begin(); &*ii != bb; ++ii)
|
|
|
|
i += ii->size();
|
|
|
|
for(BasicBlock::const_iterator ii = bb->begin(); &*ii != I; ++ii)
|
|
|
|
++i;
|
|
|
|
offset = i;
|
2005-07-07 21:52:58 +02:00
|
|
|
} else if (const Constant* C = dyn_cast<Constant>(v)) {
|
|
|
|
//Don't know how to look these up yet
|
|
|
|
type = 0;
|
|
|
|
fun = 0;
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
assert(0 && "Error in value marking");
|
2005-06-29 20:54:02 +02:00
|
|
|
}
|
2005-07-01 21:12:13 +02:00
|
|
|
//type = 4: register spilling
|
|
|
|
//type = 5: global address loading or constant loading
|
2005-06-22 19:19:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int getUID()
|
|
|
|
{
|
|
|
|
static int id = 0;
|
|
|
|
return ++id;
|
|
|
|
}
|
2005-06-06 21:03:55 +02:00
|
|
|
|
2005-04-08 19:28:49 +02:00
|
|
|
//Factorize a number using the list of constants
|
|
|
|
static bool factorize(int v[], int res[], int size, uint64_t c)
|
|
|
|
{
|
|
|
|
bool cont = true;
|
|
|
|
while (c != 1 && cont)
|
|
|
|
{
|
|
|
|
cont = false;
|
|
|
|
for(int i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
if (c % v[i] == 0)
|
|
|
|
{
|
|
|
|
c /= v[i];
|
|
|
|
++res[i];
|
|
|
|
cont=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
//Shamelessly adapted from PPC32
|
2005-04-22 01:13:11 +02:00
|
|
|
// Structure used to return the necessary information to codegen an SDIV as
|
2005-04-06 22:25:34 +02:00
|
|
|
// a multiply.
|
|
|
|
struct ms {
|
|
|
|
int64_t m; // magic number
|
|
|
|
int64_t s; // shift amount
|
2005-02-10 07:25:22 +01:00
|
|
|
};
|
2005-04-06 22:25:34 +02:00
|
|
|
|
|
|
|
struct mu {
|
|
|
|
uint64_t m; // magic number
|
|
|
|
int64_t a; // add indicator
|
|
|
|
int64_t s; // shift amount
|
|
|
|
};
|
|
|
|
|
|
|
|
/// magic - calculate the magic numbers required to codegen an integer sdiv as
|
2005-04-22 01:13:11 +02:00
|
|
|
/// a sequence of multiply and shifts. Requires that the divisor not be 0, 1,
|
2005-04-06 22:25:34 +02:00
|
|
|
/// or -1.
|
|
|
|
static struct ms magic(int64_t d) {
|
|
|
|
int64_t p;
|
|
|
|
uint64_t ad, anc, delta, q1, r1, q2, r2, t;
|
|
|
|
const uint64_t two63 = 9223372036854775808ULL; // 2^63
|
|
|
|
struct ms mag;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
ad = abs(d);
|
|
|
|
t = two63 + ((uint64_t)d >> 63);
|
|
|
|
anc = t - 1 - t%ad; // absolute value of nc
|
2005-04-07 19:19:16 +02:00
|
|
|
p = 63; // initialize p
|
2005-04-06 22:25:34 +02:00
|
|
|
q1 = two63/anc; // initialize q1 = 2p/abs(nc)
|
|
|
|
r1 = two63 - q1*anc; // initialize r1 = rem(2p,abs(nc))
|
|
|
|
q2 = two63/ad; // initialize q2 = 2p/abs(d)
|
|
|
|
r2 = two63 - q2*ad; // initialize r2 = rem(2p,abs(d))
|
|
|
|
do {
|
|
|
|
p = p + 1;
|
|
|
|
q1 = 2*q1; // update q1 = 2p/abs(nc)
|
|
|
|
r1 = 2*r1; // update r1 = rem(2p/abs(nc))
|
|
|
|
if (r1 >= anc) { // must be unsigned comparison
|
|
|
|
q1 = q1 + 1;
|
|
|
|
r1 = r1 - anc;
|
|
|
|
}
|
|
|
|
q2 = 2*q2; // update q2 = 2p/abs(d)
|
|
|
|
r2 = 2*r2; // update r2 = rem(2p/abs(d))
|
|
|
|
if (r2 >= ad) { // must be unsigned comparison
|
|
|
|
q2 = q2 + 1;
|
|
|
|
r2 = r2 - ad;
|
|
|
|
}
|
|
|
|
delta = ad - r2;
|
|
|
|
} while (q1 < delta || (q1 == delta && r1 == 0));
|
|
|
|
|
|
|
|
mag.m = q2 + 1;
|
|
|
|
if (d < 0) mag.m = -mag.m; // resulting magic number
|
|
|
|
mag.s = p - 64; // resulting shift
|
|
|
|
return mag;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
/// magicu - calculate the magic numbers required to codegen an integer udiv as
|
|
|
|
/// a sequence of multiply, add and shifts. Requires that the divisor not be 0.
|
|
|
|
static struct mu magicu(uint64_t d)
|
|
|
|
{
|
|
|
|
int64_t p;
|
|
|
|
uint64_t nc, delta, q1, r1, q2, r2;
|
|
|
|
struct mu magu;
|
|
|
|
magu.a = 0; // initialize "add" indicator
|
|
|
|
nc = - 1 - (-d)%d;
|
2005-04-07 19:19:16 +02:00
|
|
|
p = 63; // initialize p
|
|
|
|
q1 = 0x8000000000000000ull/nc; // initialize q1 = 2p/nc
|
|
|
|
r1 = 0x8000000000000000ull - q1*nc; // initialize r1 = rem(2p,nc)
|
|
|
|
q2 = 0x7FFFFFFFFFFFFFFFull/d; // initialize q2 = (2p-1)/d
|
|
|
|
r2 = 0x7FFFFFFFFFFFFFFFull - q2*d; // initialize r2 = rem((2p-1),d)
|
2005-04-06 22:25:34 +02:00
|
|
|
do {
|
|
|
|
p = p + 1;
|
|
|
|
if (r1 >= nc - r1 ) {
|
|
|
|
q1 = 2*q1 + 1; // update q1
|
|
|
|
r1 = 2*r1 - nc; // update r1
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
q1 = 2*q1; // update q1
|
|
|
|
r1 = 2*r1; // update r1
|
|
|
|
}
|
|
|
|
if (r2 + 1 >= d - r2) {
|
2005-04-07 19:19:16 +02:00
|
|
|
if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1;
|
2005-04-06 22:25:34 +02:00
|
|
|
q2 = 2*q2 + 1; // update q2
|
|
|
|
r2 = 2*r2 + 1 - d; // update r2
|
|
|
|
}
|
|
|
|
else {
|
2005-04-07 19:19:16 +02:00
|
|
|
if (q2 >= 0x8000000000000000ull) magu.a = 1;
|
2005-04-06 22:25:34 +02:00
|
|
|
q2 = 2*q2; // update q2
|
|
|
|
r2 = 2*r2 + 1; // update r2
|
|
|
|
}
|
|
|
|
delta = d - 1 - r2;
|
|
|
|
} while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0)));
|
|
|
|
magu.m = q2 + 1; // resulting magic number
|
2005-04-07 19:19:16 +02:00
|
|
|
magu.s = p - 64; // resulting shift
|
2005-04-06 22:25:34 +02:00
|
|
|
return magu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant,
|
|
|
|
/// return a DAG expression to select that will generate the same value by
|
|
|
|
/// multiplying by a magic number. See:
|
|
|
|
/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
|
2005-06-22 19:19:45 +02:00
|
|
|
SDOperand AlphaISel::BuildSDIVSequence(SDOperand N) {
|
2005-04-07 19:19:16 +02:00
|
|
|
int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
|
2005-04-06 22:25:34 +02:00
|
|
|
ms magics = magic(d);
|
|
|
|
// Multiply the numerator (operand 0) by the magic value
|
2005-04-22 01:13:11 +02:00
|
|
|
SDOperand Q = ISelDAG->getNode(ISD::MULHS, MVT::i64, N.getOperand(0),
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getConstant(magics.m, MVT::i64));
|
|
|
|
// If d > 0 and m < 0, add the numerator
|
|
|
|
if (d > 0 && magics.m < 0)
|
|
|
|
Q = ISelDAG->getNode(ISD::ADD, MVT::i64, Q, N.getOperand(0));
|
|
|
|
// If d < 0 and m > 0, subtract the numerator.
|
|
|
|
if (d < 0 && magics.m > 0)
|
|
|
|
Q = ISelDAG->getNode(ISD::SUB, MVT::i64, Q, N.getOperand(0));
|
|
|
|
// Shift right algebraic if shift value is nonzero
|
|
|
|
if (magics.s > 0)
|
2005-04-22 01:13:11 +02:00
|
|
|
Q = ISelDAG->getNode(ISD::SRA, MVT::i64, Q,
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getConstant(magics.s, MVT::i64));
|
|
|
|
// Extract the sign bit and add it to the quotient
|
2005-04-22 01:13:11 +02:00
|
|
|
SDOperand T =
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getNode(ISD::SRL, MVT::i64, Q, ISelDAG->getConstant(63, MVT::i64));
|
|
|
|
return ISelDAG->getNode(ISD::ADD, MVT::i64, Q, T);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant,
|
|
|
|
/// return a DAG expression to select that will generate the same value by
|
|
|
|
/// multiplying by a magic number. See:
|
|
|
|
/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
|
2005-06-22 19:19:45 +02:00
|
|
|
SDOperand AlphaISel::BuildUDIVSequence(SDOperand N) {
|
2005-04-22 01:13:11 +02:00
|
|
|
unsigned d =
|
2005-04-06 22:25:34 +02:00
|
|
|
(unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
|
|
|
|
mu magics = magicu(d);
|
|
|
|
// Multiply the numerator (operand 0) by the magic value
|
2005-04-22 01:13:11 +02:00
|
|
|
SDOperand Q = ISelDAG->getNode(ISD::MULHU, MVT::i64, N.getOperand(0),
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getConstant(magics.m, MVT::i64));
|
|
|
|
if (magics.a == 0) {
|
2005-04-22 01:13:11 +02:00
|
|
|
Q = ISelDAG->getNode(ISD::SRL, MVT::i64, Q,
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getConstant(magics.s, MVT::i64));
|
|
|
|
} else {
|
|
|
|
SDOperand NPQ = ISelDAG->getNode(ISD::SUB, MVT::i64, N.getOperand(0), Q);
|
2005-04-22 01:13:11 +02:00
|
|
|
NPQ = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getConstant(1, MVT::i64));
|
|
|
|
NPQ = ISelDAG->getNode(ISD::ADD, MVT::i64, NPQ, Q);
|
2005-04-22 01:13:11 +02:00
|
|
|
Q = ISelDAG->getNode(ISD::SRL, MVT::i64, NPQ,
|
2005-04-06 22:25:34 +02:00
|
|
|
ISelDAG->getConstant(magics.s-1, MVT::i64));
|
|
|
|
}
|
|
|
|
return Q;
|
|
|
|
}
|
|
|
|
|
2005-04-07 00:03:13 +02:00
|
|
|
//From PPC32
|
|
|
|
/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It
|
|
|
|
/// returns zero when the input is not exactly a power of two.
|
|
|
|
static unsigned ExactLog2(uint64_t Val) {
|
|
|
|
if (Val == 0 || (Val & (Val-1))) return 0;
|
|
|
|
unsigned Count = 0;
|
|
|
|
while (Val != 1) {
|
|
|
|
Val >>= 1;
|
|
|
|
++Count;
|
|
|
|
}
|
|
|
|
return Count;
|
|
|
|
}
|
2005-04-06 22:25:34 +02:00
|
|
|
|
|
|
|
|
2005-03-11 18:48:05 +01:00
|
|
|
//These describe LDAx
|
2005-03-29 21:24:04 +02:00
|
|
|
static const int IMM_LOW = -32768;
|
|
|
|
static const int IMM_HIGH = 32767;
|
2005-03-11 18:48:05 +01:00
|
|
|
static const int IMM_MULT = 65536;
|
|
|
|
|
|
|
|
static long getUpper16(long l)
|
|
|
|
{
|
|
|
|
long y = l / IMM_MULT;
|
|
|
|
if (l % IMM_MULT > IMM_HIGH)
|
|
|
|
++y;
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long getLower16(long l)
|
|
|
|
{
|
|
|
|
long h = getUpper16(l);
|
|
|
|
return l - h * IMM_MULT;
|
|
|
|
}
|
|
|
|
|
2005-06-27 19:15:36 +02:00
|
|
|
static unsigned GetRelVersion(unsigned opcode)
|
|
|
|
{
|
|
|
|
switch (opcode) {
|
|
|
|
default: assert(0 && "unknown load or store"); return 0;
|
|
|
|
case Alpha::LDQ: return Alpha::LDQr;
|
|
|
|
case Alpha::LDS: return Alpha::LDSr;
|
|
|
|
case Alpha::LDT: return Alpha::LDTr;
|
|
|
|
case Alpha::LDL: return Alpha::LDLr;
|
|
|
|
case Alpha::LDBU: return Alpha::LDBUr;
|
|
|
|
case Alpha::LDWU: return Alpha::LDWUr;
|
2005-06-29 02:39:17 +02:00
|
|
|
case Alpha::STB: return Alpha::STBr;
|
|
|
|
case Alpha::STW: return Alpha::STWr;
|
|
|
|
case Alpha::STL: return Alpha::STLr;
|
|
|
|
case Alpha::STQ: return Alpha::STQr;
|
|
|
|
case Alpha::STS: return Alpha::STSr;
|
|
|
|
case Alpha::STT: return Alpha::STTr;
|
|
|
|
|
2005-06-27 19:15:36 +02:00
|
|
|
}
|
|
|
|
}
|
2005-02-06 17:22:15 +01:00
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
|
2005-04-02 23:06:51 +02:00
|
|
|
{
|
|
|
|
unsigned Opc;
|
|
|
|
if (EnableAlphaFTOI) {
|
|
|
|
Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS;
|
|
|
|
BuildMI(BB, Opc, 1, dst).addReg(src);
|
|
|
|
} else {
|
|
|
|
//The hard way:
|
|
|
|
// Spill the integer to memory and reload it from there.
|
|
|
|
unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
|
|
|
|
MachineFunction *F = BB->getParent();
|
|
|
|
int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
|
|
|
|
|
2005-07-01 21:12:13 +02:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-02 23:06:51 +02:00
|
|
|
Opc = isDouble ? Alpha::STT : Alpha::STS;
|
|
|
|
BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-07-01 21:12:13 +02:00
|
|
|
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-02 23:06:51 +02:00
|
|
|
Opc = isDouble ? Alpha::LDQ : Alpha::LDL;
|
|
|
|
BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
|
2005-04-02 23:06:51 +02:00
|
|
|
{
|
|
|
|
unsigned Opc;
|
|
|
|
if (EnableAlphaFTOI) {
|
|
|
|
Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS;
|
|
|
|
BuildMI(BB, Opc, 1, dst).addReg(src);
|
|
|
|
} else {
|
|
|
|
//The hard way:
|
|
|
|
// Spill the integer to memory and reload it from there.
|
|
|
|
unsigned Size = MVT::getSizeInBits(MVT::f64)/8;
|
|
|
|
MachineFunction *F = BB->getParent();
|
|
|
|
int FrameIdx = F->getFrameInfo()->CreateStackObject(Size, 8);
|
|
|
|
|
2005-07-01 21:12:13 +02:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-02 23:06:51 +02:00
|
|
|
Opc = isDouble ? Alpha::STQ : Alpha::STL;
|
|
|
|
BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-07-01 21:12:13 +02:00
|
|
|
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-02 23:06:51 +02:00
|
|
|
Opc = isDouble ? Alpha::LDT : Alpha::LDS;
|
|
|
|
BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst)
|
2005-04-03 00:32:39 +02:00
|
|
|
{
|
|
|
|
SDNode *Node = N.Val;
|
|
|
|
unsigned Opc, Tmp1, Tmp2, Tmp3;
|
|
|
|
SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node);
|
|
|
|
|
|
|
|
bool rev = false;
|
|
|
|
bool inv = false;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 00:32:39 +02:00
|
|
|
switch (SetCC->getCondition()) {
|
|
|
|
default: Node->dump(); assert(0 && "Unknown FP comparison!");
|
|
|
|
case ISD::SETEQ: Opc = Alpha::CMPTEQ; break;
|
|
|
|
case ISD::SETLT: Opc = Alpha::CMPTLT; break;
|
|
|
|
case ISD::SETLE: Opc = Alpha::CMPTLE; break;
|
|
|
|
case ISD::SETGT: Opc = Alpha::CMPTLT; rev = true; break;
|
|
|
|
case ISD::SETGE: Opc = Alpha::CMPTLE; rev = true; break;
|
|
|
|
case ISD::SETNE: Opc = Alpha::CMPTEQ; inv = true; break;
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 00:32:39 +02:00
|
|
|
ConstantFPSDNode *CN;
|
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
Tmp1 = Alpha::F31;
|
|
|
|
else
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 00:32:39 +02:00
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
Tmp2 = Alpha::F31;
|
|
|
|
else
|
2005-04-30 06:44:07 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 00:32:39 +02:00
|
|
|
//Can only compare doubles, and dag won't promote for me
|
|
|
|
if (SetCC->getOperand(0).getValueType() == MVT::f32)
|
|
|
|
{
|
|
|
|
//assert(0 && "Setcc On float?\n");
|
|
|
|
std::cerr << "Setcc on float!\n";
|
|
|
|
Tmp3 = MakeReg(MVT::f64);
|
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
|
|
|
|
Tmp1 = Tmp3;
|
|
|
|
}
|
|
|
|
if (SetCC->getOperand(1).getValueType() == MVT::f32)
|
|
|
|
{
|
|
|
|
//assert (0 && "Setcc On float?\n");
|
|
|
|
std::cerr << "Setcc on float!\n";
|
|
|
|
Tmp3 = MakeReg(MVT::f64);
|
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
|
|
|
|
Tmp2 = Tmp3;
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 00:32:39 +02:00
|
|
|
if (rev) std::swap(Tmp1, Tmp2);
|
|
|
|
//do the comparison
|
|
|
|
BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
return inv;
|
|
|
|
}
|
|
|
|
|
2005-02-06 16:40:40 +01:00
|
|
|
//Check to see if the load is a constant offset from a base register
|
2005-06-22 19:19:45 +02:00
|
|
|
void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
|
2005-02-06 16:40:40 +01:00
|
|
|
{
|
|
|
|
unsigned opcode = N.getOpcode();
|
2005-06-27 01:01:11 +02:00
|
|
|
if (opcode == ISD::ADD && N.getOperand(1).getOpcode() == ISD::Constant &&
|
|
|
|
cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 32767)
|
|
|
|
{ //Normal imm add
|
|
|
|
Reg = SelectExpr(N.getOperand(0));
|
|
|
|
offset = cast<ConstantSDNode>(N.getOperand(1))->getValue();
|
|
|
|
return;
|
2005-02-06 16:40:40 +01:00
|
|
|
}
|
|
|
|
Reg = SelectExpr(N);
|
|
|
|
offset = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
void AlphaISel::SelectBranchCC(SDOperand N)
|
2005-02-08 01:40:03 +01:00
|
|
|
{
|
|
|
|
assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
|
2005-04-22 01:13:11 +02:00
|
|
|
MachineBasicBlock *Dest =
|
2005-02-10 07:25:22 +01:00
|
|
|
cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
|
|
|
|
unsigned Opc = Alpha::WTF;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-08 01:40:03 +01:00
|
|
|
Select(N.getOperand(0)); //chain
|
|
|
|
SDOperand CC = N.getOperand(1);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-08 01:40:03 +01:00
|
|
|
if (CC.getOpcode() == ISD::SETCC)
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
|
|
|
SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
|
|
|
|
if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
|
|
|
|
//Dropping the CC is only useful if we are comparing to 0
|
2005-06-08 20:02:21 +02:00
|
|
|
bool RightZero = SetCC->getOperand(1).getOpcode() == ISD::Constant &&
|
|
|
|
cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0;
|
2005-02-10 07:25:22 +01:00
|
|
|
bool isNE = false;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 22:35:21 +02:00
|
|
|
//Fix up CC
|
|
|
|
ISD::CondCode cCode= SetCC->getCondition();
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 22:35:21 +02:00
|
|
|
if(cCode == ISD::SETNE)
|
2005-02-10 07:25:22 +01:00
|
|
|
isNE = true;
|
|
|
|
|
2005-06-27 01:01:11 +02:00
|
|
|
if (RightZero) {
|
2005-06-08 20:02:21 +02:00
|
|
|
switch (cCode) {
|
2005-02-10 07:25:22 +01:00
|
|
|
default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
|
|
|
|
case ISD::SETEQ: Opc = Alpha::BEQ; break;
|
|
|
|
case ISD::SETLT: Opc = Alpha::BLT; break;
|
|
|
|
case ISD::SETLE: Opc = Alpha::BLE; break;
|
|
|
|
case ISD::SETGT: Opc = Alpha::BGT; break;
|
|
|
|
case ISD::SETGE: Opc = Alpha::BGE; break;
|
|
|
|
case ISD::SETULT: assert(0 && "x (unsigned) < 0 is never true"); break;
|
|
|
|
case ISD::SETUGT: Opc = Alpha::BNE; break;
|
2005-06-27 19:39:17 +02:00
|
|
|
//Technically you could have this CC
|
|
|
|
case ISD::SETULE: Opc = Alpha::BEQ; break;
|
2005-02-10 07:25:22 +01:00
|
|
|
case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
|
|
|
|
case ISD::SETNE: Opc = Alpha::BNE; break;
|
|
|
|
}
|
2005-06-27 01:01:11 +02:00
|
|
|
unsigned Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
|
2005-02-10 07:25:22 +01:00
|
|
|
BuildMI(BB, Opc, 2).addReg(Tmp1).addMBB(Dest);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
unsigned Tmp1 = SelectExpr(CC);
|
|
|
|
if (isNE)
|
|
|
|
BuildMI(BB, Alpha::BEQ, 2).addReg(CCInvMap[CC]).addMBB(Dest);
|
|
|
|
else
|
|
|
|
BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
|
2005-02-08 01:40:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
} else { //FP
|
2005-06-27 19:39:17 +02:00
|
|
|
//Any comparison between 2 values should be codegened as an folded
|
|
|
|
//branch, as moving CC to the integer register is very expensive
|
2005-02-10 07:25:22 +01:00
|
|
|
//for a cmp b: c = a - b;
|
|
|
|
//a = b: c = 0
|
|
|
|
//a < b: c < 0
|
|
|
|
//a > b: c > 0
|
2005-02-25 23:55:15 +01:00
|
|
|
|
|
|
|
bool invTest = false;
|
|
|
|
unsigned Tmp3;
|
|
|
|
|
|
|
|
ConstantFPSDNode *CN;
|
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
Tmp3 = SelectExpr(SetCC->getOperand(0));
|
|
|
|
else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
{
|
|
|
|
Tmp3 = SelectExpr(SetCC->getOperand(1));
|
|
|
|
invTest = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
|
|
|
|
unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
|
|
|
|
bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
|
|
|
|
Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
|
|
|
|
BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
|
|
|
|
.addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
|
|
|
|
switch (SetCC->getCondition()) {
|
|
|
|
default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
|
2005-02-25 23:55:15 +01:00
|
|
|
case ISD::SETEQ: Opc = invTest ? Alpha::FBNE : Alpha::FBEQ; break;
|
|
|
|
case ISD::SETLT: Opc = invTest ? Alpha::FBGT : Alpha::FBLT; break;
|
|
|
|
case ISD::SETLE: Opc = invTest ? Alpha::FBGE : Alpha::FBLE; break;
|
|
|
|
case ISD::SETGT: Opc = invTest ? Alpha::FBLT : Alpha::FBGT; break;
|
|
|
|
case ISD::SETGE: Opc = invTest ? Alpha::FBLE : Alpha::FBGE; break;
|
|
|
|
case ISD::SETNE: Opc = invTest ? Alpha::FBEQ : Alpha::FBNE; break;
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
|
|
|
BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
|
2005-02-08 01:40:03 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
abort(); //Should never be reached
|
|
|
|
} else {
|
|
|
|
//Giveup and do the stupid thing
|
|
|
|
unsigned Tmp1 = SelectExpr(CC);
|
|
|
|
BuildMI(BB, Alpha::BNE, 2).addReg(Tmp1).addMBB(Dest);
|
|
|
|
return;
|
|
|
|
}
|
2005-02-08 01:40:03 +01:00
|
|
|
abort(); //Should never be reached
|
|
|
|
}
|
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
unsigned AlphaISel::SelectExpr(SDOperand N) {
|
2005-01-23 00:41:55 +01:00
|
|
|
unsigned Result;
|
2005-04-07 20:15:28 +02:00
|
|
|
unsigned Tmp1, Tmp2 = 0, Tmp3;
|
2005-01-23 00:41:55 +01:00
|
|
|
unsigned Opc = 0;
|
2005-01-28 07:57:18 +01:00
|
|
|
unsigned opcode = N.getOpcode();
|
2005-01-23 00:41:55 +01:00
|
|
|
|
|
|
|
SDNode *Node = N.Val;
|
2005-01-28 07:57:18 +01:00
|
|
|
MVT::ValueType DestType = N.getValueType();
|
2005-06-29 14:49:51 +02:00
|
|
|
bool isFP = DestType == MVT::f64 || DestType == MVT::f32;
|
2005-01-23 00:41:55 +01:00
|
|
|
|
|
|
|
unsigned &Reg = ExprMap[N];
|
|
|
|
if (Reg) return Reg;
|
|
|
|
|
2005-05-13 22:29:26 +02:00
|
|
|
if (N.getOpcode() != ISD::CALL && N.getOpcode() != ISD::TAILCALL)
|
2005-01-23 00:41:55 +01:00
|
|
|
Reg = Result = (N.getValueType() != MVT::Other) ?
|
2005-01-29 00:17:54 +01:00
|
|
|
MakeReg(N.getValueType()) : notIn;
|
2005-01-23 00:41:55 +01:00
|
|
|
else {
|
|
|
|
// If this is a call instruction, make sure to prepare ALL of the result
|
|
|
|
// values as well as the chain.
|
|
|
|
if (Node->getNumValues() == 1)
|
2005-01-29 00:17:54 +01:00
|
|
|
Reg = Result = notIn; // Void call, just a chain.
|
2005-01-23 00:41:55 +01:00
|
|
|
else {
|
|
|
|
Result = MakeReg(Node->getValueType(0));
|
|
|
|
ExprMap[N.getValue(0)] = Result;
|
|
|
|
for (unsigned i = 1, e = N.Val->getNumValues()-1; i != e; ++i)
|
|
|
|
ExprMap[N.getValue(i)] = MakeReg(Node->getValueType(i));
|
2005-01-29 00:17:54 +01:00
|
|
|
ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-28 07:57:18 +01:00
|
|
|
switch (opcode) {
|
2005-01-23 00:41:55 +01:00
|
|
|
default:
|
|
|
|
Node->dump();
|
|
|
|
assert(0 && "Node not handled!\n");
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-05-03 19:19:30 +02:00
|
|
|
case ISD::CTPOP:
|
|
|
|
case ISD::CTTZ:
|
|
|
|
case ISD::CTLZ:
|
|
|
|
Opc = opcode == ISD::CTPOP ? Alpha::CTPOP :
|
|
|
|
(opcode == ISD::CTTZ ? Alpha::CTTZ : Alpha::CTLZ);
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
|
|
|
|
return Result;
|
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
case ISD::MULHU:
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Alpha::UMULH, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
2005-04-07 15:55:53 +02:00
|
|
|
return Result;
|
2005-04-06 22:25:34 +02:00
|
|
|
case ISD::MULHS:
|
|
|
|
{
|
|
|
|
//MULHU - Ra<63>*Rb - Rb<63>*Ra
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
Tmp3 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::UMULH, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
unsigned V1 = MakeReg(MVT::i64);
|
|
|
|
unsigned V2 = MakeReg(MVT::i64);
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::CMOVGE, 3, V1).addReg(Tmp2).addReg(Alpha::R31)
|
|
|
|
.addReg(Tmp1);
|
|
|
|
BuildMI(BB, Alpha::CMOVGE, 3, V2).addReg(Tmp1).addReg(Alpha::R31)
|
|
|
|
.addReg(Tmp2);
|
2005-04-06 22:25:34 +02:00
|
|
|
unsigned IRes = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, IRes).addReg(Tmp3).addReg(V1);
|
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(IRes).addReg(V2);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-02 21:11:07 +02:00
|
|
|
case ISD::UNDEF: {
|
|
|
|
BuildMI(BB, Alpha::IDEF, 0, Result);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-22 22:59:48 +01:00
|
|
|
case ISD::DYNAMIC_STACKALLOC:
|
|
|
|
// Generate both result values.
|
2005-02-23 18:33:42 +01:00
|
|
|
if (Result != notIn)
|
|
|
|
ExprMap[N.getValue(1)] = notIn; // Generate the token
|
2005-02-22 22:59:48 +01:00
|
|
|
else
|
|
|
|
Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
|
|
|
|
|
|
|
|
// FIXME: We are currently ignoring the requested alignment for handling
|
|
|
|
// greater than the stack alignment. This will need to be revisited at some
|
|
|
|
// point. Align = N.getOperand(2);
|
|
|
|
|
|
|
|
if (!isa<ConstantSDNode>(N.getOperand(2)) ||
|
|
|
|
cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
|
|
|
|
std::cerr << "Cannot allocate stack object with greater alignment than"
|
|
|
|
<< " the stack alignment yet!";
|
|
|
|
abort();
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-22 22:59:48 +01:00
|
|
|
Select(N.getOperand(0));
|
|
|
|
if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
|
|
|
|
{
|
|
|
|
if (CN->getValue() < 32000)
|
|
|
|
{
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
|
|
|
|
.addImm(-CN->getValue()).addReg(Alpha::R30);
|
|
|
|
} else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
// Subtract size from stack pointer, thereby allocating some space.
|
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
// Subtract size from stack pointer, thereby allocating some space.
|
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put a pointer to the space into the result register, by copying the stack
|
|
|
|
// pointer.
|
2005-02-23 00:29:25 +01:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
|
2005-02-22 22:59:48 +01:00
|
|
|
return Result;
|
|
|
|
|
2005-06-27 23:02:56 +02:00
|
|
|
case ISD::ConstantPool:
|
|
|
|
Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
|
|
|
|
AlphaLowering.restoreGP(BB);
|
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp2).addConstantPoolIndex(Tmp1)
|
|
|
|
.addReg(Alpha::R29);
|
|
|
|
BuildMI(BB, Alpha::LDAr, 2, Result).addConstantPoolIndex(Tmp1)
|
|
|
|
.addReg(Tmp2);
|
|
|
|
return Result;
|
2005-01-29 16:42:07 +01:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::FrameIndex:
|
2005-02-22 22:59:48 +01:00
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result)
|
|
|
|
.addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
|
|
|
|
.addReg(Alpha::F31);
|
2005-01-23 00:41:55 +01:00
|
|
|
return Result;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::EXTLOAD:
|
2005-02-07 06:18:02 +01:00
|
|
|
case ISD::ZEXTLOAD:
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::SEXTLOAD:
|
2005-04-22 01:13:11 +02:00
|
|
|
case ISD::LOAD:
|
2005-02-06 16:40:40 +01:00
|
|
|
{
|
|
|
|
// Make sure we generate both values.
|
|
|
|
if (Result != notIn)
|
|
|
|
ExprMap[N.getValue(1)] = notIn; // Generate the token
|
|
|
|
else
|
|
|
|
Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-06 16:40:40 +01:00
|
|
|
SDOperand Chain = N.getOperand(0);
|
|
|
|
SDOperand Address = N.getOperand(1);
|
|
|
|
Select(Chain);
|
|
|
|
|
2005-06-29 02:31:08 +02:00
|
|
|
bool fpext = true;
|
|
|
|
|
2005-02-07 06:55:55 +01:00
|
|
|
if (opcode == ISD::LOAD)
|
2005-06-29 02:31:08 +02:00
|
|
|
switch (Node->getValueType(0)) {
|
|
|
|
default: Node->dump(); assert(0 && "Bad load!");
|
|
|
|
case MVT::i64: Opc = Alpha::LDQ; break;
|
|
|
|
case MVT::f64: Opc = Alpha::LDT; break;
|
|
|
|
case MVT::f32: Opc = Alpha::LDS; break;
|
|
|
|
}
|
2005-02-07 06:55:55 +01:00
|
|
|
else
|
2005-02-06 16:40:40 +01:00
|
|
|
switch (cast<MVTSDNode>(Node)->getExtraValueType()) {
|
|
|
|
default: Node->dump(); assert(0 && "Bad sign extend!");
|
2005-04-22 01:13:11 +02:00
|
|
|
case MVT::i32: Opc = Alpha::LDL;
|
2005-02-10 07:25:22 +01:00
|
|
|
assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
|
2005-04-22 01:13:11 +02:00
|
|
|
case MVT::i16: Opc = Alpha::LDWU;
|
2005-02-10 07:25:22 +01:00
|
|
|
assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
|
2005-02-07 06:18:02 +01:00
|
|
|
case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
|
2005-04-22 01:13:11 +02:00
|
|
|
case MVT::i8: Opc = Alpha::LDBU;
|
2005-02-10 07:25:22 +01:00
|
|
|
assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
|
2005-02-06 16:40:40 +01:00
|
|
|
}
|
|
|
|
|
2005-06-29 20:54:02 +02:00
|
|
|
int i, j, k;
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
getValueInfo(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue(),
|
|
|
|
i, j, k);
|
|
|
|
|
2005-07-01 21:12:13 +02:00
|
|
|
GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address);
|
|
|
|
if (GASD && !GASD->getGlobal()->isExternal()) {
|
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
|
|
|
AlphaLowering.restoreGP(BB);
|
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp1)
|
|
|
|
.addGlobalAddress(GASD->getGlobal()).addReg(Alpha::R29);
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
|
|
|
BuildMI(BB, GetRelVersion(Opc), 2, Result)
|
|
|
|
.addGlobalAddress(GASD->getGlobal()).addReg(Tmp1);
|
2005-06-29 02:31:08 +02:00
|
|
|
} else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
|
2005-02-06 16:40:40 +01:00
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-04-08 19:28:49 +02:00
|
|
|
has_sym = true;
|
2005-06-27 19:15:36 +02:00
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CP->getIndex())
|
|
|
|
.addReg(Alpha::R29);
|
2005-06-29 02:31:08 +02:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-29 20:54:02 +02:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-06-29 02:31:08 +02:00
|
|
|
BuildMI(BB, GetRelVersion(Opc), 2, Result)
|
|
|
|
.addConstantPoolIndex(CP->getIndex()).addReg(Tmp1);
|
|
|
|
} else if(Address.getOpcode() == ISD::FrameIndex) {
|
|
|
|
if (EnableAlphaLSMark)
|
2005-06-29 20:54:02 +02:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-22 22:59:48 +01:00
|
|
|
BuildMI(BB, Opc, 2, Result)
|
|
|
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
|
|
|
.addReg(Alpha::F31);
|
2005-02-10 07:25:22 +01:00
|
|
|
} else {
|
|
|
|
long offset;
|
|
|
|
SelectAddr(Address, Tmp1, offset);
|
2005-06-29 02:31:08 +02:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-29 20:54:02 +02:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-10 07:25:22 +01:00
|
|
|
BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
|
2005-02-06 16:40:40 +01:00
|
|
|
}
|
|
|
|
return Result;
|
2005-01-25 01:35:34 +01:00
|
|
|
}
|
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::GlobalAddress:
|
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-04-08 19:28:49 +02:00
|
|
|
has_sym = true;
|
2005-07-03 22:06:13 +02:00
|
|
|
|
|
|
|
Reg = Result = MakeReg(MVT::i64);
|
2005-06-29 02:31:08 +02:00
|
|
|
|
|
|
|
if (EnableAlphaLSMark)
|
2005-07-01 21:12:13 +02:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
|
2005-06-29 20:54:02 +02:00
|
|
|
.addImm(getUID());
|
2005-06-29 02:31:08 +02:00
|
|
|
|
|
|
|
BuildMI(BB, Alpha::LDQl, 2, Result)
|
2005-06-27 23:11:40 +02:00
|
|
|
.addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal())
|
|
|
|
.addReg(Alpha::R29);
|
2005-01-23 00:41:55 +01:00
|
|
|
return Result;
|
|
|
|
|
2005-07-01 21:12:13 +02:00
|
|
|
case ISD::ExternalSymbol:
|
|
|
|
AlphaLowering.restoreGP(BB);
|
|
|
|
has_sym = true;
|
|
|
|
|
2005-07-03 22:06:13 +02:00
|
|
|
Reg = Result = MakeReg(MVT::i64);
|
|
|
|
|
2005-07-01 21:12:13 +02:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
|
|
|
|
|
|
|
BuildMI(BB, Alpha::LDQl, 2, Result)
|
|
|
|
.addExternalSymbol(cast<ExternalSymbolSDNode>(N)->getSymbol())
|
|
|
|
.addReg(Alpha::R29);
|
|
|
|
return Result;
|
|
|
|
|
2005-05-13 22:29:26 +02:00
|
|
|
case ISD::TAILCALL:
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::CALL:
|
|
|
|
{
|
|
|
|
Select(N.getOperand(0));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
// The chain for this call is now lowered.
|
2005-01-29 00:17:54 +01:00
|
|
|
ExprMap.insert(std::make_pair(N.getValue(Node->getNumValues()-1), notIn));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
//grab the arguments
|
|
|
|
std::vector<unsigned> argvregs;
|
2005-01-30 21:42:36 +01:00
|
|
|
//assert(Node->getNumOperands() < 8 && "Only 6 args supported");
|
2005-01-23 00:41:55 +01:00
|
|
|
for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
|
2005-02-10 07:25:22 +01:00
|
|
|
argvregs.push_back(SelectExpr(N.getOperand(i)));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-30 01:35:27 +01:00
|
|
|
//in reg args
|
|
|
|
for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
2005-04-22 01:13:11 +02:00
|
|
|
unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
|
2005-02-10 07:25:22 +01:00
|
|
|
Alpha::R19, Alpha::R20, Alpha::R21};
|
2005-04-22 01:13:11 +02:00
|
|
|
unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
|
2005-02-10 07:25:22 +01:00
|
|
|
Alpha::F19, Alpha::F20, Alpha::F21};
|
|
|
|
switch(N.getOperand(i+2).getValueType()) {
|
2005-04-22 01:13:11 +02:00
|
|
|
default:
|
|
|
|
Node->dump();
|
2005-02-10 07:25:22 +01:00
|
|
|
N.getOperand(i).Val->dump();
|
2005-04-22 01:13:11 +02:00
|
|
|
std::cerr << "Type for " << i << " is: " <<
|
2005-02-10 07:25:22 +01:00
|
|
|
N.getOperand(i+2).getValueType() << "\n";
|
|
|
|
assert(0 && "Unknown value type for call");
|
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i])
|
|
|
|
.addReg(argvregs[i]);
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i])
|
|
|
|
.addReg(argvregs[i]);
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
2005-01-30 01:35:27 +01:00
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
2005-01-30 01:35:27 +01:00
|
|
|
//in mem args
|
|
|
|
for (int i = 6, e = argvregs.size(); i < e; ++i)
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
|
|
|
switch(N.getOperand(i+2).getValueType()) {
|
2005-04-22 01:13:11 +02:00
|
|
|
default:
|
|
|
|
Node->dump();
|
2005-02-10 07:25:22 +01:00
|
|
|
N.getOperand(i).Val->dump();
|
2005-04-22 01:13:11 +02:00
|
|
|
std::cerr << "Type for " << i << " is: " <<
|
2005-02-10 07:25:22 +01:00
|
|
|
N.getOperand(i+2).getValueType() << "\n";
|
|
|
|
assert(0 && "Unknown value type for call");
|
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
|
|
|
|
.addReg(Alpha::R30);
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
|
|
|
case MVT::f32:
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
|
|
|
|
.addReg(Alpha::R30);
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
|
|
|
case MVT::f64:
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
|
|
|
|
.addReg(Alpha::R30);
|
2005-02-10 07:25:22 +01:00
|
|
|
break;
|
2005-01-30 01:35:27 +01:00
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
2005-01-26 22:54:09 +01:00
|
|
|
//build the right kind of call
|
2005-07-01 21:12:13 +02:00
|
|
|
GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(N.getOperand(1));
|
|
|
|
if (GASD && !GASD->getGlobal()->isExternal()) {
|
|
|
|
//use PC relative branch call
|
2005-02-10 07:25:22 +01:00
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-07-01 21:12:13 +02:00
|
|
|
BuildMI(BB, Alpha::BSR, 1, Alpha::R26)
|
|
|
|
.addGlobalAddress(GASD->getGlobal(),true);
|
2005-02-10 07:25:22 +01:00
|
|
|
} else {
|
2005-07-07 21:52:58 +02:00
|
|
|
//Must always reread relocation table before a call
|
|
|
|
if (GASD)
|
|
|
|
ExprMap.erase(N.getOperand(1));
|
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
//no need to restore GP as we are doing an indirect call
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp1).addReg(Tmp1);
|
|
|
|
BuildMI(BB, Alpha::JSR, 2, Alpha::R26).addReg(Alpha::R27).addImm(0);
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-26 22:54:09 +01:00
|
|
|
//push the result into a virtual register
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-26 22:54:09 +01:00
|
|
|
switch (Node->getValueType(0)) {
|
|
|
|
default: Node->dump(); assert(0 && "Unknown value type for call result!");
|
2005-01-29 00:17:54 +01:00
|
|
|
case MVT::Other: return notIn;
|
2005-01-26 22:54:09 +01:00
|
|
|
case MVT::i1:
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
2005-04-22 19:54:37 +02:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
|
|
|
|
break;
|
2005-01-26 22:54:09 +01:00
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
2005-04-22 19:54:37 +02:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
|
|
|
|
break;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-01-26 22:54:09 +01:00
|
|
|
return Result+N.ResNo;
|
2005-04-22 01:13:11 +02:00
|
|
|
}
|
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
{
|
2005-04-08 19:28:49 +02:00
|
|
|
//do SDIV opt for all levels of ints if not dividing by a constant
|
|
|
|
if (EnableAlphaIDIV && N.getOperand(0).getOpcode() == ISD::SDIV
|
|
|
|
&& N.getOperand(0).getOperand(1).getOpcode() != ISD::Constant)
|
2005-03-22 01:24:07 +01:00
|
|
|
{
|
|
|
|
unsigned Tmp4 = MakeReg(MVT::f64);
|
|
|
|
unsigned Tmp5 = MakeReg(MVT::f64);
|
|
|
|
unsigned Tmp6 = MakeReg(MVT::f64);
|
|
|
|
unsigned Tmp7 = MakeReg(MVT::f64);
|
|
|
|
unsigned Tmp8 = MakeReg(MVT::f64);
|
|
|
|
unsigned Tmp9 = MakeReg(MVT::f64);
|
2005-04-02 23:06:51 +02:00
|
|
|
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
|
|
|
|
MoveInt2FP(Tmp1, Tmp4, true);
|
|
|
|
MoveInt2FP(Tmp2, Tmp5, true);
|
2005-03-22 01:24:07 +01:00
|
|
|
BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Tmp4);
|
|
|
|
BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Tmp5);
|
|
|
|
BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7);
|
|
|
|
BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Tmp8);
|
2005-04-02 23:06:51 +02:00
|
|
|
MoveFP2Int(Tmp9, Result, true);
|
2005-03-22 01:24:07 +01:00
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-29 00:17:54 +01:00
|
|
|
//Alpha has instructions for a bunch of signed 32 bit stuff
|
|
|
|
if( dyn_cast<MVTSDNode>(Node)->getExtraValueType() == MVT::i32)
|
2005-03-22 01:24:07 +01:00
|
|
|
{
|
2005-02-10 07:25:22 +01:00
|
|
|
switch (N.getOperand(0).getOpcode()) {
|
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::MUL:
|
|
|
|
{
|
|
|
|
bool isAdd = N.getOperand(0).getOpcode() == ISD::ADD;
|
|
|
|
bool isMul = N.getOperand(0).getOpcode() == ISD::MUL;
|
|
|
|
//FIXME: first check for Scaled Adds and Subs!
|
2005-04-13 07:19:55 +02:00
|
|
|
ConstantSDNode* CSD = NULL;
|
|
|
|
if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL &&
|
|
|
|
(CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(0).getOperand(1))) &&
|
|
|
|
(CSD->getValue() == 2 || CSD->getValue() == 3))
|
|
|
|
{
|
|
|
|
bool use4 = CSD->getValue() == 2;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0).getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
|
|
|
|
BuildMI(BB, isAdd?(use4?Alpha::S4ADDL:Alpha::S8ADDL):(use4?Alpha::S4SUBL:Alpha::S8SUBL),
|
|
|
|
2,Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
|
|
|
else if(isAdd && N.getOperand(0).getOperand(1).getOpcode() == ISD::SHL &&
|
|
|
|
(CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1).getOperand(1))) &&
|
|
|
|
(CSD->getValue() == 2 || CSD->getValue() == 3))
|
|
|
|
{
|
|
|
|
bool use4 = CSD->getValue() == 2;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(1).getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
|
|
|
|
BuildMI(BB, use4?Alpha::S4ADDL:Alpha::S8ADDL, 2,Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
|
|
|
else if(N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
|
2005-02-10 07:25:22 +01:00
|
|
|
cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue() <= 255)
|
|
|
|
{ //Normal imm add/sub
|
|
|
|
Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
|
2005-04-13 07:19:55 +02:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-02-10 07:25:22 +01:00
|
|
|
Tmp2 = cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getValue();
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //Normal add/sub
|
2005-04-13 07:19:55 +02:00
|
|
|
Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL);
|
2005-02-10 07:25:22 +01:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-04-13 07:19:55 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
|
2005-02-10 07:25:22 +01:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
2005-01-29 00:17:54 +01:00
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
return Result;
|
2005-01-29 00:17:54 +01:00
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
default: break; //Fall Though;
|
|
|
|
}
|
|
|
|
} //Every thing else fall though too, including unhandled opcodes above
|
2005-01-23 00:41:55 +01:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
MVTSDNode* MVN = dyn_cast<MVTSDNode>(Node);
|
2005-01-26 22:54:09 +01:00
|
|
|
//std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
|
2005-01-23 00:41:55 +01:00
|
|
|
switch(MVN->getExtraValueType())
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
Node->dump();
|
|
|
|
assert(0 && "Sign Extend InReg not there yet");
|
|
|
|
break;
|
|
|
|
case MVT::i32:
|
2005-01-27 04:49:45 +01:00
|
|
|
{
|
2005-02-10 07:25:22 +01:00
|
|
|
BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
|
2005-01-27 04:49:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
case MVT::i16:
|
|
|
|
BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
|
|
|
|
break;
|
|
|
|
case MVT::i8:
|
|
|
|
BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
|
|
|
|
break;
|
2005-02-12 20:35:12 +01:00
|
|
|
case MVT::i1:
|
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
|
2005-04-08 19:28:49 +02:00
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2);
|
2005-02-12 20:35:12 +01:00
|
|
|
break;
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::SETCC:
|
2005-01-27 04:49:45 +01:00
|
|
|
{
|
|
|
|
if (SetCCSDNode *SetCC = dyn_cast<SetCCSDNode>(Node)) {
|
|
|
|
if (MVT::isInteger(SetCC->getOperand(0).getValueType())) {
|
2005-06-27 01:01:11 +02:00
|
|
|
bool isConst = false;
|
2005-01-27 04:49:45 +01:00
|
|
|
int dir;
|
2005-04-22 19:54:37 +02:00
|
|
|
|
2005-01-27 04:49:45 +01:00
|
|
|
//Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
if(N.getOperand(1).getOpcode() == ISD::Constant &&
|
|
|
|
cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
|
2005-06-27 01:01:11 +02:00
|
|
|
isConst = true;
|
2005-01-27 04:49:45 +01:00
|
|
|
|
|
|
|
switch (SetCC->getCondition()) {
|
|
|
|
default: Node->dump(); assert(0 && "Unknown integer comparison!");
|
2005-06-27 01:01:11 +02:00
|
|
|
case ISD::SETEQ:
|
|
|
|
Opc = isConst ? Alpha::CMPEQi : Alpha::CMPEQ; dir=1; break;
|
2005-04-22 01:13:11 +02:00
|
|
|
case ISD::SETLT:
|
2005-06-27 01:01:11 +02:00
|
|
|
Opc = isConst ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
|
2005-04-22 01:13:11 +02:00
|
|
|
case ISD::SETLE:
|
2005-06-27 01:01:11 +02:00
|
|
|
Opc = isConst ? Alpha::CMPLEi : Alpha::CMPLE; dir = 1; break;
|
|
|
|
case ISD::SETGT: Opc = Alpha::CMPLT; dir = 2; break;
|
|
|
|
case ISD::SETGE: Opc = Alpha::CMPLE; dir = 2; break;
|
2005-04-22 01:13:11 +02:00
|
|
|
case ISD::SETULT:
|
2005-06-27 01:01:11 +02:00
|
|
|
Opc = isConst ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
|
|
|
|
case ISD::SETUGT: Opc = Alpha::CMPULT; dir = 2; break;
|
2005-04-22 01:13:11 +02:00
|
|
|
case ISD::SETULE:
|
2005-06-27 01:01:11 +02:00
|
|
|
Opc = isConst ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
|
|
|
|
case ISD::SETUGE: Opc = Alpha::CMPULE; dir = 2; break;
|
2005-01-27 08:50:35 +01:00
|
|
|
case ISD::SETNE: {//Handle this one special
|
|
|
|
//std::cerr << "Alpha does not have a setne.\n";
|
|
|
|
//abort();
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
Tmp3 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::CMPEQ, 2, Tmp3).addReg(Tmp1).addReg(Tmp2);
|
2005-02-08 01:40:03 +01:00
|
|
|
//Remeber we have the Inv for this CC
|
|
|
|
CCInvMap[N] = Tmp3;
|
2005-01-27 08:50:35 +01:00
|
|
|
//and invert
|
2005-01-29 00:17:54 +01:00
|
|
|
BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
|
2005-01-27 08:50:35 +01:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
2005-01-27 04:49:45 +01:00
|
|
|
if (dir == 1) {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-06-27 01:01:11 +02:00
|
|
|
if (isConst) {
|
2005-01-27 04:49:45 +01:00
|
|
|
Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
|
|
|
|
} else {
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
2005-06-27 01:01:11 +02:00
|
|
|
} else { //if (dir == 2) {
|
2005-01-27 04:49:45 +01:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
2005-06-27 01:01:11 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
2005-02-05 17:41:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//do the comparison
|
2005-04-03 00:32:39 +02:00
|
|
|
Tmp1 = MakeReg(MVT::f64);
|
|
|
|
bool inv = SelectFPSetCC(N, Tmp1);
|
|
|
|
|
2005-02-05 17:41:03 +01:00
|
|
|
//now arrange for Result (int) to have a 1 or 0
|
2005-04-03 00:32:39 +02:00
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1);
|
2005-03-22 01:24:07 +01:00
|
|
|
Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP;
|
2005-04-03 00:32:39 +02:00
|
|
|
BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1);
|
2005-02-05 17:41:03 +01:00
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-01-27 04:49:45 +01:00
|
|
|
return Result;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
{
|
2005-04-08 19:28:49 +02:00
|
|
|
++count_ins;
|
|
|
|
|
2005-01-28 07:57:18 +01:00
|
|
|
// Make sure we generate both values.
|
2005-01-29 00:17:54 +01:00
|
|
|
if (Result != notIn)
|
2005-04-22 19:54:37 +02:00
|
|
|
ExprMap[N.getValue(1)] = notIn; // Generate the token
|
2005-01-28 07:57:18 +01:00
|
|
|
else
|
2005-04-22 19:54:37 +02:00
|
|
|
Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
SDOperand Chain = N.getOperand(0);
|
|
|
|
|
|
|
|
Select(Chain);
|
|
|
|
unsigned r = dyn_cast<RegSDNode>(Node)->getReg();
|
|
|
|
//std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
|
2005-07-04 22:07:21 +02:00
|
|
|
if (MVT::isFloatingPoint(N.getValue(0).getValueType()))
|
2005-06-29 02:31:08 +02:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Result).addReg(r).addReg(r);
|
|
|
|
else
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(r).addReg(r);
|
2005-01-23 00:41:55 +01:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2005-04-22 01:13:11 +02:00
|
|
|
//Most of the plain arithmetic and logic share the same form, and the same
|
2005-01-24 20:44:07 +01:00
|
|
|
//constant immediate test
|
2005-04-08 19:28:49 +02:00
|
|
|
case ISD::XOR:
|
2005-04-02 23:06:51 +02:00
|
|
|
//Match Not
|
|
|
|
if (N.getOperand(1).getOpcode() == ISD::Constant &&
|
2005-04-22 19:54:37 +02:00
|
|
|
cast<ConstantSDNode>(N.getOperand(1))->getSignExtended() == -1)
|
2005-04-02 23:06:51 +02:00
|
|
|
{
|
2005-04-22 19:54:37 +02:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1);
|
|
|
|
return Result;
|
2005-04-02 23:06:51 +02:00
|
|
|
}
|
|
|
|
//Fall through
|
|
|
|
case ISD::AND:
|
2005-04-13 05:47:03 +02:00
|
|
|
//handle zap
|
|
|
|
if (opcode == ISD::AND && N.getOperand(1).getOpcode() == ISD::Constant)
|
|
|
|
{
|
|
|
|
uint64_t k = cast<ConstantSDNode>(N.getOperand(1))->getValue();
|
|
|
|
unsigned int build = 0;
|
|
|
|
for(int i = 0; i < 8; ++i)
|
|
|
|
{
|
2005-04-14 18:24:00 +02:00
|
|
|
if ((k & 0x00FF) == 0x00FF)
|
2005-04-13 05:47:03 +02:00
|
|
|
build |= 1 << i;
|
2005-04-14 18:24:00 +02:00
|
|
|
else if ((k & 0x00FF) != 0)
|
2005-04-13 05:47:03 +02:00
|
|
|
{ build = 0; break; }
|
|
|
|
k >>= 8;
|
|
|
|
}
|
|
|
|
if (build)
|
|
|
|
{
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
2005-04-08 19:28:49 +02:00
|
|
|
case ISD::OR:
|
2005-04-02 23:06:51 +02:00
|
|
|
//Check operand(0) == Not
|
2005-04-22 01:13:11 +02:00
|
|
|
if (N.getOperand(0).getOpcode() == ISD::XOR &&
|
2005-04-02 23:06:51 +02:00
|
|
|
N.getOperand(0).getOperand(1).getOpcode() == ISD::Constant &&
|
2005-06-27 19:39:17 +02:00
|
|
|
cast<ConstantSDNode>(N.getOperand(0).getOperand(1))->getSignExtended()
|
|
|
|
== -1) {
|
|
|
|
switch(opcode) {
|
2005-04-22 19:54:37 +02:00
|
|
|
case ISD::AND: Opc = Alpha::BIC; break;
|
|
|
|
case ISD::OR: Opc = Alpha::ORNOT; break;
|
|
|
|
case ISD::XOR: Opc = Alpha::EQV; break;
|
2005-04-02 23:06:51 +02:00
|
|
|
}
|
2005-06-27 19:39:17 +02:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-02 23:06:51 +02:00
|
|
|
//Check operand(1) == Not
|
2005-04-22 01:13:11 +02:00
|
|
|
if (N.getOperand(1).getOpcode() == ISD::XOR &&
|
2005-04-02 23:06:51 +02:00
|
|
|
N.getOperand(1).getOperand(1).getOpcode() == ISD::Constant &&
|
2005-06-27 19:39:17 +02:00
|
|
|
cast<ConstantSDNode>(N.getOperand(1).getOperand(1))->getSignExtended()
|
|
|
|
== -1) {
|
|
|
|
switch(opcode) {
|
2005-04-22 19:54:37 +02:00
|
|
|
case ISD::AND: Opc = Alpha::BIC; break;
|
|
|
|
case ISD::OR: Opc = Alpha::ORNOT; break;
|
|
|
|
case ISD::XOR: Opc = Alpha::EQV; break;
|
2005-04-02 23:06:51 +02:00
|
|
|
}
|
2005-06-27 19:39:17 +02:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-02 23:06:51 +02:00
|
|
|
//Fall through
|
2005-01-24 20:44:07 +01:00
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRL:
|
2005-01-29 16:42:07 +01:00
|
|
|
case ISD::SRA:
|
2005-01-24 20:44:07 +01:00
|
|
|
case ISD::MUL:
|
2005-01-28 07:57:18 +01:00
|
|
|
if(N.getOperand(1).getOpcode() == ISD::Constant &&
|
|
|
|
cast<ConstantSDNode>(N.getOperand(1))->getValue() <= 255)
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
|
|
|
switch(opcode) {
|
|
|
|
case ISD::AND: Opc = Alpha::ANDi; break;
|
|
|
|
case ISD::OR: Opc = Alpha::BISi; break;
|
|
|
|
case ISD::XOR: Opc = Alpha::XORi; break;
|
|
|
|
case ISD::SHL: Opc = Alpha::SLi; break;
|
|
|
|
case ISD::SRL: Opc = Alpha::SRLi; break;
|
|
|
|
case ISD::SRA: Opc = Alpha::SRAi; break;
|
|
|
|
case ISD::MUL: Opc = Alpha::MULQi; break;
|
|
|
|
};
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(Tmp2);
|
|
|
|
} else {
|
|
|
|
switch(opcode) {
|
|
|
|
case ISD::AND: Opc = Alpha::AND; break;
|
|
|
|
case ISD::OR: Opc = Alpha::BIS; break;
|
|
|
|
case ISD::XOR: Opc = Alpha::XOR; break;
|
|
|
|
case ISD::SHL: Opc = Alpha::SL; break;
|
|
|
|
case ISD::SRL: Opc = Alpha::SRL; break;
|
|
|
|
case ISD::SRA: Opc = Alpha::SRA; break;
|
2005-06-29 14:49:51 +02:00
|
|
|
case ISD::MUL:
|
|
|
|
Opc = isFP ? (DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS)
|
|
|
|
: Alpha::MULQ;
|
|
|
|
break;
|
2005-02-10 07:25:22 +01:00
|
|
|
};
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
2005-01-26 22:54:09 +01:00
|
|
|
return Result;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-26 22:54:09 +01:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
2005-06-29 14:49:51 +02:00
|
|
|
if (isFP) {
|
|
|
|
ConstantFPSDNode *CN;
|
|
|
|
if (opcode == ISD::ADD)
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS;
|
|
|
|
else
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS;
|
|
|
|
if (opcode == ISD::SUB
|
|
|
|
&& (CN = dyn_cast<ConstantFPSDNode>(N.getOperand(0)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
{
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp2).addReg(Tmp2);
|
|
|
|
} else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
} else {
|
2005-01-28 07:57:18 +01:00
|
|
|
bool isAdd = opcode == ISD::ADD;
|
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
//first check for Scaled Adds and Subs!
|
|
|
|
//Valid for add and sub
|
2005-04-13 07:19:55 +02:00
|
|
|
ConstantSDNode* CSD = NULL;
|
2005-04-06 22:25:34 +02:00
|
|
|
if(N.getOperand(0).getOpcode() == ISD::SHL &&
|
2005-04-13 07:19:55 +02:00
|
|
|
(CSD = dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) &&
|
|
|
|
(CSD->getValue() == 2 || CSD->getValue() == 3))
|
2005-04-06 22:25:34 +02:00
|
|
|
{
|
2005-04-13 07:19:55 +02:00
|
|
|
bool use4 = CSD->getValue() == 2;
|
2005-04-06 22:25:34 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-04-13 07:19:55 +02:00
|
|
|
if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) && CSD->getValue() <= 255)
|
|
|
|
BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
|
|
|
|
2, Result).addReg(Tmp2).addImm(CSD->getValue());
|
2005-04-06 22:59:59 +02:00
|
|
|
else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
2005-04-13 07:19:55 +02:00
|
|
|
BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
|
|
|
|
2, Result).addReg(Tmp2).addReg(Tmp1);
|
2005-04-06 22:59:59 +02:00
|
|
|
}
|
2005-04-06 22:25:34 +02:00
|
|
|
}
|
|
|
|
//Position prevents subs
|
2005-04-07 16:18:13 +02:00
|
|
|
else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd &&
|
2005-04-13 07:19:55 +02:00
|
|
|
(CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) &&
|
|
|
|
(CSD->getValue() == 2 || CSD->getValue() == 3))
|
2005-04-06 22:25:34 +02:00
|
|
|
{
|
2005-04-13 07:19:55 +02:00
|
|
|
bool use4 = CSD->getValue() == 2;
|
2005-04-06 22:25:34 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
|
2005-04-13 07:19:55 +02:00
|
|
|
if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(0))) && CSD->getValue() <= 255)
|
|
|
|
BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2)
|
|
|
|
.addImm(CSD->getValue());
|
2005-04-06 22:59:59 +02:00
|
|
|
else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-04-13 07:19:55 +02:00
|
|
|
BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1);
|
2005-04-06 22:59:59 +02:00
|
|
|
}
|
2005-04-06 22:25:34 +02:00
|
|
|
}
|
|
|
|
//small addi
|
2005-04-13 07:19:55 +02:00
|
|
|
else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
|
|
|
|
CSD->getValue() <= 255)
|
2005-02-10 07:25:22 +01:00
|
|
|
{ //Normal imm add/sub
|
|
|
|
Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-04-13 07:19:55 +02:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(CSD->getValue());
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
2005-04-06 22:25:34 +02:00
|
|
|
//larger addi
|
2005-04-13 07:19:55 +02:00
|
|
|
else if((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1))) &&
|
|
|
|
CSD->getSignExtended() <= 32767 &&
|
|
|
|
CSD->getSignExtended() >= -32767)
|
2005-03-02 18:23:03 +01:00
|
|
|
{ //LDA
|
2005-02-10 07:25:22 +01:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-04-13 07:19:55 +02:00
|
|
|
Tmp2 = (long)CSD->getSignExtended();
|
2005-02-10 07:25:22 +01:00
|
|
|
if (!isAdd)
|
|
|
|
Tmp2 = -Tmp2;
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result).addImm(Tmp2).addReg(Tmp1);
|
2005-04-06 22:25:34 +02:00
|
|
|
}
|
|
|
|
//give up and do the operation
|
|
|
|
else {
|
2005-02-10 07:25:22 +01:00
|
|
|
//Normal add/sub
|
|
|
|
Opc = isAdd ? Alpha::ADDQ : Alpha::SUBQ;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
2005-01-26 22:54:09 +01:00
|
|
|
return Result;
|
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
|
2005-03-22 01:24:07 +01:00
|
|
|
case ISD::SDIV:
|
2005-06-29 14:49:51 +02:00
|
|
|
if (isFP) {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS, 2, Result)
|
|
|
|
.addReg(Tmp1).addReg(Tmp2);
|
2005-06-29 15:35:05 +02:00
|
|
|
return Result;
|
2005-06-29 14:49:51 +02:00
|
|
|
} else {
|
2005-04-07 00:03:13 +02:00
|
|
|
ConstantSDNode* CSD;
|
|
|
|
//check if we can convert into a shift!
|
|
|
|
if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) &&
|
|
|
|
(int64_t)CSD->getSignExtended() != 0 &&
|
|
|
|
ExactLog2(abs((int64_t)CSD->getSignExtended())) != 0)
|
|
|
|
{
|
|
|
|
unsigned k = ExactLog2(abs(CSD->getSignExtended()));
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
if (k == 1)
|
|
|
|
Tmp2 = Tmp1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::SRAi, 2, Tmp2).addReg(Tmp1).addImm(k - 1);
|
|
|
|
}
|
|
|
|
Tmp3 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::SRLi, 2, Tmp3).addReg(Tmp2).addImm(64-k);
|
|
|
|
unsigned Tmp4 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::ADDQ, 2, Tmp4).addReg(Tmp3).addReg(Tmp1);
|
|
|
|
if ((int64_t)CSD->getSignExtended() > 0)
|
|
|
|
BuildMI(BB, Alpha::SRAi, 2, Result).addReg(Tmp4).addImm(k);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned Tmp5 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::SRAi, 2, Tmp5).addReg(Tmp4).addImm(k);
|
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp5);
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Else fall through
|
|
|
|
|
2005-04-06 22:25:34 +02:00
|
|
|
case ISD::UDIV:
|
|
|
|
{
|
2005-04-07 00:03:13 +02:00
|
|
|
ConstantSDNode* CSD;
|
|
|
|
if ((CSD = dyn_cast<ConstantSDNode>(N.getOperand(1).Val)) &&
|
|
|
|
((int64_t)CSD->getSignExtended() >= 2 ||
|
|
|
|
(int64_t)CSD->getSignExtended() <= -2))
|
|
|
|
{
|
|
|
|
// If this is a divide by constant, we can emit code using some magic
|
|
|
|
// constants to implement it as a multiply instead.
|
|
|
|
ExprMap.erase(N);
|
2005-04-22 01:13:11 +02:00
|
|
|
if (opcode == ISD::SDIV)
|
2005-04-07 00:03:13 +02:00
|
|
|
return SelectExpr(BuildSDIVSequence(N));
|
|
|
|
else
|
|
|
|
return SelectExpr(BuildUDIVSequence(N));
|
|
|
|
}
|
2005-04-06 22:25:34 +02:00
|
|
|
}
|
|
|
|
//else fall though
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::UREM:
|
2005-07-01 21:12:13 +02:00
|
|
|
case ISD::SREM: {
|
|
|
|
const char* opstr = 0;
|
2005-01-28 07:57:18 +01:00
|
|
|
switch(opcode) {
|
2005-07-01 21:12:13 +02:00
|
|
|
case ISD::UREM: opstr = "__remqu"; break;
|
|
|
|
case ISD::SREM: opstr = "__remq"; break;
|
|
|
|
case ISD::UDIV: opstr = "__divqu"; break;
|
|
|
|
case ISD::SDIV: opstr = "__divq"; break;
|
2005-01-26 22:54:09 +01:00
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
2005-07-01 21:12:13 +02:00
|
|
|
SDOperand Addr =
|
|
|
|
ISelDAG->getExternalSymbol(opstr, AlphaLowering.getPointerTy());
|
|
|
|
Tmp3 = SelectExpr(Addr);
|
2005-03-04 21:09:23 +01:00
|
|
|
//set up regs explicitly (helps Reg alloc)
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1);
|
2005-04-22 01:13:11 +02:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2);
|
2005-07-01 21:12:13 +02:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R27).addReg(Tmp3).addReg(Tmp3);
|
|
|
|
BuildMI(BB, Alpha::JSRs, 2, Alpha::R23).addReg(Alpha::R27).addImm(0);
|
2005-04-22 01:13:11 +02:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27);
|
2005-01-23 00:41:55 +01:00
|
|
|
return Result;
|
2005-07-01 21:12:13 +02:00
|
|
|
}
|
2005-01-31 02:44:26 +01:00
|
|
|
|
2005-02-01 21:40:27 +01:00
|
|
|
case ISD::FP_TO_UINT:
|
2005-01-31 02:44:26 +01:00
|
|
|
case ISD::FP_TO_SINT:
|
2005-02-10 07:25:22 +01:00
|
|
|
{
|
2005-01-31 02:44:26 +01:00
|
|
|
assert (DestType == MVT::i64 && "only quads can be loaded to");
|
|
|
|
MVT::ValueType SrcType = N.getOperand(0).getValueType();
|
2005-02-07 06:55:55 +01:00
|
|
|
assert (SrcType == MVT::f32 || SrcType == MVT::f64);
|
2005-01-31 02:44:26 +01:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
|
|
|
|
if (SrcType == MVT::f32)
|
2005-04-22 19:54:37 +02:00
|
|
|
{
|
|
|
|
Tmp2 = MakeReg(MVT::f64);
|
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Tmp1);
|
|
|
|
Tmp1 = Tmp2;
|
|
|
|
}
|
2005-01-31 02:44:26 +01:00
|
|
|
Tmp2 = MakeReg(MVT::f64);
|
|
|
|
BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Tmp1);
|
2005-04-02 23:06:51 +02:00
|
|
|
MoveFP2Int(Tmp2, Result, true);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-31 02:44:26 +01:00
|
|
|
return Result;
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
2005-01-26 22:54:09 +01:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::SELECT:
|
2005-06-29 14:49:51 +02:00
|
|
|
if (isFP) {
|
|
|
|
//Tmp1 = SelectExpr(N.getOperand(0)); //Cond
|
|
|
|
unsigned TV = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
unsigned FV = SelectExpr(N.getOperand(2)); //Use if FALSE
|
|
|
|
|
|
|
|
SDOperand CC = N.getOperand(0);
|
|
|
|
SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
|
|
|
|
|
|
|
|
if (CC.getOpcode() == ISD::SETCC &&
|
|
|
|
!MVT::isInteger(SetCC->getOperand(0).getValueType()))
|
|
|
|
{ //FP Setcc -> Select yay!
|
|
|
|
|
|
|
|
|
|
|
|
//for a cmp b: c = a - b;
|
|
|
|
//a = b: c = 0
|
|
|
|
//a < b: c < 0
|
|
|
|
//a > b: c > 0
|
|
|
|
|
|
|
|
bool invTest = false;
|
|
|
|
unsigned Tmp3;
|
|
|
|
|
|
|
|
ConstantFPSDNode *CN;
|
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
Tmp3 = SelectExpr(SetCC->getOperand(0));
|
|
|
|
else if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(0)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
{
|
|
|
|
Tmp3 = SelectExpr(SetCC->getOperand(1));
|
|
|
|
invTest = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned Tmp1 = SelectExpr(SetCC->getOperand(0));
|
|
|
|
unsigned Tmp2 = SelectExpr(SetCC->getOperand(1));
|
|
|
|
bool isD = SetCC->getOperand(0).getValueType() == MVT::f64;
|
|
|
|
Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
|
|
|
|
BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
|
|
|
|
.addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (SetCC->getCondition()) {
|
|
|
|
default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
|
|
|
|
case ISD::SETEQ: Opc = invTest ? Alpha::FCMOVNE : Alpha::FCMOVEQ; break;
|
|
|
|
case ISD::SETLT: Opc = invTest ? Alpha::FCMOVGT : Alpha::FCMOVLT; break;
|
|
|
|
case ISD::SETLE: Opc = invTest ? Alpha::FCMOVGE : Alpha::FCMOVLE; break;
|
|
|
|
case ISD::SETGT: Opc = invTest ? Alpha::FCMOVLT : Alpha::FCMOVGT; break;
|
|
|
|
case ISD::SETGE: Opc = invTest ? Alpha::FCMOVLE : Alpha::FCMOVGE; break;
|
|
|
|
case ISD::SETNE: Opc = invTest ? Alpha::FCMOVEQ : Alpha::FCMOVNE; break;
|
|
|
|
}
|
|
|
|
BuildMI(BB, Opc, 3, Result).addReg(FV).addReg(TV).addReg(Tmp3);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0)); //Cond
|
|
|
|
BuildMI(BB, Alpha::FCMOVEQ_INT, 3, Result).addReg(TV).addReg(FV)
|
|
|
|
.addReg(Tmp1);
|
|
|
|
// // Spill the cond to memory and reload it from there.
|
|
|
|
// unsigned Tmp4 = MakeReg(MVT::f64);
|
|
|
|
// MoveIntFP(Tmp1, Tmp4, true);
|
|
|
|
// //now ideally, we don't have to do anything to the flag...
|
|
|
|
// // Get the condition into the zero flag.
|
|
|
|
// BuildMI(BB, Alpha::FCMOVEQ, 3, Result).addReg(TV).addReg(FV).addReg(Tmp4);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
} else {
|
2005-06-27 19:39:17 +02:00
|
|
|
//FIXME: look at parent to decide if intCC can be folded, or if setCC(FP)
|
|
|
|
//and can save stack use
|
2005-04-03 00:32:39 +02:00
|
|
|
//Tmp1 = SelectExpr(N.getOperand(0)); //Cond
|
2005-04-03 22:35:21 +02:00
|
|
|
//Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
//Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
2005-01-23 00:41:55 +01:00
|
|
|
// Get the condition into the zero flag.
|
2005-04-03 00:32:39 +02:00
|
|
|
//BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
|
2005-04-03 22:35:21 +02:00
|
|
|
|
2005-04-03 00:32:39 +02:00
|
|
|
SDOperand CC = N.getOperand(0);
|
|
|
|
SetCCSDNode* SetCC = dyn_cast<SetCCSDNode>(CC.Val);
|
|
|
|
|
2005-04-22 01:13:11 +02:00
|
|
|
if (CC.getOpcode() == ISD::SETCC &&
|
2005-04-03 00:32:39 +02:00
|
|
|
!MVT::isInteger(SetCC->getOperand(0).getValueType()))
|
|
|
|
{ //FP Setcc -> Int Select
|
2005-04-22 19:54:37 +02:00
|
|
|
Tmp1 = MakeReg(MVT::f64);
|
2005-04-03 22:35:21 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
2005-04-22 19:54:37 +02:00
|
|
|
bool inv = SelectFPSetCC(CC, Tmp1);
|
|
|
|
BuildMI(BB, inv?Alpha::CMOVNE_FP:Alpha::CMOVEQ_FP, 2, Result)
|
|
|
|
.addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
|
|
|
|
return Result;
|
2005-04-03 00:32:39 +02:00
|
|
|
}
|
|
|
|
if (CC.getOpcode() == ISD::SETCC) {
|
2005-04-22 19:54:37 +02:00
|
|
|
//Int SetCC -> Select
|
|
|
|
//Dropping the CC is only useful if we are comparing to 0
|
|
|
|
if((SetCC->getOperand(1).getOpcode() == ISD::Constant &&
|
2005-06-27 01:01:11 +02:00
|
|
|
cast<ConstantSDNode>(SetCC->getOperand(1))->getValue() == 0))
|
2005-04-03 22:35:21 +02:00
|
|
|
{
|
|
|
|
//figure out a few things
|
2005-06-27 01:01:11 +02:00
|
|
|
bool useImm = N.getOperand(2).getOpcode() == ISD::Constant &&
|
2005-04-03 22:35:21 +02:00
|
|
|
cast<ConstantSDNode>(N.getOperand(2))->getValue() <= 255;
|
|
|
|
|
|
|
|
//Fix up CC
|
|
|
|
ISD::CondCode cCode= SetCC->getCondition();
|
2005-06-27 01:01:11 +02:00
|
|
|
if (useImm) //Invert sense to get Imm field right
|
2005-04-03 22:35:21 +02:00
|
|
|
cCode = ISD::getSetCCInverse(cCode, true);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-04-03 22:35:21 +02:00
|
|
|
//Choose the CMOV
|
|
|
|
switch (cCode) {
|
|
|
|
default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
|
2005-06-27 19:39:17 +02:00
|
|
|
case ISD::SETEQ: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
|
|
|
|
case ISD::SETLT: Opc = useImm?Alpha::CMOVLTi:Alpha::CMOVLT; break;
|
|
|
|
case ISD::SETLE: Opc = useImm?Alpha::CMOVLEi:Alpha::CMOVLE; break;
|
|
|
|
case ISD::SETGT: Opc = useImm?Alpha::CMOVGTi:Alpha::CMOVGT; break;
|
|
|
|
case ISD::SETGE: Opc = useImm?Alpha::CMOVGEi:Alpha::CMOVGE; break;
|
|
|
|
case ISD::SETULT: assert(0 && "unsigned < 0 is never true"); break;
|
|
|
|
case ISD::SETUGT: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
|
|
|
|
//Technically you could have this CC
|
|
|
|
case ISD::SETULE: Opc = useImm?Alpha::CMOVEQi:Alpha::CMOVEQ; break;
|
|
|
|
case ISD::SETUGE: assert(0 && "unsgined >= 0 is always true"); break;
|
|
|
|
case ISD::SETNE: Opc = useImm?Alpha::CMOVNEi:Alpha::CMOVNE; break;
|
2005-04-03 22:35:21 +02:00
|
|
|
}
|
2005-06-27 01:01:11 +02:00
|
|
|
Tmp1 = SelectExpr(SetCC->getOperand(0)); //Cond
|
|
|
|
|
|
|
|
if (useImm) {
|
2005-04-03 22:35:21 +02:00
|
|
|
Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp3)
|
2005-04-22 19:54:37 +02:00
|
|
|
.addImm(cast<ConstantSDNode>(N.getOperand(2))->getValue())
|
2005-04-03 22:35:21 +02:00
|
|
|
.addReg(Tmp1);
|
|
|
|
} else {
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addReg(Tmp2).addReg(Tmp1);
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 19:54:37 +02:00
|
|
|
//Otherwise, fall though
|
2005-04-03 00:32:39 +02:00
|
|
|
}
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0)); //Cond
|
2005-04-03 22:35:21 +02:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3)
|
|
|
|
.addReg(Tmp1);
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::Constant:
|
|
|
|
{
|
2005-03-29 21:24:04 +02:00
|
|
|
int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
|
2005-03-11 18:48:05 +01:00
|
|
|
if (val <= IMM_HIGH && val >= IMM_LOW) {
|
2005-04-22 19:54:37 +02:00
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31);
|
2005-03-11 18:48:05 +01:00
|
|
|
}
|
2005-04-22 19:54:37 +02:00
|
|
|
else if (val <= (int64_t)IMM_HIGH +(int64_t)IMM_HIGH* (int64_t)IMM_MULT &&
|
|
|
|
val >= (int64_t)IMM_LOW + (int64_t)IMM_LOW * (int64_t)IMM_MULT) {
|
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val))
|
|
|
|
.addReg(Alpha::R31);
|
2005-04-22 19:54:37 +02:00
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1);
|
2005-03-11 18:48:05 +01:00
|
|
|
}
|
2005-02-10 07:25:22 +01:00
|
|
|
else {
|
|
|
|
MachineConstantPool *CP = BB->getParent()->getConstantPool();
|
2005-06-27 19:39:17 +02:00
|
|
|
ConstantUInt *C =
|
|
|
|
ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
|
2005-02-10 07:25:22 +01:00
|
|
|
unsigned CPI = CP->getConstantPoolIndex(C);
|
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-06-27 19:15:36 +02:00
|
|
|
has_sym = true;
|
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPI)
|
|
|
|
.addReg(Alpha::R29);
|
2005-07-01 21:12:13 +02:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::LDQr, 2, Result).addConstantPoolIndex(CPI)
|
|
|
|
.addReg(Tmp1);
|
2005-02-10 07:25:22 +01:00
|
|
|
}
|
|
|
|
return Result;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-06-29 14:49:51 +02:00
|
|
|
case ISD::FNEG:
|
|
|
|
if(ISD::FABS == N.getOperand(0).getOpcode())
|
|
|
|
{
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
|
|
|
|
} else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Tmp1).addReg(Tmp1);
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
case ISD::FABS:
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31).addReg(Tmp1);
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
case ISD::FP_ROUND:
|
|
|
|
assert (DestType == MVT::f32 &&
|
|
|
|
N.getOperand(0).getValueType() == MVT::f64 &&
|
|
|
|
"only f64 to f32 conversion supported here");
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Tmp1);
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
case ISD::FP_EXTEND:
|
|
|
|
assert (DestType == MVT::f64 &&
|
|
|
|
N.getOperand(0).getValueType() == MVT::f32 &&
|
|
|
|
"only f32 to f64 conversion supported here");
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Tmp1);
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
case ISD::ConstantFP:
|
|
|
|
if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N)) {
|
|
|
|
if (CN->isExactlyValue(+0.0)) {
|
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F31)
|
|
|
|
.addReg(Alpha::F31);
|
|
|
|
} else if ( CN->isExactlyValue(-0.0)) {
|
|
|
|
BuildMI(BB, Alpha::CPYSN, 2, Result).addReg(Alpha::F31)
|
|
|
|
.addReg(Alpha::F31);
|
|
|
|
} else {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
{
|
|
|
|
assert (N.getOperand(0).getValueType() == MVT::i64
|
|
|
|
&& "only quads can be loaded from");
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
|
|
|
|
Tmp2 = MakeReg(MVT::f64);
|
|
|
|
MoveInt2FP(Tmp1, Tmp2, true);
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::CVTQT : Alpha::CVTQS;
|
|
|
|
BuildMI(BB, Opc, 1, Result).addReg(Tmp2);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-22 19:19:45 +02:00
|
|
|
void AlphaISel::Select(SDOperand N) {
|
2005-01-23 00:41:55 +01:00
|
|
|
unsigned Tmp1, Tmp2, Opc;
|
2005-02-08 00:02:23 +01:00
|
|
|
unsigned opcode = N.getOpcode();
|
2005-01-23 00:41:55 +01:00
|
|
|
|
2005-03-24 05:39:54 +01:00
|
|
|
if (!ExprMap.insert(std::make_pair(N, notIn)).second)
|
2005-01-28 15:06:46 +01:00
|
|
|
return; // Already selected.
|
2005-01-23 00:41:55 +01:00
|
|
|
|
|
|
|
SDNode *Node = N.Val;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-02-08 00:02:23 +01:00
|
|
|
switch (opcode) {
|
2005-01-23 00:41:55 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
Node->dump(); std::cerr << "\n";
|
|
|
|
assert(0 && "Node not handled yet!");
|
|
|
|
|
|
|
|
case ISD::BRCOND: {
|
2005-02-08 01:40:03 +01:00
|
|
|
SelectBranchCC(N);
|
2005-01-23 00:41:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::BR: {
|
|
|
|
MachineBasicBlock *Dest =
|
|
|
|
cast<BasicBlockSDNode>(N.getOperand(1))->getBasicBlock();
|
|
|
|
|
|
|
|
Select(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::BR, 1, Alpha::R31).addMBB(Dest);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::ImplicitDef:
|
2005-04-08 19:28:49 +02:00
|
|
|
++count_ins;
|
2005-01-23 00:41:55 +01:00
|
|
|
Select(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::IDEF, 0, cast<RegSDNode>(N)->getReg());
|
|
|
|
return;
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::EntryToken: return; // Noop
|
|
|
|
|
|
|
|
case ISD::TokenFactor:
|
|
|
|
for (unsigned i = 0, e = Node->getNumOperands(); i != e; ++i)
|
|
|
|
Select(Node->getOperand(i));
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
//N.Val->dump(); std::cerr << "\n";
|
|
|
|
//assert(0 && "Node not handled yet!");
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ISD::CopyToReg:
|
2005-04-08 19:28:49 +02:00
|
|
|
++count_outs;
|
2005-01-23 00:41:55 +01:00
|
|
|
Select(N.getOperand(0));
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
Tmp2 = cast<RegSDNode>(N)->getReg();
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-01-23 00:41:55 +01:00
|
|
|
if (Tmp1 != Tmp2) {
|
2005-04-22 01:13:11 +02:00
|
|
|
if (N.getOperand(1).getValueType() == MVT::f64 ||
|
2005-02-10 07:25:22 +01:00
|
|
|
N.getOperand(1).getValueType() == MVT::f32)
|
2005-02-07 07:31:44 +01:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
|
|
|
|
else
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Tmp2).addReg(Tmp1).addReg(Tmp1);
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2005-02-10 07:25:22 +01:00
|
|
|
case ISD::RET:
|
2005-04-08 19:28:49 +02:00
|
|
|
++count_outs;
|
2005-02-10 07:25:22 +01:00
|
|
|
switch (N.getNumOperands()) {
|
|
|
|
default:
|
|
|
|
std::cerr << N.getNumOperands() << "\n";
|
|
|
|
for (unsigned i = 0; i < N.getNumOperands(); ++i)
|
|
|
|
std::cerr << N.getOperand(i).getValueType() << "\n";
|
|
|
|
Node->dump();
|
|
|
|
assert(0 && "Unknown return instruction!");
|
|
|
|
case 2:
|
|
|
|
Select(N.getOperand(0));
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
switch (N.getOperand(1).getValueType()) {
|
2005-04-22 01:13:11 +02:00
|
|
|
default: Node->dump();
|
2005-02-10 07:25:22 +01:00
|
|
|
assert(0 && "All other types should have been promoted!!");
|
|
|
|
case MVT::f64:
|
|
|
|
case MVT::f32:
|
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Alpha::F0).addReg(Tmp1).addReg(Tmp1);
|
|
|
|
break;
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R0).addReg(Tmp1).addReg(Tmp1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
Select(N.getOperand(0));
|
|
|
|
break;
|
|
|
|
}
|
2005-06-27 19:39:17 +02:00
|
|
|
// Just emit a 'ret' instruction
|
2005-06-28 01:24:11 +02:00
|
|
|
AlphaLowering.restoreRA(BB);
|
|
|
|
BuildMI(BB, Alpha::RET, 1, Alpha::R31).addReg(Alpha::R26);
|
2005-02-10 07:25:22 +01:00
|
|
|
return;
|
2005-01-23 00:41:55 +01:00
|
|
|
|
2005-04-22 01:13:11 +02:00
|
|
|
case ISD::TRUNCSTORE:
|
|
|
|
case ISD::STORE:
|
2005-02-02 18:32:39 +01:00
|
|
|
{
|
2005-02-06 16:40:40 +01:00
|
|
|
SDOperand Chain = N.getOperand(0);
|
|
|
|
SDOperand Value = N.getOperand(1);
|
|
|
|
SDOperand Address = N.getOperand(2);
|
|
|
|
Select(Chain);
|
|
|
|
|
|
|
|
Tmp1 = SelectExpr(Value); //value
|
2005-02-08 00:02:23 +01:00
|
|
|
|
|
|
|
if (opcode == ISD::STORE) {
|
|
|
|
switch(Value.getValueType()) {
|
|
|
|
default: assert(0 && "unknown Type in store");
|
|
|
|
case MVT::i64: Opc = Alpha::STQ; break;
|
|
|
|
case MVT::f64: Opc = Alpha::STT; break;
|
|
|
|
case MVT::f32: Opc = Alpha::STS; break;
|
|
|
|
}
|
|
|
|
} else { //ISD::TRUNCSTORE
|
2005-07-10 02:29:18 +02:00
|
|
|
switch(cast<VTSDNode>(Node->getOperand(4))->getVT()) {
|
2005-02-08 00:02:23 +01:00
|
|
|
default: assert(0 && "unknown Type in store");
|
|
|
|
case MVT::i1: //FIXME: DAG does not promote this load
|
|
|
|
case MVT::i8: Opc = Alpha::STB; break;
|
|
|
|
case MVT::i16: Opc = Alpha::STW; break;
|
|
|
|
case MVT::i32: Opc = Alpha::STL; break;
|
|
|
|
}
|
2005-02-06 17:22:15 +01:00
|
|
|
}
|
2005-02-08 00:02:23 +01:00
|
|
|
|
2005-06-29 20:54:02 +02:00
|
|
|
int i, j, k;
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
getValueInfo(dyn_cast<SrcValueSDNode>(N.getOperand(3))->getValue(),
|
|
|
|
i, j, k);
|
2005-06-22 19:19:45 +02:00
|
|
|
|
2005-07-01 21:12:13 +02:00
|
|
|
GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(Address);
|
|
|
|
if (GASD && !GASD->getGlobal()->isExternal()) {
|
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
AlphaLowering.restoreGP(BB);
|
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp2)
|
|
|
|
.addGlobalAddress(GASD->getGlobal()).addReg(Alpha::R29);
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
|
|
|
BuildMI(BB, GetRelVersion(Opc), 3).addReg(Tmp1)
|
|
|
|
.addGlobalAddress(GASD->getGlobal()).addReg(Tmp2);
|
2005-06-29 02:39:17 +02:00
|
|
|
} else if(Address.getOpcode() == ISD::FrameIndex) {
|
2005-06-29 02:31:08 +02:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-29 20:54:02 +02:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-22 22:59:48 +01:00
|
|
|
BuildMI(BB, Opc, 3).addReg(Tmp1)
|
|
|
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
|
|
|
.addReg(Alpha::F31);
|
2005-06-29 02:31:08 +02:00
|
|
|
} else {
|
2005-02-10 07:25:22 +01:00
|
|
|
long offset;
|
|
|
|
SelectAddr(Address, Tmp2, offset);
|
2005-06-29 02:31:08 +02:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-29 20:54:02 +02:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-10 07:25:22 +01:00
|
|
|
BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
|
|
|
|
}
|
2005-02-02 18:32:39 +01:00
|
|
|
return;
|
|
|
|
}
|
2005-01-23 00:41:55 +01:00
|
|
|
|
|
|
|
case ISD::EXTLOAD:
|
|
|
|
case ISD::SEXTLOAD:
|
|
|
|
case ISD::ZEXTLOAD:
|
|
|
|
case ISD::LOAD:
|
|
|
|
case ISD::CopyFromReg:
|
2005-05-13 22:29:26 +02:00
|
|
|
case ISD::TAILCALL:
|
2005-01-23 00:41:55 +01:00
|
|
|
case ISD::CALL:
|
2005-02-22 22:59:48 +01:00
|
|
|
case ISD::DYNAMIC_STACKALLOC:
|
2005-01-28 15:06:46 +01:00
|
|
|
ExprMap.erase(N);
|
2005-01-23 00:41:55 +01:00
|
|
|
SelectExpr(N);
|
|
|
|
return;
|
|
|
|
|
2005-05-13 01:24:06 +02:00
|
|
|
case ISD::CALLSEQ_START:
|
|
|
|
case ISD::CALLSEQ_END:
|
2005-01-23 00:41:55 +01:00
|
|
|
Select(N.getOperand(0));
|
|
|
|
Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
|
2005-04-22 01:13:11 +02:00
|
|
|
|
2005-05-13 01:24:06 +02:00
|
|
|
Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN :
|
2005-01-23 00:41:55 +01:00
|
|
|
Alpha::ADJUSTSTACKUP;
|
|
|
|
BuildMI(BB, Opc, 1).addImm(Tmp1);
|
|
|
|
return;
|
2005-03-31 23:24:06 +02:00
|
|
|
|
|
|
|
case ISD::PCMARKER:
|
|
|
|
Select(N.getOperand(0)); //Chain
|
2005-06-27 19:39:17 +02:00
|
|
|
BuildMI(BB, Alpha::PCLABEL, 2)
|
|
|
|
.addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue());
|
2005-03-31 23:24:06 +02:00
|
|
|
return;
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
|
|
|
assert(0 && "Should not be reached!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// createAlphaPatternInstructionSelector - This pass converts an LLVM function
|
|
|
|
/// into a machine code representation using pattern matching and a machine
|
|
|
|
/// description file.
|
|
|
|
///
|
|
|
|
FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
|
2005-06-22 19:19:45 +02:00
|
|
|
return new AlphaISel(TM);
|
2005-01-23 00:41:55 +01:00
|
|
|
}
|
2005-04-13 07:19:55 +02:00
|
|
|
|