2009-05-03 12:57:15 +00:00
|
|
|
//===-- MSP430ISelDAGToDAG.cpp - A dag to dag inst selector for MSP430 ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines an instruction selector for the MSP430 target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MSP430.h"
|
|
|
|
#include "MSP430TargetMachine.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/CallingConv.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
2009-05-03 12:57:15 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2009-05-03 12:57:15 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-11-07 17:13:35 +00:00
|
|
|
namespace {
|
|
|
|
struct MSP430ISelAddressMode {
|
|
|
|
enum {
|
|
|
|
RegBase,
|
|
|
|
FrameIndexBase
|
|
|
|
} BaseType;
|
|
|
|
|
|
|
|
struct { // This is really a union, discriminated by BaseType!
|
|
|
|
SDValue Reg;
|
|
|
|
int FrameIndex;
|
|
|
|
} Base;
|
|
|
|
|
|
|
|
int16_t Disp;
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalValue *GV;
|
|
|
|
const Constant *CP;
|
|
|
|
const BlockAddress *BlockAddr;
|
2009-11-07 17:13:35 +00:00
|
|
|
const char *ES;
|
|
|
|
int JT;
|
|
|
|
unsigned Align; // CP alignment.
|
|
|
|
|
|
|
|
MSP430ISelAddressMode()
|
|
|
|
: BaseType(RegBase), Disp(0), GV(0), CP(0), BlockAddr(0),
|
|
|
|
ES(0), JT(-1), Align(0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasSymbolicDisplacement() const {
|
|
|
|
return GV != 0 || CP != 0 || ES != 0 || JT != -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump() {
|
|
|
|
errs() << "MSP430ISelAddressMode " << this << '\n';
|
2009-12-13 01:00:32 +00:00
|
|
|
if (BaseType == RegBase && Base.Reg.getNode() != 0) {
|
2009-11-07 17:13:35 +00:00
|
|
|
errs() << "Base.Reg ";
|
|
|
|
Base.Reg.getNode()->dump();
|
2009-12-13 01:00:32 +00:00
|
|
|
} else if (BaseType == FrameIndexBase) {
|
2009-11-07 17:13:35 +00:00
|
|
|
errs() << " Base.FrameIndex " << Base.FrameIndex << '\n';
|
|
|
|
}
|
|
|
|
errs() << " Disp " << Disp << '\n';
|
|
|
|
if (GV) {
|
|
|
|
errs() << "GV ";
|
|
|
|
GV->dump();
|
|
|
|
} else if (CP) {
|
|
|
|
errs() << " CP ";
|
|
|
|
CP->dump();
|
|
|
|
errs() << " Align" << Align << '\n';
|
|
|
|
} else if (ES) {
|
|
|
|
errs() << "ES ";
|
|
|
|
errs() << ES << '\n';
|
|
|
|
} else if (JT != -1)
|
|
|
|
errs() << " JT" << JT << " Align" << Align << '\n';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-05-03 12:57:15 +00:00
|
|
|
/// MSP430DAGToDAGISel - MSP430 specific code to select MSP430 machine
|
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
///
|
|
|
|
namespace {
|
|
|
|
class MSP430DAGToDAGISel : public SelectionDAGISel {
|
2010-04-17 15:26:15 +00:00
|
|
|
const MSP430TargetLowering &Lowering;
|
2009-05-03 12:57:15 +00:00
|
|
|
const MSP430Subtarget &Subtarget;
|
|
|
|
|
|
|
|
public:
|
2009-05-03 13:19:42 +00:00
|
|
|
MSP430DAGToDAGISel(MSP430TargetMachine &TM, CodeGenOpt::Level OptLevel)
|
|
|
|
: SelectionDAGISel(TM, OptLevel),
|
2009-05-03 12:57:15 +00:00
|
|
|
Lowering(*TM.getTargetLowering()),
|
|
|
|
Subtarget(*TM.getSubtargetImpl()) { }
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "MSP430 DAG->DAG Pattern Instruction Selection";
|
|
|
|
}
|
|
|
|
|
2009-11-07 17:13:35 +00:00
|
|
|
bool MatchAddress(SDValue N, MSP430ISelAddressMode &AM);
|
|
|
|
bool MatchWrapper(SDValue N, MSP430ISelAddressMode &AM);
|
|
|
|
bool MatchAddressBase(SDValue N, MSP430ISelAddressMode &AM);
|
|
|
|
|
2009-10-11 19:14:21 +00:00
|
|
|
virtual bool
|
|
|
|
SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps);
|
|
|
|
|
2009-05-03 12:57:15 +00:00
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "MSP430GenDAGISel.inc"
|
|
|
|
|
|
|
|
private:
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *Select(SDNode *N);
|
|
|
|
SDNode *SelectIndexedLoad(SDNode *Op);
|
|
|
|
SDNode *SelectIndexedBinOp(SDNode *Op, SDValue N1, SDValue N2,
|
2009-11-07 17:15:25 +00:00
|
|
|
unsigned Opc8, unsigned Opc16);
|
|
|
|
|
2010-09-21 20:31:19 +00:00
|
|
|
bool SelectAddr(SDValue Addr, SDValue &Base, SDValue &Disp);
|
2009-05-03 12:57:15 +00:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// createMSP430ISelDag - This pass converts a legalized DAG into a
|
|
|
|
/// MSP430-specific DAG, ready for instruction scheduling.
|
|
|
|
///
|
2009-05-03 13:19:42 +00:00
|
|
|
FunctionPass *llvm::createMSP430ISelDag(MSP430TargetMachine &TM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
|
|
|
return new MSP430DAGToDAGISel(TM, OptLevel);
|
2009-05-03 12:57:15 +00:00
|
|
|
}
|
|
|
|
|
2009-11-07 17:13:35 +00:00
|
|
|
|
|
|
|
/// MatchWrapper - Try to match MSP430ISD::Wrapper node into an addressing mode.
|
|
|
|
/// These wrap things that will resolve down into a symbol reference. If no
|
|
|
|
/// match is possible, this returns true, otherwise it returns false.
|
|
|
|
bool MSP430DAGToDAGISel::MatchWrapper(SDValue N, MSP430ISelAddressMode &AM) {
|
|
|
|
// If the addressing mode already has a symbol as the displacement, we can
|
|
|
|
// never match another symbol.
|
|
|
|
if (AM.hasSymbolicDisplacement())
|
2009-05-03 13:10:11 +00:00
|
|
|
return true;
|
2009-11-07 17:13:35 +00:00
|
|
|
|
|
|
|
SDValue N0 = N.getOperand(0);
|
|
|
|
|
|
|
|
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
|
|
|
|
AM.GV = G->getGlobal();
|
|
|
|
AM.Disp += G->getOffset();
|
|
|
|
//AM.SymbolFlags = G->getTargetFlags();
|
|
|
|
} else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) {
|
|
|
|
AM.CP = CP->getConstVal();
|
|
|
|
AM.Align = CP->getAlignment();
|
|
|
|
AM.Disp += CP->getOffset();
|
|
|
|
//AM.SymbolFlags = CP->getTargetFlags();
|
|
|
|
} else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) {
|
|
|
|
AM.ES = S->getSymbol();
|
|
|
|
//AM.SymbolFlags = S->getTargetFlags();
|
|
|
|
} else if (JumpTableSDNode *J = dyn_cast<JumpTableSDNode>(N0)) {
|
|
|
|
AM.JT = J->getIndex();
|
|
|
|
//AM.SymbolFlags = J->getTargetFlags();
|
|
|
|
} else {
|
|
|
|
AM.BlockAddr = cast<BlockAddressSDNode>(N0)->getBlockAddress();
|
|
|
|
//AM.SymbolFlags = cast<BlockAddressSDNode>(N0)->getTargetFlags();
|
2009-05-03 13:10:11 +00:00
|
|
|
}
|
2009-11-07 17:13:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-05-03 13:06:03 +00:00
|
|
|
|
2009-11-07 17:13:35 +00:00
|
|
|
/// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
|
|
|
|
/// specified addressing mode without any further recursion.
|
|
|
|
bool MSP430DAGToDAGISel::MatchAddressBase(SDValue N, MSP430ISelAddressMode &AM) {
|
|
|
|
// Is the base register already occupied?
|
|
|
|
if (AM.BaseType != MSP430ISelAddressMode::RegBase || AM.Base.Reg.getNode()) {
|
|
|
|
// If so, we cannot select it.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default, generate it as a register.
|
|
|
|
AM.BaseType = MSP430ISelAddressMode::RegBase;
|
|
|
|
AM.Base.Reg = N;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MSP430DAGToDAGISel::MatchAddress(SDValue N, MSP430ISelAddressMode &AM) {
|
2010-03-02 22:30:08 +00:00
|
|
|
DEBUG(errs() << "MatchAddress: "; AM.dump());
|
2009-11-07 17:13:35 +00:00
|
|
|
|
|
|
|
switch (N.getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case ISD::Constant: {
|
|
|
|
uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
|
|
|
|
AM.Disp += Val;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MSP430ISD::Wrapper:
|
|
|
|
if (!MatchWrapper(N, AM))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::FrameIndex:
|
|
|
|
if (AM.BaseType == MSP430ISelAddressMode::RegBase
|
|
|
|
&& AM.Base.Reg.getNode() == 0) {
|
|
|
|
AM.BaseType = MSP430ISelAddressMode::FrameIndexBase;
|
|
|
|
AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
|
|
|
|
return false;
|
2009-05-03 13:06:03 +00:00
|
|
|
}
|
2009-05-03 13:08:51 +00:00
|
|
|
break;
|
2009-11-07 17:13:35 +00:00
|
|
|
|
|
|
|
case ISD::ADD: {
|
|
|
|
MSP430ISelAddressMode Backup = AM;
|
|
|
|
if (!MatchAddress(N.getNode()->getOperand(0), AM) &&
|
|
|
|
!MatchAddress(N.getNode()->getOperand(1), AM))
|
|
|
|
return false;
|
|
|
|
AM = Backup;
|
|
|
|
if (!MatchAddress(N.getNode()->getOperand(1), AM) &&
|
|
|
|
!MatchAddress(N.getNode()->getOperand(0), AM))
|
|
|
|
return false;
|
|
|
|
AM = Backup;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ISD::OR:
|
2012-09-27 10:14:43 +00:00
|
|
|
// Handle "X | C" as "X + C" iff X is known to have C bits clear.
|
2009-11-07 17:13:35 +00:00
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
|
|
|
|
MSP430ISelAddressMode Backup = AM;
|
|
|
|
uint64_t Offset = CN->getSExtValue();
|
|
|
|
// Start with the LHS as an addr mode.
|
|
|
|
if (!MatchAddress(N.getOperand(0), AM) &&
|
|
|
|
// Address could not have picked a GV address for the displacement.
|
|
|
|
AM.GV == NULL &&
|
|
|
|
// Check to see if the LHS & C is zero.
|
|
|
|
CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
|
|
|
|
AM.Disp += Offset;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
AM = Backup;
|
2009-05-03 13:08:51 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-11-07 17:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return MatchAddressBase(N, AM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// SelectAddr - returns true if it is able pattern match an addressing mode.
|
|
|
|
/// It returns the operands which make up the maximal addressing mode it can
|
|
|
|
/// match by reference.
|
2010-09-21 20:31:19 +00:00
|
|
|
bool MSP430DAGToDAGISel::SelectAddr(SDValue N,
|
2009-11-07 17:13:35 +00:00
|
|
|
SDValue &Base, SDValue &Disp) {
|
|
|
|
MSP430ISelAddressMode AM;
|
|
|
|
|
|
|
|
if (MatchAddress(N, AM))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
EVT VT = N.getValueType();
|
|
|
|
if (AM.BaseType == MSP430ISelAddressMode::RegBase) {
|
|
|
|
if (!AM.Base.Reg.getNode())
|
|
|
|
AM.Base.Reg = CurDAG->getRegister(0, VT);
|
|
|
|
}
|
|
|
|
|
|
|
|
Base = (AM.BaseType == MSP430ISelAddressMode::FrameIndexBase) ?
|
2013-06-19 21:36:55 +00:00
|
|
|
CurDAG->getTargetFrameIndex(AM.Base.FrameIndex,
|
|
|
|
getTargetLowering()->getPointerTy()) :
|
2009-11-07 17:13:35 +00:00
|
|
|
AM.Base.Reg;
|
2009-05-03 13:06:03 +00:00
|
|
|
|
2009-11-07 17:13:35 +00:00
|
|
|
if (AM.GV)
|
2013-05-25 02:42:55 +00:00
|
|
|
Disp = CurDAG->getTargetGlobalAddress(AM.GV, SDLoc(N),
|
2010-07-06 22:08:15 +00:00
|
|
|
MVT::i16, AM.Disp,
|
2009-11-07 17:13:35 +00:00
|
|
|
0/*AM.SymbolFlags*/);
|
|
|
|
else if (AM.CP)
|
|
|
|
Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i16,
|
|
|
|
AM.Align, AM.Disp, 0/*AM.SymbolFlags*/);
|
|
|
|
else if (AM.ES)
|
|
|
|
Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i16, 0/*AM.SymbolFlags*/);
|
|
|
|
else if (AM.JT != -1)
|
|
|
|
Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i16, 0/*AM.SymbolFlags*/);
|
|
|
|
else if (AM.BlockAddr)
|
2012-09-12 21:43:09 +00:00
|
|
|
Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr, MVT::i32, 0,
|
|
|
|
0/*AM.SymbolFlags*/);
|
2009-11-07 17:13:35 +00:00
|
|
|
else
|
|
|
|
Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i16);
|
2009-05-03 13:06:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-11 19:14:21 +00:00
|
|
|
bool MSP430DAGToDAGISel::
|
|
|
|
SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
SDValue Op0, Op1;
|
|
|
|
switch (ConstraintCode) {
|
|
|
|
default: return true;
|
|
|
|
case 'm': // memory
|
2010-09-21 20:31:19 +00:00
|
|
|
if (!SelectAddr(Op, Op0, Op1))
|
2009-10-11 19:14:21 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutOps.push_back(Op0);
|
|
|
|
OutOps.push_back(Op1);
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-03 13:06:03 +00:00
|
|
|
|
2009-11-07 17:15:25 +00:00
|
|
|
static bool isValidIndexedLoad(const LoadSDNode *LD) {
|
2009-11-07 17:15:06 +00:00
|
|
|
ISD::MemIndexedMode AM = LD->getAddressingMode();
|
|
|
|
if (AM != ISD::POST_INC || LD->getExtensionType() != ISD::NON_EXTLOAD)
|
2009-11-07 17:15:25 +00:00
|
|
|
return false;
|
2009-11-07 17:15:06 +00:00
|
|
|
|
|
|
|
EVT VT = LD->getMemoryVT();
|
|
|
|
|
|
|
|
switch (VT.getSimpleVT().SimpleTy) {
|
|
|
|
case MVT::i8:
|
|
|
|
// Sanity check
|
|
|
|
if (cast<ConstantSDNode>(LD->getOffset())->getZExtValue() != 1)
|
2009-11-07 17:15:25 +00:00
|
|
|
return false;
|
2009-11-07 17:15:06 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case MVT::i16:
|
|
|
|
// Sanity check
|
|
|
|
if (cast<ConstantSDNode>(LD->getOffset())->getZExtValue() != 2)
|
2009-11-07 17:15:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-07 17:15:06 +00:00
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *MSP430DAGToDAGISel::SelectIndexedLoad(SDNode *N) {
|
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(N);
|
2009-11-07 17:15:25 +00:00
|
|
|
if (!isValidIndexedLoad(LD))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MVT VT = LD->getMemoryVT().getSimpleVT();
|
|
|
|
|
|
|
|
unsigned Opcode = 0;
|
|
|
|
switch (VT.SimpleTy) {
|
|
|
|
case MVT::i8:
|
|
|
|
Opcode = MSP430::MOV8rm_POST;
|
|
|
|
break;
|
|
|
|
case MVT::i16:
|
2009-11-07 17:15:06 +00:00
|
|
|
Opcode = MSP430::MOV16rm_POST;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-25 02:42:55 +00:00
|
|
|
return CurDAG->getMachineNode(Opcode, SDLoc(N),
|
2009-11-07 17:15:25 +00:00
|
|
|
VT, MVT::i16, MVT::Other,
|
|
|
|
LD->getBasePtr(), LD->getChain());
|
2009-11-07 17:15:06 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *MSP430DAGToDAGISel::SelectIndexedBinOp(SDNode *Op,
|
2009-11-07 17:15:25 +00:00
|
|
|
SDValue N1, SDValue N2,
|
|
|
|
unsigned Opc8, unsigned Opc16) {
|
|
|
|
if (N1.getOpcode() == ISD::LOAD &&
|
|
|
|
N1.hasOneUse() &&
|
2010-04-17 15:26:15 +00:00
|
|
|
IsLegalToFold(N1, Op, Op, OptLevel)) {
|
2009-11-07 17:15:25 +00:00
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(N1);
|
|
|
|
if (!isValidIndexedLoad(LD))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MVT VT = LD->getMemoryVT().getSimpleVT();
|
|
|
|
unsigned Opc = (VT == MVT::i16 ? Opc16 : Opc8);
|
|
|
|
MachineSDNode::mmo_iterator MemRefs0 = MF->allocateMemRefsArray(1);
|
|
|
|
MemRefs0[0] = cast<MemSDNode>(N1)->getMemOperand();
|
|
|
|
SDValue Ops0[] = { N2, LD->getBasePtr(), LD->getChain() };
|
|
|
|
SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
CurDAG->SelectNodeTo(Op, Opc,
|
2009-11-07 17:15:25 +00:00
|
|
|
VT, MVT::i16, MVT::Other,
|
|
|
|
Ops0, 3);
|
|
|
|
cast<MachineSDNode>(ResNode)->setMemRefs(MemRefs0, MemRefs0 + 1);
|
2009-11-08 14:27:38 +00:00
|
|
|
// Transfer chain.
|
|
|
|
ReplaceUses(SDValue(N1.getNode(), 2), SDValue(ResNode, 2));
|
|
|
|
// Transfer writeback.
|
|
|
|
ReplaceUses(SDValue(N1.getNode(), 1), SDValue(ResNode, 1));
|
2009-11-07 17:15:25 +00:00
|
|
|
return ResNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *MSP430DAGToDAGISel::Select(SDNode *Node) {
|
2013-05-25 02:42:55 +00:00
|
|
|
SDLoc dl(Node);
|
2009-05-03 12:58:58 +00:00
|
|
|
|
|
|
|
// Dump information about the Node being selected
|
2010-03-02 06:34:30 +00:00
|
|
|
DEBUG(errs() << "Selecting: ");
|
2009-05-03 12:58:58 +00:00
|
|
|
DEBUG(Node->dump(CurDAG));
|
2009-08-23 06:49:22 +00:00
|
|
|
DEBUG(errs() << "\n");
|
2009-05-03 12:58:58 +00:00
|
|
|
|
|
|
|
// If we have a custom node, we already have selected!
|
|
|
|
if (Node->isMachineOpcode()) {
|
2010-03-02 06:34:30 +00:00
|
|
|
DEBUG(errs() << "== ";
|
2009-08-23 06:49:22 +00:00
|
|
|
Node->dump(CurDAG);
|
|
|
|
errs() << "\n");
|
2009-05-03 12:58:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-03 13:10:26 +00:00
|
|
|
// Few custom selection stuff.
|
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case ISD::FrameIndex: {
|
2010-01-05 01:24:18 +00:00
|
|
|
assert(Node->getValueType(0) == MVT::i16);
|
2009-05-03 13:10:26 +00:00
|
|
|
int FI = cast<FrameIndexSDNode>(Node)->getIndex();
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue TFI = CurDAG->getTargetFrameIndex(FI, MVT::i16);
|
2009-05-03 13:10:26 +00:00
|
|
|
if (Node->hasOneUse())
|
2009-08-11 20:47:22 +00:00
|
|
|
return CurDAG->SelectNodeTo(Node, MSP430::ADD16ri, MVT::i16,
|
|
|
|
TFI, CurDAG->getTargetConstant(0, MVT::i16));
|
2009-09-25 18:54:59 +00:00
|
|
|
return CurDAG->getMachineNode(MSP430::ADD16ri, dl, MVT::i16,
|
|
|
|
TFI, CurDAG->getTargetConstant(0, MVT::i16));
|
2009-05-03 13:10:26 +00:00
|
|
|
}
|
2009-11-07 17:15:06 +00:00
|
|
|
case ISD::LOAD:
|
2010-01-05 01:24:18 +00:00
|
|
|
if (SDNode *ResNode = SelectIndexedLoad(Node))
|
2009-11-07 17:15:06 +00:00
|
|
|
return ResNode;
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
2009-11-08 14:27:38 +00:00
|
|
|
case ISD::ADD:
|
|
|
|
if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node,
|
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
else if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
|
|
|
case ISD::SUB:
|
|
|
|
if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node,
|
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::SUB8rm_POST, MSP430::SUB16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
|
|
|
case ISD::AND:
|
|
|
|
if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node,
|
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::AND8rm_POST, MSP430::AND16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
else if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::AND8rm_POST, MSP430::AND16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
|
|
|
case ISD::OR:
|
|
|
|
if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node,
|
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::OR8rm_POST, MSP430::OR16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
else if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::OR8rm_POST, MSP430::OR16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
|
|
|
case ISD::XOR:
|
|
|
|
if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node,
|
|
|
|
Node->getOperand(0), Node->getOperand(1),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
|
|
|
|
return ResNode;
|
|
|
|
else if (SDNode *ResNode =
|
2010-01-05 01:24:18 +00:00
|
|
|
SelectIndexedBinOp(Node, Node->getOperand(1), Node->getOperand(0),
|
2009-11-08 14:27:38 +00:00
|
|
|
MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
|
|
|
|
return ResNode;
|
2009-11-07 17:15:25 +00:00
|
|
|
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
2009-05-03 13:10:26 +00:00
|
|
|
}
|
2009-05-03 12:58:58 +00:00
|
|
|
|
|
|
|
// Select the default instruction
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *ResNode = SelectCode(Node);
|
2009-05-03 12:58:58 +00:00
|
|
|
|
2010-03-02 06:34:30 +00:00
|
|
|
DEBUG(errs() << "=> ");
|
2010-01-05 01:24:18 +00:00
|
|
|
if (ResNode == NULL || ResNode == Node)
|
|
|
|
DEBUG(Node->dump(CurDAG));
|
2009-05-03 12:58:58 +00:00
|
|
|
else
|
|
|
|
DEBUG(ResNode->dump(CurDAG));
|
2009-08-23 06:49:22 +00:00
|
|
|
DEBUG(errs() << "\n");
|
2009-05-03 12:58:58 +00:00
|
|
|
|
|
|
|
return ResNode;
|
2009-05-03 12:57:15 +00:00
|
|
|
}
|