2009-05-03 20:57:15 +08: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 "MSP430ISelLowering.h"
|
|
|
|
#include "MSP430TargetMachine.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
#include "llvm/CallingConv.h"
|
|
|
|
#include "llvm/Constants.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"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2009-10-22 03:18:28 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-05-03 20:57:15 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 04:53:28 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-10-12 07:03:28 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
|
2009-05-03 20:57:15 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-10-22 03:18:28 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
static cl::opt<bool>
|
|
|
|
ViewRMWDAGs("view-msp430-rmw-dags", cl::Hidden,
|
|
|
|
cl::desc("Pop up a window to show isel dags after RMW preprocess"));
|
|
|
|
#else
|
|
|
|
static const bool ViewRMWDAGs = false;
|
|
|
|
#endif
|
|
|
|
|
2009-10-12 07:03:28 +08:00
|
|
|
STATISTIC(NumLoadMoved, "Number of loads moved below TokenFactor");
|
|
|
|
|
2009-05-03 20:57:15 +08:00
|
|
|
/// MSP430DAGToDAGISel - MSP430 specific code to select MSP430 machine
|
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
///
|
|
|
|
namespace {
|
|
|
|
class MSP430DAGToDAGISel : public SelectionDAGISel {
|
|
|
|
MSP430TargetLowering &Lowering;
|
|
|
|
const MSP430Subtarget &Subtarget;
|
|
|
|
|
|
|
|
public:
|
2009-05-03 21:19:42 +08:00
|
|
|
MSP430DAGToDAGISel(MSP430TargetMachine &TM, CodeGenOpt::Level OptLevel)
|
|
|
|
: SelectionDAGISel(TM, OptLevel),
|
2009-05-03 20:57:15 +08:00
|
|
|
Lowering(*TM.getTargetLowering()),
|
|
|
|
Subtarget(*TM.getSubtargetImpl()) { }
|
|
|
|
|
|
|
|
virtual void InstructionSelect();
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "MSP430 DAG->DAG Pattern Instruction Selection";
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:16:00 +08:00
|
|
|
bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U,
|
|
|
|
SDNode *Root) const;
|
|
|
|
|
2009-10-12 03:14:21 +08:00
|
|
|
virtual bool
|
|
|
|
SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps);
|
|
|
|
|
2009-05-03 20:57:15 +08:00
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "MSP430GenDAGISel.inc"
|
|
|
|
|
|
|
|
private:
|
2009-10-22 08:16:00 +08:00
|
|
|
DenseMap<SDNode*, SDNode*> RMWStores;
|
2009-10-12 07:03:28 +08:00
|
|
|
void PreprocessForRMW();
|
2009-05-03 20:57:15 +08:00
|
|
|
SDNode *Select(SDValue Op);
|
2009-05-03 21:09:40 +08:00
|
|
|
bool SelectAddr(SDValue Op, SDValue Addr, SDValue &Base, SDValue &Disp);
|
2009-05-03 20:58:58 +08:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
unsigned Indent;
|
|
|
|
#endif
|
2009-05-03 20:57:15 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
/// createMSP430ISelDag - This pass converts a legalized DAG into a
|
|
|
|
/// MSP430-specific DAG, ready for instruction scheduling.
|
|
|
|
///
|
2009-05-03 21:19:42 +08:00
|
|
|
FunctionPass *llvm::createMSP430ISelDag(MSP430TargetMachine &TM,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
|
|
|
return new MSP430DAGToDAGISel(TM, OptLevel);
|
2009-05-03 20:57:15 +08:00
|
|
|
}
|
|
|
|
|
2009-05-03 21:09:10 +08:00
|
|
|
// FIXME: This is pretty dummy routine and needs to be rewritten in the future.
|
2009-05-03 21:06:03 +08:00
|
|
|
bool MSP430DAGToDAGISel::SelectAddr(SDValue Op, SDValue Addr,
|
2009-05-03 21:09:40 +08:00
|
|
|
SDValue &Base, SDValue &Disp) {
|
2009-05-03 21:10:11 +08:00
|
|
|
// Try to match frame address first.
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
2009-08-12 04:47:22 +08:00
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i16);
|
|
|
|
Disp = CurDAG->getTargetConstant(0, MVT::i16);
|
2009-05-03 21:10:11 +08:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-03 21:06:03 +08:00
|
|
|
|
2009-05-03 21:08:51 +08:00
|
|
|
switch (Addr.getOpcode()) {
|
|
|
|
case ISD::ADD:
|
2009-05-03 21:11:35 +08:00
|
|
|
// Operand is a result from ADD with constant operand which fits into i16.
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
|
2009-05-03 21:06:03 +08:00
|
|
|
uint64_t CVal = CN->getZExtValue();
|
|
|
|
// Offset should fit into 16 bits.
|
|
|
|
if (((CVal << 48) >> 48) == CVal) {
|
2009-05-03 21:10:11 +08:00
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(N0))
|
2009-08-12 04:47:22 +08:00
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i16);
|
2009-05-03 21:10:11 +08:00
|
|
|
else
|
|
|
|
Base = N0;
|
2009-05-03 21:06:03 +08:00
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
Disp = CurDAG->getTargetConstant(CVal, MVT::i16);
|
2009-05-03 21:06:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-05-03 21:08:51 +08:00
|
|
|
break;
|
|
|
|
case MSP430ISD::Wrapper:
|
|
|
|
SDValue N0 = Addr.getOperand(0);
|
|
|
|
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
|
2009-05-03 21:09:40 +08:00
|
|
|
Base = CurDAG->getTargetGlobalAddress(G->getGlobal(),
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::i16, G->getOffset());
|
|
|
|
Disp = CurDAG->getTargetConstant(0, MVT::i16);
|
2009-05-03 21:09:10 +08:00
|
|
|
return true;
|
2009-05-03 21:14:46 +08:00
|
|
|
} else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(N0)) {
|
2009-08-12 04:47:22 +08:00
|
|
|
Base = CurDAG->getTargetExternalSymbol(E->getSymbol(), MVT::i16);
|
|
|
|
Disp = CurDAG->getTargetConstant(0, MVT::i16);
|
2009-05-03 21:08:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
};
|
2009-05-03 21:06:03 +08:00
|
|
|
|
2009-05-03 21:09:40 +08:00
|
|
|
Base = Addr;
|
2009-08-12 04:47:22 +08:00
|
|
|
Disp = CurDAG->getTargetConstant(0, MVT::i16);
|
2009-05-03 21:06:03 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-12 03:14:21 +08:00
|
|
|
bool MSP430DAGToDAGISel::
|
|
|
|
SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
SDValue Op0, Op1;
|
|
|
|
switch (ConstraintCode) {
|
|
|
|
default: return true;
|
|
|
|
case 'm': // memory
|
|
|
|
if (!SelectAddr(Op, Op, Op0, Op1))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutOps.push_back(Op0);
|
|
|
|
OutOps.push_back(Op1);
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-03 21:06:03 +08:00
|
|
|
|
2009-10-22 08:16:00 +08:00
|
|
|
bool MSP430DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U,
|
|
|
|
SDNode *Root) const {
|
|
|
|
if (OptLevel == CodeGenOpt::None) return false;
|
|
|
|
|
|
|
|
/// RMW preprocessing creates the following code:
|
2009-10-22 17:28:49 +08:00
|
|
|
/// [Load1]
|
|
|
|
/// ^ ^
|
|
|
|
/// / |
|
|
|
|
/// / |
|
2009-10-22 08:16:00 +08:00
|
|
|
/// [Load2] |
|
|
|
|
/// ^ ^ |
|
|
|
|
/// | | |
|
|
|
|
/// | \-|
|
|
|
|
/// | |
|
|
|
|
/// | [Op]
|
|
|
|
/// | ^
|
|
|
|
/// | |
|
|
|
|
/// \ /
|
|
|
|
/// \ /
|
|
|
|
/// [Store]
|
|
|
|
///
|
|
|
|
/// The path Store => Load2 => Load1 is via chain. Note that in general it is
|
|
|
|
/// not allowed to fold Load1 into Op (and Store) since it will creates a
|
|
|
|
/// cycle. However, this is perfectly legal for the loads moved below the
|
|
|
|
/// TokenFactor by PreprocessForRMW. Query the map Store => Load1 (created
|
|
|
|
/// during preprocessing) to determine whether it's legal to introduce such
|
|
|
|
/// "cycle" for a moment.
|
|
|
|
DenseMap<SDNode*, SDNode*>::iterator I = RMWStores.find(Root);
|
|
|
|
if (I != RMWStores.end() && I->second == N)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Proceed to 'generic' cycle finder code
|
|
|
|
return SelectionDAGISel::IsLegalAndProfitableToFold(N, U, Root);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 07:03:28 +08:00
|
|
|
/// MoveBelowTokenFactor - Replace TokenFactor operand with load's chain operand
|
|
|
|
/// and move load below the TokenFactor. Replace store's chain operand with
|
|
|
|
/// load's chain result.
|
|
|
|
static void MoveBelowTokenFactor(SelectionDAG *CurDAG, SDValue Load,
|
|
|
|
SDValue Store, SDValue TF) {
|
|
|
|
SmallVector<SDValue, 4> Ops;
|
|
|
|
for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i)
|
2009-10-22 03:17:55 +08:00
|
|
|
if (Load.getNode() == TF.getOperand(i).getNode())
|
|
|
|
Ops.push_back(Load.getOperand(0));
|
|
|
|
else
|
|
|
|
Ops.push_back(TF.getOperand(i));
|
|
|
|
SDValue NewTF = CurDAG->UpdateNodeOperands(TF, &Ops[0], Ops.size());
|
2009-10-12 07:03:28 +08:00
|
|
|
SDValue NewLoad = CurDAG->UpdateNodeOperands(Load, NewTF,
|
|
|
|
Load.getOperand(1),
|
|
|
|
Load.getOperand(2));
|
|
|
|
CurDAG->UpdateNodeOperands(Store, NewLoad.getValue(1), Store.getOperand(1),
|
|
|
|
Store.getOperand(2), Store.getOperand(3));
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:16:00 +08:00
|
|
|
/// MoveBelowTokenFactor2 - Replace TokenFactor operand with load's chain operand
|
|
|
|
/// and move load below the TokenFactor. Replace store's chain operand with
|
|
|
|
/// load's chain result. This a version which sinks two loads below token factor.
|
|
|
|
/// Look into PreprocessForRMW comments for explanation of transform.
|
|
|
|
static void MoveBelowTokenFactor2(SelectionDAG *CurDAG,
|
|
|
|
SDValue Load1, SDValue Load2,
|
|
|
|
SDValue Store, SDValue TF) {
|
|
|
|
SmallVector<SDValue, 4> Ops;
|
|
|
|
for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i) {
|
|
|
|
SDNode* N = TF.getOperand(i).getNode();
|
|
|
|
if (Load2.getNode() == N)
|
|
|
|
Ops.push_back(Load2.getOperand(0));
|
|
|
|
else if (Load1.getNode() != N)
|
|
|
|
Ops.push_back(TF.getOperand(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue NewTF = SDValue(CurDAG->MorphNodeTo(TF.getNode(),
|
|
|
|
TF.getOpcode(),
|
|
|
|
TF.getNode()->getVTList(),
|
|
|
|
&Ops[0], Ops.size()), TF.getResNo());
|
|
|
|
SDValue NewLoad2 = CurDAG->UpdateNodeOperands(Load2, NewTF,
|
|
|
|
Load2.getOperand(1),
|
|
|
|
Load2.getOperand(2));
|
|
|
|
|
|
|
|
SDValue NewLoad1 = CurDAG->UpdateNodeOperands(Load1, NewLoad2.getValue(1),
|
|
|
|
Load1.getOperand(1),
|
|
|
|
Load1.getOperand(2));
|
|
|
|
|
|
|
|
CurDAG->UpdateNodeOperands(Store,
|
|
|
|
NewLoad1.getValue(1),
|
|
|
|
Store.getOperand(1),
|
|
|
|
Store.getOperand(2), Store.getOperand(3));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isAllowedToSink - return true if N a load which can be moved below token
|
|
|
|
/// factor. Basically, the load should be non-volatile and has single use.
|
|
|
|
static bool isLoadAllowedToSink(SDValue N, SDValue Chain) {
|
2009-10-12 07:03:28 +08:00
|
|
|
if (N.getOpcode() == ISD::BIT_CONVERT)
|
|
|
|
N = N.getOperand(0);
|
|
|
|
|
|
|
|
LoadSDNode *LD = dyn_cast<LoadSDNode>(N);
|
|
|
|
if (!LD || LD->isVolatile())
|
|
|
|
return false;
|
|
|
|
if (LD->getAddressingMode() != ISD::UNINDEXED)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ISD::LoadExtType ExtType = LD->getExtensionType();
|
|
|
|
if (ExtType != ISD::NON_EXTLOAD && ExtType != ISD::EXTLOAD)
|
|
|
|
return false;
|
|
|
|
|
2009-10-22 08:16:00 +08:00
|
|
|
return (N.hasOneUse() &&
|
|
|
|
LD->hasNUsesOfValue(1, 1) &&
|
|
|
|
LD->isOperandOf(Chain.getNode()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// isRMWLoad - Return true if N is a load that's part of RMW sub-DAG.
|
|
|
|
/// The chain produced by the load must only be used by the store's chain
|
|
|
|
/// operand, otherwise this may produce a cycle in the DAG.
|
|
|
|
static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address,
|
|
|
|
SDValue &Load) {
|
|
|
|
if (isLoadAllowedToSink(N, Chain) &&
|
|
|
|
N.getOperand(1) == Address) {
|
2009-10-12 07:03:28 +08:00
|
|
|
Load = N;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// PreprocessForRMW - Preprocess the DAG to make instruction selection better.
|
2009-10-22 03:17:55 +08:00
|
|
|
/// This is only run if not in -O0 mode.
|
|
|
|
/// This allows the instruction selector to pick more read-modify-write
|
|
|
|
/// instructions. This is a common case:
|
|
|
|
///
|
|
|
|
/// [Load chain]
|
|
|
|
/// ^
|
|
|
|
/// |
|
|
|
|
/// [Load]
|
|
|
|
/// ^ ^
|
|
|
|
/// | |
|
|
|
|
/// / \-
|
|
|
|
/// / |
|
|
|
|
/// [TokenFactor] [Op]
|
|
|
|
/// ^ ^
|
|
|
|
/// | |
|
|
|
|
/// \ /
|
|
|
|
/// \ /
|
|
|
|
/// [Store]
|
|
|
|
///
|
|
|
|
/// The fact the store's chain operand != load's chain will prevent the
|
|
|
|
/// (store (op (load))) instruction from being selected. We can transform it to:
|
|
|
|
///
|
|
|
|
/// [Load chain]
|
|
|
|
/// ^
|
|
|
|
/// |
|
|
|
|
/// [TokenFactor]
|
|
|
|
/// ^
|
|
|
|
/// |
|
|
|
|
/// [Load]
|
|
|
|
/// ^ ^
|
|
|
|
/// | |
|
|
|
|
/// | \-
|
|
|
|
/// | |
|
|
|
|
/// | [Op]
|
|
|
|
/// | ^
|
|
|
|
/// | |
|
|
|
|
/// \ /
|
|
|
|
/// \ /
|
|
|
|
/// [Store]
|
2009-10-22 08:16:00 +08:00
|
|
|
///
|
|
|
|
/// We also recognize the case where second operand of Op is load as well and
|
|
|
|
/// move it below token factor as well creating DAG as follows:
|
|
|
|
///
|
2009-10-22 17:28:49 +08:00
|
|
|
/// [Load chain]
|
|
|
|
/// ^
|
|
|
|
/// |
|
|
|
|
/// [TokenFactor]
|
|
|
|
/// ^
|
|
|
|
/// |
|
|
|
|
/// [Load1]
|
|
|
|
/// ^ ^
|
|
|
|
/// / |
|
|
|
|
/// / |
|
2009-10-22 08:16:00 +08:00
|
|
|
/// [Load2] |
|
|
|
|
/// ^ ^ |
|
|
|
|
/// | | |
|
|
|
|
/// | \-|
|
|
|
|
/// | |
|
|
|
|
/// | [Op]
|
|
|
|
/// | ^
|
|
|
|
/// | |
|
|
|
|
/// \ /
|
|
|
|
/// \ /
|
|
|
|
/// [Store]
|
|
|
|
///
|
|
|
|
/// This allows selection of mem-mem instructions. Yay!
|
|
|
|
|
2009-10-12 07:03:28 +08:00
|
|
|
void MSP430DAGToDAGISel::PreprocessForRMW() {
|
|
|
|
for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
|
|
|
|
E = CurDAG->allnodes_end(); I != E; ++I) {
|
|
|
|
if (!ISD::isNON_TRUNCStore(I))
|
|
|
|
continue;
|
|
|
|
SDValue Chain = I->getOperand(0);
|
2009-10-22 03:17:55 +08:00
|
|
|
|
2009-10-12 07:03:28 +08:00
|
|
|
if (Chain.getNode()->getOpcode() != ISD::TokenFactor)
|
|
|
|
continue;
|
|
|
|
|
2009-10-22 03:17:55 +08:00
|
|
|
SDValue N1 = I->getOperand(1);
|
|
|
|
SDValue N2 = I->getOperand(2);
|
|
|
|
if ((N1.getValueType().isFloatingPoint() &&
|
|
|
|
!N1.getValueType().isVector()) ||
|
|
|
|
!N1.hasOneUse())
|
2009-10-12 07:03:28 +08:00
|
|
|
continue;
|
|
|
|
|
2009-10-22 08:16:00 +08:00
|
|
|
unsigned RModW = 0;
|
|
|
|
SDValue Load1, Load2;
|
2009-10-12 07:03:28 +08:00
|
|
|
unsigned Opcode = N1.getNode()->getOpcode();
|
|
|
|
switch (Opcode) {
|
2009-10-22 03:17:55 +08:00
|
|
|
case ISD::ADD:
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
|
|
|
case ISD::ADDC:
|
|
|
|
case ISD::ADDE: {
|
|
|
|
SDValue N10 = N1.getOperand(0);
|
|
|
|
SDValue N11 = N1.getOperand(1);
|
2009-10-22 08:16:00 +08:00
|
|
|
if (isRMWLoad(N10, Chain, N2, Load1)) {
|
|
|
|
if (isLoadAllowedToSink(N11, Chain)) {
|
|
|
|
Load2 = N11;
|
|
|
|
RModW = 2;
|
|
|
|
} else
|
|
|
|
RModW = 1;
|
|
|
|
} else if (isRMWLoad(N11, Chain, N2, Load1)) {
|
|
|
|
if (isLoadAllowedToSink(N10, Chain)) {
|
|
|
|
Load2 = N10;
|
|
|
|
RModW = 2;
|
|
|
|
} else
|
|
|
|
RModW = 1;
|
|
|
|
}
|
2009-10-22 03:17:55 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::SUBC:
|
|
|
|
case ISD::SUBE: {
|
|
|
|
SDValue N10 = N1.getOperand(0);
|
2009-10-22 08:16:00 +08:00
|
|
|
SDValue N11 = N1.getOperand(1);
|
|
|
|
if (isRMWLoad(N10, Chain, N2, Load1)) {
|
|
|
|
if (isLoadAllowedToSink(N11, Chain)) {
|
|
|
|
Load2 = N11;
|
|
|
|
RModW = 2;
|
|
|
|
} else
|
|
|
|
RModW = 1;
|
|
|
|
}
|
2009-10-22 03:17:55 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-10-12 07:03:28 +08:00
|
|
|
}
|
|
|
|
|
2009-10-22 08:16:00 +08:00
|
|
|
NumLoadMoved += RModW;
|
|
|
|
if (RModW == 1)
|
|
|
|
MoveBelowTokenFactor(CurDAG, Load1, SDValue(I, 0), Chain);
|
|
|
|
else if (RModW == 2) {
|
|
|
|
MoveBelowTokenFactor2(CurDAG, Load1, Load2, SDValue(I, 0), Chain);
|
|
|
|
SDNode* Store = I;
|
|
|
|
RMWStores[Store] = Load2.getNode();
|
2009-10-12 07:03:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 20:57:15 +08:00
|
|
|
/// InstructionSelect - This callback is invoked by
|
|
|
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
2009-05-03 20:58:40 +08:00
|
|
|
void MSP430DAGToDAGISel::InstructionSelect() {
|
2009-10-22 03:18:28 +08:00
|
|
|
std::string BlockName;
|
|
|
|
if (ViewRMWDAGs)
|
|
|
|
BlockName = MF->getFunction()->getNameStr() + ":" +
|
|
|
|
BB->getBasicBlock()->getNameStr();
|
|
|
|
|
2009-10-12 07:03:28 +08:00
|
|
|
PreprocessForRMW();
|
|
|
|
|
2009-10-22 03:18:28 +08:00
|
|
|
if (ViewRMWDAGs) CurDAG->viewGraph("RMW preprocessed:" + BlockName);
|
|
|
|
|
2009-10-12 07:03:28 +08:00
|
|
|
DEBUG(errs() << "Selection DAG after RMW preprocessing:\n");
|
|
|
|
DEBUG(CurDAG->dump());
|
|
|
|
|
2009-05-03 20:57:15 +08:00
|
|
|
DEBUG(BB->dump());
|
|
|
|
|
2009-05-03 21:16:37 +08:00
|
|
|
// Codegen the basic block.
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << "===== Instruction selection begins:\n");
|
2009-08-23 16:50:52 +08:00
|
|
|
DEBUG(Indent = 0);
|
2009-05-03 20:57:15 +08:00
|
|
|
SelectRoot(*CurDAG);
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << "===== Instruction selection ends:\n");
|
2009-05-03 20:57:15 +08:00
|
|
|
|
|
|
|
CurDAG->RemoveDeadNodes();
|
2009-10-22 08:16:00 +08:00
|
|
|
RMWStores.clear();
|
2009-05-03 20:57:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *MSP430DAGToDAGISel::Select(SDValue Op) {
|
2009-05-03 20:58:58 +08:00
|
|
|
SDNode *Node = Op.getNode();
|
2009-05-03 21:10:26 +08:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2009-05-03 20:58:58 +08:00
|
|
|
|
|
|
|
// Dump information about the Node being selected
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs().indent(Indent) << "Selecting: ");
|
2009-05-03 20:58:58 +08:00
|
|
|
DEBUG(Node->dump(CurDAG));
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << "\n");
|
2009-08-23 16:50:52 +08:00
|
|
|
DEBUG(Indent += 2);
|
2009-05-03 20:58:58 +08:00
|
|
|
|
|
|
|
// If we have a custom node, we already have selected!
|
|
|
|
if (Node->isMachineOpcode()) {
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs().indent(Indent-2) << "== ";
|
|
|
|
Node->dump(CurDAG);
|
|
|
|
errs() << "\n");
|
2009-08-23 16:50:52 +08:00
|
|
|
DEBUG(Indent -= 2);
|
2009-05-03 20:58:58 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-03 21:10:26 +08:00
|
|
|
// Few custom selection stuff.
|
|
|
|
switch (Node->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case ISD::FrameIndex: {
|
2009-08-12 04:47:22 +08:00
|
|
|
assert(Op.getValueType() == MVT::i16);
|
2009-05-03 21:10:26 +08:00
|
|
|
int FI = cast<FrameIndexSDNode>(Node)->getIndex();
|
2009-08-12 04:47:22 +08:00
|
|
|
SDValue TFI = CurDAG->getTargetFrameIndex(FI, MVT::i16);
|
2009-05-03 21:10:26 +08:00
|
|
|
if (Node->hasOneUse())
|
2009-08-12 04:47:22 +08:00
|
|
|
return CurDAG->SelectNodeTo(Node, MSP430::ADD16ri, MVT::i16,
|
|
|
|
TFI, CurDAG->getTargetConstant(0, MVT::i16));
|
2009-09-26 02:54:59 +08:00
|
|
|
return CurDAG->getMachineNode(MSP430::ADD16ri, dl, MVT::i16,
|
|
|
|
TFI, CurDAG->getTargetConstant(0, MVT::i16));
|
2009-05-03 21:10:26 +08:00
|
|
|
}
|
|
|
|
}
|
2009-05-03 20:58:58 +08:00
|
|
|
|
|
|
|
// Select the default instruction
|
|
|
|
SDNode *ResNode = SelectCode(Op);
|
|
|
|
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << std::string(Indent-2, ' ') << "=> ");
|
2009-05-03 20:58:58 +08:00
|
|
|
if (ResNode == NULL || ResNode == Op.getNode())
|
|
|
|
DEBUG(Op.getNode()->dump(CurDAG));
|
|
|
|
else
|
|
|
|
DEBUG(ResNode->dump(CurDAG));
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << "\n");
|
2009-08-23 16:50:52 +08:00
|
|
|
DEBUG(Indent -= 2);
|
2009-05-03 20:58:58 +08:00
|
|
|
|
|
|
|
return ResNode;
|
2009-05-03 20:57:15 +08:00
|
|
|
}
|