setOperationAction(ISD::SRA, MVT::i16, Custom);
setOperationAction(ISD::RET, MVT::Other, Custom);
setOperationAction(ISD::GlobalAddress, MVT::i16, Custom);
+ setOperationAction(ISD::BR_CC, MVT::Other, Expand);
+ setOperationAction(ISD::BRCOND, MVT::Other, Custom);
+ setOperationAction(ISD::SETCC, MVT::i8 , Custom);
+ setOperationAction(ISD::SETCC, MVT::i16 , Custom);
}
SDValue MSP430TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
case ISD::RET: return LowerRET(Op, DAG);
case ISD::CALL: return LowerCALL(Op, DAG);
case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
+ case ISD::SETCC: return LowerSETCC(Op, DAG);
+ case ISD::BRCOND: return LowerBRCOND(Op, DAG);
default:
assert(0 && "unimplemented operand");
return SDValue();
getPointerTy(), Result);
}
+MVT MSP430TargetLowering::getSetCCResultType(MVT VT) const {
+ return MVT::i8;
+}
+
+SDValue MSP430TargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) {
+ assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer");
+ SDValue LHS = Op.getOperand(0);
+ SDValue RHS = Op.getOperand(1);
+ DebugLoc dl = Op.getDebugLoc();
+ ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
+
+ // FIXME: Handle bittests someday
+ assert(!LHS.getValueType().isFloatingPoint() && "We don't handle FP yet");
+
+ // FIXME: Handle jump negative someday
+ unsigned TargetCC = 0;
+ switch (CC) {
+ default: assert(0 && "Invalid integer condition!");
+ case ISD::SETEQ:
+ TargetCC = MSP430::COND_E; // aka COND_Z
+ break;
+ case ISD::SETNE:
+ TargetCC = MSP430::COND_NE; // aka COND_NZ
+ break;
+ case ISD::SETULE:
+ std::swap(LHS, RHS); // FALLTHROUGH
+ case ISD::SETUGE:
+ TargetCC = MSP430::COND_HS; // aka COND_C
+ break;
+ case ISD::SETUGT:
+ std::swap(LHS, RHS); // FALLTHROUGH
+ case ISD::SETULT:
+ TargetCC = MSP430::COND_LO; // aka COND_NC
+ break;
+ case ISD::SETLE:
+ std::swap(LHS, RHS); // FALLTHROUGH
+ case ISD::SETGE:
+ TargetCC = MSP430::COND_GE;
+ break;
+ case ISD::SETGT:
+ std::swap(LHS, RHS); // FALLTHROUGH
+ case ISD::SETLT:
+ TargetCC = MSP430::COND_L;
+ break;
+ }
+
+ SDValue Cond = DAG.getNode(MSP430ISD::CMP, dl, MVT::i16, LHS, RHS);
+ return DAG.getNode(MSP430ISD::SETCC, dl, MVT::i8,
+ DAG.getConstant(TargetCC, MVT::i8), Cond);
+}
+
+SDValue MSP430TargetLowering::LowerBRCOND(SDValue Op, SelectionDAG &DAG) {
+ SDValue Chain = Op.getOperand(0);
+ SDValue Cond = Op.getOperand(1);
+ SDValue Dest = Op.getOperand(2);
+ DebugLoc dl = Op.getDebugLoc();
+ SDValue CC;
+
+ // Lower condition if not lowered yet
+ if (Cond.getOpcode() == ISD::SETCC)
+ Cond = LowerSETCC(Cond, DAG);
+
+ // If condition flag is set by a MSP430ISD::CMP, then use it as the condition
+ // setting operand in place of the MSP430ISD::SETCC.
+ if (Cond.getOpcode() == MSP430ISD::SETCC) {
+ CC = Cond.getOperand(0);
+ Cond = Cond.getOperand(1);
+ } else
+ assert(0 && "Unimplemented condition!");
+
+ return DAG.getNode(MSP430ISD::BRCOND, dl, Op.getValueType(),
+ Chain, Dest, CC, Cond);
+}
+
const char *MSP430TargetLowering::getTargetNodeName(unsigned Opcode) const {
switch (Opcode) {
default: return NULL;
case MSP430ISD::RRA: return "MSP430ISD::RRA";
case MSP430ISD::CALL: return "MSP430ISD::CALL";
case MSP430ISD::Wrapper: return "MSP430ISD::Wrapper";
+ case MSP430ISD::BRCOND: return "MSP430ISD::BRCOND";
+ case MSP430ISD::CMP: return "MSP430ISD::CMP";
+ case MSP430ISD::SETCC: return "MSP430ISD::SETCC";
}
}
def SDT_MSP430CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>]>;
def SDT_MSP430CallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
def SDT_MSP430Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
+def SDT_MSP430SetCC : SDTypeProfile<1, 2, [SDTCisVT<0, i8>,
+ SDTCisVT<1, i8>, SDTCisVT<2, i16>]>;
+def SDT_MSP430Cmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
+def SDT_MSP430BrCond : SDTypeProfile<0, 3, [SDTCisVT<0, OtherVT>,
+ SDTCisVT<1, i8>, SDTCisVT<2, i16>]>;
//===----------------------------------------------------------------------===//
// MSP430 Specific Node Definitions.
def MSP430callseq_end :
SDNode<"ISD::CALLSEQ_END", SDT_MSP430CallSeqEnd,
[SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
-def MSP430Wrapper : SDNode<"MSP430ISD::Wrapper", SDT_MSP430Wrapper>;
+def MSP430Wrapper : SDNode<"MSP430ISD::Wrapper", SDT_MSP430Wrapper>;
+def MSP430setcc : SDNode<"MSP430ISD::SETCC", SDT_MSP430SetCC>;
+def MSP430cmp : SDNode<"MSP430ISD::CMP", SDT_MSP430Cmp>;
+def MSP430brcond : SDNode<"MSP430ISD::BRCOND", SDT_MSP430BrCond, [SDNPHasChain]>;
//===----------------------------------------------------------------------===//
// MSP430 Operand Definitions.
let MIOperandInfo = (ops GR16, i16imm);
}
+// Branch targets have OtherVT type.
+def brtarget : Operand<OtherVT>;
+
//===----------------------------------------------------------------------===//
// MSP430 Complex Pattern Definitions.
//===----------------------------------------------------------------------===//
def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
def extloadi16i8 : PatFrag<(ops node:$ptr), (i16 ( extloadi8 node:$ptr))>;
+// MSP430 specific condition code. These correspond to CondCode in
+// MSP430InstrInfo.h. They must be kept in synch.
+def MSP430_COND_E : PatLeaf<(i8 0)>; // aka COND_Z
+def MSP430_COND_NE : PatLeaf<(i8 1)>; // aka COND_NZ
+def MSP430_COND_HS : PatLeaf<(i8 2)>; // aka COND_C
+def MSP430_COND_LO : PatLeaf<(i8 3)>; // aka COND_NC
+def MSP430_COND_GE : PatLeaf<(i8 4)>;
+def MSP430_COND_L : PatLeaf<(i8 5)>;
+
//===----------------------------------------------------------------------===//
// Instruction list..
let neverHasSideEffects = 1 in
def NOP : Pseudo<(outs), (ins), "nop", []>;
+//===----------------------------------------------------------------------===//
+// Control Flow Instructions...
+//
+
// FIXME: Provide proper encoding!
let isReturn = 1, isTerminator = 1 in {
def RET : Pseudo<(outs), (ins), "ret", [(MSP430retflag)]>;
}
+// Conditional branches
+let isBranch = 1, isTerminator = 1, Uses = [SRW] in {
+def JE : Pseudo<(outs), (ins brtarget:$dst), "je\t$dst",
+ [(MSP430brcond bb:$dst, MSP430_COND_E, SRW)]>;
+def JNE : Pseudo<(outs), (ins brtarget:$dst), "jne\t$dst",
+ [(MSP430brcond bb:$dst, MSP430_COND_NE, SRW)]>;
+def JHS : Pseudo<(outs), (ins brtarget:$dst), "jhs\t$dst",
+ [(MSP430brcond bb:$dst, MSP430_COND_HS, SRW)]>;
+def JLO : Pseudo<(outs), (ins brtarget:$dst), "jlo\t$dst",
+ [(MSP430brcond bb:$dst, MSP430_COND_LO, SRW)]>;
+def JGE : Pseudo<(outs), (ins brtarget:$dst), "jge\t$dst",
+ [(MSP430brcond bb:$dst, MSP430_COND_GE, SRW)]>;
+def JL : Pseudo<(outs), (ins brtarget:$dst), "jl\t$dst",
+ [(MSP430brcond bb:$dst, MSP430_COND_L, SRW)]>;
+} // Uses = [SRW]
+
//===----------------------------------------------------------------------===//
// Call Instructions...
//
} // isTwoAddress = 1
+// Integer comparisons
+let Defs = [SRW] in {
+def CMP8rr : Pseudo<(outs), (ins GR8:$src1, GR8:$src2),
+ "cmp.b\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp GR8:$src1, GR8:$src2), (implicit SRW)]>;
+def CMP16rr : Pseudo<(outs), (ins GR16:$src1, GR16:$src2),
+ "cmp.w\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp GR16:$src1, GR16:$src2), (implicit SRW)]>;
+
+def CMP8ri : Pseudo<(outs), (ins GR8:$src1, i8imm:$src2),
+ "cmp.b\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp GR8:$src1, imm:$src2), (implicit SRW)]>;
+def CMP16ri : Pseudo<(outs), (ins GR16:$src1, i16imm:$src2),
+ "cmp.w\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp GR16:$src1, imm:$src2), (implicit SRW)]>;
+
+def CMP8rm : Pseudo<(outs), (ins GR8:$src1, memsrc:$src2),
+ "cmp.b\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp GR8:$src1, (load addr:$src2)), (implicit SRW)]>;
+def CMP16rm : Pseudo<(outs), (ins GR16:$src1, memsrc:$src2),
+ "cmp.w\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp GR16:$src1, (load addr:$src2)), (implicit SRW)]>;
+
+def CMP8mr : Pseudo<(outs), (ins memsrc:$src1, GR8:$src2),
+ "cmp.b\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp (load addr:$src1), GR8:$src2), (implicit SRW)]>;
+def CMP16mr : Pseudo<(outs), (ins memsrc:$src1, GR16:$src2),
+ "cmp.w\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp (load addr:$src1), GR16:$src2), (implicit SRW)]>;
+
+def CMP8mi : Pseudo<(outs), (ins memsrc:$src1, i8imm:$src2),
+ "cmp.b\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp (load addr:$src1), (i8 imm:$src2)), (implicit SRW)]>;
+def CMP16mi : Pseudo<(outs), (ins memsrc:$src1, i16imm:$src2),
+ "cmp.w\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp (load addr:$src1), (i16 imm:$src2)), (implicit SRW)]>;
+
+def CMP8mm : Pseudo<(outs), (ins memsrc:$src1, memsrc:$src2),
+ "cmp.b\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp (load addr:$src1), (i8 (load addr:$src2))), (implicit SRW)]>;
+def CMP16mm : Pseudo<(outs), (ins memsrc:$src1, memsrc:$src2),
+ "cmp.w\t{$src2, $src1|$src1, $src2}",
+ [(MSP430cmp (load addr:$src1), (i16 (load addr:$src2))), (implicit SRW)]>;
+} // Defs = [SRW]
+
//===----------------------------------------------------------------------===//
// Non-Instruction Patterns