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"
|
|
|
|
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 {
|
|
|
|
SparcTargetLowering Lowering;
|
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:
|
2006-02-05 05:50:24 +00:00
|
|
|
SparcDAGToDAGISel(TargetMachine &TM)
|
|
|
|
: SelectionDAGISel(Lowering), Lowering(TM),
|
|
|
|
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
|
|
|
|
2006-08-26 05:34:46 +00:00
|
|
|
SDNode *Select(SDOperand Op);
|
2005-12-17 07:47:01 +00:00
|
|
|
|
2005-12-17 20:04:49 +00:00
|
|
|
// Complex Pattern Selectors.
|
2006-11-08 20:34:28 +00:00
|
|
|
bool SelectADDRrr(SDOperand Op, SDOperand N, SDOperand &R1, SDOperand &R2);
|
|
|
|
bool SelectADDRri(SDOperand Op, SDOperand N, SDOperand &Base,
|
|
|
|
SDOperand &Offset);
|
2005-12-17 20:04:49 +00:00
|
|
|
|
2005-12-17 07:47:01 +00:00
|
|
|
/// InstructionSelectBasicBlock - This callback is invoked by
|
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
|
|
|
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG);
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
2006-02-05 05:50:24 +00:00
|
|
|
return "SPARC DAG->DAG Pattern Instruction Selection";
|
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
|
|
|
|
|
|
|
|
/// InstructionSelectBasicBlock - This callback is invoked by
|
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
2006-02-05 05:50:24 +00:00
|
|
|
void SparcDAGToDAGISel::InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
2005-12-17 07:47:01 +00:00
|
|
|
DEBUG(BB->dump());
|
|
|
|
|
|
|
|
// Select target instructions for the DAG.
|
2006-02-05 06:51:51 +00:00
|
|
|
DAG.setRoot(SelectRoot(DAG.getRoot()));
|
2005-12-17 07:47:01 +00:00
|
|
|
DAG.RemoveDeadNodes();
|
|
|
|
|
|
|
|
// Emit machine code to BB.
|
|
|
|
ScheduleAndEmitDAG(DAG);
|
|
|
|
}
|
|
|
|
|
2006-11-08 20:34:28 +00:00
|
|
|
bool SparcDAGToDAGISel::SelectADDRri(SDOperand Op, SDOperand Addr,
|
|
|
|
SDOperand &Base, SDOperand &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;
|
|
|
|
}
|
2006-02-10 07:35:42 +00:00
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress)
|
|
|
|
return false; // direct calls.
|
2005-12-18 06:59:57 +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)) {
|
2005-12-18 07:09:06 +00:00
|
|
|
if (FrameIndexSDNode *FIN =
|
|
|
|
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
|
|
|
}
|
2005-12-17 21:25:27 +00:00
|
|
|
Offset = CurDAG->getTargetConstant(CN->getValue(), MVT::i32);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-11-08 20:34:28 +00:00
|
|
|
bool SparcDAGToDAGISel::SelectADDRrr(SDOperand Op, SDOperand Addr,
|
|
|
|
SDOperand &R1, SDOperand &R2) {
|
2006-02-10 07:35:42 +00:00
|
|
|
if (Addr.getOpcode() == ISD::FrameIndex) return false;
|
|
|
|
if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress)
|
|
|
|
return false; // direct calls.
|
|
|
|
|
2005-12-18 06:59:57 +00:00
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
|
|
|
if (isa<ConstantSDNode>(Addr.getOperand(1)) &&
|
|
|
|
Predicate_simm13(Addr.getOperand(1).Val))
|
|
|
|
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
|
|
|
|
2006-08-26 05:34:46 +00:00
|
|
|
SDNode *SparcDAGToDAGISel::Select(SDOperand Op) {
|
2005-12-17 07:47:01 +00:00
|
|
|
SDNode *N = Op.Val;
|
2005-12-18 01:20:35 +00:00
|
|
|
if (N->getOpcode() >= ISD::BUILTIN_OP_END &&
|
2006-08-26 05:34:46 +00:00
|
|
|
N->getOpcode() < SPISD::FIRST_NUMBER)
|
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.
|
2006-08-26 01:07:58 +00:00
|
|
|
SDOperand DivLHS = N->getOperand(0);
|
|
|
|
SDOperand DivRHS = N->getOperand(1);
|
|
|
|
AddToISelQueue(DivLHS);
|
|
|
|
AddToISelQueue(DivRHS);
|
2005-12-17 22:39:19 +00:00
|
|
|
|
|
|
|
// Set the Y register to the high-part.
|
|
|
|
SDOperand TopPart;
|
|
|
|
if (N->getOpcode() == ISD::SDIV) {
|
2006-02-09 07:17:49 +00:00
|
|
|
TopPart = SDOperand(CurDAG->getTargetNode(SP::SRAri, MVT::i32, DivLHS,
|
|
|
|
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
|
|
|
}
|
2006-02-09 07:17:49 +00:00
|
|
|
TopPart = SDOperand(CurDAG->getTargetNode(SP::WRYrr, MVT::Flag, TopPart,
|
|
|
|
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);
|
2005-12-17 22:39:19 +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.
|
2006-08-26 01:07:58 +00:00
|
|
|
SDOperand MulLHS = N->getOperand(0);
|
|
|
|
SDOperand MulRHS = N->getOperand(1);
|
|
|
|
AddToISelQueue(MulLHS);
|
|
|
|
AddToISelQueue(MulRHS);
|
2006-02-05 05:50:24 +00:00
|
|
|
unsigned Opcode = N->getOpcode() == ISD::MULHU ? SP::UMULrr : SP::SMULrr;
|
2006-02-09 07:17:49 +00:00
|
|
|
SDNode *Mul = CurDAG->getTargetNode(Opcode, 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.
|
2006-08-26 08:00:10 +00:00
|
|
|
return CurDAG->SelectNodeTo(N, SP::RDY, MVT::i32, SDOperand(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
|
|
|
}
|
|
|
|
|
2006-08-26 05:34:46 +00:00
|
|
|
return SelectCode(Op);
|
2005-12-17 07:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-05 05:50:24 +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
|
|
|
///
|
2006-02-05 05:50:24 +00:00
|
|
|
FunctionPass *llvm::createSparcISelDag(TargetMachine &TM) {
|
|
|
|
return new SparcDAGToDAGISel(TM);
|
2005-12-17 07:47:01 +00:00
|
|
|
}
|