2005-02-05 10:24:26 +08:00
|
|
|
//===- AlphaISelPattern.cpp - A pattern matching inst selector for Alpha --===//
|
2005-04-22 07:13:11 +08:00
|
|
|
//
|
2005-01-23 07:41:55 +08: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 07:13:11 +08:00
|
|
|
//
|
2005-01-23 07:41:55 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a pattern matching instruction selector for Alpha.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Alpha.h"
|
|
|
|
#include "AlphaRegisterInfo.h"
|
2005-09-30 06:54:56 +08:00
|
|
|
#include "AlphaTargetMachine.h"
|
2005-09-03 02:46:02 +08:00
|
|
|
#include "AlphaISelLowering.h"
|
2005-01-23 07:41:55 +08:00
|
|
|
#include "llvm/Constants.h" // FIXME: REMOVE
|
|
|
|
#include "llvm/Function.h"
|
2005-06-23 01:19:45 +08:00
|
|
|
#include "llvm/Module.h"
|
2005-01-23 07:41:55 +08: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-23 05:59:48 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2005-04-01 05:24:06 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2005-01-23 07:41:55 +08:00
|
|
|
#include <set>
|
2005-01-30 08:35:27 +08:00
|
|
|
#include <algorithm>
|
2005-01-23 07:41:55 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2005-04-01 05:24:06 +08:00
|
|
|
namespace llvm {
|
2005-04-22 07:13:11 +08:00
|
|
|
cl::opt<bool> EnableAlphaIDIV("enable-alpha-intfpdiv",
|
2005-06-28 01:39:17 +08:00
|
|
|
cl::desc("Use the FP div instruction for integer div when possible"),
|
2005-04-01 05:24:06 +08:00
|
|
|
cl::Hidden);
|
2005-04-22 07:13:11 +08:00
|
|
|
cl::opt<bool> EnableAlphaCount("enable-alpha-count",
|
2005-06-28 01:39:17 +08:00
|
|
|
cl::desc("Print estimates on live ins and outs"),
|
|
|
|
cl::Hidden);
|
2005-06-07 03:03:55 +08:00
|
|
|
cl::opt<bool> EnableAlphaLSMark("enable-alpha-lsmark",
|
2005-06-28 01:39:17 +08:00
|
|
|
cl::desc("Emit symbols to correlate Mem ops to LLVM Values"),
|
|
|
|
cl::Hidden);
|
2005-04-01 05:24:06 +08:00
|
|
|
}
|
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
namespace {
|
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// ISel - Alpha specific code to select Alpha machine instructions for
|
|
|
|
/// SelectionDAG operations.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2005-06-23 01:19:45 +08:00
|
|
|
class AlphaISel : public SelectionDAGISel {
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
/// AlphaLowering - This object fully describes how to lower LLVM code to an
|
|
|
|
/// Alpha-specific SelectionDAG.
|
|
|
|
AlphaTargetLowering AlphaLowering;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-04-07 04:25:34 +08: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 14:25:22 +08: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 07:13:11 +08:00
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
//CCInvMap sometimes (SetNE) we have the inverse CC code for free
|
|
|
|
std::map<SDOperand, unsigned> CCInvMap;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-04-09 01:28:49 +08:00
|
|
|
int count_ins;
|
|
|
|
int count_outs;
|
|
|
|
bool has_sym;
|
2005-04-22 21:35:18 +08:00
|
|
|
int max_depth;
|
2005-04-09 01:28:49 +08:00
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
public:
|
2005-07-27 14:12:32 +08:00
|
|
|
AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering),
|
2005-06-28 01:39:17 +08:00
|
|
|
AlphaLowering(TM)
|
2005-02-10 14:25:22 +08:00
|
|
|
{}
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-10 14:25:22 +08: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-23 05:59:48 +08:00
|
|
|
DEBUG(BB->dump());
|
2005-04-09 01:28:49 +08:00
|
|
|
count_ins = 0;
|
|
|
|
count_outs = 0;
|
2005-04-22 21:35:18 +08:00
|
|
|
max_depth = 0;
|
2005-04-09 01:28:49 +08:00
|
|
|
has_sym = false;
|
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
// Codegen the basic block.
|
2005-04-07 04:25:34 +08:00
|
|
|
ISelDAG = &DAG;
|
2005-04-22 21:35:18 +08:00
|
|
|
max_depth = DAG.getRoot().getNodeDepth();
|
2005-02-10 14:25:22 +08:00
|
|
|
Select(DAG.getRoot());
|
2005-04-09 01:28:49 +08:00
|
|
|
|
|
|
|
if(has_sym)
|
|
|
|
++count_ins;
|
|
|
|
if(EnableAlphaCount)
|
2005-07-27 14:12:32 +08:00
|
|
|
std::cerr << "COUNT: "
|
|
|
|
<< BB->getParent()->getFunction ()->getName() << " "
|
|
|
|
<< BB->getNumber() << " "
|
2005-04-22 21:35:18 +08:00
|
|
|
<< max_depth << " "
|
2005-04-09 01:28:49 +08:00
|
|
|
<< count_ins << " "
|
|
|
|
<< count_outs << "\n";
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
// Clear state used for selection.
|
|
|
|
ExprMap.clear();
|
|
|
|
CCInvMap.clear();
|
|
|
|
}
|
2005-07-27 14:12:32 +08:00
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
unsigned SelectExpr(SDOperand N);
|
|
|
|
void Select(SDOperand N);
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
void SelectAddr(SDOperand N, unsigned& Reg, long& offset);
|
|
|
|
void SelectBranchCC(SDOperand N);
|
2005-04-03 05:06:51 +08:00
|
|
|
void MoveFP2Int(unsigned src, unsigned dst, bool isDouble);
|
|
|
|
void MoveInt2FP(unsigned src, unsigned dst, bool isDouble);
|
2005-04-03 06:32:39 +08:00
|
|
|
//returns whether the sense of the comparison was inverted
|
|
|
|
bool SelectFPSetCC(SDOperand N, unsigned dst);
|
2005-04-07 04:25:34 +08:00
|
|
|
|
|
|
|
// dag -> dag expanders for integer divide by constant
|
|
|
|
SDOperand BuildSDIVSequence(SDOperand N);
|
|
|
|
SDOperand BuildUDIVSequence(SDOperand N);
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-08-15 22:31:37 +08:00
|
|
|
static bool isSIntImmediate(SDOperand N, int64_t& Imm) {
|
|
|
|
// test for constant
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) {
|
|
|
|
// retrieve value
|
|
|
|
Imm = CN->getSignExtended();
|
|
|
|
// passes muster
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// not a constant
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// isSIntImmediateBounded - This method tests to see if a constant operand
|
|
|
|
// bounded s.t. low <= Imm <= high
|
|
|
|
// If so Imm will receive the 64 bit value.
|
|
|
|
static bool isSIntImmediateBounded(SDOperand N, int64_t& Imm,
|
|
|
|
int64_t low, int64_t high) {
|
2005-08-17 08:47:24 +08:00
|
|
|
if (isSIntImmediate(N, Imm) && Imm <= high && Imm >= low)
|
2005-08-15 22:31:37 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool isUIntImmediate(SDOperand N, uint64_t& Imm) {
|
|
|
|
// test for constant
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) {
|
|
|
|
// retrieve value
|
|
|
|
Imm = (uint64_t)CN->getValue();
|
|
|
|
// passes muster
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// not a constant
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isUIntImmediateBounded(SDOperand N, uint64_t& Imm,
|
|
|
|
uint64_t low, uint64_t high) {
|
2005-08-17 08:47:24 +08:00
|
|
|
if (isUIntImmediate(N, Imm) && Imm <= high && Imm >= low)
|
2005-08-15 22:31:37 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-30 02:54:02 +08:00
|
|
|
static void getValueInfo(const Value* v, int& type, int& fun, int& offset)
|
2005-06-07 03:03:55 +08:00
|
|
|
{
|
2005-07-12 12:20:52 +08:00
|
|
|
fun = type = offset = 0;
|
2005-06-30 02:54:02 +08:00
|
|
|
if (v == NULL) {
|
|
|
|
type = 0;
|
|
|
|
} else if (const GlobalValue* GV = dyn_cast<GlobalValue>(v)) {
|
|
|
|
type = 1;
|
|
|
|
const Module* M = GV->getParent();
|
2005-07-12 12:20:52 +08:00
|
|
|
for(Module::const_global_iterator ii = M->global_begin(); &*ii != GV; ++ii)
|
|
|
|
++offset;
|
2005-06-30 02:54:02 +08:00
|
|
|
} else if (const Argument* Arg = dyn_cast<Argument>(v)) {
|
|
|
|
type = 2;
|
|
|
|
const Function* F = Arg->getParent();
|
|
|
|
const Module* M = F->getParent();
|
|
|
|
for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
|
2005-07-12 12:20:52 +08:00
|
|
|
++fun;
|
2005-06-30 02:54:02 +08:00
|
|
|
for(Function::const_arg_iterator ii = F->arg_begin(); &*ii != Arg; ++ii)
|
2005-07-12 12:20:52 +08:00
|
|
|
++offset;
|
2005-06-30 02:54:02 +08:00
|
|
|
} else if (const Instruction* I = dyn_cast<Instruction>(v)) {
|
2005-07-08 03:52:58 +08:00
|
|
|
assert(dyn_cast<PointerType>(I->getType()));
|
2005-06-30 02:54:02 +08:00
|
|
|
type = 3;
|
|
|
|
const BasicBlock* bb = I->getParent();
|
|
|
|
const Function* F = bb->getParent();
|
|
|
|
const Module* M = F->getParent();
|
|
|
|
for(Module::const_iterator ii = M->begin(); &*ii != F; ++ii)
|
2005-07-12 12:20:52 +08:00
|
|
|
++fun;
|
2005-06-30 02:54:02 +08:00
|
|
|
for(Function::const_iterator ii = F->begin(); &*ii != bb; ++ii)
|
2005-07-12 12:20:52 +08:00
|
|
|
offset += ii->size();
|
2005-06-30 02:54:02 +08:00
|
|
|
for(BasicBlock::const_iterator ii = bb->begin(); &*ii != I; ++ii)
|
2005-07-12 12:20:52 +08:00
|
|
|
++offset;
|
2005-07-08 03:52:58 +08:00
|
|
|
} else if (const Constant* C = dyn_cast<Constant>(v)) {
|
|
|
|
//Don't know how to look these up yet
|
|
|
|
type = 0;
|
|
|
|
} else {
|
|
|
|
assert(0 && "Error in value marking");
|
2005-06-30 02:54:02 +08:00
|
|
|
}
|
2005-07-02 03:12:13 +08:00
|
|
|
//type = 4: register spilling
|
|
|
|
//type = 5: global address loading or constant loading
|
2005-06-23 01:19:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int getUID()
|
|
|
|
{
|
|
|
|
static int id = 0;
|
|
|
|
return ++id;
|
|
|
|
}
|
2005-06-07 03:03:55 +08:00
|
|
|
|
2005-04-09 01:28:49 +08: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-03-12 01:48:05 +08:00
|
|
|
//These describe LDAx
|
2005-03-30 03:24:04 +08:00
|
|
|
static const int IMM_LOW = -32768;
|
|
|
|
static const int IMM_HIGH = 32767;
|
2005-03-12 01:48:05 +08: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-28 01:15:36 +08: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 08:39:17 +08: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-28 01:15:36 +08:00
|
|
|
}
|
|
|
|
}
|
2005-02-07 00:22:15 +08:00
|
|
|
|
2005-06-23 01:19:45 +08:00
|
|
|
void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
|
2005-04-03 05:06:51 +08:00
|
|
|
{
|
|
|
|
unsigned Opc;
|
2005-09-30 06:54:56 +08:00
|
|
|
if (TLI.getTargetMachine().getSubtarget<AlphaSubtarget>().hasF2I()) {
|
2005-04-03 05:06:51 +08:00
|
|
|
Opc = isDouble ? Alpha::FTOIT : Alpha::FTOIS;
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Opc, 1, dst).addReg(src).addReg(Alpha::F31);
|
2005-04-03 05:06:51 +08:00
|
|
|
} 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-02 03:12:13 +08:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-03 05:06:51 +08:00
|
|
|
Opc = isDouble ? Alpha::STT : Alpha::STS;
|
|
|
|
BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-07-02 03:12:13 +08:00
|
|
|
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-03 05:06:51 +08:00
|
|
|
Opc = isDouble ? Alpha::LDQ : Alpha::LDL;
|
|
|
|
BuildMI(BB, Alpha::LDQ, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:19:45 +08:00
|
|
|
void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
|
2005-04-03 05:06:51 +08:00
|
|
|
{
|
|
|
|
unsigned Opc;
|
2005-09-30 06:54:56 +08:00
|
|
|
if (TLI.getTargetMachine().getSubtarget<AlphaSubtarget>().hasF2I()) {
|
2005-04-03 05:06:51 +08:00
|
|
|
Opc = isDouble?Alpha::ITOFT:Alpha::ITOFS;
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Opc, 1, dst).addReg(src).addReg(Alpha::R31);
|
2005-04-03 05:06:51 +08:00
|
|
|
} 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-02 03:12:13 +08:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-03 05:06:51 +08:00
|
|
|
Opc = isDouble ? Alpha::STQ : Alpha::STL;
|
|
|
|
BuildMI(BB, Opc, 3).addReg(src).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-07-02 03:12:13 +08:00
|
|
|
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(4).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-04-03 05:06:51 +08:00
|
|
|
Opc = isDouble ? Alpha::LDT : Alpha::LDS;
|
|
|
|
BuildMI(BB, Opc, 2, dst).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:19:45 +08:00
|
|
|
bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst)
|
2005-04-03 06:32:39 +08:00
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
SDNode *SetCC = N.Val;
|
2005-04-03 06:32:39 +08:00
|
|
|
unsigned Opc, Tmp1, Tmp2, Tmp3;
|
2005-08-10 04:21:10 +08:00
|
|
|
ISD::CondCode CC = cast<CondCodeSDNode>(SetCC->getOperand(2))->get();
|
2005-04-03 06:32:39 +08:00
|
|
|
bool rev = false;
|
|
|
|
bool inv = false;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-08-10 04:21:10 +08:00
|
|
|
switch (CC) {
|
|
|
|
default: SetCC->dump(); assert(0 && "Unknown FP comparison!");
|
2005-04-03 06:32:39 +08:00
|
|
|
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 07:13:11 +08:00
|
|
|
|
2005-04-03 06:32:39 +08: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 07:13:11 +08:00
|
|
|
|
2005-04-03 06:32:39 +08:00
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(SetCC->getOperand(1)))
|
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
Tmp2 = Alpha::F31;
|
|
|
|
else
|
2005-04-30 12:44:07 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-04-03 06:32:39 +08: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);
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Alpha::F31).addReg(Tmp1);
|
2005-04-03 06:32:39 +08:00
|
|
|
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);
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Alpha::F31).addReg(Tmp2);
|
2005-04-03 06:32:39 +08:00
|
|
|
Tmp2 = Tmp3;
|
|
|
|
}
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-04-03 06:32:39 +08:00
|
|
|
if (rev) std::swap(Tmp1, Tmp2);
|
|
|
|
//do the comparison
|
|
|
|
BuildMI(BB, Opc, 2, dst).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
return inv;
|
|
|
|
}
|
|
|
|
|
2005-02-06 23:40:40 +08:00
|
|
|
//Check to see if the load is a constant offset from a base register
|
2005-06-23 01:19:45 +08:00
|
|
|
void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
|
2005-02-06 23:40:40 +08:00
|
|
|
{
|
|
|
|
unsigned opcode = N.getOpcode();
|
2005-06-27 07:01:11 +08: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 23:40:40 +08:00
|
|
|
}
|
|
|
|
Reg = SelectExpr(N);
|
|
|
|
offset = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:19:45 +08:00
|
|
|
void AlphaISel::SelectBranchCC(SDOperand N)
|
2005-02-08 08:40:03 +08:00
|
|
|
{
|
|
|
|
assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
|
2005-04-22 07:13:11 +08:00
|
|
|
MachineBasicBlock *Dest =
|
2005-02-10 14:25:22 +08:00
|
|
|
cast<BasicBlockSDNode>(N.getOperand(2))->getBasicBlock();
|
|
|
|
unsigned Opc = Alpha::WTF;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-08 08:40:03 +08:00
|
|
|
Select(N.getOperand(0)); //chain
|
|
|
|
SDOperand CC = N.getOperand(1);
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-08 08:40:03 +08:00
|
|
|
if (CC.getOpcode() == ISD::SETCC)
|
2005-02-10 14:25:22 +08:00
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
ISD::CondCode cCode= cast<CondCodeSDNode>(CC.getOperand(2))->get();
|
|
|
|
if (MVT::isInteger(CC.getOperand(0).getValueType())) {
|
2005-02-10 14:25:22 +08:00
|
|
|
//Dropping the CC is only useful if we are comparing to 0
|
2005-08-10 04:21:10 +08:00
|
|
|
bool RightZero = CC.getOperand(1).getOpcode() == ISD::Constant &&
|
|
|
|
cast<ConstantSDNode>(CC.getOperand(1))->getValue() == 0;
|
2005-02-10 14:25:22 +08:00
|
|
|
bool isNE = false;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-04-04 04:35:21 +08:00
|
|
|
//Fix up CC
|
|
|
|
if(cCode == ISD::SETNE)
|
2005-02-10 14:25:22 +08:00
|
|
|
isNE = true;
|
|
|
|
|
2005-06-27 07:01:11 +08:00
|
|
|
if (RightZero) {
|
2005-06-09 02:02:21 +08:00
|
|
|
switch (cCode) {
|
2005-02-10 14:25:22 +08: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-28 01:39:17 +08:00
|
|
|
//Technically you could have this CC
|
|
|
|
case ISD::SETULE: Opc = Alpha::BEQ; break;
|
2005-02-10 14:25:22 +08:00
|
|
|
case ISD::SETUGE: assert(0 && "x (unsgined >= 0 is always true"); break;
|
|
|
|
case ISD::SETNE: Opc = Alpha::BNE; break;
|
|
|
|
}
|
2005-08-10 04:21:10 +08:00
|
|
|
unsigned Tmp1 = SelectExpr(CC.getOperand(0)); //Cond
|
2005-02-10 14:25:22 +08: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 08:40:03 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
} else { //FP
|
2005-07-27 14:12:32 +08:00
|
|
|
//Any comparison between 2 values should be codegened as an folded
|
2005-06-28 01:39:17 +08:00
|
|
|
//branch, as moving CC to the integer register is very expensive
|
2005-02-10 14:25:22 +08:00
|
|
|
//for a cmp b: c = a - b;
|
|
|
|
//a = b: c = 0
|
|
|
|
//a < b: c < 0
|
|
|
|
//a > b: c > 0
|
2005-02-26 06:55:15 +08:00
|
|
|
|
|
|
|
bool invTest = false;
|
|
|
|
unsigned Tmp3;
|
|
|
|
|
|
|
|
ConstantFPSDNode *CN;
|
2005-08-10 04:21:10 +08:00
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(1)))
|
2005-02-26 06:55:15 +08:00
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
2005-08-10 04:21:10 +08:00
|
|
|
Tmp3 = SelectExpr(CC.getOperand(0));
|
|
|
|
else if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(0)))
|
2005-02-26 06:55:15 +08:00
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
Tmp3 = SelectExpr(CC.getOperand(1));
|
2005-02-26 06:55:15 +08:00
|
|
|
invTest = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
unsigned Tmp1 = SelectExpr(CC.getOperand(0));
|
|
|
|
unsigned Tmp2 = SelectExpr(CC.getOperand(1));
|
|
|
|
bool isD = CC.getOperand(0).getValueType() == MVT::f64;
|
2005-02-26 06:55:15 +08:00
|
|
|
Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
|
|
|
|
BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
|
|
|
|
.addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
|
2005-08-10 04:21:10 +08:00
|
|
|
switch (cCode) {
|
2005-02-10 14:25:22 +08:00
|
|
|
default: CC.Val->dump(); assert(0 && "Unknown FP comparison!");
|
2005-02-26 06:55:15 +08: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 14:25:22 +08:00
|
|
|
}
|
|
|
|
BuildMI(BB, Opc, 2).addReg(Tmp3).addMBB(Dest);
|
2005-02-08 08:40:03 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-02-10 14:25:22 +08: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 08:40:03 +08:00
|
|
|
abort(); //Should never be reached
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:19:45 +08:00
|
|
|
unsigned AlphaISel::SelectExpr(SDOperand N) {
|
2005-01-23 07:41:55 +08:00
|
|
|
unsigned Result;
|
2005-04-08 02:15:28 +08:00
|
|
|
unsigned Tmp1, Tmp2 = 0, Tmp3;
|
2005-01-23 07:41:55 +08:00
|
|
|
unsigned Opc = 0;
|
2005-01-28 14:57:18 +08:00
|
|
|
unsigned opcode = N.getOpcode();
|
2005-10-22 00:01:26 +08:00
|
|
|
int64_t SImm = 0;
|
2005-08-15 22:31:37 +08:00
|
|
|
uint64_t UImm;
|
2005-01-23 07:41:55 +08:00
|
|
|
|
|
|
|
SDNode *Node = N.Val;
|
2005-01-28 14:57:18 +08:00
|
|
|
MVT::ValueType DestType = N.getValueType();
|
2005-06-29 20:49:51 +08:00
|
|
|
bool isFP = DestType == MVT::f64 || DestType == MVT::f32;
|
2005-01-23 07:41:55 +08:00
|
|
|
|
|
|
|
unsigned &Reg = ExprMap[N];
|
|
|
|
if (Reg) return Reg;
|
|
|
|
|
2005-09-07 01:00:23 +08:00
|
|
|
switch(N.getOpcode()) {
|
|
|
|
default:
|
2005-01-23 07:41:55 +08:00
|
|
|
Reg = Result = (N.getValueType() != MVT::Other) ?
|
2005-01-29 07:17:54 +08:00
|
|
|
MakeReg(N.getValueType()) : notIn;
|
2005-09-07 01:00:23 +08:00
|
|
|
break;
|
|
|
|
case ISD::AssertSext:
|
|
|
|
case ISD::AssertZext:
|
|
|
|
return Reg = SelectExpr(N.getOperand(0));
|
|
|
|
case ISD::CALL:
|
|
|
|
case ISD::TAILCALL:
|
2005-01-23 07:41:55 +08:00
|
|
|
// 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 07:17:54 +08:00
|
|
|
Reg = Result = notIn; // Void call, just a chain.
|
2005-01-23 07:41:55 +08: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 07:17:54 +08:00
|
|
|
ExprMap[SDOperand(Node, Node->getNumValues()-1)] = notIn;
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
2005-09-07 01:00:23 +08:00
|
|
|
break;
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
|
|
|
|
2005-01-28 14:57:18 +08:00
|
|
|
switch (opcode) {
|
2005-01-23 07:41:55 +08:00
|
|
|
default:
|
|
|
|
Node->dump();
|
|
|
|
assert(0 && "Node not handled!\n");
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-05-04 01:19:30 +08: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));
|
2005-10-21 03:39:24 +08:00
|
|
|
BuildMI(BB, Opc, 1, Result).addReg(Tmp1);
|
2005-05-04 01:19:30 +08:00
|
|
|
return Result;
|
|
|
|
|
2005-04-07 04:25:34 +08: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 21:55:53 +08:00
|
|
|
return Result;
|
2005-04-07 04:25:34 +08: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-28 01:39:17 +08: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-07 04:25:34 +08: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-03 03:11:07 +08:00
|
|
|
case ISD::UNDEF: {
|
|
|
|
BuildMI(BB, Alpha::IDEF, 0, Result);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-23 05:59:48 +08:00
|
|
|
case ISD::DYNAMIC_STACKALLOC:
|
|
|
|
// Generate both result values.
|
2005-02-24 01:33:42 +08:00
|
|
|
if (Result != notIn)
|
|
|
|
ExprMap[N.getValue(1)] = notIn; // Generate the token
|
2005-02-23 05:59:48 +08: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 07:13:11 +08:00
|
|
|
|
2005-02-23 05:59:48 +08:00
|
|
|
Select(N.getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
if (isSIntImmediateBounded(N.getOperand(1), SImm, 0, 32767))
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Alpha::R30).addImm(-SImm).addReg(Alpha::R30);
|
|
|
|
else {
|
2005-02-23 05:59:48 +08:00
|
|
|
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 07:29:25 +08:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R30).addReg(Alpha::R30);
|
2005-02-23 05:59:48 +08:00
|
|
|
return Result;
|
|
|
|
|
2005-06-28 05:02:56 +08:00
|
|
|
case ISD::ConstantPool:
|
2005-08-27 01:15:30 +08:00
|
|
|
Tmp1 = BB->getParent()->getConstantPool()->
|
|
|
|
getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
|
2005-06-28 05:02:56 +08:00
|
|
|
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 23:42:07 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::FrameIndex:
|
2005-02-23 05:59:48 +08:00
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result)
|
|
|
|
.addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
|
|
|
|
.addReg(Alpha::F31);
|
2005-01-23 07:41:55 +08:00
|
|
|
return Result;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::EXTLOAD:
|
2005-02-07 13:18:02 +08:00
|
|
|
case ISD::ZEXTLOAD:
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::SEXTLOAD:
|
2005-04-22 07:13:11 +08:00
|
|
|
case ISD::LOAD:
|
2005-02-06 23:40:40 +08: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 07:13:11 +08:00
|
|
|
|
2005-02-06 23:40:40 +08:00
|
|
|
SDOperand Chain = N.getOperand(0);
|
|
|
|
SDOperand Address = N.getOperand(1);
|
|
|
|
Select(Chain);
|
|
|
|
|
2005-06-29 08:31:08 +08:00
|
|
|
bool fpext = true;
|
|
|
|
|
2005-02-07 13:55:55 +08:00
|
|
|
if (opcode == ISD::LOAD)
|
2005-06-29 08:31:08 +08: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 13:55:55 +08:00
|
|
|
else
|
2005-07-10 09:56:13 +08:00
|
|
|
switch (cast<VTSDNode>(Node->getOperand(3))->getVT()) {
|
2005-02-06 23:40:40 +08:00
|
|
|
default: Node->dump(); assert(0 && "Bad sign extend!");
|
2005-04-22 07:13:11 +08:00
|
|
|
case MVT::i32: Opc = Alpha::LDL;
|
2005-02-10 14:25:22 +08:00
|
|
|
assert(opcode != ISD::ZEXTLOAD && "Not sext"); break;
|
2005-04-22 07:13:11 +08:00
|
|
|
case MVT::i16: Opc = Alpha::LDWU;
|
2005-02-10 14:25:22 +08:00
|
|
|
assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
|
2005-02-07 13:18:02 +08:00
|
|
|
case MVT::i1: //FIXME: Treat i1 as i8 since there are problems otherwise
|
2005-04-22 07:13:11 +08:00
|
|
|
case MVT::i8: Opc = Alpha::LDBU;
|
2005-02-10 14:25:22 +08:00
|
|
|
assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
|
2005-02-06 23:40:40 +08:00
|
|
|
}
|
|
|
|
|
2005-06-30 02:54:02 +08:00
|
|
|
int i, j, k;
|
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
getValueInfo(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue(),
|
|
|
|
i, j, k);
|
|
|
|
|
2005-07-02 03:12:13 +08: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-07-10 09:56:13 +08:00
|
|
|
} else if (ConstantPoolSDNode *CP =
|
|
|
|
dyn_cast<ConstantPoolSDNode>(Address)) {
|
2005-08-27 01:15:30 +08:00
|
|
|
unsigned CPIdx = BB->getParent()->getConstantPool()->
|
|
|
|
getConstantPoolIndex(CP->get());
|
2005-02-06 23:40:40 +08:00
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-04-09 01:28:49 +08:00
|
|
|
has_sym = true;
|
2005-06-28 01:15:36 +08:00
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
2005-08-27 01:15:30 +08:00
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPIdx)
|
2005-06-28 01:39:17 +08:00
|
|
|
.addReg(Alpha::R29);
|
2005-06-29 08:31:08 +08:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-30 02:54:02 +08:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-06-29 08:31:08 +08:00
|
|
|
BuildMI(BB, GetRelVersion(Opc), 2, Result)
|
2005-08-27 01:15:30 +08:00
|
|
|
.addConstantPoolIndex(CPIdx).addReg(Tmp1);
|
2005-06-29 08:31:08 +08:00
|
|
|
} else if(Address.getOpcode() == ISD::FrameIndex) {
|
|
|
|
if (EnableAlphaLSMark)
|
2005-06-30 02:54:02 +08:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-23 05:59:48 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result)
|
|
|
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
|
|
|
.addReg(Alpha::F31);
|
2005-02-10 14:25:22 +08:00
|
|
|
} else {
|
|
|
|
long offset;
|
|
|
|
SelectAddr(Address, Tmp1, offset);
|
2005-06-29 08:31:08 +08:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-30 02:54:02 +08:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-10 14:25:22 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addImm(offset).addReg(Tmp1);
|
2005-02-06 23:40:40 +08:00
|
|
|
}
|
|
|
|
return Result;
|
2005-01-25 08:35:34 +08:00
|
|
|
}
|
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::GlobalAddress:
|
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-04-09 01:28:49 +08:00
|
|
|
has_sym = true;
|
2005-07-27 14:12:32 +08:00
|
|
|
|
2005-07-04 04:06:13 +08:00
|
|
|
Reg = Result = MakeReg(MVT::i64);
|
2005-06-29 08:31:08 +08:00
|
|
|
|
|
|
|
if (EnableAlphaLSMark)
|
2005-07-02 03:12:13 +08:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
|
2005-06-30 02:54:02 +08:00
|
|
|
.addImm(getUID());
|
2005-06-29 08:31:08 +08:00
|
|
|
|
|
|
|
BuildMI(BB, Alpha::LDQl, 2, Result)
|
2005-06-28 05:11:40 +08:00
|
|
|
.addGlobalAddress(cast<GlobalAddressSDNode>(N)->getGlobal())
|
|
|
|
.addReg(Alpha::R29);
|
2005-01-23 07:41:55 +08:00
|
|
|
return Result;
|
|
|
|
|
2005-07-02 03:12:13 +08:00
|
|
|
case ISD::ExternalSymbol:
|
|
|
|
AlphaLowering.restoreGP(BB);
|
|
|
|
has_sym = true;
|
|
|
|
|
2005-07-04 04:06:13 +08:00
|
|
|
Reg = Result = MakeReg(MVT::i64);
|
|
|
|
|
2005-07-02 03:12:13 +08: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-14 04:29:26 +08:00
|
|
|
case ISD::TAILCALL:
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::CALL:
|
|
|
|
{
|
|
|
|
Select(N.getOperand(0));
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
// The chain for this call is now lowered.
|
2005-07-23 04:50:29 +08:00
|
|
|
ExprMap[N.getValue(Node->getNumValues()-1)] = notIn;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
//grab the arguments
|
|
|
|
std::vector<unsigned> argvregs;
|
2005-01-31 04:42:36 +08:00
|
|
|
//assert(Node->getNumOperands() < 8 && "Only 6 args supported");
|
2005-01-23 07:41:55 +08:00
|
|
|
for(int i = 2, e = Node->getNumOperands(); i < e; ++i)
|
2005-02-10 14:25:22 +08:00
|
|
|
argvregs.push_back(SelectExpr(N.getOperand(i)));
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-30 08:35:27 +08:00
|
|
|
//in reg args
|
|
|
|
for(int i = 0, e = std::min(6, (int)argvregs.size()); i < e; ++i)
|
2005-02-10 14:25:22 +08:00
|
|
|
{
|
2005-04-22 07:13:11 +08:00
|
|
|
unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
|
2005-02-10 14:25:22 +08:00
|
|
|
Alpha::R19, Alpha::R20, Alpha::R21};
|
2005-04-22 07:13:11 +08:00
|
|
|
unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
|
2005-02-10 14:25:22 +08:00
|
|
|
Alpha::F19, Alpha::F20, Alpha::F21};
|
|
|
|
switch(N.getOperand(i+2).getValueType()) {
|
2005-04-22 07:13:11 +08:00
|
|
|
default:
|
|
|
|
Node->dump();
|
2005-02-10 14:25:22 +08:00
|
|
|
N.getOperand(i).Val->dump();
|
2005-04-22 07:13:11 +08:00
|
|
|
std::cerr << "Type for " << i << " is: " <<
|
2005-02-10 14:25:22 +08: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-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, args_int[i]).addReg(argvregs[i])
|
|
|
|
.addReg(argvregs[i]);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, args_float[i]).addReg(argvregs[i])
|
|
|
|
.addReg(argvregs[i]);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
2005-01-30 08:35:27 +08:00
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
2005-01-30 08:35:27 +08:00
|
|
|
//in mem args
|
|
|
|
for (int i = 6, e = argvregs.size(); i < e; ++i)
|
2005-02-10 14:25:22 +08:00
|
|
|
{
|
|
|
|
switch(N.getOperand(i+2).getValueType()) {
|
2005-04-22 07:13:11 +08:00
|
|
|
default:
|
|
|
|
Node->dump();
|
2005-02-10 14:25:22 +08:00
|
|
|
N.getOperand(i).Val->dump();
|
2005-04-22 07:13:11 +08:00
|
|
|
std::cerr << "Type for " << i << " is: " <<
|
2005-02-10 14:25:22 +08: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-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::STQ, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
|
|
|
|
.addReg(Alpha::R30);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
|
|
|
case MVT::f32:
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::STS, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
|
|
|
|
.addReg(Alpha::R30);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
|
|
|
case MVT::f64:
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::STT, 3).addReg(argvregs[i]).addImm((i - 6) * 8)
|
|
|
|
.addReg(Alpha::R30);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
2005-01-30 08:35:27 +08:00
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
2005-01-27 05:54:09 +08:00
|
|
|
//build the right kind of call
|
2005-07-02 03:12:13 +08:00
|
|
|
GlobalAddressSDNode *GASD = dyn_cast<GlobalAddressSDNode>(N.getOperand(1));
|
|
|
|
if (GASD && !GASD->getGlobal()->isExternal()) {
|
|
|
|
//use PC relative branch call
|
2005-02-10 14:25:22 +08:00
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-07-02 03:12:13 +08:00
|
|
|
BuildMI(BB, Alpha::BSR, 1, Alpha::R26)
|
|
|
|
.addGlobalAddress(GASD->getGlobal(),true);
|
2005-02-10 14:25:22 +08:00
|
|
|
} else {
|
|
|
|
//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 07:13:11 +08:00
|
|
|
|
2005-01-27 05:54:09 +08:00
|
|
|
//push the result into a virtual register
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-27 05:54:09 +08:00
|
|
|
switch (Node->getValueType(0)) {
|
|
|
|
default: Node->dump(); assert(0 && "Unknown value type for call result!");
|
2005-01-29 07:17:54 +08:00
|
|
|
case MVT::Other: return notIn;
|
2005-01-27 05:54:09 +08:00
|
|
|
case MVT::i64:
|
2005-04-23 01:54:37 +08:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R0).addReg(Alpha::R0);
|
|
|
|
break;
|
2005-01-27 05:54:09 +08:00
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
2005-04-23 01:54:37 +08:00
|
|
|
BuildMI(BB, Alpha::CPYS, 2, Result).addReg(Alpha::F0).addReg(Alpha::F0);
|
|
|
|
break;
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
2005-01-27 05:54:09 +08:00
|
|
|
return Result+N.ResNo;
|
2005-04-22 07:13:11 +08:00
|
|
|
}
|
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::SIGN_EXTEND_INREG:
|
|
|
|
{
|
2005-04-09 01:28:49 +08: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 08:24:07 +08: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-03 05:06:51 +08:00
|
|
|
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
|
|
|
|
MoveInt2FP(Tmp1, Tmp4, true);
|
|
|
|
MoveInt2FP(Tmp2, Tmp5, true);
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTQT, 1, Tmp6).addReg(Alpha::F31).addReg(Tmp4);
|
|
|
|
BuildMI(BB, Alpha::CVTQT, 1, Tmp7).addReg(Alpha::F31).addReg(Tmp5);
|
2005-03-22 08:24:07 +08:00
|
|
|
BuildMI(BB, Alpha::DIVT, 2, Tmp8).addReg(Tmp6).addReg(Tmp7);
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTTQ, 1, Tmp9).addReg(Alpha::F31).addReg(Tmp8);
|
2005-04-03 05:06:51 +08:00
|
|
|
MoveFP2Int(Tmp9, Result, true);
|
2005-03-22 08:24:07 +08:00
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-29 07:17:54 +08:00
|
|
|
//Alpha has instructions for a bunch of signed 32 bit stuff
|
2005-07-10 09:56:13 +08:00
|
|
|
if(cast<VTSDNode>(Node->getOperand(1))->getVT() == MVT::i32) {
|
2005-02-10 14:25:22 +08: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 13:19:55 +08:00
|
|
|
if(!isMul && N.getOperand(0).getOperand(0).getOpcode() == ISD::SHL &&
|
2005-08-15 22:31:37 +08:00
|
|
|
isSIntImmediateBounded(N.getOperand(0).getOperand(0).getOperand(1), SImm, 2, 3))
|
2005-04-13 13:19:55 +08:00
|
|
|
{
|
2005-08-15 22:31:37 +08:00
|
|
|
bool use4 = SImm == 2;
|
2005-04-13 13:19:55 +08:00
|
|
|
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 &&
|
2005-08-15 22:31:37 +08:00
|
|
|
isSIntImmediateBounded(N.getOperand(0).getOperand(1).getOperand(1), SImm, 2, 3))
|
2005-04-13 13:19:55 +08:00
|
|
|
{
|
2005-08-15 22:31:37 +08:00
|
|
|
bool use4 = SImm == 2;
|
2005-04-13 13:19:55 +08:00
|
|
|
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);
|
|
|
|
}
|
2005-08-15 22:31:37 +08:00
|
|
|
else if(isSIntImmediateBounded(N.getOperand(0).getOperand(1), SImm, 0, 255))
|
2005-02-10 14:25:22 +08:00
|
|
|
{ //Normal imm add/sub
|
|
|
|
Opc = isAdd ? Alpha::ADDLi : (isMul ? Alpha::MULLi : Alpha::SUBLi);
|
2005-04-13 13:19:55 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
2005-08-15 22:31:37 +08:00
|
|
|
else if(!isMul && isSIntImmediate(N.getOperand(0).getOperand(1), SImm) &&
|
|
|
|
(((SImm << 32) >> 32) >= -255) && (((SImm << 32) >> 32) <= 0))
|
2005-07-23 06:24:01 +08:00
|
|
|
{ //handle canonicalization
|
|
|
|
Opc = isAdd ? Alpha::SUBLi : Alpha::ADDLi;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
SImm = 0 - ((SImm << 32) >> 32);
|
|
|
|
assert(SImm >= 0 && SImm <= 255);
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
|
2005-07-23 06:24:01 +08:00
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
else
|
|
|
|
{ //Normal add/sub
|
2005-04-13 13:19:55 +08:00
|
|
|
Opc = isAdd ? Alpha::ADDL : (isMul ? Alpha::MULL : Alpha::SUBL);
|
2005-02-10 14:25:22 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-04-13 13:19:55 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(1));
|
2005-02-10 14:25:22 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
2005-01-29 07:17:54 +08:00
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
return Result;
|
2005-01-29 07:17:54 +08:00
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
default: break; //Fall Though;
|
|
|
|
}
|
|
|
|
} //Every thing else fall though too, including unhandled opcodes above
|
2005-01-23 07:41:55 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-01-27 05:54:09 +08:00
|
|
|
//std::cerr << "SrcT: " << MVN->getExtraValueType() << "\n";
|
2005-07-10 09:56:13 +08:00
|
|
|
switch(cast<VTSDNode>(Node->getOperand(1))->getVT()) {
|
2005-02-10 14:25:22 +08:00
|
|
|
default:
|
|
|
|
Node->dump();
|
|
|
|
assert(0 && "Sign Extend InReg not there yet");
|
|
|
|
break;
|
|
|
|
case MVT::i32:
|
2005-01-27 11:49:45 +08:00
|
|
|
{
|
2005-02-10 14:25:22 +08:00
|
|
|
BuildMI(BB, Alpha::ADDLi, 2, Result).addReg(Tmp1).addImm(0);
|
2005-01-27 11:49:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
case MVT::i16:
|
2005-10-21 03:39:24 +08:00
|
|
|
BuildMI(BB, Alpha::SEXTW, 1, Result).addReg(Tmp1);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
|
|
|
case MVT::i8:
|
2005-10-21 03:39:24 +08:00
|
|
|
BuildMI(BB, Alpha::SEXTB, 1, Result).addReg(Tmp1);
|
2005-02-10 14:25:22 +08:00
|
|
|
break;
|
2005-02-13 03:35:12 +08:00
|
|
|
case MVT::i1:
|
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::ANDi, 2, Tmp2).addReg(Tmp1).addImm(1);
|
2005-04-09 01:28:49 +08:00
|
|
|
BuildMI(BB, Alpha::SUBQ, 2, Result).addReg(Alpha::R31).addReg(Tmp2);
|
2005-02-13 03:35:12 +08:00
|
|
|
break;
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
2005-01-23 07:41:55 +08:00
|
|
|
return Result;
|
|
|
|
}
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::SETCC:
|
2005-01-27 11:49:45 +08:00
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
ISD::CondCode CC = cast<CondCodeSDNode>(N.getOperand(2))->get();
|
|
|
|
if (MVT::isInteger(N.getOperand(0).getValueType())) {
|
|
|
|
bool isConst = false;
|
|
|
|
int dir;
|
|
|
|
|
|
|
|
//Tmp1 = SelectExpr(N.getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
if(isSIntImmediate(N.getOperand(1), SImm) && SImm <= 255 && SImm >= 0)
|
2005-08-10 04:21:10 +08:00
|
|
|
isConst = true;
|
|
|
|
|
|
|
|
switch (CC) {
|
|
|
|
default: Node->dump(); assert(0 && "Unknown integer comparison!");
|
|
|
|
case ISD::SETEQ:
|
|
|
|
Opc = isConst ? Alpha::CMPEQi : Alpha::CMPEQ; dir=1; break;
|
|
|
|
case ISD::SETLT:
|
|
|
|
Opc = isConst ? Alpha::CMPLTi : Alpha::CMPLT; dir = 1; break;
|
|
|
|
case ISD::SETLE:
|
|
|
|
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;
|
|
|
|
case ISD::SETULT:
|
|
|
|
Opc = isConst ? Alpha::CMPULTi : Alpha::CMPULT; dir = 1; break;
|
|
|
|
case ISD::SETUGT: Opc = Alpha::CMPULT; dir = 2; break;
|
|
|
|
case ISD::SETULE:
|
|
|
|
Opc = isConst ? Alpha::CMPULEi : Alpha::CMPULE; dir = 1; break;
|
|
|
|
case ISD::SETUGE: Opc = Alpha::CMPULE; dir = 2; break;
|
|
|
|
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);
|
|
|
|
//Remeber we have the Inv for this CC
|
|
|
|
CCInvMap[N] = Tmp3;
|
|
|
|
//and invert
|
|
|
|
BuildMI(BB, Alpha::CMPEQ, 2, Result).addReg(Alpha::R31).addReg(Tmp3);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dir == 1) {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
if (isConst) {
|
2005-08-15 22:31:37 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
|
2005-08-10 04:21:10 +08:00
|
|
|
} else {
|
2005-01-27 15:50:35 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
2005-06-27 07:01:11 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
2005-02-06 00:41:03 +08:00
|
|
|
}
|
2005-08-10 04:21:10 +08:00
|
|
|
} else { //if (dir == 2) {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
2005-02-06 00:41:03 +08:00
|
|
|
}
|
2005-08-10 04:21:10 +08:00
|
|
|
} else {
|
|
|
|
//do the comparison
|
|
|
|
Tmp1 = MakeReg(MVT::f64);
|
|
|
|
bool inv = SelectFPSetCC(N, Tmp1);
|
|
|
|
|
|
|
|
//now arrange for Result (int) to have a 1 or 0
|
|
|
|
Tmp2 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::ADDQi, 2, Tmp2).addReg(Alpha::R31).addImm(1);
|
|
|
|
Opc = inv?Alpha::CMOVNEi_FP:Alpha::CMOVEQi_FP;
|
|
|
|
BuildMI(BB, Opc, 3, Result).addReg(Tmp2).addImm(0).addReg(Tmp1);
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
2005-01-27 11:49:45 +08:00
|
|
|
return Result;
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::CopyFromReg:
|
|
|
|
{
|
2005-04-09 01:28:49 +08:00
|
|
|
++count_ins;
|
|
|
|
|
2005-01-28 14:57:18 +08:00
|
|
|
// Make sure we generate both values.
|
2005-01-29 07:17:54 +08:00
|
|
|
if (Result != notIn)
|
2005-04-23 01:54:37 +08:00
|
|
|
ExprMap[N.getValue(1)] = notIn; // Generate the token
|
2005-01-28 14:57:18 +08:00
|
|
|
else
|
2005-04-23 01:54:37 +08:00
|
|
|
Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
SDOperand Chain = N.getOperand(0);
|
|
|
|
|
|
|
|
Select(Chain);
|
2005-08-17 05:56:37 +08:00
|
|
|
unsigned r = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
|
2005-01-23 07:41:55 +08:00
|
|
|
//std::cerr << "CopyFromReg " << Result << " = " << r << "\n";
|
2005-07-05 04:07:21 +08:00
|
|
|
if (MVT::isFloatingPoint(N.getValue(0).getValueType()))
|
2005-06-29 08:31:08 +08: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 07:41:55 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2005-04-22 07:13:11 +08:00
|
|
|
//Most of the plain arithmetic and logic share the same form, and the same
|
2005-01-25 03:44:07 +08:00
|
|
|
//constant immediate test
|
2005-04-09 01:28:49 +08:00
|
|
|
case ISD::XOR:
|
2005-04-03 05:06:51 +08:00
|
|
|
//Match Not
|
2005-08-15 22:31:37 +08:00
|
|
|
if (isSIntImmediate(N.getOperand(1), SImm) && SImm == -1) {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::ORNOT, 2, Result).addReg(Alpha::R31).addReg(Tmp1);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-04-03 05:06:51 +08:00
|
|
|
//Fall through
|
|
|
|
case ISD::AND:
|
2005-04-13 11:47:03 +08:00
|
|
|
//handle zap
|
2005-08-15 22:31:37 +08:00
|
|
|
if (opcode == ISD::AND && isUIntImmediate(N.getOperand(1), UImm))
|
2005-04-13 11:47:03 +08:00
|
|
|
{
|
|
|
|
unsigned int build = 0;
|
|
|
|
for(int i = 0; i < 8; ++i)
|
|
|
|
{
|
2005-08-15 22:31:37 +08:00
|
|
|
if ((UImm & 0x00FF) == 0x00FF)
|
2005-04-13 11:47:03 +08:00
|
|
|
build |= 1 << i;
|
2005-08-15 22:31:37 +08:00
|
|
|
else if ((UImm & 0x00FF) != 0)
|
2005-04-13 11:47:03 +08:00
|
|
|
{ build = 0; break; }
|
2005-08-15 22:31:37 +08:00
|
|
|
UImm >>= 8;
|
2005-04-13 11:47:03 +08:00
|
|
|
}
|
|
|
|
if (build)
|
|
|
|
{
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
BuildMI(BB, Alpha::ZAPNOTi, 2, Result).addReg(Tmp1).addImm(build);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
2005-04-09 01:28:49 +08:00
|
|
|
case ISD::OR:
|
2005-04-03 05:06:51 +08:00
|
|
|
//Check operand(0) == Not
|
2005-04-22 07:13:11 +08:00
|
|
|
if (N.getOperand(0).getOpcode() == ISD::XOR &&
|
2005-08-15 22:31:37 +08:00
|
|
|
isSIntImmediate(N.getOperand(0).getOperand(1), SImm) && SImm == -1) {
|
2005-06-28 01:39:17 +08:00
|
|
|
switch(opcode) {
|
2005-04-23 01:54:37 +08:00
|
|
|
case ISD::AND: Opc = Alpha::BIC; break;
|
|
|
|
case ISD::OR: Opc = Alpha::ORNOT; break;
|
|
|
|
case ISD::XOR: Opc = Alpha::EQV; break;
|
2005-04-03 05:06:51 +08:00
|
|
|
}
|
2005-06-28 01:39:17 +08: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-03 05:06:51 +08:00
|
|
|
//Check operand(1) == Not
|
2005-04-22 07:13:11 +08:00
|
|
|
if (N.getOperand(1).getOpcode() == ISD::XOR &&
|
2005-08-15 22:31:37 +08:00
|
|
|
isSIntImmediate(N.getOperand(1).getOperand(1), SImm) && SImm == -1) {
|
2005-06-28 01:39:17 +08:00
|
|
|
switch(opcode) {
|
2005-04-23 01:54:37 +08:00
|
|
|
case ISD::AND: Opc = Alpha::BIC; break;
|
|
|
|
case ISD::OR: Opc = Alpha::ORNOT; break;
|
|
|
|
case ISD::XOR: Opc = Alpha::EQV; break;
|
2005-04-03 05:06:51 +08:00
|
|
|
}
|
2005-06-28 01:39:17 +08: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-03 05:06:51 +08:00
|
|
|
//Fall through
|
2005-01-25 03:44:07 +08:00
|
|
|
case ISD::SHL:
|
|
|
|
case ISD::SRL:
|
2005-01-29 23:42:07 +08:00
|
|
|
case ISD::SRA:
|
2005-01-25 03:44:07 +08:00
|
|
|
case ISD::MUL:
|
2005-08-15 22:31:37 +08:00
|
|
|
if(isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255)) {
|
2005-02-10 14:25:22 +08: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));
|
2005-08-15 22:31:37 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
|
2005-02-10 14:25:22 +08:00
|
|
|
} 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-09-29 06:29:17 +08:00
|
|
|
case ISD::MUL: Opc = Alpha::MULQ; break;
|
2005-02-10 14:25:22 +08:00
|
|
|
};
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
2005-01-27 05:54:09 +08:00
|
|
|
return Result;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-27 05:54:09 +08:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::SUB:
|
2005-09-29 06:29:17 +08:00
|
|
|
{
|
2005-01-28 14:57:18 +08:00
|
|
|
bool isAdd = opcode == ISD::ADD;
|
|
|
|
|
2005-04-07 04:25:34 +08:00
|
|
|
//first check for Scaled Adds and Subs!
|
|
|
|
//Valid for add and sub
|
2005-08-15 22:31:37 +08:00
|
|
|
if(N.getOperand(0).getOpcode() == ISD::SHL &&
|
|
|
|
isSIntImmediate(N.getOperand(0).getOperand(1), SImm) &&
|
|
|
|
(SImm == 2 || SImm == 3)) {
|
|
|
|
bool use4 = SImm == 2;
|
2005-04-07 04:25:34 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(0).getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
if (isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255))
|
2005-04-13 13:19:55 +08:00
|
|
|
BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
|
2005-08-15 22:31:37 +08:00
|
|
|
2, Result).addReg(Tmp2).addImm(SImm);
|
2005-04-07 04:59:59 +08:00
|
|
|
else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(1));
|
2005-04-13 13:19:55 +08:00
|
|
|
BuildMI(BB, isAdd?(use4?Alpha::S4ADDQi:Alpha::S8ADDQi):(use4?Alpha::S4SUBQi:Alpha::S8SUBQi),
|
|
|
|
2, Result).addReg(Tmp2).addReg(Tmp1);
|
2005-04-07 04:59:59 +08:00
|
|
|
}
|
2005-04-07 04:25:34 +08:00
|
|
|
}
|
|
|
|
//Position prevents subs
|
2005-04-07 22:18:13 +08:00
|
|
|
else if(N.getOperand(1).getOpcode() == ISD::SHL && isAdd &&
|
2005-08-15 22:31:37 +08:00
|
|
|
isSIntImmediate(N.getOperand(1).getOperand(1), SImm) &&
|
|
|
|
(SImm == 2 || SImm == 3)) {
|
|
|
|
bool use4 = SImm == 2;
|
2005-04-07 04:25:34 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1).getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
if (isSIntImmediateBounded(N.getOperand(0), SImm, 0, 255))
|
|
|
|
BuildMI(BB, use4?Alpha::S4ADDQi:Alpha::S8ADDQi, 2, Result).addReg(Tmp2).addImm(SImm);
|
2005-04-07 04:59:59 +08:00
|
|
|
else {
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-04-13 13:19:55 +08:00
|
|
|
BuildMI(BB, use4?Alpha::S4ADDQ:Alpha::S8ADDQ, 2, Result).addReg(Tmp2).addReg(Tmp1);
|
2005-04-07 04:59:59 +08:00
|
|
|
}
|
2005-04-07 04:25:34 +08:00
|
|
|
}
|
|
|
|
//small addi
|
2005-08-15 22:31:37 +08:00
|
|
|
else if(isSIntImmediateBounded(N.getOperand(1), SImm, 0, 255))
|
2005-02-10 14:25:22 +08:00
|
|
|
{ //Normal imm add/sub
|
|
|
|
Opc = isAdd ? Alpha::ADDQi : Alpha::SUBQi;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(SImm);
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
2005-08-15 22:31:37 +08:00
|
|
|
else if(isSIntImmediateBounded(N.getOperand(1), SImm, -255, 0))
|
2005-07-23 06:24:01 +08:00
|
|
|
{ //inverted imm add/sub
|
|
|
|
Opc = isAdd ? Alpha::SUBQi : Alpha::ADDQi;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
2005-08-15 22:31:37 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addImm(-SImm);
|
2005-07-23 06:24:01 +08:00
|
|
|
}
|
2005-04-07 04:25:34 +08:00
|
|
|
//larger addi
|
2005-08-15 22:31:37 +08:00
|
|
|
else if(isSIntImmediateBounded(N.getOperand(1), SImm, -32767, 32767))
|
2005-03-03 01:23:03 +08:00
|
|
|
{ //LDA
|
2005-02-10 14:25:22 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
if (!isAdd)
|
2005-08-15 22:31:37 +08:00
|
|
|
SImm = -SImm;
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result).addImm(SImm).addReg(Tmp1);
|
2005-04-07 04:25:34 +08:00
|
|
|
}
|
|
|
|
//give up and do the operation
|
|
|
|
else {
|
2005-02-10 14:25:22 +08: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-27 05:54:09 +08:00
|
|
|
return Result;
|
|
|
|
}
|
2005-09-29 06:29:17 +08:00
|
|
|
case ISD::FADD:
|
|
|
|
case ISD::FSUB:
|
|
|
|
case ISD::FMUL:
|
|
|
|
case ISD::FDIV: {
|
|
|
|
if (opcode == ISD::FADD)
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::ADDT : Alpha::ADDS;
|
|
|
|
else if (opcode == ISD::FSUB)
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::SUBT : Alpha::SUBS;
|
|
|
|
else if (opcode == ISD::FMUL)
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::MULT : Alpha::MULS;
|
|
|
|
else
|
|
|
|
Opc = DestType == MVT::f64 ? Alpha::DIVT : Alpha::DIVS;
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp1).addReg(Tmp2);
|
|
|
|
return Result;
|
|
|
|
}
|
2005-03-22 08:24:07 +08:00
|
|
|
case ISD::SDIV:
|
2005-09-29 06:29:17 +08:00
|
|
|
{
|
2005-04-07 06:03:13 +08:00
|
|
|
//check if we can convert into a shift!
|
2005-08-15 22:31:37 +08:00
|
|
|
if (isSIntImmediate(N.getOperand(1), SImm) &&
|
|
|
|
SImm != 0 && isPowerOf2_64(llabs(SImm))) {
|
|
|
|
unsigned k = Log2_64(llabs(SImm));
|
2005-04-07 06:03:13 +08:00
|
|
|
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);
|
2005-08-15 22:31:37 +08:00
|
|
|
if (SImm > 0)
|
2005-04-07 06:03:13 +08:00
|
|
|
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-07 04:25:34 +08:00
|
|
|
case ISD::UDIV:
|
|
|
|
//else fall though
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::UREM:
|
2005-07-02 03:12:13 +08:00
|
|
|
case ISD::SREM: {
|
|
|
|
const char* opstr = 0;
|
2005-01-28 14:57:18 +08:00
|
|
|
switch(opcode) {
|
2005-07-02 03:12:13 +08: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-27 05:54:09 +08:00
|
|
|
}
|
2005-01-23 07:41:55 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0));
|
|
|
|
Tmp2 = SelectExpr(N.getOperand(1));
|
2005-07-27 14:12:32 +08:00
|
|
|
SDOperand Addr =
|
2005-07-02 03:12:13 +08:00
|
|
|
ISelDAG->getExternalSymbol(opstr, AlphaLowering.getPointerTy());
|
|
|
|
Tmp3 = SelectExpr(Addr);
|
2005-03-05 04:09:23 +08:00
|
|
|
//set up regs explicitly (helps Reg alloc)
|
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R24).addReg(Tmp1).addReg(Tmp1);
|
2005-04-22 07:13:11 +08:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Alpha::R25).addReg(Tmp2).addReg(Tmp2);
|
2005-07-02 03:12:13 +08: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 07:13:11 +08:00
|
|
|
BuildMI(BB, Alpha::BIS, 2, Result).addReg(Alpha::R27).addReg(Alpha::R27);
|
2005-01-23 07:41:55 +08:00
|
|
|
return Result;
|
2005-07-02 03:12:13 +08:00
|
|
|
}
|
2005-01-31 09:44:26 +08:00
|
|
|
|
2005-02-02 04:40:27 +08:00
|
|
|
case ISD::FP_TO_UINT:
|
2005-01-31 09:44:26 +08:00
|
|
|
case ISD::FP_TO_SINT:
|
2005-02-10 14:25:22 +08:00
|
|
|
{
|
2005-01-31 09:44:26 +08:00
|
|
|
assert (DestType == MVT::i64 && "only quads can be loaded to");
|
|
|
|
MVT::ValueType SrcType = N.getOperand(0).getValueType();
|
2005-02-07 13:55:55 +08:00
|
|
|
assert (SrcType == MVT::f32 || SrcType == MVT::f64);
|
2005-01-31 09:44:26 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(0)); // Get the operand register
|
|
|
|
if (SrcType == MVT::f32)
|
2005-04-23 01:54:37 +08:00
|
|
|
{
|
|
|
|
Tmp2 = MakeReg(MVT::f64);
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Tmp2).addReg(Alpha::F31).addReg(Tmp1);
|
2005-04-23 01:54:37 +08:00
|
|
|
Tmp1 = Tmp2;
|
|
|
|
}
|
2005-01-31 09:44:26 +08:00
|
|
|
Tmp2 = MakeReg(MVT::f64);
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTTQ, 1, Tmp2).addReg(Alpha::F31).addReg(Tmp1);
|
2005-04-03 05:06:51 +08:00
|
|
|
MoveFP2Int(Tmp2, Result, true);
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-31 09:44:26 +08:00
|
|
|
return Result;
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
2005-01-27 05:54:09 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::SELECT:
|
2005-06-29 20:49:51 +08: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);
|
|
|
|
|
2005-08-10 04:21:10 +08:00
|
|
|
if (CC.getOpcode() == ISD::SETCC &&
|
|
|
|
!MVT::isInteger(CC.getOperand(0).getValueType())) {
|
|
|
|
//FP Setcc -> Select yay!
|
2005-06-29 20:49:51 +08:00
|
|
|
|
2005-07-27 14:12:32 +08:00
|
|
|
|
2005-06-29 20:49:51 +08:00
|
|
|
//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;
|
2005-08-10 04:21:10 +08:00
|
|
|
if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(1)))
|
2005-06-29 20:49:51 +08:00
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
2005-08-10 04:21:10 +08:00
|
|
|
Tmp3 = SelectExpr(CC.getOperand(0));
|
|
|
|
else if ((CN = dyn_cast<ConstantFPSDNode>(CC.getOperand(0)))
|
2005-06-29 20:49:51 +08:00
|
|
|
&& (CN->isExactlyValue(+0.0) || CN->isExactlyValue(-0.0)))
|
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
Tmp3 = SelectExpr(CC.getOperand(1));
|
2005-06-29 20:49:51 +08:00
|
|
|
invTest = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-10 04:21:10 +08:00
|
|
|
unsigned Tmp1 = SelectExpr(CC.getOperand(0));
|
|
|
|
unsigned Tmp2 = SelectExpr(CC.getOperand(1));
|
|
|
|
bool isD = CC.getOperand(0).getValueType() == MVT::f64;
|
2005-06-29 20:49:51 +08:00
|
|
|
Tmp3 = MakeReg(isD ? MVT::f64 : MVT::f32);
|
|
|
|
BuildMI(BB, isD ? Alpha::SUBT : Alpha::SUBS, 2, Tmp3)
|
|
|
|
.addReg(Tmp1).addReg(Tmp2);
|
|
|
|
}
|
|
|
|
|
2005-08-10 04:21:10 +08:00
|
|
|
switch (cast<CondCodeSDNode>(CC.getOperand(2))->get()) {
|
2005-06-29 20:49:51 +08:00
|
|
|
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;
|
2005-07-27 14:12:32 +08:00
|
|
|
}
|
2005-06-29 20:49:51 +08:00
|
|
|
} else {
|
2005-06-28 01:39:17 +08:00
|
|
|
//FIXME: look at parent to decide if intCC can be folded, or if setCC(FP)
|
|
|
|
//and can save stack use
|
2005-04-03 06:32:39 +08:00
|
|
|
//Tmp1 = SelectExpr(N.getOperand(0)); //Cond
|
2005-04-04 04:35:21 +08:00
|
|
|
//Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
//Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
2005-01-23 07:41:55 +08:00
|
|
|
// Get the condition into the zero flag.
|
2005-04-03 06:32:39 +08:00
|
|
|
//BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3).addReg(Tmp1);
|
2005-04-04 04:35:21 +08:00
|
|
|
|
2005-04-03 06:32:39 +08:00
|
|
|
SDOperand CC = N.getOperand(0);
|
|
|
|
|
2005-04-22 07:13:11 +08:00
|
|
|
if (CC.getOpcode() == ISD::SETCC &&
|
2005-08-10 04:21:10 +08:00
|
|
|
!MVT::isInteger(CC.getOperand(0).getValueType()))
|
2005-04-03 06:32:39 +08:00
|
|
|
{ //FP Setcc -> Int Select
|
2005-04-23 01:54:37 +08:00
|
|
|
Tmp1 = MakeReg(MVT::f64);
|
2005-04-04 04:35:21 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
2005-04-23 01:54:37 +08: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 06:32:39 +08:00
|
|
|
}
|
|
|
|
if (CC.getOpcode() == ISD::SETCC) {
|
2005-04-23 01:54:37 +08:00
|
|
|
//Int SetCC -> Select
|
|
|
|
//Dropping the CC is only useful if we are comparing to 0
|
2005-08-15 22:31:37 +08:00
|
|
|
if(isSIntImmediateBounded(CC.getOperand(1), SImm, 0, 0)) {
|
2005-04-04 04:35:21 +08:00
|
|
|
//figure out a few things
|
2005-08-15 22:31:37 +08:00
|
|
|
bool useImm = isSIntImmediateBounded(N.getOperand(2), SImm, 0, 255);
|
2005-04-04 04:35:21 +08:00
|
|
|
|
|
|
|
//Fix up CC
|
2005-08-10 04:21:10 +08:00
|
|
|
ISD::CondCode cCode= cast<CondCodeSDNode>(CC.getOperand(2))->get();
|
2005-06-27 07:01:11 +08:00
|
|
|
if (useImm) //Invert sense to get Imm field right
|
2005-04-04 04:35:21 +08:00
|
|
|
cCode = ISD::getSetCCInverse(cCode, true);
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-04-04 04:35:21 +08:00
|
|
|
//Choose the CMOV
|
|
|
|
switch (cCode) {
|
|
|
|
default: CC.Val->dump(); assert(0 && "Unknown integer comparison!");
|
2005-06-28 01:39:17 +08: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-04 04:35:21 +08:00
|
|
|
}
|
2005-08-10 04:21:10 +08:00
|
|
|
Tmp1 = SelectExpr(CC.getOperand(0)); //Cond
|
2005-06-27 07:01:11 +08:00
|
|
|
|
|
|
|
if (useImm) {
|
2005-04-04 04:35:21 +08:00
|
|
|
Tmp3 = SelectExpr(N.getOperand(1)); //Use if FALSE
|
2005-08-15 22:31:37 +08:00
|
|
|
BuildMI(BB, Opc, 2, Result).addReg(Tmp3).addImm(SImm).addReg(Tmp1);
|
2005-04-04 04:35:21 +08:00
|
|
|
} 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-23 01:54:37 +08:00
|
|
|
//Otherwise, fall though
|
2005-04-03 06:32:39 +08:00
|
|
|
}
|
|
|
|
Tmp1 = SelectExpr(N.getOperand(0)); //Cond
|
2005-04-04 04:35:21 +08:00
|
|
|
Tmp2 = SelectExpr(N.getOperand(1)); //Use if TRUE
|
|
|
|
Tmp3 = SelectExpr(N.getOperand(2)); //Use if FALSE
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::CMOVEQ, 2, Result).addReg(Tmp2).addReg(Tmp3)
|
|
|
|
.addReg(Tmp1);
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::Constant:
|
|
|
|
{
|
2005-03-30 03:24:04 +08:00
|
|
|
int64_t val = (int64_t)cast<ConstantSDNode>(N)->getValue();
|
2005-07-23 06:24:01 +08:00
|
|
|
int zero_extend_top = 0;
|
2005-07-23 15:46:48 +08:00
|
|
|
if (val > 0 && (val & 0xFFFFFFFF00000000ULL) == 0 &&
|
2005-07-23 06:24:01 +08:00
|
|
|
((int32_t)val < 0)) {
|
|
|
|
//try a small load and zero extend
|
|
|
|
val = (int32_t)val;
|
|
|
|
zero_extend_top = 15;
|
|
|
|
}
|
|
|
|
|
2005-03-12 01:48:05 +08:00
|
|
|
if (val <= IMM_HIGH && val >= IMM_LOW) {
|
2005-07-23 06:24:01 +08:00
|
|
|
if(!zero_extend_top)
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result).addImm(val).addReg(Alpha::R31);
|
|
|
|
else {
|
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Tmp1).addImm(val).addReg(Alpha::R31);
|
|
|
|
BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp1).addImm(zero_extend_top);
|
|
|
|
}
|
2005-03-12 01:48:05 +08:00
|
|
|
}
|
2005-04-23 01:54:37 +08: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-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::LDAH, 2, Tmp1).addImm(getUpper16(val))
|
|
|
|
.addReg(Alpha::R31);
|
2005-07-23 06:24:01 +08:00
|
|
|
if (!zero_extend_top)
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Result).addImm(getLower16(val)).addReg(Tmp1);
|
|
|
|
else {
|
|
|
|
Tmp3 = MakeReg(MVT::i64);
|
|
|
|
BuildMI(BB, Alpha::LDA, 2, Tmp3).addImm(getLower16(val)).addReg(Tmp1);
|
|
|
|
BuildMI(BB, Alpha::ZAPNOT, 2, Result).addReg(Tmp3).addImm(zero_extend_top);
|
|
|
|
}
|
2005-03-12 01:48:05 +08:00
|
|
|
}
|
2005-02-10 14:25:22 +08:00
|
|
|
else {
|
2005-07-23 06:24:01 +08:00
|
|
|
//re-get the val since we are going to mem anyway
|
|
|
|
val = (int64_t)cast<ConstantSDNode>(N)->getValue();
|
2005-02-10 14:25:22 +08:00
|
|
|
MachineConstantPool *CP = BB->getParent()->getConstantPool();
|
2005-07-27 14:12:32 +08:00
|
|
|
ConstantUInt *C =
|
2005-06-28 01:39:17 +08:00
|
|
|
ConstantUInt::get(Type::getPrimitiveType(Type::ULongTyID) , val);
|
2005-02-10 14:25:22 +08:00
|
|
|
unsigned CPI = CP->getConstantPoolIndex(C);
|
|
|
|
AlphaLowering.restoreGP(BB);
|
2005-06-28 01:15:36 +08:00
|
|
|
has_sym = true;
|
|
|
|
Tmp1 = MakeReg(MVT::i64);
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPI)
|
|
|
|
.addReg(Alpha::R29);
|
2005-07-02 03:12:13 +08:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(5).addImm(0).addImm(0)
|
|
|
|
.addImm(getUID());
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::LDQr, 2, Result).addConstantPoolIndex(CPI)
|
|
|
|
.addReg(Tmp1);
|
2005-02-10 14:25:22 +08:00
|
|
|
}
|
|
|
|
return Result;
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
2005-06-29 20:49:51 +08: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));
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTTS, 1, Result).addReg(Alpha::F31).addReg(Tmp1);
|
2005-06-29 20:49:51 +08:00
|
|
|
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));
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Alpha::CVTST, 1, Result).addReg(Alpha::F31).addReg(Tmp1);
|
2005-06-29 20:49:51 +08:00
|
|
|
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;
|
2005-07-29 02:14:47 +08:00
|
|
|
BuildMI(BB, Opc, 1, Result).addReg(Alpha::F31).addReg(Tmp2);
|
2005-06-29 20:49:51 +08:00
|
|
|
return Result;
|
|
|
|
}
|
2005-09-04 14:12:19 +08:00
|
|
|
|
|
|
|
case ISD::AssertSext:
|
|
|
|
case ISD::AssertZext:
|
|
|
|
return SelectExpr(N.getOperand(0));
|
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:19:45 +08:00
|
|
|
void AlphaISel::Select(SDOperand N) {
|
2005-01-23 07:41:55 +08:00
|
|
|
unsigned Tmp1, Tmp2, Opc;
|
2005-02-08 07:02:23 +08:00
|
|
|
unsigned opcode = N.getOpcode();
|
2005-01-23 07:41:55 +08:00
|
|
|
|
2005-03-24 12:39:54 +08:00
|
|
|
if (!ExprMap.insert(std::make_pair(N, notIn)).second)
|
2005-01-28 22:06:46 +08:00
|
|
|
return; // Already selected.
|
2005-01-23 07:41:55 +08:00
|
|
|
|
|
|
|
SDNode *Node = N.Val;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-02-08 07:02:23 +08:00
|
|
|
switch (opcode) {
|
2005-01-23 07:41:55 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
Node->dump(); std::cerr << "\n";
|
|
|
|
assert(0 && "Node not handled yet!");
|
|
|
|
|
|
|
|
case ISD::BRCOND: {
|
2005-02-08 08:40:03 +08:00
|
|
|
SelectBranchCC(N);
|
2005-01-23 07:41:55 +08: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-09 01:28:49 +08:00
|
|
|
++count_ins;
|
2005-01-23 07:41:55 +08:00
|
|
|
Select(N.getOperand(0));
|
2005-08-17 05:56:37 +08:00
|
|
|
BuildMI(BB, Alpha::IDEF, 0,
|
|
|
|
cast<RegisterSDNode>(N.getOperand(1))->getReg());
|
2005-01-23 07:41:55 +08:00
|
|
|
return;
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08: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 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
//N.Val->dump(); std::cerr << "\n";
|
|
|
|
//assert(0 && "Node not handled yet!");
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ISD::CopyToReg:
|
2005-04-09 01:28:49 +08:00
|
|
|
++count_outs;
|
2005-01-23 07:41:55 +08:00
|
|
|
Select(N.getOperand(0));
|
2005-08-17 05:56:37 +08:00
|
|
|
Tmp1 = SelectExpr(N.getOperand(2));
|
|
|
|
Tmp2 = cast<RegisterSDNode>(N.getOperand(1))->getReg();
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-01-23 07:41:55 +08:00
|
|
|
if (Tmp1 != Tmp2) {
|
2005-08-17 05:56:37 +08:00
|
|
|
if (N.getOperand(2).getValueType() == MVT::f64 ||
|
|
|
|
N.getOperand(2).getValueType() == MVT::f32)
|
2005-02-07 14:31:44 +08: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 07:41:55 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2005-02-10 14:25:22 +08:00
|
|
|
case ISD::RET:
|
2005-04-09 01:28:49 +08:00
|
|
|
++count_outs;
|
2005-02-10 14:25:22 +08: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 07:13:11 +08:00
|
|
|
default: Node->dump();
|
2005-02-10 14:25:22 +08: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-28 01:39:17 +08:00
|
|
|
// Just emit a 'ret' instruction
|
2005-06-28 07:24:11 +08:00
|
|
|
AlphaLowering.restoreRA(BB);
|
2005-07-23 04:50:29 +08:00
|
|
|
BuildMI(BB, Alpha::RET, 2, Alpha::R31).addReg(Alpha::R26).addImm(1);
|
2005-02-10 14:25:22 +08:00
|
|
|
return;
|
2005-01-23 07:41:55 +08:00
|
|
|
|
2005-04-22 07:13:11 +08:00
|
|
|
case ISD::TRUNCSTORE:
|
|
|
|
case ISD::STORE:
|
2005-02-03 01:32:39 +08:00
|
|
|
{
|
2005-02-06 23:40:40 +08: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 07:02:23 +08: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 08:29:18 +08:00
|
|
|
switch(cast<VTSDNode>(Node->getOperand(4))->getVT()) {
|
2005-02-08 07:02:23 +08:00
|
|
|
default: assert(0 && "unknown Type in store");
|
|
|
|
case MVT::i8: Opc = Alpha::STB; break;
|
|
|
|
case MVT::i16: Opc = Alpha::STW; break;
|
|
|
|
case MVT::i32: Opc = Alpha::STL; break;
|
|
|
|
}
|
2005-02-07 00:22:15 +08:00
|
|
|
}
|
2005-02-08 07:02:23 +08:00
|
|
|
|
2005-06-30 02:54:02 +08:00
|
|
|
int i, j, k;
|
2005-07-27 14:12:32 +08:00
|
|
|
if (EnableAlphaLSMark)
|
|
|
|
getValueInfo(cast<SrcValueSDNode>(N.getOperand(3))->getValue(),
|
2005-06-30 02:54:02 +08:00
|
|
|
i, j, k);
|
2005-06-23 01:19:45 +08:00
|
|
|
|
2005-07-02 03:12:13 +08: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 08:39:17 +08:00
|
|
|
} else if(Address.getOpcode() == ISD::FrameIndex) {
|
2005-06-29 08:31:08 +08:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-30 02:54:02 +08:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-23 05:59:48 +08:00
|
|
|
BuildMI(BB, Opc, 3).addReg(Tmp1)
|
|
|
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
|
|
|
.addReg(Alpha::F31);
|
2005-06-29 08:31:08 +08:00
|
|
|
} else {
|
2005-02-10 14:25:22 +08:00
|
|
|
long offset;
|
|
|
|
SelectAddr(Address, Tmp2, offset);
|
2005-06-29 08:31:08 +08:00
|
|
|
if (EnableAlphaLSMark)
|
2005-06-30 02:54:02 +08:00
|
|
|
BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
|
|
|
|
.addImm(getUID());
|
2005-02-10 14:25:22 +08:00
|
|
|
BuildMI(BB, Opc, 3).addReg(Tmp1).addImm(offset).addReg(Tmp2);
|
|
|
|
}
|
2005-02-03 01:32:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-01-23 07:41:55 +08:00
|
|
|
|
|
|
|
case ISD::EXTLOAD:
|
|
|
|
case ISD::SEXTLOAD:
|
|
|
|
case ISD::ZEXTLOAD:
|
|
|
|
case ISD::LOAD:
|
|
|
|
case ISD::CopyFromReg:
|
2005-05-14 04:29:26 +08:00
|
|
|
case ISD::TAILCALL:
|
2005-01-23 07:41:55 +08:00
|
|
|
case ISD::CALL:
|
2005-02-23 05:59:48 +08:00
|
|
|
case ISD::DYNAMIC_STACKALLOC:
|
2005-01-28 22:06:46 +08:00
|
|
|
ExprMap.erase(N);
|
2005-01-23 07:41:55 +08:00
|
|
|
SelectExpr(N);
|
|
|
|
return;
|
|
|
|
|
2005-05-13 07:24:06 +08:00
|
|
|
case ISD::CALLSEQ_START:
|
|
|
|
case ISD::CALLSEQ_END:
|
2005-01-23 07:41:55 +08:00
|
|
|
Select(N.getOperand(0));
|
|
|
|
Tmp1 = cast<ConstantSDNode>(N.getOperand(1))->getValue();
|
2005-04-22 07:13:11 +08:00
|
|
|
|
2005-05-13 07:24:06 +08:00
|
|
|
Opc = N.getOpcode() == ISD::CALLSEQ_START ? Alpha::ADJUSTSTACKDOWN :
|
2005-01-23 07:41:55 +08:00
|
|
|
Alpha::ADJUSTSTACKUP;
|
|
|
|
BuildMI(BB, Opc, 1).addImm(Tmp1);
|
|
|
|
return;
|
2005-04-01 05:24:06 +08:00
|
|
|
|
|
|
|
case ISD::PCMARKER:
|
|
|
|
Select(N.getOperand(0)); //Chain
|
2005-06-28 01:39:17 +08:00
|
|
|
BuildMI(BB, Alpha::PCLABEL, 2)
|
|
|
|
.addImm( cast<ConstantSDNode>(N.getOperand(1))->getValue());
|
2005-04-01 05:24:06 +08:00
|
|
|
return;
|
2005-01-23 07:41:55 +08: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-23 01:19:45 +08:00
|
|
|
return new AlphaISel(TM);
|
2005-01-23 07:41:55 +08:00
|
|
|
}
|
2005-04-13 13:19:55 +08:00
|
|
|
|