return "MSP430 Assembly Printer";
}
- void printOperand(const MachineInstr *MI, int OpNum);
+ void printOperand(const MachineInstr *MI, int OpNum,
+ const char* Modifier = 0);
+ void printSrcMemOperand(const MachineInstr *MI, int OpNum,
+ const char* Modifier = 0);
bool printInstruction(const MachineInstr *MI); // autogenerated.
void printMachineInstruction(const MachineInstr * MI);
bool runOnMachineFunction(MachineFunction &F);
assert(0 && "Should not happen");
}
-void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum) {
+void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
+ const char* Modifier) {
const MachineOperand &MO = MI->getOperand(OpNum);
switch (MO.getType()) {
case MachineOperand::MO_Register:
assert(0 && "not implemented");
break;
case MachineOperand::MO_Immediate:
- O << "#" << MO.getImm();
+ if (!Modifier || strcmp(Modifier, "nohash"))
+ O << '#';
+ O << MO.getImm();
break;
case MachineOperand::MO_MachineBasicBlock:
printBasicBlockLabel(MO.getMBB());
assert(0 && "Not implemented yet!");
}
}
+
+void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
+ const char* Modifier) {
+ const MachineOperand &Disp = MI->getOperand(OpNum);
+ assert(Disp.isImm() && "Displacement can be only immediate!");
+
+ // Special case: 0(Reg) -> @Reg
+ if (Disp.getImm() == 0) {
+ O << "@";
+ printOperand(MI, OpNum + 1);
+ } else {
+ printOperand(MI, OpNum, "nohash");
+ O << '(';
+ printOperand(MI, OpNum + 1);
+ O << ')';
+ }
+}
+
private:
SDNode *Select(SDValue Op);
+ bool SelectAddr(SDValue Op, SDValue Addr, SDValue &Disp, SDValue &Base);
#ifndef NDEBUG
unsigned Indent;
return new MSP430DAGToDAGISel(TM);
}
+bool MSP430DAGToDAGISel::SelectAddr(SDValue Op, SDValue Addr,
+ SDValue &Disp, SDValue &Base) {
+ // We don't support frame index stuff yet.
+ if (isa<FrameIndexSDNode>(Addr))
+ return false;
+
+ // Operand is a result from ADD with constant operand which fits into i16.
+ if (Addr.getOpcode() == ISD::ADD) {
+ if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1))) {
+ uint64_t CVal = CN->getZExtValue();
+ // Offset should fit into 16 bits.
+ if (((CVal << 48) >> 48) == CVal) {
+ // We don't support frame index stuff yet.
+ if (isa<FrameIndexSDNode>(Addr.getOperand(0)))
+ return false;
+
+ Base = Addr.getOperand(0);
+ Disp = CurDAG->getTargetConstant(CVal, MVT::i16);
+
+ return true;
+ }
+ }
+ }
+
+ Base = Addr;
+ Disp = CurDAG->getTargetConstant(0, MVT::i16);
+
+ return true;
+}
+
+
+
/// InstructionSelect - This callback is invoked by
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
void MSP430DAGToDAGISel::InstructionSelect() {
def MSP430rra : SDNode<"MSP430ISD::RRA", SDTIntUnaryOp, []>;
//===----------------------------------------------------------------------===//
-// Pseudo Instructions
+// MSP430 Operand Definitions.
+//===----------------------------------------------------------------------===//
+
+// Address operand
+def memsrc : Operand<i16> {
+ let PrintMethod = "printSrcMemOperand";
+ let MIOperandInfo = (ops i16imm, GR16);
+}
+
+
+//===----------------------------------------------------------------------===//
+// MSP430 Complex Pattern Definitions.
+//===----------------------------------------------------------------------===//
+
+def addr : ComplexPattern<iPTR, 2, "SelectAddr", [], []>;
+
+//===----------------------------------------------------------------------===//
+// Pattern Fragments
+def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
+def extloadi16i8 : PatFrag<(ops node:$ptr), (i16 ( extloadi8 node:$ptr))>;
+
//===----------------------------------------------------------------------===//
+// Pseudo Instructions
let neverHasSideEffects = 1 in
def NOP : Pseudo<(outs), (ins), "nop", []>;
//===----------------------------------------------------------------------===//
// Real Instructions
-//===----------------------------------------------------------------------===//
// FIXME: Provide proper encoding!
let isReturn = 1, isTerminator = 1 in {
// FIXME: Provide proper encoding!
let neverHasSideEffects = 1 in {
-def MOV16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src),
- "mov.w\t{$src, $dst|$dst, $src}",
- []>;
def MOV8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src),
"mov.b\t{$src, $dst|$dst, $src}",
[]>;
+def MOV16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src),
+ "mov.w\t{$src, $dst|$dst, $src}",
+ []>;
}
// FIXME: Provide proper encoding!
let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
-def MOV16ri : Pseudo<(outs GR16:$dst), (ins i16imm:$src),
- "mov.w\t{$src, $dst|$dst, $src}",
- [(set GR16:$dst, imm:$src)]>;
def MOV8ri : Pseudo<(outs GR8:$dst), (ins i8imm:$src),
"mov.b\t{$src, $dst|$dst, $src}",
[(set GR8:$dst, imm:$src)]>;
+def MOV16ri : Pseudo<(outs GR16:$dst), (ins i16imm:$src),
+ "mov.w\t{$src, $dst|$dst, $src}",
+ [(set GR16:$dst, imm:$src)]>;
+}
+let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
+def MOV8rm : Pseudo<(outs GR8:$dst), (ins memsrc:$src),
+ "mov.b\t{$src, $dst|$dst, $src}",
+ [(set GR8:$dst, (load addr:$src))]>;
+def MOV16rm : Pseudo<(outs GR16:$dst), (ins memsrc:$src),
+ "mov.w\t{$src, $dst|$dst, $src}",
+ [(set GR16:$dst, (load addr:$src))]>;
}
+def MOVZX16rr8 : Pseudo<(outs GR16:$dst), (ins GR8:$src),
+ "mov.b\t{$src, $dst|$dst, $src}",
+ [(set GR16:$dst, (zext GR8:$src))]>;
+def MOVZX16rm8 : Pseudo<(outs GR16:$dst), (ins memsrc:$src),
+ "mov.b\t{$src, $dst|$dst, $src}",
+ [(set GR16:$dst, (zextloadi16i8 addr:$src))]>;
+
//===----------------------------------------------------------------------===//
// Arithmetic Instructions
[(set GR8:$dst, (or GR8:$src1, imm:$src2))]>;
} // isTwoAddress = 1
+
+//===----------------------------------------------------------------------===//
+// Non-Instruction Patterns
+
+// extload
+def : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>;