Correct asmprinting of memory operands

llvm-svn: 70732
This commit is contained in:
Anton Korobeynikov 2009-05-03 13:09:10 +00:00
parent a3bce28ae0
commit 6399a3d628
2 changed files with 24 additions and 20 deletions

View File

@ -162,17 +162,23 @@ void MSP430AsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum, void MSP430AsmPrinter::printSrcMemOperand(const MachineInstr *MI, int OpNum,
const char* Modifier) { const char* Modifier) {
const MachineOperand &Disp = MI->getOperand(OpNum); const MachineOperand &Disp = MI->getOperand(OpNum);
assert(Disp.isImm() && "Displacement can be only immediate!"); const MachineOperand &Base = MI->getOperand(OpNum+1);
// Special case: 0(Reg) -> @Reg if (Disp.isGlobal())
if (Disp.getImm() == 0) { printOperand(MI, OpNum, "mem");
O << "@"; else if (Disp.isImm() && !Base.getReg())
printOperand(MI, OpNum + 1); printOperand(MI, OpNum);
} else { else if (Base.getReg()) {
printOperand(MI, OpNum, "nohash"); if (Disp.getImm()) {
O << '('; printOperand(MI, OpNum, "nohash");
printOperand(MI, OpNum + 1); O << '(';
O << ')'; printOperand(MI, OpNum + 1);
} O << ')';
} else {
O << '@';
printOperand(MI, OpNum + 1);
}
} else
assert(0 && "Unsupported memory operand");
} }

View File

@ -72,6 +72,7 @@ FunctionPass *llvm::createMSP430ISelDag(MSP430TargetMachine &TM) {
return new MSP430DAGToDAGISel(TM); return new MSP430DAGToDAGISel(TM);
} }
// FIXME: This is pretty dummy routine and needs to be rewritten in the future.
bool MSP430DAGToDAGISel::SelectAddr(SDValue Op, SDValue Addr, bool MSP430DAGToDAGISel::SelectAddr(SDValue Op, SDValue Addr,
SDValue &Disp, SDValue &Base) { SDValue &Disp, SDValue &Base) {
// We don't support frame index stuff yet. // We don't support frame index stuff yet.
@ -99,20 +100,17 @@ bool MSP430DAGToDAGISel::SelectAddr(SDValue Op, SDValue Addr,
case MSP430ISD::Wrapper: case MSP430ISD::Wrapper:
SDValue N0 = Addr.getOperand(0); SDValue N0 = Addr.getOperand(0);
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) { if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
// We can match addresses of globals without any offsets Base = CurDAG->getRegister(0, MVT::i16);
if (!G->getOffset()) { Disp = CurDAG->getTargetGlobalAddress(G->getGlobal(),
Base = CurDAG->getTargetGlobalAddress(G->getGlobal(), MVT::i16, G->getOffset());
MVT::i16, 0);
Disp = CurDAG->getTargetConstant(0, MVT::i16);
return true; return true;
}
} }
break; break;
}; };
Base = Addr; Base = CurDAG->getRegister(0, MVT::i16);
Disp = CurDAG->getTargetConstant(0, MVT::i16); Disp = Addr;
return true; return true;
} }