35 struct MSP430ISelAddressMode {
54 MSP430ISelAddressMode()
55 : BaseType(RegBase), Disp(0), GV(0), CP(0), BlockAddr(0),
56 ES(0), JT(-1),
Align(0) {
59 bool hasSymbolicDisplacement()
const {
60 return GV != 0 || CP != 0 || ES != 0 || JT != -1;
64 errs() <<
"MSP430ISelAddressMode " <<
this <<
'\n';
65 if (BaseType == RegBase && Base.Reg.getNode() != 0) {
66 errs() <<
"Base.Reg ";
67 Base.Reg.getNode()->dump();
68 }
else if (BaseType == FrameIndexBase) {
69 errs() <<
" Base.FrameIndex " << Base.FrameIndex <<
'\n';
71 errs() <<
" Disp " << Disp <<
'\n';
83 errs() <<
" JT" << JT <<
" Align" <<
Align <<
'\n';
99 Lowering(*TM.getTargetLowering()),
100 Subtarget(*TM.getSubtargetImpl()) { }
102 virtual const char *getPassName()
const {
103 return "MSP430 DAG->DAG Pattern Instruction Selection";
106 bool MatchAddress(
SDValue N, MSP430ISelAddressMode &AM);
107 bool MatchWrapper(
SDValue N, MSP430ISelAddressMode &AM);
108 bool MatchAddressBase(
SDValue N, MSP430ISelAddressMode &AM);
111 SelectInlineAsmMemoryOperand(
const SDValue &Op,
char ConstraintCode,
112 std::vector<SDValue> &OutOps);
115 #include "MSP430GenDAGISel.inc"
121 unsigned Opc8,
unsigned Opc16);
132 return new MSP430DAGToDAGISel(TM, OptLevel);
139 bool MSP430DAGToDAGISel::MatchWrapper(
SDValue N, MSP430ISelAddressMode &AM) {
142 if (AM.hasSymbolicDisplacement())
148 AM.GV =
G->getGlobal();
149 AM.Disp +=
G->getOffset();
152 AM.CP = CP->getConstVal();
153 AM.Align = CP->getAlignment();
154 AM.Disp += CP->getOffset();
157 AM.ES = S->getSymbol();
160 AM.JT = J->getIndex();
163 AM.BlockAddr = cast<BlockAddressSDNode>(N0)->getBlockAddress();
171 bool MSP430DAGToDAGISel::MatchAddressBase(
SDValue N, MSP430ISelAddressMode &AM) {
173 if (AM.BaseType != MSP430ISelAddressMode::RegBase || AM.Base.Reg.getNode()) {
179 AM.BaseType = MSP430ISelAddressMode::RegBase;
184 bool MSP430DAGToDAGISel::MatchAddress(
SDValue N, MSP430ISelAddressMode &AM) {
185 DEBUG(
errs() <<
"MatchAddress: "; AM.dump());
190 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
196 if (!MatchWrapper(N, AM))
201 if (AM.BaseType == MSP430ISelAddressMode::RegBase
202 && AM.Base.Reg.getNode() == 0) {
203 AM.BaseType = MSP430ISelAddressMode::FrameIndexBase;
204 AM.Base.FrameIndex = cast<FrameIndexSDNode>(
N)->getIndex();
210 MSP430ISelAddressMode Backup = AM;
226 MSP430ISelAddressMode Backup = AM;
227 uint64_t Offset = CN->getSExtValue();
233 CurDAG->MaskedValueIsZero(N.
getOperand(0), CN->getAPIntValue())) {
242 return MatchAddressBase(N, AM);
248 bool MSP430DAGToDAGISel::SelectAddr(
SDValue N,
250 MSP430ISelAddressMode AM;
252 if (MatchAddress(N, AM))
256 if (AM.BaseType == MSP430ISelAddressMode::RegBase) {
257 if (!AM.Base.Reg.getNode())
258 AM.Base.Reg = CurDAG->getRegister(0, VT);
261 Base = (AM.BaseType == MSP430ISelAddressMode::FrameIndexBase) ?
262 CurDAG->getTargetFrameIndex(AM.Base.FrameIndex,
263 getTargetLowering()->getPointerTy()) :
267 Disp = CurDAG->getTargetGlobalAddress(AM.GV,
SDLoc(N),
271 Disp = CurDAG->getTargetConstantPool(AM.CP,
MVT::i16,
272 AM.Align, AM.Disp, 0);
274 Disp = CurDAG->getTargetExternalSymbol(AM.ES,
MVT::i16, 0);
275 else if (AM.JT != -1)
276 Disp = CurDAG->getTargetJumpTable(AM.JT,
MVT::i16, 0);
277 else if (AM.BlockAddr)
278 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr,
MVT::i32, 0,
281 Disp = CurDAG->getTargetConstant(AM.Disp,
MVT::i16);
286 bool MSP430DAGToDAGISel::
287 SelectInlineAsmMemoryOperand(
const SDValue &Op,
char ConstraintCode,
288 std::vector<SDValue> &OutOps) {
290 switch (ConstraintCode) {
291 default:
return true;
293 if (!SelectAddr(Op, Op0, Op1))
298 OutOps.push_back(Op0);
299 OutOps.push_back(Op1);
313 if (cast<ConstantSDNode>(LD->
getOffset())->getZExtValue() != 1)
319 if (cast<ConstantSDNode>(LD->
getOffset())->getZExtValue() != 2)
330 SDNode *MSP430DAGToDAGISel::SelectIndexedLoad(
SDNode *N) {
340 Opcode = MSP430::MOV8rm_POST;
343 Opcode = MSP430::MOV16rm_POST;
349 return CurDAG->getMachineNode(Opcode,
SDLoc(N),
354 SDNode *MSP430DAGToDAGISel::SelectIndexedBinOp(
SDNode *Op,
356 unsigned Opc8,
unsigned Opc16) {
359 IsLegalToFold(N1, Op, Op, OptLevel)) {
365 unsigned Opc = (VT ==
MVT::i16 ? Opc16 : Opc8);
367 MemRefs0[0] = cast<MemSDNode>(N1)->getMemOperand();
370 CurDAG->SelectNodeTo(Op, Opc,
373 cast<MachineSDNode>(ResNode)->setMemRefs(MemRefs0, MemRefs0 + 1);
407 int FI = cast<FrameIndexSDNode>(Node)->getIndex();
410 return CurDAG->SelectNodeTo(Node, MSP430::ADD16ri,
MVT::i16,
411 TFI, CurDAG->getTargetConstant(0,
MVT::i16));
412 return CurDAG->getMachineNode(MSP430::ADD16ri, dl,
MVT::i16,
413 TFI, CurDAG->getTargetConstant(0,
MVT::i16));
416 if (
SDNode *ResNode = SelectIndexedLoad(Node))
422 SelectIndexedBinOp(Node,
424 MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
426 else if (
SDNode *ResNode =
428 MSP430::ADD8rm_POST, MSP430::ADD16rm_POST))
435 SelectIndexedBinOp(Node,
437 MSP430::SUB8rm_POST, MSP430::SUB16rm_POST))
444 SelectIndexedBinOp(Node,
446 MSP430::AND8rm_POST, MSP430::AND16rm_POST))
448 else if (
SDNode *ResNode =
450 MSP430::AND8rm_POST, MSP430::AND16rm_POST))
457 SelectIndexedBinOp(Node,
459 MSP430::OR8rm_POST, MSP430::OR16rm_POST))
461 else if (
SDNode *ResNode =
463 MSP430::OR8rm_POST, MSP430::OR16rm_POST))
470 SelectIndexedBinOp(Node,
472 MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
474 else if (
SDNode *ResNode =
476 MSP430::XOR8rm_POST, MSP430::XOR16rm_POST))
484 SDNode *ResNode = SelectCode(Node);
487 if (ResNode == NULL || ResNode == Node)
void dump() const
dump - Dump this node, for debugging.
unsigned getOpcode() const
const SDValue & getOperand(unsigned Num) const
void setNodeId(int Id)
setNodeId - Set unique node id.
const SDValue & getBasePtr() const
FunctionPass * createMSP430ISelDag(MSP430TargetMachine &TM, CodeGenOpt::Level OptLevel)
EVT getValueType(unsigned ResNo) const
Simple integer binary arithmetic operators.
EVT getMemoryVT() const
getMemoryVT - Return the type of the in-memory value.
SDNode * getNode() const
get the SDNode which holds the desired result
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
const SDValue & getOperand(unsigned i) const
LLVM Constant Representation.
unsigned getOpcode() const
ISD::MemIndexedMode getAddressingMode() const
const SDValue & getOffset() const
const SDValue & getChain() const
ISD::LoadExtType getExtensionType() const
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
Bitwise operators - logical and, logical or, logical xor.
static bool isValidIndexedLoad(const LoadSDNode *LD)
bool isMachineOpcode() const