2006-02-05 05:50:24 +00:00
|
|
|
//===-- SparcISelDAGToDAG.cpp - A dag to dag inst selector for Sparc ------===//
|
2005-12-17 07:47:01 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-12-17 07:47:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-02-05 05:50:24 +00:00
|
|
|
// This file defines an instruction selector for the SPARC target.
|
2005-12-17 07:47:01 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-17 03:21:36 +00:00
|
|
|
#include "SparcISelLowering.h"
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "SparcTargetMachine.h"
|
2006-03-25 06:47:10 +00:00
|
|
|
#include "llvm/Intrinsics.h"
|
2005-12-17 07:47:01 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2008-02-03 05:43:57 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2005-12-17 07:47:01 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2005-12-17 07:47:01 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Instruction Selector Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2006-02-05 05:50:24 +00:00
|
|
|
/// SparcDAGToDAGISel - SPARC specific code to select SPARC machine
|
2005-12-17 07:47:01 +00:00
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
///
|
|
|
|
namespace {
|
2006-02-05 05:50:24 +00:00
|
|
|
class SparcDAGToDAGISel : public SelectionDAGISel {
|
First step towards V9 instructions in the V8 backend, two conditional move
patterns. This allows emission of this code:
t1:
save -96, %o6, %o6
subcc %i0, %i1, %l0
move %icc, %i0, %i2
or %g0, %i2, %i0
restore %g0, %g0, %g0
retl
nop
instead of this:
t1:
save -96, %o6, %o6
subcc %i0, %i1, %l0
be .LBBt1_2 !
nop
.LBBt1_1: !
or %g0, %i2, %i0
.LBBt1_2: !
restore %g0, %g0, %g0
retl
nop
for this:
int %t1(int %a, int %b, int %c) {
%tmp.2 = seteq int %a, %b
%tmp3 = select bool %tmp.2, int %a, int %c
ret int %tmp3
}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25809 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-30 05:35:57 +00:00
|
|
|
/// Subtarget - Keep a pointer to the Sparc Subtarget around so that we can
|
|
|
|
/// make the right decision when generating code for different targets.
|
2006-02-05 05:50:24 +00:00
|
|
|
const SparcSubtarget &Subtarget;
|
2005-12-17 07:47:01 +00:00
|
|
|
public:
|
2008-10-03 16:55:19 +00:00
|
|
|
explicit SparcDAGToDAGISel(SparcTargetMachine &TM)
|
2009-01-15 19:20:50 +00:00
|
|
|
: SelectionDAGISel(TM),
|
2006-02-05 05:50:24 +00:00
|
|
|
Subtarget(TM.getSubtarget<SparcSubtarget>()) {
|
First step towards V9 instructions in the V8 backend, two conditional move
patterns. This allows emission of this code:
t1:
save -96, %o6, %o6
subcc %i0, %i1, %l0
move %icc, %i0, %i2
or %g0, %i2, %i0
restore %g0, %g0, %g0
retl
nop
instead of this:
t1:
save -96, %o6, %o6
subcc %i0, %i1, %l0
be .LBBt1_2 !
nop
.LBBt1_1: !
or %g0, %i2, %i0
.LBBt1_2: !
restore %g0, %g0, %g0
retl
nop
for this:
int %t1(int %a, int %b, int %c) {
%tmp.2 = seteq int %a, %b
%tmp3 = select bool %tmp.2, int %a, int %c
ret int %tmp3
}
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25809 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-30 05:35:57 +00:00
|
|
|
}
|
2005-12-17 07:47:01 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDNode *Select(SDValue Op);
|
2005-12-17 07:47:01 +00:00
|
|
|
|
2005-12-17 20:04:49 +00:00
|
|
|
// Complex Pattern Selectors.
|
2008-07-27 21:46:04 +00:00
|
|
|
bool SelectADDRrr(SDValue Op, SDValue N, SDValue &R1, SDValue &R2);
|
|
|
|
bool SelectADDRri(SDValue Op, SDValue N, SDValue &Base,
|
|
|
|
SDValue &Offset);
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2008-10-10 10:14:47 +00:00
|
|
|
/// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
|
|
|
|
/// inline asm expressions.
|
|
|
|
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
|
|
|
|
char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps);
|
|
|
|
|
2008-06-30 20:45:06 +00:00
|
|
|
/// InstructionSelect - This callback is invoked by
|
2005-12-17 07:47:01 +00:00
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
2008-08-23 02:25:05 +00:00
|
|
|
virtual void InstructionSelect();
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2005-12-17 07:47:01 +00:00
|
|
|
virtual const char *getPassName() const {
|
2006-02-05 05:50:24 +00:00
|
|
|
return "SPARC DAG->DAG Pattern Instruction Selection";
|
2008-10-10 10:14:15 +00:00
|
|
|
}
|
|
|
|
|
2005-12-17 07:47:01 +00:00
|
|
|
// Include the pieces autogenerated from the target description.
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "SparcGenDAGISel.inc"
|
2005-12-17 07:47:01 +00:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2008-06-30 20:45:06 +00:00
|
|
|
/// InstructionSelect - This callback is invoked by
|
2005-12-17 07:47:01 +00:00
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
2008-08-23 02:25:05 +00:00
|
|
|
void SparcDAGToDAGISel::InstructionSelect() {
|
2005-12-17 07:47:01 +00:00
|
|
|
DEBUG(BB->dump());
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2005-12-17 07:47:01 +00:00
|
|
|
// Select target instructions for the DAG.
|
2008-10-27 21:56:29 +00:00
|
|
|
SelectRoot(*CurDAG);
|
2008-08-23 02:25:05 +00:00
|
|
|
CurDAG->RemoveDeadNodes();
|
2005-12-17 07:47:01 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
bool SparcDAGToDAGISel::SelectADDRri(SDValue Op, SDValue Addr,
|
|
|
|
SDValue &Base, SDValue &Offset) {
|
2005-12-18 07:09:06 +00:00
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
2005-12-18 06:59:57 +00:00
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
return true;
|
|
|
|
}
|
2008-09-16 21:48:12 +00:00
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
2006-02-10 07:35:42 +00:00
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress)
|
|
|
|
return false; // direct calls.
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2005-12-17 21:25:27 +00:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
2005-12-18 06:59:57 +00:00
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
|
2005-12-17 21:25:27 +00:00
|
|
|
if (Predicate_simm13(CN)) {
|
2008-10-10 10:14:15 +00:00
|
|
|
if (FrameIndexSDNode *FIN =
|
2005-12-18 07:09:06 +00:00
|
|
|
dyn_cast<FrameIndexSDNode>(Addr.getOperand(0))) {
|
2005-12-18 06:59:57 +00:00
|
|
|
// Constant offset from frame ref.
|
2005-12-18 07:09:06 +00:00
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
2005-12-18 06:59:57 +00:00
|
|
|
} else {
|
2006-02-05 08:35:50 +00:00
|
|
|
Base = Addr.getOperand(0);
|
2005-12-18 06:59:57 +00:00
|
|
|
}
|
2008-09-12 16:56:44 +00:00
|
|
|
Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
|
2005-12-17 21:25:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-12-18 06:59:57 +00:00
|
|
|
}
|
2006-02-05 05:50:24 +00:00
|
|
|
if (Addr.getOperand(0).getOpcode() == SPISD::Lo) {
|
2006-02-05 08:35:50 +00:00
|
|
|
Base = Addr.getOperand(1);
|
Teach the addressing mode stuff to fold "%lo" into 'ri' addressing modes,
allowing us to compile this:
to this:
%G1 = external global int
%G2 = external global int
void %test() {
%X = load int* %G1
store int %X, int* %G2
ret void
}
test:
save -96, %sp, %sp
sethi %hi(G1), %l0
ld [%l0+%lo(G1)], %l0
sethi %hi(G2), %l1
st %l0, [%l1+%lo(G2)]
restore %g0, %g0, %g0
retl
nop
instead of this:
test:
save -96, %sp, %sp
sethi %hi(G1), %l0
or %g0, %lo(G1), %l1
ld [%l1+%l0], %l0
sethi %hi(G2), %l1
or %g0, %lo(G2), %l2
st %l0, [%l2+%l1]
restore %g0, %g0, %g0
retl
nop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24812 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-18 02:27:00 +00:00
|
|
|
Offset = Addr.getOperand(0).getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-05 05:50:24 +00:00
|
|
|
if (Addr.getOperand(1).getOpcode() == SPISD::Lo) {
|
2006-02-05 08:35:50 +00:00
|
|
|
Base = Addr.getOperand(0);
|
Teach the addressing mode stuff to fold "%lo" into 'ri' addressing modes,
allowing us to compile this:
to this:
%G1 = external global int
%G2 = external global int
void %test() {
%X = load int* %G1
store int %X, int* %G2
ret void
}
test:
save -96, %sp, %sp
sethi %hi(G1), %l0
ld [%l0+%lo(G1)], %l0
sethi %hi(G2), %l1
st %l0, [%l1+%lo(G2)]
restore %g0, %g0, %g0
retl
nop
instead of this:
test:
save -96, %sp, %sp
sethi %hi(G1), %l0
or %g0, %lo(G1), %l1
ld [%l1+%l0], %l0
sethi %hi(G2), %l1
or %g0, %lo(G2), %l2
st %l0, [%l2+%l1]
restore %g0, %g0, %g0
retl
nop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24812 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-18 02:27:00 +00:00
|
|
|
Offset = Addr.getOperand(1).getOperand(0);
|
|
|
|
return true;
|
|
|
|
}
|
2005-12-17 21:25:27 +00:00
|
|
|
}
|
2006-02-05 08:35:50 +00:00
|
|
|
Base = Addr;
|
2005-12-17 20:04:49 +00:00
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
bool SparcDAGToDAGISel::SelectADDRrr(SDValue Op, SDValue Addr,
|
|
|
|
SDValue &R1, SDValue &R2) {
|
2006-02-10 07:35:42 +00:00
|
|
|
if (Addr.getOpcode() == ISD::FrameIndex) return false;
|
2008-09-16 21:48:12 +00:00
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
2006-02-10 07:35:42 +00:00
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress)
|
|
|
|
return false; // direct calls.
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2005-12-18 06:59:57 +00:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
if (isa<ConstantSDNode>(Addr.getOperand(1)) &&
|
2008-08-28 21:40:38 +00:00
|
|
|
Predicate_simm13(Addr.getOperand(1).getNode()))
|
2005-12-18 06:59:57 +00:00
|
|
|
return false; // Let the reg+imm pattern catch this!
|
2006-02-05 05:50:24 +00:00
|
|
|
if (Addr.getOperand(0).getOpcode() == SPISD::Lo ||
|
|
|
|
Addr.getOperand(1).getOpcode() == SPISD::Lo)
|
2005-12-18 06:59:57 +00:00
|
|
|
return false; // Let the reg+imm pattern catch this!
|
2006-02-05 08:35:50 +00:00
|
|
|
R1 = Addr.getOperand(0);
|
|
|
|
R2 = Addr.getOperand(1);
|
2005-12-18 06:59:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-02-05 08:35:50 +00:00
|
|
|
R1 = Addr;
|
2006-02-05 05:50:24 +00:00
|
|
|
R2 = CurDAG->getRegister(SP::G0, MVT::i32);
|
2005-12-18 06:59:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-12-17 07:47:01 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDNode *SparcDAGToDAGISel::Select(SDValue Op) {
|
2008-08-28 21:40:38 +00:00
|
|
|
SDNode *N = Op.getNode();
|
2009-02-06 19:16:40 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2008-07-17 19:10:17 +00:00
|
|
|
if (N->isMachineOpcode())
|
2006-08-11 09:08:15 +00:00
|
|
|
return NULL; // Already selected.
|
2006-02-09 00:37:58 +00:00
|
|
|
|
2005-12-17 07:47:01 +00:00
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default: break;
|
2005-12-17 22:39:19 +00:00
|
|
|
case ISD::SDIV:
|
|
|
|
case ISD::UDIV: {
|
|
|
|
// FIXME: should use a custom expander to expose the SRA to the dag.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue DivLHS = N->getOperand(0);
|
|
|
|
SDValue DivRHS = N->getOperand(1);
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2005-12-17 22:39:19 +00:00
|
|
|
// Set the Y register to the high-part.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue TopPart;
|
2005-12-17 22:39:19 +00:00
|
|
|
if (N->getOpcode() == ISD::SDIV) {
|
2009-02-06 19:16:40 +00:00
|
|
|
TopPart = SDValue(CurDAG->getTargetNode(SP::SRAri, dl, MVT::i32, DivLHS,
|
2006-02-09 07:17:49 +00:00
|
|
|
CurDAG->getTargetConstant(31, MVT::i32)), 0);
|
2005-12-17 22:39:19 +00:00
|
|
|
} else {
|
2006-02-05 05:50:24 +00:00
|
|
|
TopPart = CurDAG->getRegister(SP::G0, MVT::i32);
|
2005-12-17 22:39:19 +00:00
|
|
|
}
|
2009-02-06 19:16:40 +00:00
|
|
|
TopPart = SDValue(CurDAG->getTargetNode(SP::WRYrr, dl, MVT::Flag, TopPart,
|
2006-02-09 07:17:49 +00:00
|
|
|
CurDAG->getRegister(SP::G0, MVT::i32)), 0);
|
2005-12-17 22:39:19 +00:00
|
|
|
|
|
|
|
// FIXME: Handle div by immediate.
|
2006-02-05 05:50:24 +00:00
|
|
|
unsigned Opcode = N->getOpcode() == ISD::SDIV ? SP::SDIVrr : SP::UDIVrr;
|
2006-08-16 07:30:09 +00:00
|
|
|
return CurDAG->SelectNodeTo(N, Opcode, MVT::i32, DivLHS, DivRHS,
|
2006-08-26 08:00:10 +00:00
|
|
|
TopPart);
|
2008-10-10 10:14:15 +00:00
|
|
|
}
|
2005-12-17 22:30:00 +00:00
|
|
|
case ISD::MULHU:
|
|
|
|
case ISD::MULHS: {
|
2005-12-17 22:39:19 +00:00
|
|
|
// FIXME: Handle mul by immediate.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue MulLHS = N->getOperand(0);
|
|
|
|
SDValue MulRHS = N->getOperand(1);
|
2006-02-05 05:50:24 +00:00
|
|
|
unsigned Opcode = N->getOpcode() == ISD::MULHU ? SP::UMULrr : SP::SMULrr;
|
2009-02-06 19:16:40 +00:00
|
|
|
SDNode *Mul = CurDAG->getTargetNode(Opcode, dl, MVT::i32, MVT::Flag,
|
2006-02-10 07:35:42 +00:00
|
|
|
MulLHS, MulRHS);
|
2005-12-17 22:30:00 +00:00
|
|
|
// The high part is in the Y register.
|
2008-07-27 21:46:04 +00:00
|
|
|
return CurDAG->SelectNodeTo(N, SP::RDY, MVT::i32, SDValue(Mul, 1));
|
2006-08-11 09:08:15 +00:00
|
|
|
return NULL;
|
2005-12-17 22:30:00 +00:00
|
|
|
}
|
2005-12-17 07:47:01 +00:00
|
|
|
}
|
2008-10-10 10:14:15 +00:00
|
|
|
|
2006-08-26 05:34:46 +00:00
|
|
|
return SelectCode(Op);
|
2005-12-17 07:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 10:14:47 +00:00
|
|
|
/// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
|
|
|
|
/// inline asm expressions.
|
|
|
|
bool
|
|
|
|
SparcDAGToDAGISel::SelectInlineAsmMemoryOperand(const SDValue &Op,
|
|
|
|
char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
SDValue Op0, Op1;
|
|
|
|
switch (ConstraintCode) {
|
|
|
|
default: return true;
|
|
|
|
case 'm': // memory
|
|
|
|
if (!SelectADDRrr(Op, Op, Op0, Op1))
|
|
|
|
SelectADDRri(Op, Op, Op0, Op1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutOps.push_back(Op0);
|
|
|
|
OutOps.push_back(Op1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-10 10:14:15 +00:00
|
|
|
/// createSparcISelDag - This pass converts a legalized DAG into a
|
2006-01-26 07:22:22 +00:00
|
|
|
/// SPARC-specific DAG, ready for instruction scheduling.
|
2005-12-17 07:47:01 +00:00
|
|
|
///
|
2008-10-03 16:55:19 +00:00
|
|
|
FunctionPass *llvm::createSparcISelDag(SparcTargetMachine &TM) {
|
2006-02-05 05:50:24 +00:00
|
|
|
return new SparcDAGToDAGISel(TM);
|
2005-12-17 07:47:01 +00:00
|
|
|
}
|