2005-10-20 08:29:02 +08:00
|
|
|
//===-- AlphaISelDAGToDAG.cpp - Alpha pattern matching inst selector ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-10-20 08:29:02 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a pattern matching instruction selector for Alpha,
|
|
|
|
// converting from a legalized dag to a Alpha dag.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Alpha.h"
|
|
|
|
#include "AlphaTargetMachine.h"
|
|
|
|
#include "AlphaISelLowering.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2005-11-30 15:19:56 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2005-10-20 08:29:02 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2007-12-31 12:13:23 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2005-10-20 08:29:02 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Constants.h"
|
2007-01-20 05:13:56 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2005-10-20 08:29:02 +08:00
|
|
|
#include "llvm/GlobalValue.h"
|
2006-03-25 14:47:10 +08:00
|
|
|
#include "llvm/Intrinsics.h"
|
2008-02-03 13:43:57 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2005-10-20 08:29:02 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2005-10-23 06:06:58 +08:00
|
|
|
#include <algorithm>
|
2005-10-20 08:29:02 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// AlphaDAGToDAGISel - Alpha specific code to select Alpha machine
|
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
class AlphaDAGToDAGISel : public SelectionDAGISel {
|
2005-12-30 10:30:02 +08:00
|
|
|
static const int64_t IMM_LOW = -32768;
|
|
|
|
static const int64_t IMM_HIGH = 32767;
|
|
|
|
static const int64_t IMM_MULT = 65536;
|
2006-01-02 06:16:14 +08:00
|
|
|
static const int64_t IMM_FULLHIGH = IMM_HIGH + IMM_HIGH * IMM_MULT;
|
|
|
|
static const int64_t IMM_FULLLOW = IMM_LOW + IMM_LOW * IMM_MULT;
|
|
|
|
|
|
|
|
static int64_t get_ldah16(int64_t x) {
|
|
|
|
int64_t y = x / IMM_MULT;
|
|
|
|
if (x % IMM_MULT > IMM_HIGH)
|
2007-04-17 02:10:23 +08:00
|
|
|
++y;
|
2006-01-02 06:16:14 +08:00
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int64_t get_lda16(int64_t x) {
|
|
|
|
return x - get_ldah16(x) * IMM_MULT;
|
|
|
|
}
|
|
|
|
|
Use cute tblgen tricks to make zap handling more powerful. Specifically,
when the dag combiner simplifies an and mask, notice this and allow those bits
to be missing from the zap mask.
This compiles Alpha/zapnot4.ll into:
sll $16,3,$0
zapnot $0,3,$0
ret $31,($26),1
instead of:
ldah $0,1($31)
lda $0,-8($0)
sll $16,3,$1
and $1,$0,$0
ret $31,($26),1
It would be *really* nice to replace the hunk of code in the
AlphaISelDAGToDAG.cpp file that matches (and (srl (x, C), c2) into
(SRL (ZAPNOTi)) with a similar pattern, but I've spent enough time poking
at alpha. Make andrew will do this.
llvm-svn: 30875
2006-10-11 13:13:56 +08:00
|
|
|
/// get_zapImm - Return a zap mask if X is a valid immediate for a zapnot
|
|
|
|
/// instruction (if not, return 0). Note that this code accepts partial
|
|
|
|
/// zap masks. For example (and LHS, 1) is a valid zap, as long we know
|
|
|
|
/// that the bits 1-7 of LHS are already zero. If LHS is non-null, we are
|
|
|
|
/// in checking mode. If LHS is null, we assume that the mask has already
|
|
|
|
/// been validated before.
|
2008-07-28 05:46:04 +08:00
|
|
|
uint64_t get_zapImm(SDValue LHS, uint64_t Constant) {
|
Use cute tblgen tricks to make zap handling more powerful. Specifically,
when the dag combiner simplifies an and mask, notice this and allow those bits
to be missing from the zap mask.
This compiles Alpha/zapnot4.ll into:
sll $16,3,$0
zapnot $0,3,$0
ret $31,($26),1
instead of:
ldah $0,1($31)
lda $0,-8($0)
sll $16,3,$1
and $1,$0,$0
ret $31,($26),1
It would be *really* nice to replace the hunk of code in the
AlphaISelDAGToDAG.cpp file that matches (and (srl (x, C), c2) into
(SRL (ZAPNOTi)) with a similar pattern, but I've spent enough time poking
at alpha. Make andrew will do this.
llvm-svn: 30875
2006-10-11 13:13:56 +08:00
|
|
|
uint64_t BitsToCheck = 0;
|
|
|
|
unsigned Result = 0;
|
|
|
|
for (unsigned i = 0; i != 8; ++i) {
|
|
|
|
if (((Constant >> 8*i) & 0xFF) == 0) {
|
|
|
|
// nothing to do.
|
|
|
|
} else {
|
|
|
|
Result |= 1 << i;
|
|
|
|
if (((Constant >> 8*i) & 0xFF) == 0xFF) {
|
|
|
|
// If the entire byte is set, zapnot the byte.
|
2008-08-29 05:40:38 +08:00
|
|
|
} else if (LHS.getNode() == 0) {
|
Use cute tblgen tricks to make zap handling more powerful. Specifically,
when the dag combiner simplifies an and mask, notice this and allow those bits
to be missing from the zap mask.
This compiles Alpha/zapnot4.ll into:
sll $16,3,$0
zapnot $0,3,$0
ret $31,($26),1
instead of:
ldah $0,1($31)
lda $0,-8($0)
sll $16,3,$1
and $1,$0,$0
ret $31,($26),1
It would be *really* nice to replace the hunk of code in the
AlphaISelDAGToDAG.cpp file that matches (and (srl (x, C), c2) into
(SRL (ZAPNOTi)) with a similar pattern, but I've spent enough time poking
at alpha. Make andrew will do this.
llvm-svn: 30875
2006-10-11 13:13:56 +08:00
|
|
|
// Otherwise, if the mask was previously validated, we know its okay
|
|
|
|
// to zapnot this entire byte even though all the bits aren't set.
|
|
|
|
} else {
|
|
|
|
// Otherwise we don't know that the it's okay to zapnot this entire
|
|
|
|
// byte. Only do this iff we can prove that the missing bits are
|
|
|
|
// already null, so the bytezap doesn't need to really null them.
|
|
|
|
BitsToCheck |= ~Constant & (0xFF << 8*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are missing bits in a byte (for example, X & 0xEF00), check to
|
|
|
|
// see if the missing bits (0x1000) are already known zero if not, the zap
|
|
|
|
// isn't okay to do, as it won't clear all the required bits.
|
|
|
|
if (BitsToCheck &&
|
2008-02-26 05:11:39 +08:00
|
|
|
!CurDAG->MaskedValueIsZero(LHS,
|
|
|
|
APInt(LHS.getValueSizeInBits(),
|
|
|
|
BitsToCheck)))
|
Use cute tblgen tricks to make zap handling more powerful. Specifically,
when the dag combiner simplifies an and mask, notice this and allow those bits
to be missing from the zap mask.
This compiles Alpha/zapnot4.ll into:
sll $16,3,$0
zapnot $0,3,$0
ret $31,($26),1
instead of:
ldah $0,1($31)
lda $0,-8($0)
sll $16,3,$1
and $1,$0,$0
ret $31,($26),1
It would be *really* nice to replace the hunk of code in the
AlphaISelDAGToDAG.cpp file that matches (and (srl (x, C), c2) into
(SRL (ZAPNOTi)) with a similar pattern, but I've spent enough time poking
at alpha. Make andrew will do this.
llvm-svn: 30875
2006-10-11 13:13:56 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2006-01-02 06:16:14 +08:00
|
|
|
static uint64_t get_zapImm(uint64_t x) {
|
Use cute tblgen tricks to make zap handling more powerful. Specifically,
when the dag combiner simplifies an and mask, notice this and allow those bits
to be missing from the zap mask.
This compiles Alpha/zapnot4.ll into:
sll $16,3,$0
zapnot $0,3,$0
ret $31,($26),1
instead of:
ldah $0,1($31)
lda $0,-8($0)
sll $16,3,$1
and $1,$0,$0
ret $31,($26),1
It would be *really* nice to replace the hunk of code in the
AlphaISelDAGToDAG.cpp file that matches (and (srl (x, C), c2) into
(SRL (ZAPNOTi)) with a similar pattern, but I've spent enough time poking
at alpha. Make andrew will do this.
llvm-svn: 30875
2006-10-11 13:13:56 +08:00
|
|
|
unsigned build = 0;
|
|
|
|
for(int i = 0; i != 8; ++i) {
|
|
|
|
if ((x & 0x00FF) == 0x00FF)
|
|
|
|
build |= 1 << i;
|
|
|
|
else if ((x & 0x00FF) != 0)
|
|
|
|
return 0;
|
|
|
|
x >>= 8;
|
|
|
|
}
|
2006-01-03 05:15:53 +08:00
|
|
|
return build;
|
2006-01-02 06:16:14 +08:00
|
|
|
}
|
Use cute tblgen tricks to make zap handling more powerful. Specifically,
when the dag combiner simplifies an and mask, notice this and allow those bits
to be missing from the zap mask.
This compiles Alpha/zapnot4.ll into:
sll $16,3,$0
zapnot $0,3,$0
ret $31,($26),1
instead of:
ldah $0,1($31)
lda $0,-8($0)
sll $16,3,$1
and $1,$0,$0
ret $31,($26),1
It would be *really* nice to replace the hunk of code in the
AlphaISelDAGToDAG.cpp file that matches (and (srl (x, C), c2) into
(SRL (ZAPNOTi)) with a similar pattern, but I've spent enough time poking
at alpha. Make andrew will do this.
llvm-svn: 30875
2006-10-11 13:13:56 +08:00
|
|
|
|
|
|
|
|
2006-04-03 11:18:59 +08:00
|
|
|
static uint64_t getNearPower2(uint64_t x) {
|
|
|
|
if (!x) return 0;
|
|
|
|
unsigned at = CountLeadingZeros_64(x);
|
|
|
|
uint64_t complow = 1 << (63 - at);
|
|
|
|
uint64_t comphigh = 1 << (64 - at);
|
2006-12-08 06:21:48 +08:00
|
|
|
//cerr << x << ":" << complow << ":" << comphigh << "\n";
|
2006-04-03 12:19:17 +08:00
|
|
|
if (abs(complow - x) <= abs(comphigh - x))
|
2006-04-03 11:18:59 +08:00
|
|
|
return complow;
|
|
|
|
else
|
|
|
|
return comphigh;
|
|
|
|
}
|
|
|
|
|
2006-11-01 03:52:12 +08:00
|
|
|
static bool chkRemNearPower2(uint64_t x, uint64_t r, bool swap) {
|
|
|
|
uint64_t y = getNearPower2(x);
|
|
|
|
if (swap)
|
|
|
|
return (y - x) == r;
|
|
|
|
else
|
|
|
|
return (x - y) == r;
|
|
|
|
}
|
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
static bool isFPZ(SDValue N) {
|
2006-01-02 06:16:14 +08:00
|
|
|
ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
|
2007-08-31 12:03:46 +08:00
|
|
|
return (CN && (CN->getValueAPF().isZero()));
|
2006-01-02 06:16:14 +08:00
|
|
|
}
|
2008-07-28 05:46:04 +08:00
|
|
|
static bool isFPZn(SDValue N) {
|
2006-01-02 06:16:14 +08:00
|
|
|
ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
|
2007-08-31 12:03:46 +08:00
|
|
|
return (CN && CN->getValueAPF().isNegZero());
|
2006-01-02 06:16:14 +08:00
|
|
|
}
|
2008-07-28 05:46:04 +08:00
|
|
|
static bool isFPZp(SDValue N) {
|
2006-01-02 06:16:14 +08:00
|
|
|
ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(N);
|
2007-08-31 12:03:46 +08:00
|
|
|
return (CN && CN->getValueAPF().isPosZero());
|
2006-01-02 06:16:14 +08:00
|
|
|
}
|
|
|
|
|
2005-10-20 08:29:02 +08:00
|
|
|
public:
|
2008-05-14 09:58:56 +08:00
|
|
|
explicit AlphaDAGToDAGISel(AlphaTargetMachine &TM)
|
2008-10-04 00:55:19 +08:00
|
|
|
: SelectionDAGISel(*TM.getTargetLowering())
|
2005-12-30 10:30:02 +08:00
|
|
|
{}
|
2005-10-20 08:29:02 +08:00
|
|
|
|
|
|
|
/// getI64Imm - Return a target constant with the specified value, of type
|
|
|
|
/// i64.
|
2008-07-28 05:46:04 +08:00
|
|
|
inline SDValue getI64Imm(int64_t Imm) {
|
2005-10-20 08:29:02 +08:00
|
|
|
return CurDAG->getTargetConstant(Imm, MVT::i64);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select - Convert the specified operand from a target-independent to a
|
|
|
|
// target-specific node if it hasn't already been changed.
|
2008-07-28 05:46:04 +08:00
|
|
|
SDNode *Select(SDValue Op);
|
2005-10-20 08:29:02 +08:00
|
|
|
|
2008-07-01 04:45:06 +08:00
|
|
|
/// InstructionSelect - This callback is invoked by
|
2005-10-20 08:29:02 +08:00
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
2008-08-23 10:25:05 +08:00
|
|
|
virtual void InstructionSelect();
|
2005-10-20 08:29:02 +08:00
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Alpha DAG->DAG Pattern Instruction Selection";
|
|
|
|
}
|
|
|
|
|
2006-06-21 23:42:36 +08:00
|
|
|
/// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
|
|
|
|
/// inline asm expressions.
|
2008-07-28 05:46:04 +08:00
|
|
|
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
|
2006-06-21 23:42:36 +08:00
|
|
|
char ConstraintCode,
|
2008-08-23 10:25:05 +08:00
|
|
|
std::vector<SDValue> &OutOps) {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Op0;
|
2006-06-21 23:42:36 +08:00
|
|
|
switch (ConstraintCode) {
|
|
|
|
default: return true;
|
|
|
|
case 'm': // memory
|
2006-08-26 09:07:58 +08:00
|
|
|
Op0 = Op;
|
2007-04-17 02:10:23 +08:00
|
|
|
AddToISelQueue(Op0);
|
2006-06-21 23:42:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutOps.push_back(Op0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-10-20 08:29:02 +08:00
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "AlphaGenDAGISel.inc"
|
|
|
|
|
|
|
|
private:
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue getGlobalBaseReg();
|
|
|
|
SDValue getGlobalRetAddr();
|
|
|
|
void SelectCALL(SDValue Op);
|
2005-10-23 06:06:58 +08:00
|
|
|
|
2005-10-20 08:29:02 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-10-23 06:06:58 +08:00
|
|
|
/// getGlobalBaseReg - Output the instructions required to put the
|
|
|
|
/// GOT address into a register.
|
|
|
|
///
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue AlphaDAGToDAGISel::getGlobalBaseReg() {
|
2006-10-12 00:24:51 +08:00
|
|
|
unsigned GP = 0;
|
2007-12-31 12:13:23 +08:00
|
|
|
for(MachineRegisterInfo::livein_iterator ii = RegInfo->livein_begin(),
|
|
|
|
ee = RegInfo->livein_end(); ii != ee; ++ii)
|
2006-10-12 00:24:51 +08:00
|
|
|
if (ii->first == Alpha::R29) {
|
|
|
|
GP = ii->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(GP && "GOT PTR not in liveins");
|
2005-12-01 09:53:10 +08:00
|
|
|
return CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
|
2006-10-12 00:24:51 +08:00
|
|
|
GP, MVT::i64);
|
2005-12-01 09:53:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getRASaveReg - Grab the return address
|
|
|
|
///
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue AlphaDAGToDAGISel::getGlobalRetAddr() {
|
2006-10-12 00:24:51 +08:00
|
|
|
unsigned RA = 0;
|
2007-12-31 12:13:23 +08:00
|
|
|
for(MachineRegisterInfo::livein_iterator ii = RegInfo->livein_begin(),
|
|
|
|
ee = RegInfo->livein_end(); ii != ee; ++ii)
|
2006-10-12 00:24:51 +08:00
|
|
|
if (ii->first == Alpha::R26) {
|
|
|
|
RA = ii->second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(RA && "RA PTR not in liveins");
|
2005-12-01 09:53:10 +08:00
|
|
|
return CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
|
2006-10-12 00:24:51 +08:00
|
|
|
RA, MVT::i64);
|
2005-10-23 06:06:58 +08:00
|
|
|
}
|
|
|
|
|
2008-07-01 04:45:06 +08:00
|
|
|
/// InstructionSelect - This callback is invoked by
|
2005-10-20 08:29:02 +08:00
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
2008-08-23 10:25:05 +08:00
|
|
|
void AlphaDAGToDAGISel::InstructionSelect() {
|
2005-10-20 08:29:02 +08:00
|
|
|
DEBUG(BB->dump());
|
|
|
|
|
|
|
|
// Select target instructions for the DAG.
|
2008-08-22 00:36:34 +08:00
|
|
|
SelectRoot();
|
2008-08-23 10:25:05 +08:00
|
|
|
CurDAG->RemoveDeadNodes();
|
2005-10-20 08:29:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Select - Convert the specified operand from a target-independent to a
|
|
|
|
// target-specific node if it hasn't already been changed.
|
2008-07-28 05:46:04 +08:00
|
|
|
SDNode *AlphaDAGToDAGISel::Select(SDValue Op) {
|
2008-08-29 05:40:38 +08:00
|
|
|
SDNode *N = Op.getNode();
|
2008-07-18 03:10:17 +08:00
|
|
|
if (N->isMachineOpcode()) {
|
2006-08-11 17:08:15 +08:00
|
|
|
return NULL; // Already selected.
|
2006-02-09 08:37:58 +08:00
|
|
|
}
|
2005-10-20 08:29:02 +08:00
|
|
|
|
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default: break;
|
2006-02-09 08:37:58 +08:00
|
|
|
case AlphaISD::CALL:
|
2006-08-26 13:34:46 +08:00
|
|
|
SelectCALL(Op);
|
2006-08-11 17:08:15 +08:00
|
|
|
return NULL;
|
2005-10-23 06:06:58 +08:00
|
|
|
|
2005-10-20 08:29:02 +08:00
|
|
|
case ISD::FrameIndex: {
|
2005-11-22 12:20:06 +08:00
|
|
|
int FI = cast<FrameIndexSDNode>(N)->getIndex();
|
2006-08-16 15:30:09 +08:00
|
|
|
return CurDAG->SelectNodeTo(N, Alpha::LDA, MVT::i64,
|
|
|
|
CurDAG->getTargetFrameIndex(FI, MVT::i32),
|
2006-08-26 16:00:10 +08:00
|
|
|
getI64Imm(0));
|
2005-10-20 08:29:02 +08:00
|
|
|
}
|
2006-10-11 12:29:42 +08:00
|
|
|
case ISD::GLOBAL_OFFSET_TABLE: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Result = getGlobalBaseReg();
|
2006-08-08 06:28:20 +08:00
|
|
|
ReplaceUses(Op, Result);
|
2006-08-11 17:08:15 +08:00
|
|
|
return NULL;
|
2006-08-26 13:34:46 +08:00
|
|
|
}
|
|
|
|
case AlphaISD::GlobalRetAddr: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Result = getGlobalRetAddr();
|
2006-08-08 06:28:20 +08:00
|
|
|
ReplaceUses(Op, Result);
|
2006-08-11 17:08:15 +08:00
|
|
|
return NULL;
|
2006-08-26 13:34:46 +08:00
|
|
|
}
|
2005-12-24 13:36:33 +08:00
|
|
|
|
2005-12-25 09:34:27 +08:00
|
|
|
case AlphaISD::DivCall: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Chain = CurDAG->getEntryNode();
|
|
|
|
SDValue N0 = Op.getOperand(0);
|
|
|
|
SDValue N1 = Op.getOperand(1);
|
|
|
|
SDValue N2 = Op.getOperand(2);
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(N0);
|
|
|
|
AddToISelQueue(N1);
|
|
|
|
AddToISelQueue(N2);
|
2006-02-09 08:37:58 +08:00
|
|
|
Chain = CurDAG->getCopyToReg(Chain, Alpha::R24, N1,
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue(0,0));
|
2006-02-09 08:37:58 +08:00
|
|
|
Chain = CurDAG->getCopyToReg(Chain, Alpha::R25, N2,
|
2007-04-17 02:10:23 +08:00
|
|
|
Chain.getValue(1));
|
2006-02-09 08:37:58 +08:00
|
|
|
Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, N0,
|
2007-04-17 02:10:23 +08:00
|
|
|
Chain.getValue(1));
|
2006-02-09 15:17:49 +08:00
|
|
|
SDNode *CNode =
|
|
|
|
CurDAG->getTargetNode(Alpha::JSRs, MVT::Other, MVT::Flag,
|
|
|
|
Chain, Chain.getValue(1));
|
2005-12-25 09:34:27 +08:00
|
|
|
Chain = CurDAG->getCopyFromReg(Chain, Alpha::R27, MVT::i64,
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue(CNode, 1));
|
2006-11-01 07:46:56 +08:00
|
|
|
return CurDAG->SelectNodeTo(N, Alpha::BISr, MVT::i64, Chain, Chain);
|
2005-10-20 08:29:02 +08:00
|
|
|
}
|
|
|
|
|
2006-01-17 05:22:38 +08:00
|
|
|
case ISD::READCYCLECOUNTER: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Chain = N->getOperand(0);
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(Chain); //Select chain
|
2006-08-26 13:34:46 +08:00
|
|
|
return CurDAG->getTargetNode(Alpha::RPCC, MVT::i64, MVT::Other,
|
|
|
|
Chain);
|
2006-01-17 05:22:38 +08:00
|
|
|
}
|
|
|
|
|
2005-11-22 12:20:06 +08:00
|
|
|
case ISD::Constant: {
|
2008-09-13 00:56:44 +08:00
|
|
|
uint64_t uval = cast<ConstantSDNode>(N)->getZExtValue();
|
2006-01-07 03:41:51 +08:00
|
|
|
|
2006-02-09 08:37:58 +08:00
|
|
|
if (uval == 0) {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
|
2006-08-26 13:34:46 +08:00
|
|
|
Alpha::R31, MVT::i64);
|
2006-08-08 06:28:20 +08:00
|
|
|
ReplaceUses(Op, Result);
|
2006-08-11 17:08:15 +08:00
|
|
|
return NULL;
|
2006-02-09 08:37:58 +08:00
|
|
|
}
|
2006-01-07 03:41:51 +08:00
|
|
|
|
2005-12-30 10:30:02 +08:00
|
|
|
int64_t val = (int64_t)uval;
|
|
|
|
int32_t val32 = (int32_t)val;
|
|
|
|
if (val <= IMM_HIGH + IMM_HIGH * IMM_MULT &&
|
2007-04-17 02:10:23 +08:00
|
|
|
val >= IMM_LOW + IMM_LOW * IMM_MULT)
|
2005-12-30 10:30:02 +08:00
|
|
|
break; //(LDAH (LDA))
|
|
|
|
if ((uval >> 32) == 0 && //empty upper bits
|
2007-04-17 02:10:23 +08:00
|
|
|
val32 <= IMM_HIGH + IMM_HIGH * IMM_MULT)
|
|
|
|
// val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true
|
2005-12-30 10:30:02 +08:00
|
|
|
break; //(zext (LDAH (LDA)))
|
|
|
|
//Else use the constant pool
|
2006-12-31 13:55:36 +08:00
|
|
|
ConstantInt *C = ConstantInt::get(Type::Int64Ty, uval);
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
|
2006-02-09 15:17:49 +08:00
|
|
|
SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, MVT::i64, CPI,
|
|
|
|
getGlobalBaseReg());
|
2006-08-16 15:30:09 +08:00
|
|
|
return CurDAG->SelectNodeTo(N, Alpha::LDQr, MVT::i64, MVT::Other,
|
2008-07-28 05:46:04 +08:00
|
|
|
CPI, SDValue(Tmp, 0), CurDAG->getEntryNode());
|
2005-11-22 12:20:06 +08:00
|
|
|
}
|
2008-10-07 10:10:26 +08:00
|
|
|
case ISD::TargetConstantFP:
|
|
|
|
case ISD::ConstantFP: {
|
2006-01-29 14:25:22 +08:00
|
|
|
ConstantFPSDNode *CN = cast<ConstantFPSDNode>(N);
|
|
|
|
bool isDouble = N->getValueType(0) == MVT::f64;
|
2008-06-06 20:08:01 +08:00
|
|
|
MVT T = isDouble ? MVT::f64 : MVT::f32;
|
2007-08-31 12:03:46 +08:00
|
|
|
if (CN->getValueAPF().isPosZero()) {
|
2006-08-16 15:30:09 +08:00
|
|
|
return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYST : Alpha::CPYSS,
|
|
|
|
T, CurDAG->getRegister(Alpha::F31, T),
|
2006-08-26 16:00:10 +08:00
|
|
|
CurDAG->getRegister(Alpha::F31, T));
|
2007-08-31 12:03:46 +08:00
|
|
|
} else if (CN->getValueAPF().isNegZero()) {
|
2006-08-16 15:30:09 +08:00
|
|
|
return CurDAG->SelectNodeTo(N, isDouble ? Alpha::CPYSNT : Alpha::CPYSNS,
|
|
|
|
T, CurDAG->getRegister(Alpha::F31, T),
|
2006-08-26 16:00:10 +08:00
|
|
|
CurDAG->getRegister(Alpha::F31, T));
|
2006-01-29 14:25:22 +08:00
|
|
|
} else {
|
|
|
|
abort();
|
2005-11-22 12:20:06 +08:00
|
|
|
}
|
2006-01-29 14:25:22 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-11-30 15:19:56 +08:00
|
|
|
|
|
|
|
case ISD::SETCC:
|
2008-08-29 05:40:38 +08:00
|
|
|
if (N->getOperand(0).getNode()->getValueType(0).isFloatingPoint()) {
|
2005-11-30 15:19:56 +08:00
|
|
|
ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
|
2007-01-25 02:43:14 +08:00
|
|
|
|
|
|
|
unsigned Opc = Alpha::WTF;
|
2005-11-30 15:19:56 +08:00
|
|
|
bool rev = false;
|
2007-01-25 02:43:14 +08:00
|
|
|
bool inv = false;
|
2005-11-30 15:19:56 +08:00
|
|
|
switch(CC) {
|
2007-06-19 22:13:56 +08:00
|
|
|
default: DEBUG(N->dump(CurDAG)); assert(0 && "Unknown FP comparison!");
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETEQ: case ISD::SETOEQ: case ISD::SETUEQ:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTEQ; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETLT: case ISD::SETOLT: case ISD::SETULT:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTLT; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETLE: case ISD::SETOLE: case ISD::SETULE:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTLE; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETGT: case ISD::SETOGT: case ISD::SETUGT:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTLT; rev = true; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETGE: case ISD::SETOGE: case ISD::SETUGE:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTLE; rev = true; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETNE: case ISD::SETONE: case ISD::SETUNE:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTEQ; inv = true; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETO:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTUN; inv = true; break;
|
2007-01-25 02:43:14 +08:00
|
|
|
case ISD::SETUO:
|
2007-04-17 02:10:23 +08:00
|
|
|
Opc = Alpha::CMPTUN; break;
|
2005-11-30 15:19:56 +08:00
|
|
|
};
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue tmp1 = N->getOperand(rev?1:0);
|
|
|
|
SDValue tmp2 = N->getOperand(rev?0:1);
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(tmp1);
|
|
|
|
AddToISelQueue(tmp2);
|
2007-01-25 02:43:14 +08:00
|
|
|
SDNode *cmp = CurDAG->getTargetNode(Opc, MVT::f64, tmp1, tmp2);
|
|
|
|
if (inv)
|
2008-07-28 05:46:04 +08:00
|
|
|
cmp = CurDAG->getTargetNode(Alpha::CMPTEQ, MVT::f64, SDValue(cmp, 0),
|
2005-12-01 01:11:20 +08:00
|
|
|
CurDAG->getRegister(Alpha::F31, MVT::f64));
|
2007-01-25 02:43:14 +08:00
|
|
|
switch(CC) {
|
|
|
|
case ISD::SETUEQ: case ISD::SETULT: case ISD::SETULE:
|
|
|
|
case ISD::SETUNE: case ISD::SETUGT: case ISD::SETUGE:
|
2007-04-17 02:10:23 +08:00
|
|
|
{
|
|
|
|
SDNode* cmp2 = CurDAG->getTargetNode(Alpha::CMPTUN, MVT::f64,
|
|
|
|
tmp1, tmp2);
|
|
|
|
cmp = CurDAG->getTargetNode(Alpha::ADDT, MVT::f64,
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue(cmp2, 0), SDValue(cmp, 0));
|
2007-04-17 02:10:23 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-01-25 02:43:14 +08:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
SDNode* LD = CurDAG->getTargetNode(Alpha::FTOIT, MVT::i64, SDValue(cmp, 0));
|
2006-08-26 13:34:46 +08:00
|
|
|
return CurDAG->getTargetNode(Alpha::CMPULT, MVT::i64,
|
|
|
|
CurDAG->getRegister(Alpha::R31, MVT::i64),
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue(LD,0));
|
2005-11-30 15:19:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2005-12-01 00:10:29 +08:00
|
|
|
|
2005-12-13 01:43:52 +08:00
|
|
|
case ISD::SELECT:
|
2008-06-06 20:08:01 +08:00
|
|
|
if (N->getValueType(0).isFloatingPoint() &&
|
2007-04-17 02:10:23 +08:00
|
|
|
(N->getOperand(0).getOpcode() != ISD::SETCC ||
|
2008-06-06 20:08:01 +08:00
|
|
|
!N->getOperand(0).getOperand(1).getValueType().isFloatingPoint())) {
|
2005-12-13 01:43:52 +08:00
|
|
|
//This should be the condition not covered by the Patterns
|
|
|
|
//FIXME: Don't have SelectCode die, but rather return something testable
|
|
|
|
// so that things like this can be caught in fall though code
|
|
|
|
//move int to fp
|
|
|
|
bool isDouble = N->getValueType(0) == MVT::f64;
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue cond = N->getOperand(0);
|
|
|
|
SDValue TV = N->getOperand(1);
|
|
|
|
SDValue FV = N->getOperand(2);
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(cond);
|
|
|
|
AddToISelQueue(TV);
|
|
|
|
AddToISelQueue(FV);
|
2005-12-13 01:43:52 +08:00
|
|
|
|
2007-01-25 05:09:16 +08:00
|
|
|
SDNode* LD = CurDAG->getTargetNode(Alpha::ITOFT, MVT::f64, cond);
|
2006-08-26 13:34:46 +08:00
|
|
|
return CurDAG->getTargetNode(isDouble?Alpha::FCMOVNET:Alpha::FCMOVNES,
|
2008-07-28 05:46:04 +08:00
|
|
|
MVT::f64, FV, TV, SDValue(LD,0));
|
2005-12-13 01:43:52 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-02-14 02:52:29 +08:00
|
|
|
case ISD::AND: {
|
2006-05-19 01:29:34 +08:00
|
|
|
ConstantSDNode* SC = NULL;
|
|
|
|
ConstantSDNode* MC = NULL;
|
2006-02-14 02:52:29 +08:00
|
|
|
if (N->getOperand(0).getOpcode() == ISD::SRL &&
|
2007-04-17 02:10:23 +08:00
|
|
|
(MC = dyn_cast<ConstantSDNode>(N->getOperand(1))) &&
|
|
|
|
(SC = dyn_cast<ConstantSDNode>(N->getOperand(0).getOperand(1)))) {
|
2008-09-13 00:56:44 +08:00
|
|
|
uint64_t sval = SC->getZExtValue();
|
|
|
|
uint64_t mval = MC->getZExtValue();
|
2007-04-17 02:10:23 +08:00
|
|
|
// If the result is a zap, let the autogened stuff handle it.
|
|
|
|
if (get_zapImm(N->getOperand(0), mval))
|
|
|
|
break;
|
|
|
|
// given mask X, and shift S, we want to see if there is any zap in the
|
|
|
|
// mask if we play around with the botton S bits
|
|
|
|
uint64_t dontcare = (~0ULL) >> (64 - sval);
|
|
|
|
uint64_t mask = mval << sval;
|
|
|
|
|
|
|
|
if (get_zapImm(mask | dontcare))
|
|
|
|
mask = mask | dontcare;
|
|
|
|
|
|
|
|
if (get_zapImm(mask)) {
|
|
|
|
AddToISelQueue(N->getOperand(0).getOperand(0));
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Z =
|
|
|
|
SDValue(CurDAG->getTargetNode(Alpha::ZAPNOTi, MVT::i64,
|
2007-04-17 02:10:23 +08:00
|
|
|
N->getOperand(0).getOperand(0),
|
|
|
|
getI64Imm(get_zapImm(mask))), 0);
|
|
|
|
return CurDAG->getTargetNode(Alpha::SRLr, MVT::i64, Z,
|
|
|
|
getI64Imm(sval));
|
2006-02-14 02:52:29 +08:00
|
|
|
}
|
2007-04-17 02:10:23 +08:00
|
|
|
}
|
2006-02-14 02:52:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-20 08:29:02 +08:00
|
|
|
}
|
2005-12-01 00:10:29 +08:00
|
|
|
|
2006-08-26 13:34:46 +08:00
|
|
|
return SelectCode(Op);
|
2005-10-20 08:29:02 +08:00
|
|
|
}
|
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
void AlphaDAGToDAGISel::SelectCALL(SDValue Op) {
|
2005-11-22 12:20:06 +08:00
|
|
|
//TODO: add flag stuff to prevent nondeturministic breakage!
|
|
|
|
|
2008-08-29 05:40:38 +08:00
|
|
|
SDNode *N = Op.getNode();
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Chain = N->getOperand(0);
|
|
|
|
SDValue Addr = N->getOperand(1);
|
|
|
|
SDValue InFlag(0,0); // Null incoming flag value.
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(Chain);
|
2005-10-23 06:06:58 +08:00
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
std::vector<SDValue> CallOperands;
|
2008-06-06 20:08:01 +08:00
|
|
|
std::vector<MVT> TypeOperands;
|
2005-10-23 06:06:58 +08:00
|
|
|
|
|
|
|
//grab the arguments
|
|
|
|
for(int i = 2, e = N->getNumOperands(); i < e; ++i) {
|
|
|
|
TypeOperands.push_back(N->getOperand(i).getValueType());
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(N->getOperand(i));
|
|
|
|
CallOperands.push_back(N->getOperand(i));
|
2005-10-23 06:06:58 +08:00
|
|
|
}
|
2005-10-23 11:43:48 +08:00
|
|
|
int count = N->getNumOperands() - 2;
|
|
|
|
|
2005-10-23 06:06:58 +08:00
|
|
|
static const unsigned args_int[] = {Alpha::R16, Alpha::R17, Alpha::R18,
|
|
|
|
Alpha::R19, Alpha::R20, Alpha::R21};
|
|
|
|
static const unsigned args_float[] = {Alpha::F16, Alpha::F17, Alpha::F18,
|
|
|
|
Alpha::F19, Alpha::F20, Alpha::F21};
|
|
|
|
|
2005-11-30 15:19:56 +08:00
|
|
|
for (int i = 6; i < count; ++i) {
|
|
|
|
unsigned Opc = Alpha::WTF;
|
2008-06-06 20:08:01 +08:00
|
|
|
if (TypeOperands[i].isInteger()) {
|
2005-11-30 15:19:56 +08:00
|
|
|
Opc = Alpha::STQ;
|
|
|
|
} else if (TypeOperands[i] == MVT::f32) {
|
|
|
|
Opc = Alpha::STS;
|
|
|
|
} else if (TypeOperands[i] == MVT::f64) {
|
|
|
|
Opc = Alpha::STT;
|
|
|
|
} else
|
|
|
|
assert(0 && "Unknown operand");
|
2006-08-27 16:14:06 +08:00
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Ops[] = { CallOperands[i], getI64Imm((i - 6) * 8),
|
2006-08-27 16:14:06 +08:00
|
|
|
CurDAG->getCopyFromReg(Chain, Alpha::R30, MVT::i64),
|
|
|
|
Chain };
|
2008-07-28 05:46:04 +08:00
|
|
|
Chain = SDValue(CurDAG->getTargetNode(Opc, MVT::Other, Ops, 4), 0);
|
2005-11-30 15:19:56 +08:00
|
|
|
}
|
2005-12-01 09:53:10 +08:00
|
|
|
for (int i = 0; i < std::min(6, count); ++i) {
|
2008-06-06 20:08:01 +08:00
|
|
|
if (TypeOperands[i].isInteger()) {
|
2005-12-01 09:53:10 +08:00
|
|
|
Chain = CurDAG->getCopyToReg(Chain, args_int[i], CallOperands[i], InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
} else if (TypeOperands[i] == MVT::f32 || TypeOperands[i] == MVT::f64) {
|
|
|
|
Chain = CurDAG->getCopyToReg(Chain, args_float[i], CallOperands[i], InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
} else
|
|
|
|
assert(0 && "Unknown operand");
|
|
|
|
}
|
|
|
|
|
2005-10-23 06:06:58 +08:00
|
|
|
// Finally, once everything is in registers to pass to the call, emit the
|
|
|
|
// call itself.
|
2005-12-26 01:36:48 +08:00
|
|
|
if (Addr.getOpcode() == AlphaISD::GPRelLo) {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue GOT = getGlobalBaseReg();
|
2005-12-26 01:36:48 +08:00
|
|
|
Chain = CurDAG->getCopyToReg(Chain, Alpha::R29, GOT, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
2008-07-28 05:46:04 +08:00
|
|
|
Chain = SDValue(CurDAG->getTargetNode(Alpha::BSR, MVT::Other, MVT::Flag,
|
2006-02-09 15:17:49 +08:00
|
|
|
Addr.getOperand(0), Chain, InFlag), 0);
|
2005-12-26 01:36:48 +08:00
|
|
|
} else {
|
2006-08-26 09:07:58 +08:00
|
|
|
AddToISelQueue(Addr);
|
2006-02-09 08:37:58 +08:00
|
|
|
Chain = CurDAG->getCopyToReg(Chain, Alpha::R27, Addr, InFlag);
|
2005-12-26 01:36:48 +08:00
|
|
|
InFlag = Chain.getValue(1);
|
2008-07-28 05:46:04 +08:00
|
|
|
Chain = SDValue(CurDAG->getTargetNode(Alpha::JSR, MVT::Other, MVT::Flag,
|
2006-02-09 15:17:49 +08:00
|
|
|
Chain, InFlag), 0);
|
2005-12-26 01:36:48 +08:00
|
|
|
}
|
2005-12-01 09:53:10 +08:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
std::vector<SDValue> CallResults;
|
2005-10-23 06:06:58 +08:00
|
|
|
|
2008-06-06 20:08:01 +08:00
|
|
|
switch (N->getValueType(0).getSimpleVT()) {
|
2005-10-23 06:06:58 +08:00
|
|
|
default: assert(0 && "Unexpected ret value!");
|
|
|
|
case MVT::Other: break;
|
|
|
|
case MVT::i64:
|
2005-12-01 09:53:10 +08:00
|
|
|
Chain = CurDAG->getCopyFromReg(Chain, Alpha::R0, MVT::i64, InFlag).getValue(1);
|
2005-10-23 06:06:58 +08:00
|
|
|
CallResults.push_back(Chain.getValue(0));
|
|
|
|
break;
|
2005-11-22 12:20:06 +08:00
|
|
|
case MVT::f32:
|
2005-12-01 09:53:10 +08:00
|
|
|
Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f32, InFlag).getValue(1);
|
2005-11-22 12:20:06 +08:00
|
|
|
CallResults.push_back(Chain.getValue(0));
|
|
|
|
break;
|
|
|
|
case MVT::f64:
|
2005-12-01 09:53:10 +08:00
|
|
|
Chain = CurDAG->getCopyFromReg(Chain, Alpha::F0, MVT::f64, InFlag).getValue(1);
|
2005-11-22 12:20:06 +08:00
|
|
|
CallResults.push_back(Chain.getValue(0));
|
|
|
|
break;
|
2005-10-23 06:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CallResults.push_back(Chain);
|
|
|
|
for (unsigned i = 0, e = CallResults.size(); i != e; ++i)
|
2006-08-08 06:28:20 +08:00
|
|
|
ReplaceUses(Op.getValue(i), CallResults[i]);
|
2005-10-23 06:06:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-20 08:29:02 +08:00
|
|
|
/// createAlphaISelDag - This pass converts a legalized DAG into a
|
|
|
|
/// Alpha-specific DAG, ready for instruction scheduling.
|
|
|
|
///
|
2008-05-14 09:58:56 +08:00
|
|
|
FunctionPass *llvm::createAlphaISelDag(AlphaTargetMachine &TM) {
|
2005-10-20 08:29:02 +08:00
|
|
|
return new AlphaDAGToDAGISel(TM);
|
|
|
|
}
|